stream_error.py 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. """
  2. SleekXMPP: The Sleek XMPP Library
  3. Copyright (C) 2010 Nathanael C. Fritz
  4. This file is part of SleekXMPP.
  5. See the file LICENSE for copying permission.
  6. """
  7. from sleekxmpp.stanza.error import Error
  8. from sleekxmpp.xmlstream import StanzaBase
  9. class StreamError(Error, StanzaBase):
  10. """
  11. XMPP stanzas of type 'error' should include an <error> stanza that
  12. describes the nature of the error and how it should be handled.
  13. Use the 'XEP-0086: Error Condition Mappings' plugin to include error
  14. codes used in older XMPP versions.
  15. The stream:error stanza is used to provide more information for
  16. error that occur with the underlying XML stream itself, and not
  17. a particular stanza.
  18. Note: The StreamError stanza is mostly the same as the normal
  19. Error stanza, but with different namespaces and
  20. condition names.
  21. Example error stanza:
  22. <stream:error>
  23. <not-well-formed xmlns="urn:ietf:params:xml:ns:xmpp-streams" />
  24. <text xmlns="urn:ietf:params:xml:ns:xmpp-streams">
  25. XML was not well-formed.
  26. </text>
  27. </stream:error>
  28. Stanza Interface:
  29. condition -- The name of the condition element.
  30. text -- Human readable description of the error.
  31. Attributes:
  32. conditions -- The set of allowable error condition elements.
  33. condition_ns -- The namespace for the condition element.
  34. Methods:
  35. setup -- Overrides ElementBase.setup.
  36. get_condition -- Retrieve the name of the condition element.
  37. set_condition -- Add a condition element.
  38. del_condition -- Remove the condition element.
  39. get_text -- Retrieve the contents of the <text> element.
  40. set_text -- Set the contents of the <text> element.
  41. del_text -- Remove the <text> element.
  42. """
  43. namespace = 'http://etherx.jabber.org/streams'
  44. interfaces = set(('condition', 'text', 'see_other_host'))
  45. conditions = set((
  46. 'bad-format', 'bad-namespace-prefix', 'conflict',
  47. 'connection-timeout', 'host-gone', 'host-unknown',
  48. 'improper-addressing', 'internal-server-error', 'invalid-from',
  49. 'invalid-namespace', 'invalid-xml', 'not-authorized',
  50. 'not-well-formed', 'policy-violation', 'remote-connection-failed',
  51. 'reset', 'resource-constraint', 'restricted-xml', 'see-other-host',
  52. 'system-shutdown', 'undefined-condition', 'unsupported-encoding',
  53. 'unsupported-feature', 'unsupported-stanza-type',
  54. 'unsupported-version'))
  55. condition_ns = 'urn:ietf:params:xml:ns:xmpp-streams'
  56. def get_see_other_host(self):
  57. ns = self.condition_ns
  58. return self._get_sub_text('{%s}see-other-host' % ns, '')
  59. def set_see_other_host(self, value):
  60. if value:
  61. del self['condition']
  62. ns = self.condition_ns
  63. return self._set_sub_text('{%s}see-other-host' % ns, value)
  64. elif self['condition'] == 'see-other-host':
  65. del self['condition']
  66. def del_see_other_host(self):
  67. self._del_sub('{%s}see-other-host' % self.condition_ns)