예제 #1
0
class Entry(XMLElement):
    _xml_tag = 'entry'
    _xml_namespace = namespace
    _xml_extension_type = EntryExtension
    _xml_document = ResourceListsDocument
    _xml_children_order = {DisplayName.qname: 0}

    uri = XMLElementID('uri', type=AnyURI, required=True, test_equal=True)
    display_name = XMLElementChild('display_name',
                                   type=DisplayName,
                                   required=False,
                                   test_equal=False)

    def __init__(self, uri, display_name=None):
        XMLElement.__init__(self)
        self.uri = uri
        self.display_name = display_name

    def __unicode__(self):
        return self.display_name and '"%s" <%s>' % (self.display_name,
                                                    self.uri) or self.uri

    def __repr__(self):
        return '%s(%r, %r)' % (self.__class__.__name__, self.uri,
                               self.display_name)
class Dialog(XMLElement):
    _xml_tag = 'dialog'
    _xml_namespace = namespace
    _xml_document = DialogInfoDocument

    id = XMLElementID('id', type=str, required=True, test_equal=True)

    call_id = XMLAttribute('call_id', xmlname='call-id', type=str, required=False, test_equal=True)
    local_tag = XMLAttribute('local_tag', xmlname='local-tag', type=str, required=False, test_equal=True)
    remote_tag = XMLAttribute('remote_tag', xmlname='remote-tag', type=str, required=False, test_equal=True)
    direction = XMLAttribute('direction', type=DirectionValue, required=False, test_equal=True)

    state = XMLElementChild('state', type=DialogState, required=True, test_equal=True)
    duration = XMLElementChild('duration', type=Duration, required=False, test_equal=True)
    replaces = XMLElementChild('replaces', type=Replaces, required=False, test_equal=True)
    referred_by = XMLElementChild('referred_by', type=ReferredBy, required=False, test_equal=True)
    local = XMLElementChild('local', type=Local, required=False, test_equal=True)
    remote = XMLElementChild('remote', type=Remote, required=False, test_equal=True)

    def __init__(self, id, state, call_id=None, local_tag=None, remote_tag=None, direction=None, duration=None, replaces=None, referred_by=None, local=None, remote=None):
        XMLElement.__init__(self)
        self.id = id
        self.state = state
        self.call_id = call_id
        self.local_tag = local_tag
        self.remote_tag = remote_tag
        self.direction = direction
        self.duration = duration
        self.replaces = replaces
        self.referred_by = referred_by
        self.local = local
        self.remote = remote
예제 #3
0
class List(XMLListRootElement):
    _xml_tag = 'list'
    _xml_namespace = namespace
    _xml_document = RLMIDocument
    _xml_item_type = (Name, Resource)

    uri = XMLElementID('uri', type=AnyURI, required=True, test_equal=True)
    version = XMLAttribute('version',
                           type=UnsignedInt,
                           required=True,
                           test_equal=True)
    full_state = XMLAttribute('full_state',
                              xmlname='fullState',
                              type=Boolean,
                              required=True,
                              test_equal=True)
    cid = XMLAttribute('cid', type=str, required=False, test_equal=True)

    def __init__(self, uri, version, full_state, cid=None, items=[]):
        XMLListElement.__init__(self)
        self.uri = uri
        self.version = version
        self.full_state = full_state
        self.cid = cid
        self.update(items)

    def __repr__(self):
        return '%s(%r, version=%r, full_state=%r, cid=%r, items=%r)' % (
            self.__class__.__name__, self.uri, self.version, self.full_state,
            self.cid, list(self))
예제 #4
0
class Group(XMLElement, ListElement):
    _xml_tag = 'group'
    _xml_namespace = namespace
    _xml_extension_type = ElementExtension
    _xml_document = ResourceListsDocument

    id = XMLElementID('id', type=ID, required=True, test_equal=True)
    name = XMLElementChild('name', type=Name, required=True, test_equal=True)
    contacts = XMLElementChild('contacts',
                               type=ContactList,
                               required=True,
                               test_equal=True)

    def __init__(self, id, name, contacts=[]):
        XMLElement.__init__(self)
        self.id = id
        self.name = name
        self.contacts = ContactList(contacts)

    def __unicode__(self):
        return str(self.name)

    def __repr__(self):
        return '%s(%r, %r, contacts=%r)' % (self.__class__.__name__, self.id,
                                            self.name, list(self.contacts))
