"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "buildbot/data/types.py" between
buildbot-3.0.2.tar.gz and buildbot-3.1.0.tar.gz

About: Buildbot is a continuous integration testing framework (Python-based). It supports also automation of complex build systems, application deployment, and management of sophisticated software-release processes.

types.py  (buildbot-3.0.2):types.py  (buildbot-3.1.0)
skipping to change at line 24 skipping to change at line 24
# Copyright Buildbot Team Members # Copyright Buildbot Team Members
# See "Type Validation" in master/docs/developer/tests.rst # See "Type Validation" in master/docs/developer/tests.rst
import datetime import datetime
import json import json
import re import re
from buildbot import util from buildbot import util
from buildbot.util import bytes2unicode from buildbot.util import bytes2unicode
def capitalize(word):
return ''.join(x.capitalize() or '_' for x in word.split('_'))
class Type: class Type:
name = None name = None
doc = None doc = None
graphQLType = "unknown"
@property @property
def ramlname(self): def ramlname(self):
return self.name return self.name
def valueFromString(self, arg): def valueFromString(self, arg):
# convert a urldecoded bytestring as given in a URL to a value, or # convert a urldecoded bytestring as given in a URL to a value, or
# raise an exception trying. This parent method raises an exception, # raise an exception trying. This parent method raises an exception,
# so if the method is missing in a subclass, it cannot be created from # so if the method is missing in a subclass, it cannot be created from
# a string. # a string.
skipping to change at line 57 skipping to change at line 61
def validate(self, name, object): def validate(self, name, object):
raise NotImplementedError raise NotImplementedError
def getSpec(self): def getSpec(self):
r = dict(name=self.name) r = dict(name=self.name)
if self.doc is not None: if self.doc is not None:
r["doc"] = self.doc r["doc"] = self.doc
return r return r
def toGraphQL(self):
return self.graphQLType
def toGraphQLTypeName(self):
return self.graphQLType
def graphQLDependentTypes(self):
return []
class NoneOk(Type): class NoneOk(Type):
def __init__(self, nestedType): def __init__(self, nestedType):
assert isinstance(nestedType, Type) assert isinstance(nestedType, Type)
self.nestedType = nestedType self.nestedType = nestedType
self.name = self.nestedType.name + " or None" self.name = self.nestedType.name + " or None"
@property @property
def ramlname(self): def ramlname(self):
return self.nestedType.ramlname return self.nestedType.ramlname
skipping to change at line 88 skipping to change at line 101
yield msg yield msg
def getSpec(self): def getSpec(self):
r = self.nestedType.getSpec() r = self.nestedType.getSpec()
r["can_be_null"] = True r["can_be_null"] = True
return r return r
def toRaml(self): def toRaml(self):
return self.nestedType.toRaml() return self.nestedType.toRaml()
def toGraphQL(self):
# remove trailing !
if isinstance(self.nestedType, Entity):
return capitalize(self.nestedType.name)
return self.nestedType.toGraphQL()[:-1]
def graphQLDependentTypes(self):
return [self.nestedType]
class Instance(Type): class Instance(Type):
types = () types = ()
ramlType = "unknown" ramlType = "unknown"
graphQLType = "unknown"
@property @property
def ramlname(self): def ramlname(self):
return self.ramlType return self.ramlType
def validate(self, name, object): def validate(self, name, object):
if not isinstance(object, self.types): if not isinstance(object, self.types):
yield "{} ({}) is not a {}".format(name, repr(object), self.name or repr(self.types)) yield "{} ({}) is not a {}".format(name, repr(object), self.name or repr(self.types))
def toRaml(self): def toRaml(self):
return self.ramlType return self.ramlType
def toGraphQL(self):
return self.graphQLType + "!"
class Integer(Instance): class Integer(Instance):
name = "integer" name = "integer"
types = (int,) types = (int,)
ramlType = "integer" ramlType = "integer"
graphQLType = "Int"
def valueFromString(self, arg): def valueFromString(self, arg):
return int(arg) return int(arg)
class DateTime(Instance): class DateTime(Instance):
name = "datetime" name = "datetime"
types = (datetime.datetime,) types = (datetime.datetime,)
ramlType = "date"
graphQLType = "Date" # custom
def valueFromString(self, arg): def valueFromString(self, arg):
return int(arg) return int(arg)
def validate(self, name, object): def validate(self, name, object):
if isinstance(object, datetime.datetime): if isinstance(object, datetime.datetime):
return return
if isinstance(object, int): if isinstance(object, int):
try: try:
datetime.datetime.fromtimestamp(object) datetime.datetime.fromtimestamp(object)
except (OverflowError, OSError): except (OverflowError, OSError):
pass pass
else: else:
return return
yield "{} ({}) is not a valid timestamp".format(name, object) yield "{} ({}) is not a valid timestamp".format(name, object)
ramlType = "date"
class String(Instance): class String(Instance):
name = "string" name = "string"
types = (str,) types = (str,)
ramlType = "string" ramlType = "string"
graphQLType = "String"
def valueFromString(self, arg): def valueFromString(self, arg):
val = util.bytes2unicode(arg) val = util.bytes2unicode(arg)
return val return val
class Binary(Instance): class Binary(Instance):
name = "binary" name = "binary"
types = (bytes,) types = (bytes,)
ramlType = "string" ramlType = "string"
graphQLType = "Binary" # custom
def valueFromString(self, arg): def valueFromString(self, arg):
return arg return arg
class Boolean(Instance): class Boolean(Instance):
name = "boolean" name = "boolean"
types = (bool,) types = (bool,)
ramlType = "boolean" ramlType = "boolean"
graphQLType = "Boolean" # custom
def valueFromString(self, arg): def valueFromString(self, arg):
return util.string2boolean(arg) return util.string2boolean(arg)
class Identifier(Type): class Identifier(Type):
name = "identifier" name = "identifier"
identRe = re.compile('^[a-zA-Z_-][a-zA-Z0-9._-]*$') identRe = re.compile('^[a-zA-Z_-][a-zA-Z0-9._-]*$')
ramlType = "string" ramlType = "string"
graphQLType = "String"
def __init__(self, len=None, **kwargs): def __init__(self, len=None, **kwargs):
super().__init__(**kwargs) super().__init__(**kwargs)
self.len = len self.len = len
def valueFromString(self, arg): def valueFromString(self, arg):
val = util.bytes2unicode(arg) val = util.bytes2unicode(arg)
if not self.identRe.match(val) or len(val) > self.len or not val: if not self.identRe.match(val) or len(val) > self.len or not val:
raise TypeError raise TypeError
return val return val
skipping to change at line 227 skipping to change at line 258
# a time, so we defer to the `of` # a time, so we defer to the `of`
return self.of.valueFromString(arg) return self.of.valueFromString(arg)
def getSpec(self): def getSpec(self):
return dict(type=self.name, return dict(type=self.name,
of=self.of.getSpec()) of=self.of.getSpec())
def toRaml(self): def toRaml(self):
return {'type': 'array', 'items': self.of.name} return {'type': 'array', 'items': self.of.name}
def maybeNoneOrList(k, v): def toGraphQL(self):
return f"[{self.of.toGraphQLTypeName()}]!"
def graphQLDependentTypes(self):
return [self.of]
def ramlMaybeNoneOrList(k, v):
if isinstance(v, NoneOk): if isinstance(v, NoneOk):
return k + "?" return k + "?"
if isinstance(v, List): if isinstance(v, List):
return k + "[]" return k + "[]"
return k return k
class SourcedProperties(Type): class SourcedProperties(Type):
name = "sourcedproperties" name = "sourcedproperties"
skipping to change at line 266 skipping to change at line 303
def toRaml(self): def toRaml(self):
return {'type': "object", return {'type': "object",
'properties': 'properties':
{'[]': {'type': 'object', {'[]': {'type': 'object',
'properties': { 'properties': {
1: 'string', 1: 'string',
2: 'integer | string | object | array | boolean' 2: 'integer | string | object | array | boolean'
} }
}}} }}}
class Dict(Type): def toGraphQL(self):
name = "dict" return "[Property]!"
@property def graphQLDependentTypes(self):
def ramlname(self): return [PropertyEntityType("property")]
return self.toRaml()
def __init__(self, **contents):
self.contents = contents
self.keys = set(contents)
def validate(self, name, object):
if not isinstance(object, dict):
yield "{} ({}) is not a dictionary (got type {})".format(name, repr(
object),
type(object
))
return
gotNames = set(object.keys())
unexpected = gotNames - self.keys
if unexpected:
yield "{} has unexpected keys {}".format(name, ", ".join([repr(n) fo
r n in unexpected]))
missing = self.keys - gotNames
if missing:
yield "{} is missing keys {}".format(name, ", ".join([repr(n) for n
in missing]))
for k in gotNames & self.keys:
f = self.contents[k]
for msg in f.validate("{}[{}]".format(name, repr(k)), object[k]):
yield msg
def getSpec(self):
return dict(type=self.name,
fields=[dict(name=k,
type=v.name,
type_spec=v.getSpec())
for k, v in self.contents.items()
])
def toRaml(self):
return {'type': "object",
'properties': {maybeNoneOrList(k, v): v.ramlname for k, v in sel
f.contents.items()}}
class JsonObject(Type): class JsonObject(Type):
name = "jsonobject" name = "jsonobject"
ramlname = 'object' ramlname = 'object'
graphQLType = "JSON"
def validate(self, name, object): def validate(self, name, object):
if not isinstance(object, dict): if not isinstance(object, dict):
yield "{} ({}) is not a dictionary (got type {})".format(name, repr( object), yield "{} ({}) is not a dictionary (got type {})".format(name, repr( object),
type(object )) type(object ))
return return
# make sure JSON can represent it # make sure JSON can represent it
try: try:
json.dumps(object) json.dumps(object)
skipping to change at line 383 skipping to change at line 383
return dict(type=self.name, return dict(type=self.name,
fields=[dict(name=k, fields=[dict(name=k,
type=v.name, type=v.name,
type_spec=v.getSpec()) type_spec=v.getSpec())
for k, v in self.fields.items() for k, v in self.fields.items()
]) ])
def toRaml(self): def toRaml(self):
return {'type': "object", return {'type': "object",
'properties': { 'properties': {
maybeNoneOrList(k, v): {'type': v.ramlname, 'description': ' '} ramlMaybeNoneOrList(k, v): {'type': v.ramlname, 'description ': ''}
for k, v in self.fields.items()}} for k, v in self.fields.items()}}
def toGraphQL(self):
return dict(type=capitalize(self.name),
fields=[dict(name=k,
type=v.toGraphQL())
for k, v in self.fields.items()
])
def toGraphQLTypeName(self):
return capitalize(self.name)
def graphQLDependentTypes(self):
return self.fields.values()
class PropertyEntityType(Entity):
name = String()
source = String()
value = JsonObject()
 End of changes. 19 change blocks. 
51 lines changed or deleted 46 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)