Ejemplo n.º 1
0
class Action(Record):
    """Actions a person can do in the game"""
    path = 'actions'
    fields = [String('name'), String('description')]
    keys = ['name']

    def __init__(self, parent):
        self.parent = parent
        self.name = None

    def store(self):
        """Store the Automatic"""
        self.parent.actions[self.get_id()] = self

    def remove(self):
        """Remove the Automatic from the index"""
        del self.parent.actions[self.get_id()]

    def find(self, data):
        """Find the record with the relation key"""
        if data['name'] not in self.root().actions:
            return None
        return self.root().actions[data['name']]

    def removable(self, general):
        """This record cannot be removed savely"""
        return {"action": None}
Ejemplo n.º 2
0
class RamlResponse(Model):
    schema = String()
    example = String()
    notNull = Bool()
    description = String()
    headers = Map(String(), Reference(RamlHeader))
    body = Reference("pyraml.entities.RamlBody")
Ejemplo n.º 3
0
class RamlMethod(Model):
    notNull = Bool()
    description = String()
    body = Reference(RamlBody)
    responses = Map(Int(), Reference(RamlBody))
    #responses = Map(Int(), Reference(RamlResponse))
    queryParameters = Map(String(), Reference(RamlQueryParameter))
Ejemplo n.º 4
0
class RamlResource(Model):
    displayName = String()
    description = String()
    uri = String()
    type = Reference(RamlTrait, field_name="is")
    parentResource = Reference("pyraml.entities.RamlResource")
    methods = Map(String(), Reference(RamlBody))
    resources = Map(String(), Reference("pyraml.entities.RamlResource"))
Ejemplo n.º 5
0
class RamlDocumentation(Model):
    """ The documentation property MUST be an array of documents.
    Each document MUST contain title and content attributes, both
    of which are REQUIRED. If the documentation property is specified,
    it MUST include at least one document.
    """
    title = String(required=True)
    content = String(required=True)
Ejemplo n.º 6
0
class RamlBody(Model):
    """ A method's body is defined in the body property as a hashmap,
    in which the key MUST be a valid media type.
    """
    schema = Or(JSONData(), XMLData(), String())
    example = String()
    notNull = Bool()
    formParameters = RamlNamedParametersMap()
Ejemplo n.º 7
0
class RamlResourceType(Model):
    """ A resource type is a partial resource definition that,
    like a resource, can specify a description and methods and
    their properties.
    """
    usage = String()
    description = String()
    methods = Map(String(), Reference(RamlMethod))
Ejemplo n.º 8
0
class RamlResponse(Model):
    """ Responses MUST be a map of one or more HTTP status codes,
    where each status code itself is a map that describes that status
    code.
    """
    notNull = Bool()
    description = String()
    headers = RamlNamedParametersMap()
    body = Map(String(), Reference("pyraml.entities.RamlBody"))
Ejemplo n.º 9
0
class RamlResource(ResourceTypedEntity, TraitedEntity, SecuredEntity, Model):
    """ http://raml.org/spec.html#resources-and-nested-resources """
    displayName = String()
    description = String()
    parentResource = Reference("pyraml.entities.RamlResource")
    methods = Map(String(), Reference(RamlMethod))
    resources = Map(String(), Reference("pyraml.entities.RamlResource"))
    uriParameters = RamlNamedParametersMap()
    baseUriParameters = RamlNamedParametersMap()
Ejemplo n.º 10
0
class RamlTrait(Model):
    """ A trait is a partial method definition that, like a method,
    can provide method-level properties such as
    description, headers, query string parameters, and responses.
    """
    usage = String()
    description = String()
    headers = RamlNamedParametersMap()
    queryParameters = RamlNamedParametersMap()
    responses = Map(Int(), Reference(RamlResponse))
Ejemplo n.º 11
0
class RamlMethod(TraitedEntity, SecuredEntity, Model):
    """ http://raml.org/spec.html#methods """
    notNull = Bool()
    description = String()
    body = Map(String(), Reference(RamlBody))
    responses = Map(Int(), Reference(RamlResponse))
    queryParameters = RamlNamedParametersMap()
    baseUriParameters = RamlNamedParametersMap()
    headers = RamlNamedParametersMap()
    protocols = List(
        Choice(field_name='protocols', choices=RAML_VALID_PROTOCOLS))
Ejemplo n.º 12
0
class RamlSecuritySchemeDescription(Model):
    """ The describedBy attribute MAY be used to apply a trait-like
    structure to a security scheme mechanism so as to extend the
    mechanism, such as specifying response codes, HTTP headers or
    custom documentation.
    """
    description = String()
    body = Map(String(), Reference(RamlBody))
    headers = RamlNamedParametersMap()
    queryParameters = RamlNamedParametersMap()
    responses = Map(Int(), Reference(RamlResponse))
    baseUriParameters = RamlNamedParametersMap()
    protocols = List(
        Choice(field_name='protocols', choices=RAML_VALID_PROTOCOLS))