예제 #5
0
class DeviceInfo(XMLElement, ServiceExtension):
    _xml_tag = 'device-info'
    _xml_namespace = agp_pidf_namespace
    _xml_document = PIDFDocument
    _xml_children_order = {Description.qname: 0, UserAgent.qname: 1}

    id = XMLElementID('id', type=str, required=True, test_equal=True)
    description = XMLElementChild('description',
                                  type=Description,
                                  required=False,
                                  test_equal=True)
    user_agent = XMLElementChild('user_agent',
                                 type=UserAgent,
                                 required=False,
                                 test_equal=True)
    time_offset = XMLElementChild('time_offset',
                                  type=TimeOffset,
                                  required=False,
                                  test_equal=True)

    def __init__(self,
                 id,
                 description=None,
                 user_agent=None,
                 time_offset=None):
        XMLElement.__init__(self)
        self.id = id
        self.description = description
        self.user_agent = user_agent
        self.time_offset = time_offset

    def __repr__(self):
        return '%s(%r, %r, %r, %r)' % (self.__class__.__name__, self.id,
                                       self.description, self.user_agent,
                                       self.time_offset)
예제 #6
0
class Policy(XMLElement, ListElement):
    _xml_tag = 'policy-element'
    _xml_namespace = namespace
    _xml_extension_type = ElementExtension
    _xml_document = ResourceListsDocument

    id = XMLElementID('id', type=ID, required=True, test_equal=True)
    uri = XMLAttribute('uri', type=AnyURI, required=True, test_equal=True)

    name = XMLElementChild('name', type=Name, required=True, test_equal=True)
    dialog = XMLElementChild('dialog', type=DialogHandling, required=True, test_equal=True)
    presence = XMLElementChild('presence', type=PresenceHandling, required=True, test_equal=True)

    def __init__(self, id, uri, name='', presence_handling=None, dialog_handling=None):
        XMLElement.__init__(self)
        self.id = id
        self.uri = uri
        self.name = name
        self.dialog = dialog_handling or DialogHandling('default', False)
        self.presence = presence_handling or PresenceHandling('default', False)

    def __unicode__(self):
        return str(self.uri)

    def __repr__(self):
        return '%s(%r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id, self.uri, self.name, self.presence, self.dialog)
예제 #7
0
class External(XMLElement):
    _xml_tag = 'external'
    _xml_namespace = namespace
    _xml_document = ResourceListsDocument
    _xml_children_order = {DisplayName.qname: 0}

    anchor = XMLElementID('anchor',
                          type=AnyURI,
                          required=True,
                          test_equal=True)
    display_name = XMLElementChild('display_name',
                                   type=DisplayName,
                                   required=False,
                                   test_equal=False)

    def __init__(self, anchor, display_name=None):
        XMLElement.__init__(self)
        self.anchor = anchor
        self.display_name = display_name

    def __unicode__(self):
        return self.display_name and '"%s" <%s>' % (self.display_name,
                                                    self.anchor) or self.anchor

    def __repr__(self):
        return '%s(%r, %r)' % (self.__class__.__name__, self.anchor,
                               self.display_name)
예제 #8
0
class Document(XMLElement):
    _xml_tag = 'document'
    _xml_namespace = namespace
    _xml_document = XCAPDiffDocument

    selector = XMLElementID('selector', xmlname='sel', type=XCAPURI, required=True, test_equal=True)
    new_etag = XMLAttribute('new_etag', xmlname='new-etag', type=str, required=False, test_equal=True)
    previous_etag = XMLAttribute('previous_etag', xmlname='previous-etag', type=str, required=False, test_equal=True)
    body_not_changed = XMLElementChild('body_not_changed', type=BodyNotChanged, required=False, test_equal=True)

    def __init__(self, selector, new_etag=None, previous_etag=None):
        XMLElement.__init__(self)
        self.selector = selector
        self.new_etag = new_etag
        self.previous_etag = previous_etag

    def __repr__(self):
        return '%s(%r, %r, %r)' % (self.__class__.__name__, self.selector, self.new_etag, self.previous_etag)

    @property
    def empty_body(self):
        return self.body_not_changed is not None

    @empty_body.setter
    def empty_body(self, body_not_changed):
        if body_not_changed:
            self.body_not_changed = BodyNotChanged()
        else:
            self.body_not_changed = None
