Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def generate_colander():
class User(colander.MappingSchema):
id = colander.SchemaNode(colander.Integer(),
missing=colander.drop)
email = colander.SchemaNode(colander.String(),
validator=colander.Email())
second_email = colander.SchemaNode(colander.String(),
validator=colander.Email(),
missing=colander.null)
return User()
colander.Boolean(false_choices=("", "0", "false"), true_choices=("1")),
)
docs_receive_date = colander.SchemaNode(
Date(),
missing=None,
)
docs_transfer_date = colander.SchemaNode(
Date(),
missing=None,
)
passport_receive_date = colander.SchemaNode(
Date(),
missing=None,
)
descr = colander.SchemaNode(
colander.String(),
validator=colander.Length(max=255),
missing=None
)
class SpassportForm(OrderItemForm):
_schema = _SpassportSchema
def submit(self, spassport=None):
order_item = super(SpassportForm, self).submit(spassport and spassport.order_item)
if not spassport:
spassport = Spassport(
resource=SpassportsResource.create_resource(
get_auth_employee(self.request)
)
)
missing=None,
validator=colander.Length(max=128),
)
end_additional_info = colander.SchemaNode(
colander.String(),
missing=None,
validator=colander.Length(max=128),
)
start_dt = colander.SchemaNode(
DateTime()
)
end_dt = colander.SchemaNode(
DateTime()
)
descr = colander.SchemaNode(
colander.String(),
validator=colander.Length(max=255),
missing=None
)
class TicketForm(OrderItemForm):
_schema = _TicketSchema
def submit(self, ticket=None):
order_item = super(TicketForm, self).submit(ticket and ticket.order_item)
if not ticket:
ticket = Ticket(
resource=TicketsResource.create_resource(
get_auth_employee(self.request)
)
)
class Matches(colander.MappingSchema):
broad = MatchList(missing=[])
close = MatchList(missing=[])
exact = MatchList(missing=[])
narrow = MatchList(missing=[])
related = MatchList(missing=[])
class Concept(colander.MappingSchema):
id = colander.SchemaNode(
colander.Int(),
missing=None
)
type = colander.SchemaNode(
colander.String(),
missing='concept'
)
labels = Labels(missing=[])
notes = Notes(missing=[])
sources = Sources(missing=[])
broader = Concepts(missing=[])
narrower = Concepts(missing=[])
related = Concepts(missing=[])
members = Concepts(missing=[])
member_of = Concepts(missing=[])
subordinate_arrays = Concepts(missing=[])
superordinates = Concepts(missing=[])
matches = Matches(missing={})
class ConceptScheme(colander.MappingSchema):
steps = Reference(reftype=StepsReference)
value = Reference(reftype=ValueReference)
partners = Reference(reftype=PartnersReference)
finance = Reference(reftype=FinanceReference)
experience = Reference(reftype=ExperienceReference)
mercator_sub_resources_meta = sheet_meta._replace(
isheet=IMercatorSubResources,
schema_class=MercatorSubResourcesSchema)
class StatusEnum(AdhocracySchemaNode):
"""Enum of organizational statuses."""
schema_type = colander.String
default = 'other'
missing = colander.required
validator = colander.OneOf(['registered_nonprofit',
'planned_nonprofit',
'support_needed',
'other',
])
class OrganizationInfoSchema(colander.MappingSchema):
"""Data structure for organizational information."""
name = SingleLine()
country = ISOCountryCode()
status = StatusEnum()
status_other = Text(validator=colander.Length(max=500))
import colander
from persistent import Persistent
from substanced.schema import Schema
from substanced.content import content
from substanced.property import PropertySheet
from .interfaces import IDocument
class DocumentSchema(Schema):
name = colander.SchemaNode(
colander.String(),
)
title = colander.SchemaNode(
colander.String(),
)
class DocumentBasicPropertySheet(PropertySheet):
schema = DocumentSchema()
def __init__(self, context, request):
self.context = context
self.request = request
def get(self):
context = self.context
return dict(
name=context.__name__,
import colander
from eea.corpus.processing import pipeline_component
from eea.corpus.utils import set_text
logger = logging.getLogger('eea.corpus')
class RegexTokenizer(colander.Schema):
""" Schema for the Tokenizer processing.
"""
description = "Use a regular expression to tokenize text"
regex = colander.SchemaNode(
colander.String(),
title="Regular expression",
missing="",
# usable for tokenizing code, based on
# http://blog.aylien.com/source-code-classification-using-deep-learning
default=r'[\w\']+|[""!"#$%&\'()*+,-./:;<=>?@[\]^_`{|}~""\\]',
)
def tokenizer(text, regex):
""" Tokenizes text. Returns lists of tokens (words)
"""
return [x for x in re.findall(regex, text) if x]
@pipeline_component(schema=RegexTokenizer,
colander.Integer(),
)
start_location_id = colander.SchemaNode(
SelectInteger(Location),
)
end_location_id = colander.SchemaNode(
SelectInteger(Location),
)
start_transport_id = colander.SchemaNode(
SelectInteger(Transport),
)
end_transport_id = colander.SchemaNode(
SelectInteger(Transport),
)
start_additional_info = colander.SchemaNode(
colander.String(),
missing=None,
validator=colander.Length(max=128),
)
end_additional_info = colander.SchemaNode(
colander.String(),
missing=None,
validator=colander.Length(max=128),
)
start_date = colander.SchemaNode(
Date()
)
end_date = colander.SchemaNode(
Date()
)
hotel_id = colander.SchemaNode(
SelectInteger(Hotel),
IFolder,
)
from .interfaces import (
IDocument,
ITopic
)
from .resources import (
DocumentSchema,
TopicSchema,
DocumentBasicPropertySheet,
TopicBasicPropertySheet,
)
name = colander.SchemaNode(
colander.String(),
)
@mgmt_view(
context=IFolder,
name='add_document',
tab_title='Add Document',
permission='sdi.add-content',
renderer='substanced.sdi:templates/form.pt',
tab_condition=False,
)
class AddDocumentView(FormView):
title = 'Add Document'
schema = DocumentSchema()
schema
buttons = ('add',)
from paasmaker.common.core import constants
import tornado
import tornado.testing
import colander
logger = logging.getLogger(__name__)
logger.addHandler(logging.NullHandler())
class UploadChunkSchema(colander.MappingSchema):
resumableChunkNumber = colander.SchemaNode(colander.Integer())
resumableChunkSize = colander.SchemaNode(colander.Integer())
resumableTotalSize = colander.SchemaNode(colander.Integer())
resumableIdentifier = colander.SchemaNode(colander.String())
resumableFilename = colander.SchemaNode(colander.String())
resumableRelativePath = colander.SchemaNode(colander.String())
class UploadController(BaseController):
AUTH_METHODS = [BaseController.USER]
def _identifier(self):
# Hash the identifier. (We don't take chances with user input)
# Also, we add the user key to the mix, so that users don't overwrite
# each others files.
md5 = hashlib.md5()
user = self.get_current_user()
md5.update(user.apikey)
md5.update(self.params['resumableIdentifier'])
identifier = md5.hexdigest()
return identifier