Call SAX-like content handler based on treewalker walker

    :arg walker: the treewalker to use to walk the tree to convert it

    :arg handler: SAX handler to use
778487
def to_sax(walker, handler):
    
    handler.startDocument()
    for prefix, namespace in prefix_mapping.items():
        handler.startPrefixMapping(prefix, namespace)

    for token in walker:
        type = token["type"]
        if type == "Doctype":
            continue
        elif type in ("StartTag", "EmptyTag"):
            attrs = AttributesNSImpl(token["data"],
                                     unadjustForeignAttributes)
            handler.startElementNS((token["namespace"], token["name"]),
                                   token["name"],
                                   attrs)
            if type == "EmptyTag":
                handler.endElementNS((token["namespace"], token["name"]),
                                     token["name"])
        elif type == "EndTag":
            handler.endElementNS((token["namespace"], token["name"]),
                                 token["name"])
        elif type in ("Characters", "SpaceCharacters"):
            handler.characters(token["data"])
        elif type == "Comment":
            pass
        else:
            assert False, "Unknown token type"

    for prefix, namespace in prefix_mapping.items():
        handler.endPrefixMapping(prefix)
    handler.endDocument()
94400
function TreeWalker(root, whatToShow, filter) {
  if (!root || !root.nodeType) {
    utils.NotSupportedError();
  }

  // Read-only properties
  this._root = root;
  this._whatToShow = Number(whatToShow) || 0;
  this._filter = filter || null;
  this._active = false;
  // Read-write property
  this._currentNode = root;
}
731183
def createPushParser(SAX, chunk, size, URI):
    
    ret = libxml2mod.xmlCreatePushParser(SAX, chunk, size, URI)
    if ret is None:raise parserError('xmlCreatePushParser() failed')
    return parserCtxt(_obj=ret)
565337
public static void main(String[] args) throws Exception {

    NormalAlphabet na = new NormalAlphabet();
    SAXProcessor sp = new SAXProcessor();

    String dataFileName = args[0];

    System.out.println("data file: " + dataFileName);
    double[] ts = TSProcessor.readFileColumn(dataFileName, 0, 0);
    System.out.println("data size: " + ts.length);
    System.out.println("SAX parameters:\n sliding window sizes: " + Arrays.toString(WINDOWS)
        + "\n PAA sizes: " + Arrays.toString(PAAS) + "\n alphabet sizes: "
        + Arrays.toString(ALPHABETS) + "\n NR strategis: " + Arrays.toString(NRS));

    System.out.println(
        "Performing " + NRUNS + " SAX conversion runs for each algorithm implementation ... ");

    // conventional
    //
    long tstamp1 = System.currentTimeMillis();
    for (int slidingWindowSize : WINDOWS) {
      for (int paaSize : PAAS) {
        for (int alphabetSize : ALPHABETS) {
          for (String nrStrategy : NRS) {

            for (int i = 0; i < NRUNS; i++) {
              @SuppressWarnings("unused")
              SAXRecords sequentialRes = sp.ts2saxViaWindow(ts, slidingWindowSize, paaSize,
                  na.getCuts(alphabetSize), NumerosityReductionStrategy.fromString(nrStrategy),
                  N_THRESHOLD);
            }

          }
        }
      }
    }
    long tstamp2 = System.currentTimeMillis();
    System.out.println("single thread conversion: " + String.valueOf(tstamp2 - tstamp1) + ", "
        + SAXProcessor.timeToString(tstamp1, tstamp2));

    // parallel
    for (int threadsNum = MIN_CPUS; threadsNum < MAX_CPUS; threadsNum++) {
      tstamp1 = System.currentTimeMillis();

      for (int slidingWindowSize : WINDOWS) {
        for (int paaSize : PAAS) {
          for (int alphabetSize : ALPHABETS) {
            for (String nrStrategy : NRS) {

              for (int i = 0; i < NRUNS; i++) {
                ParallelSAXImplementation ps = new ParallelSAXImplementation();
                @SuppressWarnings("unused")
                SAXRecords parallelRes = ps.process(ts, threadsNum, slidingWindowSize, paaSize,
                    alphabetSize, NumerosityReductionStrategy.fromString(nrStrategy), N_THRESHOLD);
              }

            }
          }
        }
      }

      tstamp2 = System.currentTimeMillis();
      System.out.println("parallel conversion using " + threadsNum + " threads: "
          + String.valueOf(tstamp2 - tstamp1) + ", " + SAXProcessor.timeToString(tstamp1, tstamp2));
    }
  }
377297
def walk(self, node):
        ""
        node = self.visit(node)

        if node is None:
            return None

        if isinstance(node, parso.tree.BaseNode):
            walked = map(self.walk, node.children)
            node.children = [child for child in walked if child is not None]

        return node