예제 #9
0
class List(XMLListElement):
    _xml_tag = 'list'
    _xml_namespace = namespace
    _xml_document = ResourceListsDocument
    _xml_children_order = {
        DisplayName.qname: 0,
        Entry.qname: 1,
        EntryRef.qname: 1,
        External.qname: 1
    }
    _xml_item_type = (Entry, EntryRef, External, List, ListElement)

    name = XMLElementID('name', type=str, required=False, test_equal=True)
    display_name = XMLElementChild('display_name',
                                   type=DisplayName,
                                   required=False,
                                   test_equal=False)

    def __init__(self, entries=[], name=None, display_name=None):
        XMLListElement.__init__(self)
        self.name = name
        self.display_name = display_name
        self.update(entries)

    def __repr__(self):
        return '%s(%s, %r, %r)' % (self.__class__.__name__, list(self),
                                   self.name, self.display_name)

    def __unicode__(self):
        name = 'List element'
        if self.name is not None:
            name += ' %s' % self.name
        if self.display_name is not None:
            name += ' (%s)' % self.display_name
        return name
예제 #10
0
class Service(XMLElement):
    _xml_tag = 'service'
    _xml_namespace = namespace
    _xml_document = RLSServicesDocument
    _xml_children_order = {
        List.qname: 0,
        ResourceList.qname: 0,
        Packages.qname: 1
    }

    uri = XMLElementID('uri', type=AnyURI, required=True, test_equal=True)
    list = XMLElementChoiceChild('list',
                                 types=(ResourceList, List),
                                 required=True,
                                 test_equal=True)
    packages = XMLElementChild('packages',
                               type=Packages,
                               required=False,
                               test_equal=True)

    def __init__(self, uri, list=None, packages=None):
        XMLElement.__init__(self)
        self.uri = uri
        self.list = list if list is not None else List()
        self.packages = packages if packages is not None else Packages()

    def __repr__(self):
        return '%s(%r, %r, %r)' % (self.__class__.__name__, self.uri,
                                   self.list, self.packages)
class WatcherList(XMLListElement):
    """
    Definition for a list of watchers in a watcherinfo document
    
    It behaves like a list in that it can be indexed by a number, can be
    iterated and counted.

    It also provides the properties pending, active and terminated which are
    generators returning Watcher objects with the corresponding status.
    """

    _xml_tag = 'watcher-list'
    _xml_namespace = namespace
    _xml_document = WatcherInfoDocument
    _xml_children_order = {Watcher.qname: 0}
    _xml_item_type = Watcher

    resource = XMLElementID('resource',
                            type=SIPURI,
                            required=True,
                            test_equal=True)
    package = XMLAttribute('package', type=str, required=True, test_equal=True)

    def __init__(self, resource, package, watchers=[]):
        XMLListElement.__init__(self)
        self.resource = resource
        self.package = package
        self.update(watchers)

    def __repr__(self):
        return '%s(%r, %r, %r)' % (self.__class__.__name__, self.resource,
                                   self.package, list(self))

    def __getitem__(self, key):
        if key is IterateIDs:
            return self._xmlid_map[Watcher].iterkeys()
        elif key is IterateItems:
            return self._xmlid_map[Watcher].itervalues()
        else:
            return self._xmlid_map[Watcher][key]

    def __delitem__(self, key):
        if key is All:
            for item in self._xmlid_map[Watcher].values():
                self.remove(item)
        else:
            self.remove(self._xmlid_map[Watcher][key])

    def get(self, key, default=None):
        return self._xmlid_map[Watcher].get(key, default)

    pending = property(lambda self: (watcher for watcher in self
                                     if watcher.status == 'pending'))
    waiting = property(lambda self: (watcher for watcher in self
                                     if watcher.status == 'waiting'))
    active = property(lambda self: (watcher for watcher in self
                                    if watcher.status == 'active'))
    terminated = property(lambda self: (watcher for watcher in self
                                        if watcher.status == 'terminated'))
