Permalink
Browse files

rename all contracts to trafarets

  • Loading branch information...
1 parent 22c1b6e commit 705d02cccda15a84a97553189ac173cee938fd57 @Deepwalker committed Jan 26, 2012
Showing with 171 additions and 173 deletions.
  1. +8 −8 js/contract.js
  2. +3 −3 js/contract_test.js
  3. +3 −3 js/test.html
  4. +6 −6 samples/sample1.py
  5. +6 −1 setup.py
  6. +144 −151 trafaret/__init__.py
  7. +1 −1 trafaret/utils.py
View
@@ -37,26 +37,26 @@
};
var OrC = function() {
- this.contracts = [];
+ this.trafarets = [];
for (var i=0, length = arguments.length; i < length; i++) {
- this.contracts.push(arguments[i]);
+ this.trafarets.push(arguments[i]);
}
};
OrC.prototype = new Trafaret();
OrC.prototype.check = function(value) {
- for (var i=0, length=this.contracts.length; i < length; i++) {
+ for (var i=0, length=this.trafarets.length; i < length; i++) {
try {
- this.contracts[i].check(value);
+ this.trafarets[i].check(value);
return;
} catch (e) {
if (! (e instanceof TrafaretValidationError)) {
throw e;
}
}
}
- this.failure("no one contract matches");
+ this.failure("no one trafaret matches");
};
var NullC = function() {
@@ -140,8 +140,8 @@
}
};
- var ListC = function(contract, min_length, max_length) {
- this.contract = contract;
+ var ListC = function(trafaret, min_length, max_length) {
+ this.trafaret = trafaret;
this.min_length = this._select(min_length, NaN);
this.max_length = this._select(max_length, NaN);
};
@@ -161,7 +161,7 @@
var name, message;
for (var i=0, length=value.length; i < length; i++) {
try{
- this.contract.check(value[i]);
+ this.trafaret.check(value[i]);
} catch (e) {
if (e instanceof TrafaretValidationError) {
name = e.name;
View
@@ -13,8 +13,8 @@ function assertRaises(callable, owner, args, exception_type, message) {
fail("exception " + exception_type + " was not rised");
}
-function assertTrafaretFailure(contract, value, message) {
- assertRaises(contract.check, contract, [value], TrafaretValidationError, message);
+function assertTrafaretFailure(trafaret, value, message) {
+ assertRaises(trafaret.check, trafaret, [value], TrafaretValidationError, message);
}
function testAnyC() {
@@ -59,7 +59,7 @@ function testOrC() {
var c = new OrC(new IntC(), new StringC());
c.check(1);
c.check("test");
- assertTrafaretFailure(c, "", "no one contract matches");
+ assertTrafaretFailure(c, "", "no one trafaret matches");
}
function testListC() {
View
@@ -1,9 +1,9 @@
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
- <title>contract tests</title>
+ <title>trafaret tests</title>
<script type="text/javascript" src="jsunit/app/jsUnitCore.js"></script>
- <script type="text/javascript" src="contract.js"></script>
- <script type="text/javascript" src="contract_test.js"></script>
+ <script type="text/javascript" src="trafaret.js"></script>
+ <script type="text/javascript" src="trafaret_test.js"></script>
</head>
<body>
</body>
View
@@ -1,14 +1,14 @@
-import contract as c
+import trafaret as t
import datetime
-date_tuple = c.Dict(year=c.Int, month=c.Int, day=c.Int) >> (lambda d: datetime.datetime(**d))
+date_tuple = t.Dict(year=t.Int, month=t.Int, day=t.Int) >> (lambda d: datetime.datetime(**d))
-task = c.Dict({
- 'key': c.String(),
- c.Key('timestamp', optional=True): date_tuple,
+task = t.Dict({
+ 'key': t.String(),
+ t.Key('timestamp', optional=True): date_tuple,
})
try:
print task.check({'key': 'foo', 'timestamp': {'year': 2012, 'month': 1, 'day': 12}})
-except c.TrafaretValidationError as e:
+except t.TrafaretValidationError as e:
print e
View
@@ -1,6 +1,11 @@
#!/usr/bin/env python
from setuptools import setup, find_packages
+import os.path
+
+
+def read(fname):
+ return open(os.path.join(os.path.dirname(__file__), fname)).read()
setupconf = dict(
@@ -11,7 +16,7 @@
author = 'Barbuza, Deepwalker',
author_email = 'krivushinme@gmail.com',
description = ('Validation and parsing library'),
- long_description = "Place README here",
+ long_description = read('README.rst'),
packages = find_packages(),
Oops, something went wrong.

0 comments on commit 705d02c

Please sign in to comment.