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}
class RamlResponse(Model): schema = String() example = String() notNull = Bool() description = String() headers = Map(String(), Reference(RamlHeader)) body = Reference("pyraml.entities.RamlBody")
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))
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"))
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)
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()
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))
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"))
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()
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))
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))
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))
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))
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}
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']]
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")
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}
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())
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())
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}
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}
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")
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')
class SecuredEntity(object): # [foo, {bar: {baz: [buz]}}, null] securedBy = List( Or(String(), Map(String(), Map(String(), List(String()))), Null()))
class ResourceTypedEntity(object): """ Represents entities that may have resourceTypes specified in ``type`` field. """ type = Or(String(), Map(String(), Map(String(), String())))
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))
class RamlSecurityScheme(Model): """ http://raml.org/spec.html#security """ description = String() type = String() describedBy = Reference(RamlSecuritySchemeDescription) settings = Map(String(), Or(String(), List(String())))
class RamlDocumentation(Model): content = String() title = String()
class RamlResourceType(Model): methods = Map(String(), Reference(RamlTrait)) type = String() is_ = List(String(), field_name="is")
class RamlHeader(Model): type = String() required = Bool()