예제 #12
0
class Device(XMLElement):
    _xml_tag = 'device'
    _xml_namespace = dm_namespace
    _xml_document = PIDFDocument
    _xml_extension_type = DeviceExtension
    _xml_children_order = {
        None: 0,
        DeviceID.qname: 1,
        DMNote.qname: 2,
        DeviceTimestamp.qname: 3
    }

    id = XMLElementID('id', type=ID, required=True, test_equal=True)
    device_id = XMLElementChild('device_id',
                                type=DeviceID,
                                required=False,
                                test_equal=True)
    timestamp = XMLElementChild('timestamp',
                                type=DeviceTimestamp,
                                required=False,
                                test_equal=True)

    _note_map = NoteMap()

    def __init__(self, id, device_id=None, notes=[], timestamp=None):
        XMLElement.__init__(self)
        self.id = id
        self.device_id = device_id
        self.timestamp = timestamp
        self.notes.update(notes)

    @property
    def notes(self):
        return NoteList(self, DMNote)

    def __eq__(self, other):
        if isinstance(other, Device):
            return super(Device,
                         self).__eq__(other) and self.notes == other.notes
        else:
            return self.id == other

    def __repr__(self):
        return '%s(%r, %r, %r, %r)' % (self.__class__.__name__, self.id,
                                       self.device_id, list(
                                           self.notes), self.timestamp)

    def _parse_element(self, element):
        super(Device, self)._parse_element(element)
        self.notes._parse_element(element)

    def _build_element(self):
        super(Device, self)._build_element()
        self.notes._build_element()
예제 #13
0
class XCAPDiff(XMLListRootElement):
    _xml_tag = 'xcap-diff'
    _xml_namespace = namespace
    _xml_document = XCAPDiffDocument
    _xml_item_type = (Document, Element, Attribute)

    xcap_root = XMLElementID('xcap_root', xmlname='xcap-root', type=str, required=True, test_equal=True)

    def __init__(self, xcap_root, children=[]):
        XMLListRootElement.__init__(self)
        self.xcap_root = xcap_root
        self.update(children)

    def __repr__(self):
        return '%s(%r, %r)' % (self.__class__.__name__, self.xcap_root, list(self))
예제 #14
0
class Attribute(XMLStringElement):
    _xml_tag = 'attribute'
    _xml_namespace = namespace
    _xml_document = XCAPDiffDocument

    selector = XMLElementID('selector', xmlname='sel', type=XCAPURI, required=True, test_equal=True)
    exists = XMLAttribute('exists', type=Boolean, required=False, test_equal=True)

    def __init__(self, selector, exists=None):
        XMLStringElement.__init__(self)
        self.selector = selector
        self.exists = exists

    def __repr__(self):
        return '%s(%r, %r)' % (self.__class__.__name__, self.selector, self.exists)
예제 #15
0
class Entry(XMLElement):
    _xml_tag = 'entry'
    _xml_namespace = namespace
    _xml_document = PresRulesDocument

    uri = XMLElementID('uri', xmlname='anc', type=AnyURI, required=True, test_equal=True)

    def __init__(self, uri):
        XMLElement.__init__(self)
        self.uri = uri

    def __unicode__(self):
        return self.uri

    def __str__(self):
        return str(self.uri)
예제 #16
0
class Resource(XMLListElement):
    _xml_tag = 'resource'
    _xml_namespace = namespace
    _xml_document = RLMIDocument
    _xml_item_type = (Name, Instance)

    uri = XMLElementID('uri', type=AnyURI, required=True, test_equal=True)

    def __init__(self, uri, items=[]):
        XMLElement.__init__(self)
        self.uri = uri
        self.update(items)

    def __repr__(self):
        return '%s(%r, items=%r)' % (self.__class__.__name__, self.uri,
                                     list(self))
예제 #17
0
class IdentityOne(XMLElement):
    _xml_tag = 'one'
    _xml_namespace = namespace
    _xml_document = CommonPolicyDocument

    id = XMLElementID('id', type=AnyURI, required=True, test_equal=True)

    def __init__(self, id):
        XMLElement.__init__(self)
        self.id = id

    def __repr__(self):
        return '%s(%r)' % (self.__class__.__name__, self.id)

    def __str__(self):
        return self.id

    def matches(self, uri):
        return self.id == uri
