slidge.slixfix.link_preview.stanza
#
Module Contents#
Classes#
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
|
The core of Slixmpp's stanza XML manipulation and handling is provided |
- class slidge.slixfix.link_preview.stanza.LinkPreview(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.OpenGraphMixin(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.Title(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.Description(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.Url(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.Image(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.Type_(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase
- class slidge.slixfix.link_preview.stanza.SiteName(xml=None, parent=None)#
The core of Slixmpp’s stanza XML manipulation and handling is provided by ElementBase. ElementBase wraps XML ElementTree objects and enables access to the XML contents through dictionary syntax, similar in style to the Ruby XMPP library Blather’s stanza implementation.
Stanzas are defined by their name, namespace, and interfaces. For example, a simplistic Message stanza could be defined as:
>>> class Message(ElementBase): ... name = "message" ... namespace = "jabber:client" ... interfaces = {'to', 'from', 'type', 'body'} ... sub_interfaces = {'body'}
The resulting Message stanza’s contents may be accessed as so:
>>> message['to'] = "user@example.com" >>> message['body'] = "Hi!" >>> message['body'] "Hi!" >>> del message['body'] >>> message['body'] ""
The interface values map to either custom access methods, stanza XML attributes, or (if the interface is also in sub_interfaces) the text contents of a stanza’s subelement.
Custom access methods may be created by adding methods of the form “getInterface”, “setInterface”, or “delInterface”, where “Interface” is the titlecase version of the interface name.
Stanzas may be extended through the use of plugins. A plugin is simply a stanza that has a plugin_attrib value. For example:
>>> class MessagePlugin(ElementBase): ... name = "custom_plugin" ... namespace = "custom" ... interfaces = {'useful_thing', 'custom'} ... plugin_attrib = "custom"
The plugin stanza class must be associated with its intended container stanza by using register_stanza_plugin as so:
>>> register_stanza_plugin(Message, MessagePlugin)
The plugin may then be accessed as if it were built-in to the parent stanza:
>>> message['custom']['useful_thing'] = 'foo'
If a plugin provides an interface that is the same as the plugin’s plugin_attrib value, then the plugin’s interface may be assigned directly from the parent stanza, as shown below, but retrieving information will require all interfaces to be used, as so:
>>> # Same as using message['custom']['custom'] >>> message['custom'] = 'bar' >>> # Must use all interfaces >>> message['custom']['custom'] 'bar'
If the plugin sets
is_extension
toTrue
, then both setting and getting an interface value that is the same as the plugin’s plugin_attrib value will work, as so:>>> message['custom'] = 'bar' # Using is_extension=True >>> message['custom'] 'bar'
- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – Initialize the stanza object with an existing XML object.
parent (Union[Optional[ElementBase], weakref.ReferenceType[ElementBase]]) – Optionally specify a parent stanza object will contain this substanza.
- setup(xml=None)#
Initialize the stanza’s XML contents.
Will return
True
if XML was generated according to the stanza’s definition instead of building a stanza object from an existing XML object.- Parameters:
xml (Optional[xml.etree.ElementTree.Element]) – An existing XML object to use for the stanza’s content instead of generating new XML.
- Return type:
- enable(attrib, lang=None)#
Enable and initialize a stanza plugin.
Alias for
init_plugin()
.- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
- Return type:
ElementBase
- get_plugin(name, lang=None, check=False)#
Retrieve a stanza plugin.
- init_plugin(attrib, lang=None, existing_xml=None, reuse=True, element=None)#
Enable and initialize a stanza plugin.
- Parameters:
attrib (string) – The
plugin_attrib
value of the plugin to enable.lang (Optional[str]) –
existing_xml (Optional[xml.etree.ElementTree.Element]) –
reuse (bool) –
element (Optional[ElementBase]) –
- Return type:
ElementBase
- match(xpath)#
Compare a stanza object with an XPath-like expression.
If the XPath matches the contents of the stanza object, the match is successful.
The XPath expression may include checks for stanza attributes. For example:
'presence@show=xa@priority=2/status'
Would match a presence stanza whose show value is set to
'xa'
, has a priority value of'2'
, and has a status element.- Parameters:
xpath (string) – The XPath expression to check against. It may be either a string or a list of element names with attribute checks.
- Return type:
- get(key, default=None)#
Return the value of a stanza interface.
If the found value is None or an empty string, return the supplied default value.
Allows stanza objects to be used like dictionaries.
- Parameters:
key (string) – The name of the stanza interface to check.
default (Optional[Any]) – Value to return if the stanza interface has a value of
None
or""
. Will default to returning None.
- Return type:
Any
- keys()#
Return the names of all stanza interfaces provided by the stanza object.
Allows stanza objects to be used like dictionaries.
- Return type:
List[str]
- append(item)#
Append either an XML object or a substanza to this stanza object.
If a substanza object is appended, it will be added to the list of iterable stanzas.
Allows stanza objects to be used like lists.
- Parameters:
item (Union[xml.etree.ElementTree.Element, ElementBase]) – Either an XML object or a stanza object to add to this stanza’s contents.
- Return type:
ElementBase
- appendxml(xml)#
Append an XML object to the stanza’s XML.
The added XML will not be included in the list of iterable substanzas.
- Parameters:
xml (XML) – The XML object to add to the stanza.
- Return type:
ElementBase
- pop(index=0)#
Remove and return the last substanza in the list of iterable substanzas.
Allows stanza objects to be used like lists.
- Parameters:
index (int) – The index of the substanza to remove.
- Return type:
ElementBase
- next()#
Return the next iterable substanza.
- Return type:
ElementBase
- clear()#
Remove all XML element contents and plugins.
Any attribute values will be preserved.
- Return type:
ElementBase