Ejemplo n.º 13
0
class RamlRoot(Model):
    raml_version = String(required=True)
    title = String()
    version = String()
    baseUri = String()
    protocols = List(String())
    mediaType = String()
    documentation = List(Reference(RamlDocumentation))
    traits = Map(String(), Reference(RamlTrait))
    resources = Map(String(), Reference(RamlResource))
    resourceTypes =  Map(String(), Reference(RamlResourceType))
Ejemplo n.º 14
0
class Game(Record):
    """General record with links to all other records"""
    path = ''
    fields = [
        String('title'),
        Set('statistics', Statistic),
        Set('actions', Action),
        Set('items', Item)
    ]
    keys = []

    def __init__(self, store):
        self.stored = store
        self.title = ''
        self.statistics = RBDict()
        self.actions = RBDict()
        self.items = RBDict()

    def store(self):
        """This this the top level element"""
        pass

    def remove(self):
        """The top level element cannot be removed"""
        if self.stored.remember_changes:
            if getattr(self.stored, 'changed') is None:
                setattr(self.stored, 'changed', copy.copy(self))
        else:
            setattr(self.stored, 'changed', copy.copy(self))

    def removable(self, general):
        """This record cannot be removed savely"""
        return {"general": None}
Ejemplo n.º 15
0
class Step(Record):
    """Period for the automatic invoicing"""
    __slots__ = 'step', 'type', 'url', 'data', 'response', 'changes'
    path = 'periods'
    fields = [
        Number('step'),
        Enum('type', ['data', 'call']),
        String('url'),
        String('data'),
        String('response'),
        String('changes')
    ]
    keys = ['step']

    def __init__(self, parent):
        self.parent = parent
        self.step = len(parent.steps) + 1
        self.type = 1
        self.url = ''
        self.data = ''
        self.response = None
        self.changes = None

    def store(self):
        """Store the Step"""
        self.parent.steps[self.get_id()] = self

    def remove(self):
        """Remove the Step from the test"""
        del self.parent.steps[self.get_id()]

    def removable(self, general):
        """This record can be removed savely"""
        return None

    def show(self):
        """String to show the record with"""
        return self.fields[1].show(self.type) + ' ' + self.url

    def find(self, data):
        """Find the record with the relation key"""
        if data['step'] not in self.root().steps:
            return None
        return self.root().steps[data['start']]
Ejemplo n.º 16
0
class RamlBody(Model):
    schema = String()
    example = String()
    notNull = Bool()
    description = String()
    formParameters = Map(String(), Reference(RamlHeader))
    headers = Map(String(), Reference(RamlHeader))
    body = Map(String(), Reference("pyraml.entities.RamlBody"))
    is_ = List(String(), field_name="is")
Ejemplo n.º 17
0
class Statistic(Record):
    """Statistics for persons, aliens and items"""
    path = 'statistics'
    fields = [
        Enum('type', ['training', 'skill', 'statistic']),
        String('name'),
        String('description')
    ]
    keys = ['type', 'name']

    def __init__(self, parent):
        self.parent = parent
        self.type = None
        self.name = None
        self.first_train = None
        self.second_train = None
        self.description = None

    def store(self):
        """Store the Automatic"""
        self.parent.statistics[self.get_id()] = self

    def remove(self):
        """Remove the Automatic from the index"""
        del self.parent.statistics[self.get_id()]

    def find(self, data):
        """Find the record with the relation key"""
        root = getattr(self, 'data_store').root
        fld = getattr(self, 'field_on_name')['type']
        key = "{:07d}".format(fld.read(data['type'])) + \
              "|" + data['name']
        if key not in root.statistics:
            return None
        return root.statistics[key]

    def removable(self, general):
        """This record cannot be removed savely"""
        return {"statistic": None}
Ejemplo n.º 18
0
class RamlQueryParameter(Model):
    name = String()
    description = String()
    example = Or(String(),Int(),Float())
    displayName = String()
    type = String()
    enum = List(Or(String(),Float(),Int()))
    pattern = String()
    minLength = Int()
    maxLength = Int()
    repeat = Bool()
    required = Bool()
    default = Or(String(),Int(),Float())
    minimum = Or(Int(),Float())
    maximum = Or(Int(),Float())