예제 #18
0
class Rule(XMLElement):
    _xml_tag = 'rule'
    _xml_namespace = namespace
    _xml_extension_type = RuleExtension
    _xml_document = CommonPolicyDocument
    _xml_children_order = {
        Conditions.qname: 0,
        Actions.qname: 1,
        Transformations.qname: 2
    }

    id = XMLElementID('id', type=ID, required=True, test_equal=True)

    conditions = XMLElementChild('conditions',
                                 type=Conditions,
                                 required=False,
                                 test_equal=True)
    actions = XMLElementChild('actions',
                              type=Actions,
                              required=False,
                              test_equal=True)
    transformations = XMLElementChild('transformations',
                                      type=Transformations,
                                      required=False,
                                      test_equal=True)

    def __init__(self,
                 id,
                 conditions=None,
                 actions=None,
                 transformations=None):
        XMLElement.__init__(self)
        self.id = id
        self.conditions = conditions
        self.actions = actions
        self.transformations = transformations

    def __repr__(self):
        return '%s(%r, %r, %r, %r)' % (self.__class__.__name__, self.id,
                                       self.conditions, self.actions,
                                       self.transformations)
예제 #19
0
class ContactURI(XMLElement):
    _xml_tag = 'uri'
    _xml_namespace = namespace
    _xml_extension_type = ElementExtension
    _xml_document = ResourceListsDocument

    id = XMLElementID('id', type=ID, required=True, test_equal=True)
    uri = XMLAttribute('uri', type=AnyURI, required=True, test_equal=True)
    type = XMLAttribute('type', type=str, required=False, test_equal=True)

    def __init__(self, id, uri, type=None):
        XMLElement.__init__(self)
        self.id = id
        self.uri = uri
        self.type = type

    def __unicode__(self):
        return str(self.uri)

    def __repr__(self):
        return '%s(%r, %r, %r)' % (self.__class__.__name__, self.id, self.uri, self.type)
예제 #20
0
class Contact(XMLElement, ListElement):
    _xml_tag = 'contact'
    _xml_namespace = namespace
    _xml_extension_type = ElementExtension
    _xml_document = ResourceListsDocument

    id = XMLElementID('id', type=ID, required=True, test_equal=True)

    name = XMLElementChild('name', type=Name, required=True, test_equal=True)
    uris = XMLElementChild('uris',
                           type=ContactURIList,
                           required=True,
                           test_equal=True)
    dialog = XMLElementChild('dialog',
                             type=DialogHandling,
                             required=True,
                             test_equal=True)
    presence = XMLElementChild('presence',
                               type=PresenceHandling,
                               required=True,
                               test_equal=True)

    def __init__(self,
                 id,
                 name,
                 uris=[],
                 presence_handling=None,
                 dialog_handling=None):
        XMLElement.__init__(self)
        self.id = id
        self.name = name
        self.uris = uris
        self.dialog = dialog_handling or DialogHandling('default', False)
        self.presence = presence_handling or PresenceHandling('default', False)

    def __repr__(self):
        return '%s(%r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id,
                                           self.name, list(self.uris),
                                           self.presence, self.dialog)
예제 #21
0
class EntryRef(XMLElement):
    _xml_tag = 'entry-ref'
    _xml_namespace = namespace
    _xml_document = ResourceListsDocument
    _xml_children_order = {DisplayName.qname: 0}

    ref = XMLElementID('ref', type=AnyURI, required=True, test_equal=True)
    display_name = XMLElementChild('display_name',
                                   type=DisplayName,
                                   required=False,
                                   test_equal=False)

    def __init__(self, ref, display_name=None):
        XMLElement.__init__(self)
        self.ref = ref
        self.display_name = display_name

    def __unicode__(self):
        return self.display_name and '"%s" <%s>' % (self.display_name,
                                                    self.ref) or self.ref

    def __repr__(self):
        return '%s(%r, %r)' % (self.__class__.__name__, self.ref,
                               self.display_name)
