Server IP : 85.214.239.14 / Your IP : 3.145.51.35 Web Server : Apache/2.4.62 (Debian) System : Linux h2886529.stratoserver.net 4.9.0 #1 SMP Tue Jan 9 19:45:01 MSK 2024 x86_64 User : www-data ( 33) PHP Version : 7.4.18 Disable Function : pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare, MySQL : OFF | cURL : OFF | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /proc/3/task/3/cwd/srv/modoboa/env/lib/python3.5/site-packages/caldav/elements/ |
Upload File : |
#!/usr/bin/env python # -*- encoding: utf-8 -*- from lxml import etree from six import PY3 from caldav.lib.namespace import nsmap from caldav.lib.python_utilities import to_unicode class BaseElement(object): children = None tag = None value = None attributes = None def __init__(self, name=None, value=None): self.children = [] self.attributes = {} value = to_unicode(value) self.value = None if name is not None: self.attributes['name'] = name if value is not None: self.value = value def __add__(self, other): return self.append(other) def __str__(self): utf8 = etree.tostring(self.xmlelement(), encoding="utf-8", xml_declaration=True, pretty_print=True) if PY3: return str(utf8, 'utf-8') return utf8 def xmlelement(self): root = etree.Element(self.tag, nsmap=nsmap) if self.value is not None: root.text = self.value if len(self.attributes) > 0: for k in list(self.attributes.keys()): root.set(k, self.attributes[k]) self.xmlchildren(root) return root def xmlchildren(self, root): for c in self.children: root.append(c.xmlelement()) def append(self, element): try: iter(element) self.children.extend(element) except TypeError: self.children.append(element) return self class NamedBaseElement(BaseElement): def __init__(self, name=None): super(NamedBaseElement, self).__init__(name=name) def xmlelement(self): if self.attributes.get('name') is None: raise Exception("name attribute must be defined") return super(NamedBaseElement, self).xmlelement() class ValuedBaseElement(BaseElement): def __init__(self, value=None): super(ValuedBaseElement, self).__init__(value=value)