示例#1
0
文件: builtins.py 项目: speker/core
class gMonthDay(BuiltinType, AnySimpleType):
    """gMonthDay is a gregorian date that recurs, specifically a day of the
    year such as the third of May.

    Lexical representation: --MM-DD

    """

    accepted_types = (datetime.date, ) + six.string_types
    _default_qname = xsd_ns("gMonthDay")
    _pattern = re.compile(
        r"^--(?P<month>\d\d)-(?P<day>\d\d)(?P<timezone>Z|[-+]\d\d:?\d\d)?$")

    @check_no_collection
    def xmlvalue(self, value):
        month, day, tzinfo = value
        return "--%02d-%02d%s" % (month, day, _unparse_timezone(tzinfo))

    def pythonvalue(self, value):
        match = self._pattern.match(value)
        if not match:
            raise ParseError()

        group = match.groupdict()
        return (
            int(group["month"]),
            int(group["day"]),
            _parse_timezone(group["timezone"]),
        )
示例#2
0
文件: builtins.py 项目: speker/core
class gYearMonth(BuiltinType, AnySimpleType):
    """gYearMonth represents a specific gregorian month in a specific gregorian
    year.

    Lexical representation: CCYY-MM

    """

    accepted_types = (datetime.date, ) + six.string_types
    _default_qname = xsd_ns("gYearMonth")
    _pattern = re.compile(
        r"^(?P<year>-?\d{4,})-(?P<month>\d\d)(?P<timezone>Z|[-+]\d\d:?\d\d)?$")

    @check_no_collection
    def xmlvalue(self, value):
        year, month, tzinfo = value
        return "%04d-%02d%s" % (year, month, _unparse_timezone(tzinfo))

    def pythonvalue(self, value):
        match = self._pattern.match(value)
        if not match:
            raise ParseError()
        group = match.groupdict()
        return (
            int(group["year"]),
            int(group["month"]),
            _parse_timezone(group["timezone"]),
        )
