Esempio n. 1
0
class XmlnsDoc(DocumentElement):

    __tag__ = 'nstest'
    __xmlns__ = 'http://earthreader.github.io/'
    samens_attr = Text('samens', xmlns=__xmlns__)
    otherns_attr = Text('otherns',
                        xmlns='https://github.com/earthreader/libearth')
Esempio n. 2
0
class TestMergeableDoc(MergeableDocumentElement):

    __tag__ = 'merge-test'
    multi_text = Text('multi-text', multiple=True)
    text = Text('text')
    attr = Attribute('attr')
    unique_entities = Child('unique-entity', TestUniqueEntity, multiple=True)
    rev_entities = Child('rev-multi-entity', TestRevisedEntity, multiple=True)
    rev_entity = Child('rev-single-entity', TestRevisedEntity)
    nullable = Child('nullable-entity', TestUniqueEntity)
Esempio n. 3
0
class VTElement(Element):

    req_attr = Attribute('a', required=True)
    attr = Attribute('b')
    req_child = Child('c', TextElement, required=True)
    child = Child('d', TextElement)
    req_text = Text('e', required=True)
    text = Text('f')

    def __repr__(self):
        fmt = 'VTElement(req_attr={0!r}, req_child={1!r}, req_text={2!r})'
        return fmt.format(self.req_attr, self.req_child, self.req_text)
Esempio n. 4
0
class VTDoc(DocumentElement):

    __tag__ = 'vtest'
    req_attr = Attribute('a', required=True)
    attr = Attribute('b')
    req_child = Child('c', VTElement, required=True)
    child = Child('d', VTElement)
    multi = Child('e', VTElement, multiple=True)
    req_text = Text('f', required=True)
    text = Text('g')

    def __repr__(self):
        fmt = 'VTDoc(req_attr={0!r}, req_child={1!r}, req_text={2!r})'
        return fmt.format(self.req_attr, self.req_child, self.req_text)
Esempio n. 5
0
class TestUniqueEntity(Element):

    ident = Text('ident', required=True)
    value = Attribute('value')

    def __entity_id__(self):
        return self.ident
Esempio n. 6
0
class TestDoc(DocumentElement):

    __tag__ = 'test'
    attr_attr = Attribute('attr')
    attr_decoder = Attribute('attr-decoder', decoder=lambda s: s.lower())
    attr_decoder_decorator = Attribute('attr-decoder-decorator')
    title_attr = Child('title', TextElement, required=True)
    content_attr = Child('content', TextElement, required=True)
    multi_attr = Child('multi', TextElement, multiple=True)
    sorted_children = Child('s-multi', TextElement,
                            multiple=True, sort_key=lambda e: e.value)
    text_content_attr = Text('text-content')
    text_multi_attr = Text('text-multi', multiple=True)
    sorted_texts = Text('s-text-multi',
                        multiple=True, sort_key=lambda t: t, sort_reverse=True)
    text_decoder = Text('text-decoder', decoder=float, encoder=str)
    text_decoder_decorator = Text('text-decoder-decorator')
    text_combined_decoder = Text('text-combined-decoder',
                                 decoder=int, encoder=lambda i: i and i / 100)
    ns_element_attr = Child('ns-element', TextElement,
                            xmlns='http://earthreader.github.io/')
    ns_text_attr = Text('ns-text', xmlns='http://earthreader.github.io/')
    content_decoder = Child('content-decoder', TextDecoderElement)

    @attr_decoder_decorator.decoder
    def attr_decoder_decorator(self, value):
        return value[::-1]

    @attr_decoder_decorator.encoder
    def attr_decoder_decorator(self, value):
        return value and value[::-1]

    @text_decoder_decorator.decoder
    def text_decoder_decorator(self, text):
        return int(text[::-1])

    @text_decoder_decorator.encoder
    def text_decoder_decorator(self, value):
        if value is not None:
            return str(value)[::-1]

    @text_combined_decoder.decoder
    def text_combined_decoder(self, value):
        return value * 100

    @text_combined_decoder.decoder
    def text_combined_decoder(self, value):
        return -value

    @text_combined_decoder.encoder
    def text_combined_decoder(self, value):
        if value is not None:
            return -value

    @text_combined_decoder.encoder
    def text_combined_decoder(self, value):
        if value is not None:
            if value % 1 <= 0:
                value = int(value)
            return str(value)
Esempio n. 7
0
class TestRevisedEntity(Element):

    ident = Text('ident', required=True)
    rev = Attribute('rev', Integer)
    value = Attribute('value')

    def __entity_id__(self):
        return self.ident

    def __merge_entities__(self, other):
        return max(self, other, key=operator.attrgetter('rev'))
Esempio n. 8
0
class CodecTestDoc(DocumentElement):

    __tag__ = 'codec-test'
    attr = Attribute('attr', IntPair)
    text = Text('text', IntPair)
Esempio n. 9
0
class EncodeErrorDoc(DocumentElement):

    __tag__ = 'encode-error-test'
    attr = Attribute('attr', encoder=lambda s: s and 123)
    text = Text('text', encoder=lambda s: s and object())
Esempio n. 10
0
class ChildDescriptorConflictElement(Element):

    child = Child('same-tag', TextElement)
    text = Text('same-tag')
Esempio n. 11
0
 class AdhocElement(Element):
     format_version = Attribute('version')
     name = Text('name-e')
     url = Child('url-e', AdhocTextElement, multiple=True)
     dob = Child('dob-e', AdhocTextElement, xmlns='http://example.com/')
Esempio n. 12
0
class PartialLoadTestEntry(DocumentElement):

    __tag__ = 'entry'
    __xmlns__ = 'http://example.com/'
    value = Text('value', xmlns=__xmlns__)