def to_sax(walker, handler):
 handler.startDocument()
 for (prefix, namespace) in prefix_mapping.items():
  handler.startPrefixMapping(prefix, namespace)
 for token in walker:
  type = token[u'type']
  if (type == u'Doctype'):
   continue
  elif (type in (u'StartTag', u'EmptyTag')):
   attrs = AttributesNSImpl(token[u'data'], unadjustForeignAttributes)
   handler.startElementNS((token[u'namespace'], token[u'name']), token[u'name'], attrs)
   if (type == u'EmptyTag'):
    handler.endElementNS((token[u'namespace'], token[u'name']), token[u'name'])
  elif (type == u'EndTag'):
   handler.endElementNS((token[u'namespace'], token[u'name']), token[u'name'])
  elif (type in (u'Characters', u'SpaceCharacters')):
   handler.characters(token[u'data'])
  elif (type == u'Comment'):
   pass
  else:
   assert False, u'Unknown token type'
 for (prefix, namespace) in prefix_mapping.items():
  handler.endPrefixMapping(prefix)
 handler.endDocument()

def to_sax ( walker , handler ) : handler . startDocument ( ) for ( prefix , namespace ) in prefix_mapping . items ( ) : handler . startPrefixMapping ( prefix , namespace ) for token in walker : type = token [ u'type' ] if ( type == u'Doctype' ) : continue elif ( type in ( u'StartTag' , u'EmptyTag' ) ) : attrs = AttributesNSImpl ( token [ u'data' ] , unadjustForeignAttributes ) handler . startElementNS ( ( token [ u'namespace' ] , token [ u'name' ] ) , token [ u'name' ] , attrs ) if ( type == u'EmptyTag' ) : handler . endElementNS ( ( token [ u'namespace' ] , token [ u'name' ] ) , token [ u'name' ] ) elif ( type == u'EndTag' ) : handler . endElementNS ( ( token [ u'namespace' ] , token [ u'name' ] ) , token [ u'name' ] ) elif ( type in ( u'Characters' , u'SpaceCharacters' ) ) : handler . characters ( token [ u'data' ] ) elif ( type == u'Comment' ) : pass else : assert False , u'Unknown token type' for ( prefix , namespace ) in prefix_mapping . items ( ) : handler . endPrefixMapping ( prefix ) handler . endDocument ( )
call sax-like content handler based on treewalker walker .