示例#3
0
文件: builtins.py 项目: speker/core
class DateTime(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("dateTime")
    accepted_types = (datetime.datetime, ) + six.string_types

    @check_no_collection
    def xmlvalue(self, value):
        if isinstance(value, six.string_types):
            return value

        # Bit of a hack, since datetime is a subclass of date we can't just
        # test it with an isinstance(). And actually, we should not really
        # care about the type, as long as it has the required attributes
        if not all(
                hasattr(value, attr) for attr in ("hour", "minute", "second")):
            value = datetime.datetime.combine(
                value,
                datetime.time(
                    getattr(value, "hour", 0),
                    getattr(value, "minute", 0),
                    getattr(value, "second", 0),
                ),
            )

        if getattr(value, "microsecond", 0):
            return isodate.isostrf.strftime(value, "%Y-%m-%dT%H:%M:%S.%f%Z")
        return isodate.isostrf.strftime(value, "%Y-%m-%dT%H:%M:%S%Z")

    def pythonvalue(self, value):

        # Determine based on the length of the value if it only contains a date
        # lazy hack ;-)
        if len(value) == 10:
            value += "T00:00:00"
        return isodate.parse_datetime(value)
示例#4
0
class Schema(Base):
    name = "schema"
    attr_name = "schema"
    qname = xsd_ns("schema")

    def clone(self, qname, min_occurs=1, max_occurs=1):
        return self.__class__()

    def parse_kwargs(self, kwargs, name, available_kwargs):
        if name in available_kwargs:
            value = kwargs[name]
            available_kwargs.remove(name)
            return {name: value}
        return {}

    def parse(self, xmlelement, schema, context=None):
        from core.utilities.soap.xsd.schema import Schema

        schema = Schema(xmlelement, schema._transport)
        context.schemas.append(schema)
        return schema

    def parse_xmlelements(self, xmlelements, schema, name=None, context=None):
        if xmlelements[0].tag == self.qname:
            xmlelement = xmlelements.popleft()
            result = self.parse(xmlelement, schema, context=context)
            return result

    def resolve(self):
        return self
示例#5
0
文件: builtins.py 项目: speker/core
class Integer(Decimal):
    _default_qname = xsd_ns("integer")
    accepted_types = (int, float) + six.string_types

    def xmlvalue(self, value):
        return str(value)

    def pythonvalue(self, value):
        return int(value)
示例#6
0
文件: builtins.py 项目: speker/core
class Float(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("float")
    accepted_types = (float, _Decimal) + six.string_types

    def xmlvalue(self, value):
        return str(value).upper()

    def pythonvalue(self, value):
        return float(value)
示例#7
0
文件: builtins.py 项目: speker/core
class QName(BuiltinType, AnySimpleType):
    accepted_types = six.string_types
    _default_qname = xsd_ns("QName")

    @check_no_collection
    def xmlvalue(self, value):
        return value

    def pythonvalue(self, value):
        return value
示例#8
0
文件: builtins.py 项目: speker/core
class Base64Binary(BuiltinType, AnySimpleType):
    accepted_types = six.string_types
    _default_qname = xsd_ns("base64Binary")

    @check_no_collection
    def xmlvalue(self, value):
        return base64.b64encode(value)

    def pythonvalue(self, value):
        return base64.b64decode(value)
示例#9
0
文件: builtins.py 项目: speker/core
class Double(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("double")
    accepted_types = (_Decimal, float) + six.string_types

    @check_no_collection
    def xmlvalue(self, value):
        return str(value)

    def pythonvalue(self, value):
        return float(value)
示例#10
0
文件: builtins.py 项目: speker/core
class String(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("string")
    accepted_types = six.string_types

    @check_no_collection
    def xmlvalue(self, value):
        if isinstance(value, bytes):
            return value.decode("utf-8")
        return six.text_type(value if value is not None else "")

    def pythonvalue(self, value):
        return value
示例#11
0
文件: builtins.py 项目: speker/core
class Date(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("date")
    accepted_types = (datetime.date, ) + six.string_types

    @check_no_collection
    def xmlvalue(self, value):
        if isinstance(value, six.string_types):
            return value
        return isodate.isostrf.strftime(value, "%Y-%m-%d")

    def pythonvalue(self, value):
        return isodate.parse_date(value)
示例#12
0
文件: builtins.py 项目: speker/core
class Boolean(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("boolean")
    accepted_types = (bool, )

    @check_no_collection
    def xmlvalue(self, value):
        return "true" if value and value not in ("false", "0") else "false"

    def pythonvalue(self, value):
        """Return True if the 'true' or '1'. 'false' and '0' are legal false
        values, but we consider everything not true as false.

        """
        return value in ("true", "1")
示例#13
0
文件: builtins.py 项目: speker/core
class Time(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("time")
    accepted_types = (datetime.time, ) + six.string_types

    @check_no_collection
    def xmlvalue(self, value):
        if isinstance(value, six.string_types):
            return value

        if value.microsecond:
            return isodate.isostrf.strftime(value, "%H:%M:%S.%f%Z")
        return isodate.isostrf.strftime(value, "%H:%M:%S%Z")

    def pythonvalue(self, value):
        return isodate.parse_time(value)
示例#14
0
文件: builtins.py 项目: speker/core
class Duration(BuiltinType, AnySimpleType):
    _default_qname = xsd_ns("duration")
    accepted_types = (isodate.duration.Duration, ) + six.string_types

    @check_no_collection
    def xmlvalue(self, value):
        return isodate.duration_isoformat(value)

    def pythonvalue(self, value):
        if value.startswith("PT-"):
            value = value.replace("PT-", "PT")
            result = isodate.parse_duration(value)
            return datetime.timedelta(0 - result.total_seconds())
        else:
            return isodate.parse_duration(value)
示例#15
0
文件: builtins.py 项目: speker/core
class gMonth(BuiltinType, AnySimpleType):
    """gMonth is a gregorian month that recurs every year.

    Lexical representation: --MM

    """

    accepted_types = (datetime.date, ) + six.string_types
    _default_qname = xsd_ns("gMonth")
    _pattern = re.compile(
        r"^--(?P<month>\d\d)(?P<timezone>Z|[-+]\d\d:?\d\d)?$")

    @check_no_collection
    def xmlvalue(self, value):
        month, tzinfo = value
        return "--%d%s" % (month, _unparse_timezone(tzinfo))

    def pythonvalue(self, value):
        match = self._pattern.match(value)
        if not match:
            raise ParseError()
        group = match.groupdict()
        return (int(group["month"]), _parse_timezone(group["timezone"]))
示例#16
0
文件: builtins.py 项目: speker/core
class PositiveInteger(NonNegativeInteger):
    _default_qname = xsd_ns("positiveInteger")
示例#17
0
文件: builtins.py 项目: speker/core
class UnsignedByte(UnsignedShort):
    _default_qname = xsd_ns("unsignedByte")
示例#18
0
文件: builtins.py 项目: speker/core
class UnsignedShort(UnsignedInt):
    _default_qname = xsd_ns("unsignedShort")
示例#19
0
文件: builtins.py 项目: speker/core
class UnsignedInt(UnsignedLong):
    _default_qname = xsd_ns("unsignedInt")
示例#20
0
文件: builtins.py 项目: speker/core
class UnsignedLong(NonNegativeInteger):
    _default_qname = xsd_ns("unsignedLong")
示例#21
0
文件: builtins.py 项目: speker/core
class NonNegativeInteger(Integer):
    _default_qname = xsd_ns("nonNegativeInteger")
示例#22
0
文件: builtins.py 项目: speker/core
class IDREFS(IDREF):
    _default_qname = xsd_ns("IDREFS")
示例#23
0
文件: builtins.py 项目: speker/core
class Short(Int):
    _default_qname = xsd_ns("short")
示例#24
0
文件: builtins.py 项目: speker/core
class Entities(Entity):
    _default_qname = xsd_ns("ENTITIES")
示例#25
0
文件: builtins.py 项目: speker/core
class Entity(NCName):
    _default_qname = xsd_ns("ENTITY")
示例#26
0
文件: builtins.py 项目: speker/core
class Byte(Short):
    """A signed 8-bit integer"""

    _default_qname = xsd_ns("byte")
示例#27
0
文件: builtins.py 项目: speker/core
class Long(Integer):
    _default_qname = xsd_ns("long")

    def pythonvalue(self, value):
        return long(value) if six.PY2 else int(value)  # noqa
示例#28
0
文件: builtins.py 项目: speker/core
class IDREF(NCName):
    _default_qname = xsd_ns("IDREF")
示例#29
0
文件: visitor.py 项目: speker/core
    "sequence",
    "group",
    "choice",
    "all",
    "list",
    "union",
    "attribute",
    "any",
    "anyAttribute",
    "attributeGroup",
    "restriction",
    "extension",
    "notation",
]:
    attr = name if name not in keyword.kwlist else name + "_"
    setattr(tags, attr, xsd_ns(name))


class SchemaVisitor(object):
    """Visitor which processes XSD files and registers global elements and
    types in the given schema.

    :param schema:
    :type schema: zeep.xsd.schema.Schema
    :param document:
    :type document: zeep.xsd.schema.SchemaDocument

    """

    def __init__(self, schema, document):
        self.document = document
示例#30
0
文件: builtins.py 项目: speker/core
class Int(Long):
    _default_qname = xsd_ns("int")