(cls,tag,thing = None,*args,**kwargs)
| 64 | print xml(e) |
| 65 | """ |
| 66 | def __new__(cls,tag,thing = None,*args,**kwargs): |
| 67 | if hasattr(tag,'__xml__'): |
| 68 | return tag.__xml__() |
| 69 | self = object.__new__(xml) |
| 70 | if cElementTree.iselement(tag): |
| 71 | self.__content = tag |
| 72 | elif isinstance(tag,cElementTree.ElementTree): |
| 73 | self.__content = tag.getroot() |
| 74 | elif is_file(tag): |
| 75 | self.__content = cElementTree.parse(tag).getroot() |
| 76 | elif isinstance(tag,str) and len(tag) > 0 and tag[0] == '<': |
| 77 | self.__content = cElementTree.fromstring(tag) |
| 78 | else: |
| 79 | if type(tag) != str: |
| 80 | raise TypeError("Cannot convert %s object to xml" % str(type(tag))) |
| 81 | self.__content = cElementTree.fromstring('<%s/>' % tag) |
| 82 | if is_text(thing) or type(thing) == int: |
| 83 | self.__content.text = text(thing) |
| 84 | elif thing != None: |
| 85 | self.append(xml(thing)) |
| 86 | for subthing in args: |
| 87 | self.append(xml(subthing)) |
| 88 | for key,value in kwargs.items(): |
| 89 | if key == '__class' or key == 'klass': |
| 90 | self['class'] = value |
| 91 | else: |
| 92 | self[key] = value |
| 93 | if '{' in self.__content.tag: |
| 94 | self.__prefix = PREFIX_PAT.search(self.__content.tag).groups()[0] |
| 95 | else: |
| 96 | self.__prefix = '' |
| 97 | return self |
| 98 | def clear(self): |
| 99 | self.__content.clear() |
| 100 | def append(self,xml_obj): |
nothing calls this directly
no test coverage detected