class Identifier: ''' Provides the gateway identifier. Clients - contains the client IPs or names regexes that needs to match in order to validate the gateway, if none is provided then the gateway applies to all. At least one client IP needs to match to consider the navigation valid. Pattern - contains the regex that needs to match with the requested URI. The pattern needs to produce, if is the case, capturing groups that can be used by the Filters or Navigate. Headers - The headers to be filtered in order to validate the navigation. The headers are provided as regexes that need to be matched. In case of headers that are paired as name and value the regex will receive the matching string as 'Name:Value', the name is not allowed to contain ':'. At least one header needs to match to consider the navigation valid. Methods - The list of allowed methods for the request, if no method is provided then all methods are considered valid. At least one method needs to match to consider the navigation valid. Errors - The list of errors codes that are considered to be handled by this Gateway entry, if no error is provided then it means the entry is not solving any error navigation. At least one error needs to match in order to consider the navigation valid. The gateways that solve errors will receive also parameters for error status - the status code of the error allow - the method name(s) allowed, this will be provided in case of status 405 (Method not allowed) ''' # The request identification attributes Clients = List(str) Pattern = str Headers = List(str) Methods = List(str) Errors = List(int)
class Gateway(Identifier): ''' Provides the gateway. Filters - contains a list of URIs that need to be called in order to allow the gateway Navigate. The filters are provided as 'group:URI' where group is a number from 1 to n where n is the number of capture groups obtained from the Pattern, the filter URI is allowed to have place holders of form '*' where the provided group value will be injected. In order to validate navigation at least one filter from the each group will have to return an allowed access, also pre populated parameters are allowed for filter URI. Host - The host where the request needs to be resolved, if not provided the request will be delegated to the default host. Protocol - The protocol to be used in the communication with the server that handles the request, if not provided the request will be delegated using the default protocol. Navigate - A pattern like string of forms like '*', 'resources/*' or 'redirect/Model/{1}'. The pattern is allowed to have place holders and also the '*' which stands for the actual called URI, also parameters are allowed for navigate URI, the parameters will be appended to the actual parameters. PutHeaders -The headers to be put on the forwarded requests. Exclude - The list of index block names to be excluded from the response. ''' # The navigation attributes Filters = List(str) Host = str Protocol = str Navigate = str PutHeaders = Dict(str, str) # The response attributes Exclude = List(str)
class Perform: ''' Provides the perform of an action, as defined in @see: ally.indexing.spec.model.Perform ''' Id = int Verb = str Flags = List(str) Index = str Key = str Name = str Value = str Actions = List(str) Escapes = Dict(str, str)
class Block: ''' Provides the index block, as defined in @see: ally.indexing.spec.model.Block ''' Id = int Name = str Keys = List(str)
class Action: ''' Provides the action of a block, as defined in @see: ally.indexing.spec.model.Action ''' Id = int Name = str Before = List(str) Final = bool Rewind = bool
class Message(Entity): ''' Model for a localized message. ''' Source = Source Singular = str Plural = List(str) Context = str LineNumber = int Comments = str
def get(self, mainId: MainModel.Id, scheme: Scheme, locale: List(Locale), another: AModel.Key = None, q: QMainModel = None, qa: QAModel = None, offset: int = 0, limit: int = None) -> MainModel: '''
class AsLikeExpression: ''' Provides query for properties that can be managed by a like function, this will only handle string types Also provides the boolean expression functionality, that in case of like string operator can had in the same all conditions inc - include - means that the value is mandatory for the given criteria ext - extend - means that the value is optional for the given criteria exc - exclude - means that the value if forbidden for the given criteria The query compose an 'and' condition with all 'inc' criteria, and all negated 'exc' criteria. Then it is made an or with all 'ext' criteria ''' #include - the list of included values inc = List(str) #extend - the list of extended values ext = List(str) #exclude - the list of excluded values exc = List(str)
class URLInfo: ''' Provides the URL info model. ''' URL = Reference ContentType = str Title = str Description = str SiteIcon = str Date = datetime Picture = List(Reference)
class GatewayHTTP: ''' Provides the gateway data. Pattern - contains the regex that needs to match with the requested URI. The pattern needs to produce, if is the case, capturing groups that can be used by the Filters or Navigate. Headers - The headers to be filtered in order to validate the navigation. The headers are provided as regexes that need to be matched. In case of headers that are paired as name and value the regex will receive the matching string as 'Name:Value', the name is not allowed to contain ':'. At least one header needs to match to consider the navigation valid. Methods - The list of allowed methods for the request, if no method is provided then all methods are considered valid. At least one method needs to match to consider the navigation valid. Filters - contains a list of URIs that need to be called in order to allow the gateway Navigate. The filters are allowed to have place holders of form '{1}' or '{2}' ... '{n}' where n is the number of groups obtained from the Pattern, the place holders will be replaced with their respective group value. All filters need to return a True value in order to allow the gateway Navigate, also parameters are allowed for filter URI. Errors - The list of errors codes that are considered to be handled by this Gateway entry, if no error is provided then it means the entry is not solving any error navigation. At least one error needs to match in order to consider the navigation valid. The gateways that solve errors will receive also parameters for error status - the status code of the error allow - the method name(s) allowed, this will be provided in case of status 405 (Method not allowed) Host - The host where the request needs to be resolved, if not provided the request will be delegated to the default host. Protocol - The protocol to be used in the communication with the server that handles the request, if not provided the request will be delegated using the default protocol. Navigate - A pattern like string of forms like '*', 'resources/*' or 'redirect/Model/{1}'. The pattern is allowed to have place holders and also the '*' which stands for the actual called URI, also parameters are allowed for navigate URI, the parameters will be appended to the actual parameters. PutHeaders -The headers to be put on the forwarded requests. The values are provided as 'Name:Value', the name is not allowed to contain ':'. ''' Pattern = str Headers = List(str) Methods = List(str) Filters = List(str) Errors = List(int) Host = str Protocol = str Navigate = str PutHeaders = List(str)
def process(self, chain, processing, create: Create, Decoding: DecodingOrder, Definition: DefinitionOrder, **keyargs): ''' @see: HandlerBranching.process Create the order decode. ''' assert isinstance(processing, Processing), 'Invalid processing %s' % processing assert isinstance(create, Create), 'Invalid create %s' % create assert issubclass( Decoding, DecodingOrder), 'Invalid decoding class %s' % Decoding assert issubclass( Definition, DefinitionOrder), 'Invalid definition class %s' % Definition if not create.orderSetters: return # There is not order to process. adec, ddec = Decoding(), Decoding() assert isinstance(adec, DecodingOrder), 'Invalid decoding %s' % adec assert isinstance(ddec, DecodingOrder), 'Invalid decoding %s' % ddec adec.type = ddec.type = List(str) adec.doDecode = self.createDecode(True, create.orderSetters, create.orderPriorityGetters, create.orderPrioritySetters, adec) ddec.doDecode = self.createDecode(False, create.orderSetters, create.orderPriorityGetters, create.orderPrioritySetters, ddec) adef = Definition(enumeration=sorted(create.orderSetters.keys())) ddef = Definition(enumeration=sorted(create.orderSetters.keys())) processing.wingIn(chain, True, decoding=ddec, definition=ddef, parameter=processing.ctx.parameter(path=[NAME_DESC])) processing.wingIn(chain, True, decoding=adec, definition=adef, parameter=processing.ctx.parameter(path=[NAME_ASC]))
def decorateRoot(): resourcesRoot().get = InvokerFunction(GET, partial(rootPaths, resourcesRoot()), List(TypeClass(Path)), [], {}, 'accessible', InvokerInfo('accessible', '.', 0, ''))
@copyright: 2012 Sourcefabric o.p.s. @license: http://www.gnu.org/licenses/gpl-3.0.txt @author: Gabriel Nistor Provides the accept headers handling. ''' from ally.api.type import List, Locale from ally.container.ioc import injected from ally.design.processor.attribute import optional, defines from ally.http.impl.processor.headers.accept import RequestDecode, \ AcceptRequestDecodeHandler # -------------------------------------------------------------------- LIST_LOCALE = List(Locale) # The locale list used to set as an additional argument. # -------------------------------------------------------------------- class Request(RequestDecode): ''' The request context. ''' # ---------------------------------------------------------------- Optional argumentsOfType = optional(dict) # ---------------------------------------------------------------- Defined accLanguages = defines(list, doc=''' @rtype: list[string]
def testEncode(self): transformer = CreateEncoderHandler() ioc.initialize(transformer) resolve = Resolve(transformer.encoderFor(typeFor(ModelId))) render = RenderToObject() context = dict(render=render, converter=ConverterPath(), converterId=ConverterPath(), normalizer=ConverterPath()) model = ModelId() model.Id = 12 render.obj = None resolve.request(value=model, **context).doAll() self.assertEqual({'Id': '12'}, render.obj) model.ModelKey = 'The key' render.obj = None resolve.request(value=model, **context).doAll() self.assertEqual({ 'Id': '12', 'ModelKey': { 'Key': 'The key' } }, render.obj) model.Name = 'Uau Name' model.Flags = ['1', '2', '3'] render.obj = None resolve.request(value=model, **context).doAll() self.assertEqual( { 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }, render.obj) transformer = CreateEncoderHandler() ioc.initialize(transformer) resolve = Resolve(transformer.encoderFor(typeFor(List(ModelId)))) render.obj = None resolve.request(value=[model], **context).doAll() self.assertEqual( { 'ModelIdList': [{ 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }] }, render.obj) render.obj = None resolve.request(value=[model, model, model], **context) resolve.do() self.assertEqual({'ModelIdList': []}, render.obj) resolve.do() self.assertEqual( { 'ModelIdList': [{ 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }] }, render.obj) resolve.do() self.assertEqual( { 'ModelIdList': [{ 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }, { 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }] }, render.obj) resolve.do() self.assertEqual( { 'ModelIdList': [{ 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }, { 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }, { 'ModelKey': { 'Key': 'The key' }, 'Flags': { 'Flags': ['1', '2', '3'] }, 'Id': '12', 'Name': 'Uau Name' }] }, render.obj) resolve.do() self.assertFalse(resolve.has())
class ModelId: Id = int Name = str Flags = List(str) ModelKey = ModelKey
def getByCode(self, code: Country.Code, locales: List(Locale) = ()) -> Country: '''
def getAll(self, locales: List(Locale) = (), offset: int = None, limit: int = LIMIT_DEFAULT, detailed: bool = True) -> Iter(LanguageEntity): '''
def getById( self, id: LanguageEntity.Id, locales: List(Locale) = ()) -> LanguageEntity: '''
def getAllAvailable(self, locales: List(Locale) = (), offset: int = None, limit: int = LIMIT_DEFAULT, q: QCountry = None) -> Iter(Country): '''
def getCriterias(self, locales: List(Locale), q: QQueryCriteria = None) -> Iter(QueryCriteria): '''
def getByCode(self, code: Language.Code, locales: List(Locale) = ()) -> Language: '''
def getAllAvailable(self, locales: List(Locale) = (), offset: int = None, limit: int = LIMIT_DEFAULT, q: QLanguage = None) -> Iter(Language): '''
class AsIn: ''' Provides query for properties that can be managed by 'IN' function applied to a list. ''' values = List(str)
from ally.http.spec.server import IDecoderHeader, IEncoderHeader from ally.internationalization import _ from babel import numbers as bn, dates as bd from babel.core import Locale from datetime import datetime import logging # -------------------------------------------------------------------- log = logging.getLogger(__name__) # -------------------------------------------------------------------- FORMATTED_TYPE = (Number, Percentage, Date, Time, DateTime) # The formatted types for the babel converter. LIST_LOCALE = List(TypeLocale) # The locale list used to set as an additional argument. class FormatError(Exception): ''' Thrown for invalid formatting. ''' def __init__(self, message): assert isinstance(message, str), 'Invalid message %s' % message self.message = message super().__init__(message) # -------------------------------------------------------------------- class RequestDecode(Context): '''