parameters: (self, mmaps_queue, coords_callback=None)
docstring: Read and chunk all
docstring_summary: Read and chunk all
docstring_tokens: Read and chunk all
function: def read(self, mmaps_queue, coords_callback=None):
          """
          Read and chunk all
          """
          coord_node_match = None
          xml_nodes = self._new_xml_outstream()
          coords = []
          coord_node_re_match = re.compile(r'^\s*<node id="(\d+)" .*lat="([-0-9.]+)" '
                                            'lon="([-0-9.]+)".*/>').match
          node_re_match = re.compile(r'^\s*<node .*/>').match
          xml_nodes.write(self._last_line)
          split = False
          line = ''
          for line in self.stream:
              if coords_callback:
                  coord_node_match = coord_node_re_match(line)
                  if coord_node_match:
                      osm_id, lat, lon = coord_node_match.groups()
                      coords.append((int(osm_id), float(lon), float(lat)))
                      if len(coords) >= 512:
                          coords_callback(coords)
                          coords = []
                  else:
                      xml_nodes.write(line)
              else:
                  xml_nodes.write(line)
              if split:
                  if (line.rstrip().endswith(('</way>', '</node>', '</relation>'))
                      or (coords_callback and coord_node_match)
                      or (not coords_callback and node_re_match(line))):
                      mmaps_queue.put(self._finished_xml_outstream(line, xml_nodes))
                      xml_nodes = self._new_xml_outstream()
                      split = False
              elif xml_nodes.tell() > self.size:
                  split = True
          if coords_callback:
              coords_callback(coords)
  
          # we are at the end of the stream and assume we wrote the end tag
          # to xml_nodes. we set line to closing tag here to avoid additional
          # end tag in case the last line(s) is blank
          line = '</osm'
          mmaps_queue.put(self._finished_xml_outstream(line, xml_nodes))
function_tokens: def read ( self , mmaps_queue , coords_callback = None ) : coord_node_match = None xml_nodes = self . _new_xml_outstream ( ) coords = [ ] coord_node_re_match = re . compile ( r'^\s*<node id="(\d+)" .*lat="([-0-9.]+)" ' 'lon="([-0-9.]+)".*/>' ) . match node_re_match = re . compile ( r'^\s*<node .*/>' ) . match xml_nodes . write ( self . _last_line ) split = False line = '' for line in self . stream : if coords_callback : coord_node_match = coord_node_re_match ( line ) if coord_node_match : osm_id , lat , lon = coord_node_match . groups ( ) coords . append ( ( int ( osm_id ) , float ( lon ) , float ( lat ) ) ) if len ( coords ) >= 512 : coords_callback ( coords ) coords = [ ] else : xml_nodes . write ( line ) else : xml_nodes . write ( line ) if split : if ( line . rstrip ( ) . endswith ( ( '</way>' , '</node>' , '</relation>' ) ) or ( coords_callback and coord_node_match ) or ( not coords_callback and node_re_match ( line ) ) ) : mmaps_queue . put ( self . _finished_xml_outstream ( line , xml_nodes ) ) xml_nodes = self . _new_xml_outstream ( ) split = False elif xml_nodes . tell ( ) > self . size : split = True if coords_callback : coords_callback ( coords ) # we are at the end of the stream and assume we wrote the end tag # to xml_nodes. we set line to closing tag here to avoid additional # end tag in case the last line(s) is blank line = '</osm' mmaps_queue . put ( self . _finished_xml_outstream ( line , xml_nodes ) )