Ejemplo n.º 19
0
class RamlNamedParameters(Model):
    """ http://raml.org/spec.html#named-parameters """
    displayName = String()
    description = String()
    type = Choice(default='string', choices=NAMED_PARAMETER_TYPES)
    name = String()
    example = Or(String(), Int(), Float())
    enum = List(Or(String(), Float(), Int()))
    pattern = String()
    minLength = Int()
    maxLength = Int()
    repeat = Bool()
    required = Bool()
    default = Or(String(), Int(), Float())
    minimum = Or(Int(), Float())
    maximum = Or(Int(), Float())
Ejemplo n.º 20
0
class TestFile(Record):
    """General record that holds the steps of a test"""
    __slots__ = 'description', 'steps'
    path = ''
    fields = [String('description'), Set('steps', Step)]

    def __init__(self):
        self.description = ''
        self.steps = RBDict()

    def store(self):
        """This this the top level element"""
        pass

    def remove(self):
        """The top level element cannot be removed"""
        pass

    def removable(self, general):
        """This record cannot be removed savely"""
        return {"testFile": None}
Ejemplo n.º 21
0
class Item(Record):
    """Items and some other things in the game"""
    fields = [
        Enum('type', [
            'profession', 'armor', 'shield', 'weapon', 'gear', 'ammunition',
            'module', 'vehicle', 'trap', 'body mod', 'weapon mod', 'armor mor',
            'vehicle mod', 'enemy', 'ufo', 'artifact'
        ]),
        String('name'),
        Set('values', Value)
    ]
    keys = ['type', 'name']

    def __init__(self, parent):
        self.parent = parent
        self.type = 0
        self.name = None
        self.values = RBDict()

    def store(self):
        """Store the Automatic"""
        self.parent.items[self.get_id()] = self

    def remove(self):
        """Remove the Automatic from the index"""
        del self.parent.items[self.get_id()]

    def find(self, data):
        """Find the record with the relation key"""
        key = "{:07d}".format(self.field('type').read(data['type'])) + \
              "|" + data['name']
        if key not in self.root().statistics:
            return None
        return self.root().items[key]

    def removable(self, general):
        """This record cannot be removed savely"""
        return {"statistic": None}
Ejemplo n.º 22
0
class RamlTrait(Model):
    """
    traits:
      - secured:
          usage: Apply this to any method that needs to be secured
          description: Some requests require authentication.
          queryParameters:
            access_token:
              description: Access Token
              type: string
              example: ACCESS_TOKEN
              required: true
    """

    name = String()
    usage = String()
    description = String()
    displayName = String()
    responses = Map(Int(), Reference(RamlResponse))
    method = String()
    queryParameters = Map(String(), Reference(RamlQueryParameter))
    body = Reference(RamlBody)
    # Reference to another RamlTrait
    is_ = List(String(), field_name="is")
Ejemplo n.º 23
0
class TraitedEntity(object):
    """ Represents entities that may have traits specified
    in ``is`` field.
    """
    is_ = List(Or(String(), Map(String(), Map(String(), String()))),
               field_name='is')
Ejemplo n.º 24
0
class SecuredEntity(object):
    # [foo, {bar: {baz: [buz]}}, null]
    securedBy = List(
        Or(String(), Map(String(), Map(String(), List(String()))), Null()))
Ejemplo n.º 25
0
class ResourceTypedEntity(object):
    """ Represents entities that may have resourceTypes
    specified in ``type`` field.
    """
    type = Or(String(), Map(String(), Map(String(), String())))
Ejemplo n.º 26
0
class RamlRoot(SecuredEntity, Model):
    """ http://raml.org/spec.html#root-section """
    raml_version = String(required=True)
    title = String(required=True)
    version = Or(String(), Int(), Float())
    baseUri = String(required=True)
    protocols = List(
        Choice(field_name='protocols', choices=RAML_VALID_PROTOCOLS))
    mediaType = String()
    documentation = List(Reference(RamlDocumentation))
    traits = Map(String(), Reference(RamlTrait))
    resources = Map(String(), Reference(RamlResource))
    resourceTypes = Map(String(), Reference(RamlResourceType))
    schemas = Map(String(), Or(JSONData(), XMLData(), String()))
    baseUriParameters = RamlNamedParametersMap()
    securitySchemes = Map(String(), Reference(RamlSecurityScheme))
Ejemplo n.º 27
0
class RamlSecurityScheme(Model):
    """ http://raml.org/spec.html#security """
    description = String()
    type = String()
    describedBy = Reference(RamlSecuritySchemeDescription)
    settings = Map(String(), Or(String(), List(String())))
Ejemplo n.º 28
0
class RamlDocumentation(Model):
    content = String()
    title = String()
Ejemplo n.º 29
0
class RamlResourceType(Model):
    methods = Map(String(), Reference(RamlTrait))
    type = String()
    is_ = List(String(), field_name="is")
Ejemplo n.º 30
0
class RamlHeader(Model):
    type = String()
    required = Bool()