class IntegerRestrictorStruct(Schema): allow_extra_fields = True filter_extra_fields = True location = UnicodeString() relation = UnicodeString() integer = Regex(r'^ *[0-9]+(\.[0-9]+)? *$') unit = UnicodeString()
class LoginForm(Schema): """LoginForm simply validates that both username and passwrod have been entered.""" allow_extra_fields = True filter_extra_fields = True username = UnicodeString(not_empty=True) password = UnicodeString(not_empty=True)
class NewKeywordForm(Schema): """NewKeywordForm is a Schema for validating the data entered at the Add Keyword page.""" allow_extra_fields = True filter_extra_fields = True name = formencode.All(UniqueName(), UnicodeString(not_empty=True)) description = UnicodeString()
class LockssomaticSpaceSchema(TypeOfSpaceSchema): collection_iri = UnicodeString(max=256) content_provider_id = UnicodeString(max=32) checksum_type = UnicodeString(max=64) keep_local = Bool() au_size = Int() sd_iri = URL(max=256) external_domain = URL()
class UserResetPasswordForm(Schema): """Schema for User password reset form.""" chained_validators = [FieldsMatch('password', 'confirm')] email = Email(not_empty=True) password = UnicodeString(min=6) confirm = UnicodeString(not_empty=True) token = UnicodeString(not_empty=True)
class UpdateKeywordForm(NewKeywordForm): """Schema class that inherits from NewKeywordForm and adds an ID and removes the uniqueness reqirement on the name. This really sould be changed but I DON'T KNOW HOW TO MAKE FORMENCODE ENSURE THAT A VALUE IS UNIQUE AGAINST A SET OF VALUES IN THE DB BUT STILL POSSIBLY EQUAL TO THE VALUE OF THE ID THAT IS BEING EDITED...""" ID = UnicodeString() name = UnicodeString(not_empty=True)
class LocationSchema(Schema): description = UnicodeString(max=256) purpose = OneOf(_flatten(models.Location.PURPOSE_CHOICES)) relative_path = UnicodeString() quota = Int(min=0) enabled = Bool() space = ResourceURI(model_cls=models.Space) pipeline = ForEach(ResourceURI(model_cls=models.Pipeline)) replicators = ForEach(ResourceURI(model_cls=models.Location))
class NewSpeakerForm(Schema): """NewSpeakerForm is a Schema for validating the data entered at the Add Speaker page.""" allow_extra_fields = True filter_extra_fields = True firstName = UnicodeString(not_empty=True) lastName = UnicodeString(not_empty=True) dialect = UnicodeString() speakerPageContent = UnicodeString()
class UpdateHomePageForm(Schema): """NewPageForm is a Schema for validating the data entered at the Edit Home Page page.""" allow_extra_fields = True filter_extra_fields = True name = UnicodeString() heading = UnicodeString() content = UnicodeString() ID = Int()
class NewFileForm(Schema): """NewFileForm is a Schema for validating the data entered at the Add File page.""" allow_extra_fields = True filter_extra_fields = True dateElicited = DateConverter(month_style='mm/dd/yyyy') description = UnicodeString() speaker = UnicodeString() elicitor = UnicodeString() utteranceType = UnicodeString()
class SearchDictionaryForm(Schema): """SearchDictionaryForm is a Schema for validating the search term entered at the Dictionary page. """ allow_extra_fields = True filter_extra_fields = True dictionarySearchTerm = UnicodeString(not_empty=True) dictionarySearchType = UnicodeString()
class UserSchema(Schema): username = Regex(r'^[a-zA-Z0-9_@+\.-]+$', max=150) password = UnicodeString() first_name = UnicodeString(max=30) last_name = UnicodeString(max=150) email = Email() groups = ForEach(ResourceURI(model_cls=Group)) user_permissions = ForEach(ResourceURI(model_cls=Permission)) is_staff = Bool() is_active = Bool() is_superuser = Bool()
class NewSourceForm(Schema): """NewSourceForm is a Schema for validating the data entered at the Add Source page.""" allow_extra_fields = True filter_extra_fields = True authorFirstName = UnicodeString(not_empty=True) authorLastName = UnicodeString(not_empty=True) title = UnicodeString(not_empty=True) year = Regex('[0-9]{4}', not_empty=True) fullReference = UnicodeString() file_id = Regex('[0-9]+')
class _RepoForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) description = UnicodeString(strip=True, min=1, not_empty=True) repo_group = OneOf(repo_groups, hideList=True) private = StringBoolean(if_missing=False) chained_validators = [ValidRepoName(edit, old_data), ValidPerms(), ValidSettings]
class UserRegisterForm(Schema): """Schema for User register form.""" pre_validators = [NestedVariables] chained_validators = [FieldsMatch('password', 'confirm')] email = Email(max=255, not_empty=True) password = UnicodeString(min=6) confirm = UnicodeString(not_empty=True) class profile(Schema): first_name = UnicodeString(max=100, not_empty=True) last_name = UnicodeString(max=100, not_empty=True)
class _RepoForkForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) repo_group = OneOf(repo_groups, hideList=True) repo_type = All(ValidForkType(old_data), OneOf(supported_backends)) description = UnicodeString(strip=True, min=1, not_empty=True) private = StringBoolean(if_missing=False) copy_permissions = StringBoolean(if_missing=False) update_after_clone = StringBoolean(if_missing=False) fork_parent_id = UnicodeString() chained_validators = [ValidForkName(edit, old_data)]
class _RegisterForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = True username = All(ValidUsername(edit, old_data), UnicodeString(strip=True, min=1, not_empty=True)) password = All(UnicodeString(strip=False, min=6, not_empty=True)) password_confirmation = All(UnicodeString(strip=False, min=6, not_empty=True)) active = StringBoolean(if_missing=False) name = UnicodeString(strip=True, min=1, not_empty=False) lastname = UnicodeString(strip=True, min=1, not_empty=False) email = All(Email(not_empty=True), UniqSystemEmail(old_data)) chained_validators = [ValidPasswordsMatch, ValidPassword]
class _ReposGroupForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False group_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) group_description = UnicodeString(strip=True, min=1, not_empty=True) group_parent_id = OneOf(available_groups, hideList=False, testValueList=True, if_missing=None, not_empty=False) chained_validators = [ValidReposGroup(edit, old_data), ValidPerms('group')]
class child(KajikiBootstrapFormLayout): permission_name = TextField(label=l_('Name'), css_class='form-control', validator=UnicodeString(not_empty=True)) description = TextArea(label=l_('Description'), rows=10, css_class='form-control', validator=UnicodeString(not_empty=True)) groups = MultipleSelectField(label=l_('Groups'), css_class="form-control", options=Deferred(h.query_groups))
class PackageSchema(Schema): current_location = ResourceURI(model_cls=models.Location) current_path = UnicodeString() description = UnicodeString(max=256) encryption_key_fingerprint = UnicodeString(max=512) misc_attributes = UnicodeString() origin_pipeline = ResourceURI(model_cls=models.Pipeline) package_type = OneOf(_flatten(models.Package.PACKAGE_TYPE_CHOICES)) pointer_file_location = ResourceURI(model_cls=models.Location) pointer_file_path = UnicodeString() related_packages = ForEach(ResourceURI(model_cls=models.Package)) replicated_package = ResourceURI(model_cls=models.Package) size = Int(min=0) status = OneOf(_flatten(models.Package.STATUS_CHOICES))
class SaveSettingsForm(Schema): """SaveSettingsForm is a Schema for validating changes to a User's settings. """ allow_extra_fields = True filter_extra_fields = True #collectionViewType = OneOf(app_globals.collectionViewTypes) defaultMetadataFromPreviousForm = StringBoolean() guessMorphology = StringBoolean() inputOrthography = UnicodeString() outputOrthography = UnicodeString() defaultFormView = UnicodeString() dateFormat = UnicodeString()
class NewCategoryForm(Schema): """NewCategoryForm is a Schema for validating the data entered at the Add Category page.""" allow_extra_fields = True filter_extra_fields = True name = formencode.All(UniqueName(), PlainText(not_empty=True)) description = UnicodeString()
class NewResearcherForm(Schema): """NewResearcherForm is a Schema for validating the data entered at the Add Researcher page. """ allow_extra_fields = True filter_extra_fields = True username = formencode.All(UniqueUsername(), PlainText(not_empty=True)) password = PlainText(not_empty=True) firstName = UnicodeString(not_empty=True) lastName = UnicodeString(not_empty=True) email = Email(not_empty=True) affiliation = UnicodeString() role = OneOf(app_globals.roles) personalPageContent = UnicodeString()
class child(BaseLayout): inline_engine_name = 'kajiki' template = ''' <div py:strip=""> <py:for each="c in w.children_hidden"> ${c.display()} </py:for> <div class="form form-horizontal"> <div class="form-group"> <div class="mail-templates-title">Edit mail translation</div> <div class="col-md-12"> <div py:with="c=w.children.language" class="form-group ${c.error_msg and 'has-error' or ''}"> <label for="${c.compound_id}" class="col-md-2 control-label">${c.label}</label> <div class="col-md-2"> ${c.display()} <span class="help-block" py:content="c.error_msg"/> </div> <span class="alert alert-danger" py:for="error in w.rollup_errors"> ${error}</span> </div> <div py:with="c=w.children.subject" class="form-group ${c.error_msg and 'has-error' or ''}"> <label for="${c.compound_id}" class="col-md-2 control-label">${c.label}</label> <div class="col-md-10"> ${c.display()} <span class="help-block" py:content="c.error_msg"/> </div> </div> <div py:with="c=w.children.body" class="form-group ${c.error_msg and 'has-error' or ''}"> <label for="${c.compound_id}" class="col-md-2 control-label">${c.label}</label> <div class="col-md-10"> ${c.display()} <span class="help-block" py:content="c.error_msg"/> </div> </div> </div> </div> </div> <input type="submit" class="btn btn-warning col-md-1 col-md-push-10" formaction="validate_template_edit" value="Validate"></input> <input type="submit" class="btn btn-default" formaction="test_email" value="Send test email"></input> </div> ''' translation_id = HiddenField() model_id = HiddenField() language = TextField(label='Language', css_class='form-control', validator=UnicodeString(not_empty=True, outputEncoding=None)) subject = TextField(label='Subject', css_class='form-control', validator=KajikiTextTemplateValidator()) body = TextArea(label='Email content', rows=10, css_class='form-control', validator=KajikiTemplateValidator())
class _ApplicationUiSettingsForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False web_push_ssl = OneOf(['true', 'false'], if_missing='false') paths_root_path = All(ValidPath(), UnicodeString(strip=True, min=1, not_empty=True)) hooks_changegroup_update = OneOf(['True', 'False'], if_missing=False) hooks_changegroup_repo_size = OneOf(['True', 'False'], if_missing=False) hooks_pretxnchangegroup_push_logger = OneOf(['True', 'False'], if_missing=False) hooks_preoutgoing_pull_logger = OneOf(['True', 'False'], if_missing=False)
class UpdateResearcherForm(NewResearcherForm): """Schema class that inherits from NewResearcherForm and adds an ID and modifies the password validator. """ ID = UnicodeString() username = PlainText() password = PlainText()
class SwiftSpaceSchema(TypeOfSpaceSchema): auth_url = UnicodeString(max=256) auth_version = UnicodeString(max=8) username = UnicodeString(max=64) password = UnicodeString(max=256) container = UnicodeString(max=64) tenant = UnicodeString(max=64) region = UnicodeString(max=64)
class UserCreateSchema(Schema): """Schema for User create (fields may not be missing).""" email = Email(max=255, not_empty=True) password = UnicodeString(min=6) role = OneOf(('user', 'superuser', 'admin'), if_missing='user', hideList=True) class profile(Schema): first_name = UnicodeString(max=100, not_empty=True) last_name = UnicodeString(max=100, not_empty=True)
class UserUpdateSchema(Schema): """Schema for User update (fields may be missing).""" ignore_key_missing = True email = Email(max=255, not_empty=True) password = UnicodeString(min=6) role = OneOf(('user', 'superuser', 'admin'), hideList=True, not_empty=True) class profile(Schema): first_name = UnicodeString(max=100, not_empty=True) last_name = UnicodeString(max=100, not_empty=True)
class _RepoForm(formencode.Schema): allow_extra_fields = True filter_extra_fields = False repo_name = All(UnicodeString(strip=True, min=1, not_empty=True), SlugifyName()) clone_uri = All(UnicodeString(strip=True, min=1, not_empty=False)) repo_group = OneOf(repo_groups, hideList=True) repo_type = OneOf(supported_backends) description = UnicodeString(strip=True, min=1, not_empty=True) private = StringBoolean(if_missing=False) enable_statistics = StringBoolean(if_missing=False) enable_downloads = StringBoolean(if_missing=False) if edit: #this is repo owner user = All(UnicodeString(not_empty=True), ValidRepoUser) chained_validators = [ValidCloneUri()(), ValidRepoName(edit, old_data), ValidPerms()]
def __init__(self, **kw): UnicodeString.__init__(self, **kw)
def test_unicode_encoding(): uv = UnicodeString() us = u'käse' u7s, u8s = us.encode('utf-7'), us.encode('utf-8') assert uv.to_python(u8s) == us assert type(uv.to_python(u8s)) is unicode assert uv.from_python(us) == u8s assert type(uv.from_python(us)) is str uv = UnicodeString(encoding='utf-7') assert uv.to_python(u7s) == us assert type(uv.to_python(u7s)) is unicode assert uv.from_python(us) == u7s assert type(uv.from_python(us)) is str uv = UnicodeString(inputEncoding='utf-7') assert uv.to_python(u7s) == us assert type(uv.to_python(u7s)) is unicode uv = UnicodeString(outputEncoding='utf-7') assert uv.from_python(us) == u7s assert type(uv.from_python(us)) is str uv = UnicodeString(inputEncoding=None) assert uv.to_python(us) == us assert type(uv.to_python(us)) is unicode assert uv.from_python(us) == u8s assert type(uv.from_python(us)) is str uv = UnicodeString(outputEncoding=None) assert uv.to_python(u8s) == us assert type(uv.to_python(u8s)) is unicode assert uv.from_python(us) == us assert type(uv.from_python(us)) is unicode
def test_unicode(): un = UnicodeString() assert un.to_python(12) == u'12' assert type(un.to_python(12)) is unicode assert un.from_python(12) == '12' assert type(un.from_python(12)) is str
def test_unicode_empty(): iv = UnicodeString() for input in [None, "", u""]: result = iv.to_python(input) assert u"" == result, result assert isinstance(result, unicode)