Exemple #1
0
 def __init__(self, out=None, encoding='iso-8859-1', short_empty_elements=False):
     xmltodict.XMLGenerator.__bases__.__init__(self)
     buf = BufferedIOBase()
     buf.writable = lambda : True
     buf.write = out.write
     ioWrapper = TextIOWrapper(buf, encoding=encoding, errors='xmlcharrefreplace', newline='\n')
     self._write = ioWrapper.write
     self._flush = ioWrapper.flush
     self._ns_contexts = [{}]
     self._current_context = self._ns_contexts[-1]
     self._undeclared_ns_maps = []
     self._encoding = encoding
Exemple #2
0
 def __init__(self,
              out=None,
              encoding='iso-8859-1',
              short_empty_elements=False):
     """
     :param out: output object
     :param encoding: output encoding
     :param short_empty_elements: unused parameter needed for compatibility
     """
     xmltodict.XMLGenerator.__bases__.__init__(self)
     buffer = BufferedIOBase()
     buffer.writable = lambda: True
     buffer.write = out.write
     ioWrapper = TextIOWrapper(buffer,
                               encoding=encoding,
                               errors='xmlcharrefreplace',
                               newline='\n')
     self._write = ioWrapper.write
     self._flush = ioWrapper.flush
     self._ns_contexts = [{}]
     self._current_context = self._ns_contexts[-1]
     self._undeclared_ns_maps = []
     self._encoding = encoding
Exemple #3
0
 def readinto(self,
              target_stream: io.BufferedIOBase,
              read_buffer_size: int = 1024 * 1024,
              decode_unicode: bool = False):
     """copy bytes from the ResponseIO to target stream.
     Useage: \n
     ha = HttpAccess()\n
     respio = ha.get_response_stream(\n
         'https://www.google.com',\n
         headers='''\n
         accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\n
         accept-encoding:gzip, deflate, br\n
         accept-language:,zh-CN,zh;q=0.9\n
         ''')\n        
     with open('filepath', mode='wb') as fs:\n
         respio.readinto(fs)\n
     """
     if not isinstance(target_stream, io.IOBase):
         raise Exception("target stream is not a io object")
     if not target_stream.writable():
         raise Exception("target stream is not writable")
     for bs in self.read_block(read_buffer_size=read_buffer_size,
                               decode_unicode=decode_unicode):
         target_stream.write(bs)