예제 #22
0
class Instance(XMLElement):
    _xml_tag = 'instance'
    _xml_namespace = namespace
    _xml_document = RLMIDocument

    id = XMLElementID('id', type=str, required=True, test_equal=True)
    state = XMLAttribute('state',
                         type=StateValue,
                         required=True,
                         test_equal=True)
    reason = XMLAttribute('reason', type=str, required=False, test_equal=True)
    cid = XMLAttribute('cid', type=str, required=False, test_equal=True)

    def __init__(self, id, state, reason=None, cid=None):
        XMLElement.__init__(self)
        self.id = id
        self.state = state
        self.reason = reason
        self.cid = cid

    def __repr__(self):
        return '%s(%r, state=%r, reason=%r, cid=%r)' % (
            self.__class__.__name__, self.id, self.state, self.reason,
            self.cid)
class Watcher(XMLAnyURIElement):
    """
    Definition for a watcher in a watcherinfo document

    Provides the attributes:
     * id
     * status
     * event
     * display_name
     * expiration
     * duration
     * sipuri

    Can be transformed to a string with the format DISPLAY_NAME <SIP_URI>.
    """

    _xml_tag = 'watcher'
    _xml_namespace = namespace
    _xml_document = WatcherInfoDocument
    _xml_value_type = SIPURI

    id = XMLElementID('id', type=str, required=True, test_equal=True)
    status = XMLAttribute('status',
                          type=WatcherStatus,
                          required=True,
                          test_equal=True)
    event = XMLAttribute('event',
                         type=WatcherEvent,
                         required=True,
                         test_equal=True)
    display_name = XMLAttribute('display_name',
                                xmlname='display-name',
                                type=str,
                                required=False,
                                test_equal=True)
    expiration = XMLAttribute('expiration',
                              type=UnsignedLong,
                              required=False,
                              test_equal=False)
    duration = XMLAttribute('duration',
                            xmlname='duration-subscribed',
                            type=UnsignedLong,
                            required=False,
                            test_equal=False)

    sipuri = XMLAnyURIElement.value

    def __init__(self,
                 sipuri,
                 id,
                 status,
                 event,
                 display_name=None,
                 expiration=None,
                 duration=None):
        XMLAnyURIElement.__init__(self)
        self.sipuri = sipuri
        self.id = id
        self.status = status
        self.event = event
        self.display_name = display_name
        self.expiration = expiration
        self.duration = duration

    def __repr__(self):
        return '%s(%r, %r, %r, %r, %r, %r, %r)' % (
            self.__class__.__name__, self.sipuri, self.id, self.status,
            self.event, self.display_name, self.expiration, self.duration)

    def __str__(self):
        return '"%s" <%s>' % (self.display_name, self.sipuri
                              ) if self.display_name else self.sipuri
예제 #24
0
class Service(XMLListElement):
    _xml_tag = 'tuple'
    _xml_namespace = pidf_namespace
    _xml_document = PIDFDocument
    _xml_extension_type = ServiceExtension
    _xml_item_type = (DeviceID, ServiceItemExtension)
    _xml_children_order = {
        Status.qname: 0,
        None: 1,
        Contact.qname: 2,
        PIDFNote.qname: 3,
        ServiceTimestamp.qname: 4
    }

    id = XMLElementID('id', type=ID, required=True, test_equal=True)

    status = XMLElementChild('status',
                             type=Status,
                             required=True,
                             test_equal=True)
    contact = XMLElementChild('contact',
                              type=Contact,
                              required=False,
                              test_equal=True)
    timestamp = XMLElementChild('timestamp',
                                type=ServiceTimestamp,
                                required=False,
                                test_equal=True)

    _note_map = NoteMap()

    def __init__(self,
                 id,
                 notes=[],
                 status=None,
                 contact=None,
                 timestamp=None):
        XMLListElement.__init__(self)
        self.id = id
        self.status = status
        self.contact = contact
        self.timestamp = timestamp
        self.notes.update(notes)

    @property
    def notes(self):
        return NoteList(self, PIDFNote)

    def __eq__(self, other):
        if isinstance(other, Service):
            return super(Service,
                         self).__eq__(other) and self.notes == other.notes
        else:
            return self.id == other

    def __repr__(self):
        return '%s(%r, %r, %r, %r, %r)' % (self.__class__.__name__, self.id,
                                           list(self.notes), self.status,
                                           self.contact, self.timestamp)

    def _parse_element(self, element):
        super(Service, self)._parse_element(element)
        self.notes._parse_element(element)

    def _build_element(self):
        super(Service, self)._build_element()
        self.notes._build_element()