Parameters ---------- file : writable text file-like object
| 105 | |
| 106 | |
| 107 | class _XMLWriter: |
| 108 | """ |
| 109 | Parameters |
| 110 | ---------- |
| 111 | file : writable text file-like object |
| 112 | """ |
| 113 | |
| 114 | def __init__(self, file): |
| 115 | self.__write = file.write |
| 116 | if hasattr(file, "flush"): |
| 117 | self.flush = file.flush |
| 118 | self.__open = 0 # true if start tag is open |
| 119 | self.__tags = [] |
| 120 | self.__data = [] |
| 121 | self.__indentation = " " * 64 |
| 122 | |
| 123 | def __flush(self, indent=True): |
| 124 | # flush internal buffers |
| 125 | if self.__open: |
| 126 | if indent: |
| 127 | self.__write(">\n") |
| 128 | else: |
| 129 | self.__write(">") |
| 130 | self.__open = 0 |
| 131 | if self.__data: |
| 132 | data = ''.join(self.__data) |
| 133 | self.__write(_escape_cdata(data)) |
| 134 | self.__data = [] |
| 135 | |
| 136 | def start(self, tag, attrib=None, **extra): |
| 137 | """ |
| 138 | Open a new element. Attributes can be given as keyword |
| 139 | arguments, or as a string/string dictionary. The method returns |
| 140 | an opaque identifier that can be passed to the :meth:`close` |
| 141 | method, to close all open elements up to and including this one. |
| 142 | |
| 143 | Parameters |
| 144 | ---------- |
| 145 | tag |
| 146 | Element tag. |
| 147 | attrib |
| 148 | Attribute dictionary. Alternatively, attributes can be given as |
| 149 | keyword arguments. |
| 150 | |
| 151 | Returns |
| 152 | ------- |
| 153 | An element identifier. |
| 154 | """ |
| 155 | if attrib is None: |
| 156 | attrib = {} |
| 157 | self.__flush() |
| 158 | tag = _escape_cdata(tag) |
| 159 | self.__data = [] |
| 160 | self.__tags.append(tag) |
| 161 | self.__write(self.__indentation[:len(self.__tags) - 1]) |
| 162 | self.__write(f"<{tag}") |
| 163 | for k, v in {**attrib, **extra}.items(): |
| 164 | if v: |
no outgoing calls
no test coverage detected
searching dependent graphs…