940443
def walk(self, path = None, topdown=True):
        

        if path is None:
            path = self.root

        root = self.find(path)

        if not root.isdir():
            raise ValueError("can only walk storage types")

        if not root.child_id:
            return

        if topdown:
            storage_items = []
            stream_items = []

            for item in self.listdir(root):
                if item.isdir():
                    storage_items.append(item)
                else:
                    stream_items.append(item)

            yield root, storage_items, stream_items

            for item in storage_items:
                for root, storage_items, stream_items in self.walk(item):
                    yield root, storage_items, stream_items
        else:

            def topdown_visit_node(root):
                storage_items = []
                stream_items = []
                for item in self.listdir(root):
                    if item.isdir():
                        for sub_root, sub_storage, sub_stream in topdown_visit_node(item):
                            yield sub_root, sub_storage, sub_stream

                        storage_items.append(item)
                    else:
                        stream_items.append(item)

                yield root, storage_items, stream_items

            for root_item, storage, stream in topdown_visit_node(root):
                yield root_item, storage, stream
461246
def call_command_handler(command, pymux, arguments):
    
    assert isinstance(arguments, list)

    # Resolve aliases.
    command = ALIASES.get(command, command)

    try:
        handler = COMMANDS_TO_HANDLERS[command]
    except KeyError:
        pymux.show_message('Invalid command: %s' % (command,))
    else:
        try:
            handler(pymux, arguments)
        except CommandException as e:
            pymux.show_message(e.message)
1073616
function ( root ) {
    var walker = new TreeWalker( root, SHOW_TEXT, function () {
            return true;
        }, false ),
        parent, node, index;
    while ( node = walker.nextNode() ) {
        while ( ( index = node.data.indexOf( ZWS ) ) > -1 ) {
            if ( node.length === 1 ) {
                do {
                    parent = node.parentNode;
                    parent.removeChild( node );
                    node = parent;
                    walker.currentNode = parent;
                } while ( isInline( node ) && !getLength( node ) );
                break;
            } else {
                node.deleteData( index, 1 );
            }
        }
    }
}
29893
def _dispatch_change_event(self, object, trait_name, old, new, handler):
    

    # Extract the arguments needed from the handler.
    args = self.argument_transform(object, trait_name, old, new)

    # Send a description of the event to the change event tracer.
    if tnotifier._pre_change_event_tracer is not None:
        tnotifier._pre_change_event_tracer(object, trait_name, old, new, handler)

    # Dispatch the event to the listener.
    from automate.common import SystemNotReady
    try:
        self.dispatch(handler, *args)
    except SystemNotReady:
        pass
    except Exception as e:
        if tnotifier._post_change_event_tracer is not None:
            tnotifier._post_change_event_tracer(object, trait_name, old, new,
                                                handler, exception=e)
        # This call needs to be made inside the `except` block in case
        # the handler wants to re-raise the exception.
        tnotifier.handle_exception(object, trait_name, old, new)
    else:
        if tnotifier._post_change_event_tracer is not None:
            tnotifier._post_change_event_tracer(object, trait_name, old, new,
                                                handler, exception=None)
244479
public void dispatchToEvents(int nodeHandle, org.xml.sax.ContentHandler ch)
          throws org.xml.sax.SAXException
  {
    TreeWalker treeWalker = m_walker;
    ContentHandler prevCH = treeWalker.getContentHandler();
    
    if(null != prevCH)
    {
      treeWalker = new TreeWalker(null);
    }
    treeWalker.setContentHandler(ch);
    
    try
    {
      Node node = getNode(nodeHandle);
      treeWalker.traverseFragment(node);
    }
    finally
    {
      treeWalker.setContentHandler(null);
    }
  }
420915
def add_handler(self, path, handler):
        
        self.signatures[path] = self.get_path_signature(path)
        self.handlers[path] = handler
388427
public void processingInstruction(String arg0, String arg1)
        throws SAXException
    {
        if (m_tracer != null)
            super.fireEscapingEvent(arg0, arg1);
    }
1284615
def walk(self):
        """"""
        yield self
        if self.has_arguments():
            for arg in self.args_definition:
                if not arg["name"] in self.arguments:
                    continue
                value = self.arguments[arg["name"]]
                if type(value) == list:
                    if self.__get_arg_type(arg["name"]) == ["testlist"]:
                        for t in value:
                            for node in t.walk():
                                yield node
                if isinstance(value, Command):
                    for node in value.walk():
                        yield node
        for ch in self.children:
            for node in ch.walk():
                yield node
852228
private InvocationHandlerAdapter getInvocationHandlerAdapter(Object marker) {
        if (marker == null) {
            return null;
        }

        return markerToHandler.get(marker);
    }
1195032
def htmlCreatePushParser(SAX, chunk, size, URI):
    
    ret = libxml2mod.htmlCreatePushParser(SAX, chunk, size, URI)
    if ret is None:raise parserError('htmlCreatePushParser() failed')
    return parserCtxt(_obj=ret)
913173
def _walker(self, path):
        """"""
        for root, dnames, fnames in _walk(self.recursion)(path):
            yield (root, dnames, fnames)
1219897
public void walk(ChuckWalker walker) {
        Object chunk;
        for (int i = 0, len = this.children.size(); i < len; i++) {
            chunk = this.children.get(i);
            if (chunk instanceof SourceNode) {
                ((SourceNode) chunk).walk(walker);
            } else {
                if (((String) chunk).length() != 0) {
                    walker.walk((String) chunk, new OriginalPosition(this.line, this.column, this.source, this.name));
                }
            }
        }
    }