Projects tagged ‘python’ and ‘validation’


[18 total ]

41 Users
   

FormEncode is a validation and form generation package. The validation can be used separately from the form generation. The validation works on compound data structures, with all parts being nestable. ... [More] It is separate from HTTP or any other input mechanism. [Less]
Created over 3 years ago.

2 Users

FormAlchemy greatly speeds development with SQLAlchemy mapped classes (models) in a HTML forms environment.
Created about 1 year ago.

2 Users

Structures (e.g. JSON) validator for Python language.
Created 5 months ago.

1 Users

Validino is a small Python validation library, particularly useful for validating and converting input data in web applications. Validino owes much to Ian Bicking's FormEncode in spirit and purpose ... [More] , except that it eschews the declarative style used there in favor of a functional one. If you are someone who doesn't like declarative mini-languages, then you might like Validino. Otherwise, use FormEncode. [Less]
Created 12 months ago.

1 Users
   

latua is a lightweight reusable code library. latua library contains modules and wrappers for logging, i18n initialization and file or system operations. Furthermore it contains a simple full text index engine based on sqlite.
Created about 1 year ago.

1 Users
   

Rx is a system for simple, extensible cross-language schemata for data validation.
Created about 1 year ago.

0 Users

Formosa is a library to process user input from untrusted sources, a problem admittedly already widely addressed by countless other libraries. Formosa, however, brings a number of things to the table ... [More] not found in other form processing libraries, in hopes of solving very common sources of grief for developers. Dramatis PersonaeFields translate zero or more values from a mapping (typically strings from a MultiDict given in an HTTP request) into a single atomic Python value of a particular type (or None). Examples of fields include String, Int, Date, etc. Validators implement higher-order constraints on a translated mapping of values. They execute only if all fields were successfully translated. Forms are built from fields and validators. They first translate fields into a dict of type-safe Python values, or raise an ErrorSet exception if input is invalid. If input is valid, they pass the dict of values to a set of validators for higher-order validation. If everything is well-formed, the translated and validated input is returned. Sub-forms are fields that are also forms. They are described below. Error sets are possibly nested collections of error messages raised during translation or validation. Errors may target (i.e span) any number of fields, from zero to many. This, as far as I know, is absent from all other form processing libraries, but is extremely helpful, especially for higher-order constraints. Use CasesBasic OverviewThe following implements a form asking a user for his or her first and last names, optional e-mail address, favorite number (from 1 to 10), and optional comments: from formosa import Form, ErrorSet, fields form = Form({'first_name': fields.String('first_name', max_length=30), 'last_name': fields.String('last_name', max_length=30), 'email': fields.Email('email', allow_empty=True), 'favorite_number': fields.Int('favorite_number', min=1, max=10), 'comments': fields.String('comments', max_length=1000)}) try: result = form.translate(request.POST) except ErrorSet, errors: print 'Oops!\n%s' % errors else: print 'Hello, %s!' % result['first_name']Formosa comes with a wide variety of fields, and fields are extremely simple to implement (the protocol consists of a single method). An examples of custom fields one might implement as part of a project include subclasses of Choice or MultiChoice for domain classes. Higher-Order Declarative ConstraintsHave you ever needed to express a constraint on your input along the lines of the following? I want to assert two values are always given in ascending order. I want values x, y, and z to map to unique values in columns a, b, c in a database table. I want no more than a certain number of values from a set of fields to be entered -- or that a certain minimum number of fields are entered, too. If given, I want these fields to have the same (or different) value. Enter validators. Validators are objects that implement constraints across mappings of multiple translated values, so they can have much farther-reaching logic than simple fields (which are limited in scope to single values without some sort of heroics). Validators follow a very simple protocol, and those bundled with Formosa include: Same, Different: A set of fields must all have the same or different values AtLeast, AtMost: At least, or at most a certain number of fields may or must be given Ascending, Descending: Enforce inequality constraints across multiple fields (strict or not) EqualTo: A set of fields must be equal to a given value. OnlyIf: A set of fields may have values only if every field in another set does. IfAnyThen: If any field from one set has been specified, then each field from another set must have a value. Unique: Assert that a set of values are unique to a corresponding set of SQLAlchemy model properties. For example, the following implements a form where the start date must precede the end date, via the Ascending validator. This pretty clearly demonstrates just how simple such declarative constraints make things: >>> form = Form({'start_date': fields.Date('start_date'), ... 'end_date': fields.Date('end_date')}, ... [validators.Ascending(['start_date', 'end_date'])]) >>> form.translate({'start_date': '11/26/2008', 'end_date': '11/24/2008'}) Traceback (most recent call last): ... formosa.ErrorSet: * Values are not in ascending order [end_date, start_date]Sub-FormsAnother common problem is to have sub-forms nested inside a larger form, where the sub-form is optional. (This pattern translates to nullable foreign keys in relational databases.) A very widespread example of this is optional mailing addresses: if any of the fields of the address is given, the whole sub-form should be validated, but if no field is given, its fields should be ignored (even if they're required in terms of the sub-form). Here's an example: >>> form = Form({'first_name': fields.String('first_name', max_length=30), ... 'last_name': fields.String('last_name', max_length=30), ... 'address': fields.SubForm({'street1': fields.String('street1', False, 30), ... 'street2': fields.String('street2', True, 30), ... 'city': fields.String('city', False, 20), ... 'state': fields.String('state', False, 2, 2), ... 'zip': fields.ZipCode('zip')}), ... 'notes': fields.String('notes', True, 1000)}) >>> input = dict(first_name='Nick', last_name='Murphy', street1='123 Test St.', city='Testville', state='AZ', zip='85712') >>> output = form.translate(input) >>> from pprint import pprint >>> pprint(output) {'address': {'city': 'Testville', 'state': 'AZ', 'street1': '123 Test St.', 'street2': None, 'zip': '85712'}, 'first_name': 'Nick', 'last_name': 'Murphy', 'notes': None}Here, address is translated to None if none of its fields are entered. Otherwise, it is processed like a top-level form. Assuming translation and validation succeeds, it is translated into a dict of values mapped to 'address' in the parent form. Note that ErrorSet is nestable, so any errors during translation or validation are also percolated back to the parent. AvailabilityFormosa is released under the MIT license, so please use, share and enjoy. It also comes with a very extensive unit test suite, offering full test coverage, so you can be assured of its correctness. You can check out the most recent copy from the Google Code Subversion repository as follows: $ svn checkout http://formosa.googlecode.com/svn/trunk formosa [Less]
Created 12 months ago.

0 Users

PyroGraph is a data processing utility written in Python that allows to sets of data to be compared and creates comparison plots and scatter plots for the comparison values. This project started as a ... [More] processing utility for the FDS-SMV development project ( http://fire.nist.gov/fds ) but has transferred to an independent project after a move to Matlab for data processing by that project. This is open to all interested parties for contribution. [Less]
Created 4 months ago.

0 Users

Library with a lot of unit test to help creation of Entities and ValueObjects in Python with easy validation, inspired by sintax of GORM of Groovy. Class Entity and ValueObject extends DataObject ... [More] class. The DataObject class has a common implementation of str and ValueObject has an common implementation of eq and ne methods. Class OrderedValueObject extends ValueObject and implement lt, le, gt and ge methods with easy customization. This project is independent of database or web-frameworks stuff, like most of programs of validation. So you can use it in Scripts/GUI/Console/WebApplications programs without necessity of adaptation and configuration files. It is also extensible and easy to register new constraints for validation. Example of usage:Entity from domain import dataobjects class MyEntity(dataObject.Entity): def __init__(self): self.someint = 1 self.somefloat = 1.23 self.somestring = 'abc' self.somelist = [1, 2] self.somedict = {1:1, 2:2} self.sometuple = (1, 2) MyEntity.addConstraints('someint', Nullable = False, Min = 3, Max = 4, InList = [1, 2], Custom = lambda x: x == 1) MyEntity.addConstraints('somefloat', Nullable = False, Min = 3, Max = 4, Scale = 4, InList = [1.0, 2.0], Custom = lambda x: x == 1.0) MyEntity.addConstraints('somestring', Nullable = False, Min = 3, Max = 4, InList = ['a', 'b'], Matches = '[0-9]', Email = True, IP = True, Site = True, Custom = lambda x: x == 'a') MyEntity.addConstraints('somelist', Nullable = False, Min = 3, Max = 4, InList = [[1, 2]], Custom = lambda x: x == [1, 2]) MyEntity.addConstraints('somedict', Nullable = False, Min = 3, Max = 4, InList = [{1:1, 2:2], Custom = lambda x: x == {1:1, 2:2}) MyEntity.addConstraints('sometuple', Nullable = False, Min = 3, Max = 4, InList = [(1, 2)], Custom = lambda x: x == (1, 2))Now run: example = MyEntity() print(example) print(example.valid()) print(example.hasErrors()) print(example.errors))ValueObject from domain import dataobjects class MyValueObject(dataObject.ValueObject): def __init__(self, somevariable, anothervariable): self.somevariable = somevariable self.anothervariable = anothervariable def equalsVariables(self): return ['somevariable'] MyValueObject.addConstraints('somevariable', Nullable = False, Min = 3) MyValueObject.addConstraints('anothervariable', Nullable = False, Max = 4)Now run: print(MyValueObject(3, 4)) print(MyValueObject(3, 4) == MyValueObject(3, 4)) # True print(MyValueObject(3, 4) == MyValueObject(4, 4)) # False print(MyValueObject(3, 4) == MyValueObject(3, 5)) # True print(MyValueObject(3, 4).valid()) # True print(MyValueObject(2, 5).valid()) # FalseOrderedValueObject from domain import dataobjects class MyValueObject(dataObject.ValueObject): def __init__(self, vara, varb, varc): self.vara = vara self.varb = varb self.varc = varc # Override this method is optional: Default order is lexicographical of the variable names def priorityOrder(self): return ['varb', 'vara'] MyValueObject.addConstraints('vara', Nullable = False, Min = 3) MyValueObject.addConstraints('varb', Nullable = False, Min = 3)Now run: print(MyOrderedValueObject(3,3,3)) print(MyOrderedValueObject(3,3,3) == MyOrderedValueObject(3,3,3)) # True print(MyOrderedValueObject(3,3,3) == MyOrderedValueObject(4,4,4)) # False print(MyOrderedValueObject(2,2,2).valid()) # False print(MyOrderedValueObject(3,3,3).valid()) # True print(MyOrderedValueObject(3, 3, 3) > MyOrderedValueObject(4, 4, 4)) # False: varb < varb print(MyOrderedValueObject(3, 3, 3) < MyOrderedValueObject(4, 4, 4)) # True: varb < varb print(MyOrderedValueObject(4, 4, 4) >= MyOrderedValueObject(4, 4, 4)) # True: varb = varb and vara = vara print(MyOrderedValueObject(3, 3, 3) <= MyOrderedValueObject(4, 4, 4)) # True: varb < varb print(MyOrderedValueObject(30, 4, 30) > MyOrderedValueObject(40, 3, 40)) # True: varb > varb print(MyOrderedValueObject(4, 4, 30) > MyOrderedValueObject(3, 4, 40)) # True: varb = varb and vara > vara print(MyOrderedValueObject(4, 4, 30) > MyOrderedValueObject(4, 4, 40)) # False: varb = varb and vara = vara, ignoring 30 and 40PS1: Unorderable variables are ignored. PS2: Variables thar are not in priorityOrder methods are ignores. Adding a new constraintMin refer to MinConstraint class, Matches refer to MatchesConstraint class, and so on. To register a new constraint, follow: from domain import validator class MyConstraint(validator.Constraint): def valid(self): return True # bool value def message(self): return 'some text that can link the follow variables:self.attributeName, self.value, self.requiredValue' MyConstraint.load()Now, it is possible to do this: MyEntity.addConstraints('somevariable', My = SomeRequiredValueHere)GeneralImplemented with Python 3.0 Dependencies: Distutils [Less]
Created 8 months ago.

0 Users

Local ValidatorLocal Validator library provides a small set of classes that will help you to perform local validation in your code. Using the Local Validator library, your code will be cleaner and ... [More] easier to understand. Using the Local Validator library, you will be able to validate local objects without increasing method's cyclomatic complexity. Local Validator library is available to following programming languages: Java Python The following code snippets show usage examples of Local Validator library. Java example: // Without Local Validator. void myMethod1(Object arg1, int arg2) { if (arg1 == null) { throw new NullPointerException(); } if (arg2 < 0) { throw new MyRuntimeException(); } // method's body. } // With Local validator void myMethod2(Object arg1, int arg2) { new LocalValidationContext() .addNotNullChecking(arg1) .addValidCondition((arg2 >= 0), MyRuntimeException.class) .validate(); // method's body. }Python example: # Without Local Validator def my_method1(arg1, arg2): if arg1 is None: raise RuntimeError if arg2 < 0: raise MyRuntimeError # method body # ... # With Local Validator def my_method2(arg1, arg2): (LocalValidationContext() .add_not_none_checking(arg1) .add_valid_condition(arg2 >= 0, exception_class=MyRuntimeError) .validate()) # method body # ... [Less]
Created 7 months ago.