who needs an html parser. fragile hax, but checks the result at the end
324129
def parse_wiki_terms(doc):
    ''''''
    results = []
    last3 = ['', '', '']
    header = True
    for line in doc.split('\n'):
        last3.pop(0)
        last3.append(line.strip())
        if all(s.startswith('<td>') and not s == '<td></td>' for s in last3):
            if header:
                header = False
                continue
            last3 = [s.replace('<td>', '').replace('</td>', '').strip() for s in last3]
            rank, term, count = last3
            rank = int(rank.split()[0])
            term = term.replace('</a>', '')
            term = term[term.index('>')+1:].lower()
            results.append(term)
    assert len(results) in [1000, 2000, 1284] # early docs have 1k entries, later have 2k, last doc has 1284
    return results
813518
function htmlError(result, cb) {
  var message = result.body
    .match(/<h1>Error<\/h1>.+<\/p>/).toString()
    .replace(/<h1>Error<\/h1>/, '')
    .replace(/<\/?p>/g, '');
  cb(new Error(message));
}
155224
function main(content, callback) {
  parser(content, function(error, result) {
    if (error) {
      callback(error);
    } else {
      callback(null, result);
    }
  });
}
125055
function compile(src) {
   var cached;

   if (typeof src !== "string") {
      throw new TypeError("src must be a string, instead saw '" + typeof src + "'");
   }

   if (!compile.cache) {
      return parser.parse(src);
   }

   cached = compile.cache[src];

   if (!cached) {
      cached = compile.cache[src] = parser.parse(src);
   }

   return cached;
}
974642
function CheckTodoInENML(text, index, check){

    var todo_cout = 0;
    var writer = new XMLWriter();
    var parser = new SaxParser(function(cb) {

      cb.onStartElementNS(function(elem, attrs, prefix, uri, namespaces) {

        writer.startElement(elem);


        if(elem == 'en-todo' && index == todo_cout++){

          if(attrs) attrs.forEach(function(attr) {
            if(attr[0] == 'checked') return;
            writer.writeAttribute(attr[0], attr[1]);
          });

          if(check)  writer.writeAttribute('checked', 'true');
        }else{

          if(attrs) attrs.forEach(function(attr) {
            writer.writeAttribute(attr[0], attr[1]);
          });
        }
      });
      cb.onEndElementNS(function(elem, prefix, uri) {

        writer.endElement();
      });
      cb.onCharacters(function(chars) {
        writer.text(chars);
      });

    });

    parser.parseString(text);
    return writer.toString();
  }
250538
function parseList(kind, parseElement) {
            var saveParsingContext = parsingContext;
            parsingContext |= 1 << kind;
            var result = [];
            result.pos = getNodePos();
            while (!isListTerminator(kind)) {
                if (isListElement(kind, /*inErrorRecovery*/ false)) {
                    var element = parseListElement(kind, parseElement);
                    result.push(element);
                    continue;
                }
                if (abortParsingListOrMoveToNextToken(kind)) {
                    break;
                }
            }
            result.end = getNodeEnd();
            parsingContext = saveParsingContext;
            return result;
        }
551623
function canParseHTMLNatively () {
  var Parser = root.DOMParser
  var canParse = false

  // Adapted from https://gist.github.com/1129031
  // Firefox/Opera/IE throw errors on unsupported types
  try {
    // WebKit returns null on unsupported types
    if (new Parser().parseFromString('', 'text/html')) {
      canParse = true
    }
  } catch (e) {}

  return canParse
}
226518
def ends_with(self, other):
        ''''''
        @Parser
        def ends_with_parser(text, index):
            res = self(text, index)
            if not res.status:
                return res
            end = other(text, res.index)
            if end.status:
                return res
            else:
                return Value.failure(end.index, 'ends with {}'.format(end.expected))
        return ends_with_parser
520580
function sanitizeHTML(sText) {
			return sanitizeHTML0(sText, {
				tagPolicy: fnPolicy.bind(this),
				uriRewriter: function (sUrl) {
					// by default we use the URL whitelist to check the URLs
					if (URLWhitelist.validate(sUrl)) {
						return sUrl;
					}
				}
			});
		}
263606
function Parser( tokenStream ){
   
    var debug = false;

    var currentToken, lastComment, types = [];
   
    function isAnyOf( type, possibleTypes ){
        for(var i = 0; i < possibleTypes.length; i++) {
            if ( possibleTypes[i] === type ){ 
                return true;
            }
        }
    
        return false;
    }

    function error( message ){
        throw new Error( message + 
            "\nAt line: " + currentToken.line + ", col: " +  currentToken.col + "\n\n" +
            tokenStream.neighborhood()
        );
    }

    function consume( expectedType ){
        currentToken = tokenStream.consume();

        if (debug) console.log("currentToken", currentToken);

        if ( expectedType && !isAnyOf( currentToken.type, Array.prototype.slice.call(arguments) )){
            error( "syntax error - expected \"" + Array.prototype.join.call( arguments, ", ") + "\", but got \"" + currentToken.type + "\"" ); 
        } 

        return currentToken;
    }

    function peak(){
        return tokenStream.peak();
    }

    function parseExtendsList(){
        
        consume("extends");

        return parseIdList();
    }
   

    function parseExtends(){
        
        consume("extends");

        // get the type name
        var r = consume();
        return r.contents;
    }
   
    function parseIdList(){

        var idlist = []
            , peaked;

        do {
            consume();

            if ( currentToken.type === "id" ){
                idlist.push( currentToken.contents );
            }
        } while ( (peaked = peak()) && (peaked.type === "id" || peaked.type === ",") )

        return idlist;
    }

    function parseImplements(){
         
        consume("implements");
        return parseIdList();

    }

    function parseClass( visibility ){
     
        // get visibility from current token or default
        visibility = visibility || "public";
        
        consume("class");  
       
        // get the type name for the class
        var typeName = consume().contents;
    
        // build the class type
        var def = new Class( typeName, visibility ); 
        def.line = currentToken.line;
    
        // set the description
        def.description = getLastComment();

        var peaked = peak(); 
        var parsedExtends = false;
    
        // parent class
        if ( peaked.type === "extends" ){
            parsedExtends = true;
            def.parentClass = parseExtends();
            peaked = peak();
        }
        
        // parse interfaces
        if ( peaked.type === "implements" ){
            def.interfaces = parseImplements();                       
            peaked = peak();
        }
 
        // parent class
        if ( peaked.type === "extends" ){
            if (parsedExtends) error("Duplicate extends encountered");
            def.parentClass = parseExtends();
        }       

        parseClassBody( def );

        if (debug) console.log(def);

        return def; 
    }

    function consumeBlock(){

        consume("{");
        var parenCount = 1;

        while ( parenCount != 0 ){
            consume();

            if (currentToken.type === "{") {
                parenCount++;
            } else if (currentToken.type === "}"){
                parenCount--;
            }
        }
    }

    function consumeWhile(){
        
        var possibleTypes = Array.prototype.slice.call(arguments);
        
        var consumed = [];
        while (isAnyOf( peak().type, possibleTypes)){
            consumed.push(consume.apply(null, arguments));
        }
        return consumed;
    }

    function consumeIf(){

        var possibleTypes = Array.prototype.slice.call(arguments);
        var peaked = peak();
        if (isAnyOf(peaked.type, possibleTypes)) consume();
    }

    function consumeUntil(){

        var possibleTypes = Array.prototype.slice.call(arguments);
        var peaked;
        while ( (peaked = peak()) && !isAnyOf( peaked.type, possibleTypes) ){
            consume();
        }
    }

    function consumeUntilInclusive(char){
        consumeUntil(char);
        consume(char);
    }

    function parseProperty( isStatic ){

        var currentLine = currentToken.line;

        consume("var");

        var name = consume().contents;
        var type;

        var peaked = peak();
        
        if (peaked.type === ":"){
           
            consume(":");
            type = consume("id").contents; 
            peaked = peak();
            
        }
       
        consumeUntilInclusive(";");

        var prop = new Property( name, type, getLastComment() ); 
        prop.line = currentLine;
        return prop;
    }
  
    function parseMethodArgument(){
    
        // id : Type = expression
        var name = consume("id").contents;
      
        var peaked = peak();

        var type;
        if (peaked.type === ":"){
            type = parseTypeAnnotation();
            peaked = peak();
        }

        var defaultVal;
        if (peaked.type === "="){    
            consume("=");
            defaultVal = consume("number", "string", "boolean", "null").contents; 
        }

        return new MethodArgument(name, type, defaultVal);
    }

    function parseTypeAnnotation(){
        consume(":");
        var ids = consumeWhile("id","->");
        return ids.reduce((a,x) => x.contents + a, "");
    }

    function parseMethodArguments(){

        // ( methodArgument, methodArgument )
        consume("(");

        var peaked, args = [];

        while ( (peaked = peak()) && peaked.type != ")"){
            
            if (peaked.type === "id"){
                args.push( parseMethodArgument() );
            } else if (peaked.type === ","){
                consume(","); // consume the ","
            } else {
                error("Failed to parse method arguments!");                
            }

        }
       
        consume(")");
        return args;
    }

    function getLastComment(){

        var lc = lastComment;
        lastComment = undefined;
        return lc ? lc.contents : lc;

    }

    function parseMethod( isStatic ){
    
        var currentLine = currentToken.line;

        // function MethodName( methodArgument, methodArgument ) : ExpectedType { ... } 
        consume("function");

        var name = consume("id", "new").contents;
        
        var args = parseMethodArguments();

        peaked = peak();
   
        var type;
        if (peaked.type === ":"){
           type = parseTypeAnnotation(); 
        }
    
        consumeBlock();

        var method = new Method( name, args, type, getLastComment() );
        method.line = currentLine;
        method.isStatic = isStatic;
        return method;
    }

    function parseClassMember( def, visibility ){

        // parse "public" or "private"
        var visibility = visibility ? visibility : consume("visibility").contents;     

        // hack to ignore private members
        if ( visibility === "private"){
            def = new Class();
        }

        var peaked = peak();
        var isStatic = false;
    
        if ( peaked.type === "static" ){
            isStatic = true;
            
            consume("static");
            peaked = peak();
        }

        if ( peaked.type === "inline" ){
           
            // TODO - parse inline
            consume("inline");
            peaked = peak();
        }
        
        if ( peaked.type === "var" ){
            return def.properties.push( parseProperty( isStatic ));
        } else if (peaked.type === "function"){
            return def.methods.push( parseMethod( isStatic )); 
        }

        throw new Error("Unknown class member encountered" + JSON.stringify( peaked ));
    }

    function parseClassBody( def ){

        consume("{");

        var peaked; 

        while ( (peaked = peak()) && peaked.type != "}"){
            if (peaked.type === "comment"){    
                parseComment();
                continue;
            } else if (peaked.type === "visibility"){
                parseClassMember( def );
                continue;
            } else if (peaked.type === "function"){
                parseClassMember( def, "private" );
                continue;
            } else if (peaked.type === "var"){
                parseClassMember( def, "private" );
                continue;
            } else if (peaked.type === "static"){
                parseClassMember( def, "private" );
                continue; 
            }

            consume();
        }

        consume("}");
    }

    function parseMethodDefinition(){
    
        // function MethodName( methodArgument, methodArgument ) : ExpectedType; 
        consume("function");

        var currentLine = currentToken.line;
        var name = consume("id", "new").contents;
        
        var args = parseMethodArguments();

        peaked = peak();
   
        var type;
        if (peaked.type === ":"){
           type = parseTypeAnnotation(); 
        }
    
        consumeUntilInclusive(";");

        var method = new Method( name, args, type, getLastComment() );
        method.line = currentLine;
        return method;
    }

    function parseInterfaceMember( def, visibility ){

        var visibility = visibility ? visibility : consume("visibility").contents;     

        // hack to ignore private members
        if ( visibility === "private"){
            def = new Interface();
        }

        var peaked = peak();
    
        if ( peaked.type === "var" ){
            return def.properties.push( parseProperty());
        } else if (peaked.type === "function"){
            return def.methods.push( parseMethodDefinition()); 
        }

        throw new Error("Unknown interface member type encountered" + JSON.stringify( peaked ));
    }
    
    function parseInterfaceBody( def ){

        consume("{");

        var peaked; 

        while ( (peaked = peak()) && peaked.type != "}"){
            if (peaked.type === "comment"){    
                parseComment();
                continue;
            } else if (peaked.type === "visibility"){
                parseInterfaceMember( def );
                continue;
            } else if (peaked.type === "function"){
                parseInterfaceMember( def, "public" );
                continue;
            }  

            consume();
        }

        consume("}");
    }

    function parseInterface( visibility ){

        visibility = visibility || "public";
        
        consume("interface");  
       
        // get the type name for the class
        var typeName = consume().contents;
    
        var def = new Interface( typeName, visibility ); 
        def.line = currentToken.line; 
        def.description = getLastComment();
        
        if ( peak().type === "extends" ){
            def.interfaces = parseExtendsList();
        }
        
        parseInterfaceBody( def );

        if (debug) console.log( def );

        return def; 
    }

    function parseTypedefBody( def ){

        def.isAnonymousObject = true;
        consume("{");

        var peaked; 

        while ( (peaked = peak()) && peaked.type != "}"){
            if (peaked.type === "comment"){    
                parseComment();
                continue;
            } else if (peaked.type === "var"){
                def.anonymousObject.properties.push(parseProperty());
                continue;
            } 

            consume();
        }

        consume("}");
    }

    function parseTypedef( visibility ){
      
        visibility = visibility || "public";
        
        consume("typedef");  
       
        var typeName = consume().contents;
   
        consume("=");

        var def = new Typedef( typeName, visibility ); 
        def.line = currentToken.line;
        def.description = getLastComment();
      
        // anonymous object body
        if (peak().type === "{"){
            parseTypedefBody( def );
        } else {
           def.alias = consume("id").contents;
        }

        if( debug ) console.log( def );

        return def; 
    }

    function parseComment() {
        var squashed = consume("comment");

        var peaked;
        while ( (peaked = peak()) && peaked.type === "comment" ){
            currentToken = consume();
            
            squashed.contents += "\n";
            squashed.contents += currentToken.contents; 
        }
    
        return lastComment = squashed;
    }

    function parseType(){ 
        
        var peaked = peak();
        var visibility = "public";
        
        if (peaked.type === "visibility"){
            consume("visibility");
            peaked = peak();
        }

        if (peaked.type === "class"){
            return parseClass( visibility ); 
        } else if (peaked.type === "interface"){
            return parseInterface( visibility ); 
        } else if (peaked.type === "typedef"){
            return parseTypedef( visibility );    
        } 

        error("Parser for type not implemented");    
    }
    
    this.parse = () => {
       
        var peaked;

        var types = [];
    
        while ( (peaked = peak()) ){
            if (peaked.type === "expose"){
                consume("expose"); 
                types.push( parseType() ); 
            } else if (peaked.type === "class"){
                parseClass(); 
            } else if (peaked.type === "typedef"){
                types.push( parseTypedef() ); 
            } else if (peaked.type === "interface"){
                types.push( parseInterface() ); 
            } else if ( peaked.type === "visibility" ){
                if (peaked.contents === "private") {
                    // parse, but don't add to types
                    parseType();
                    continue;
                }
                types.push( parseType() ); 
            } else if (peaked.type === "comment"){
                parseComment();
            } else {
                consume();
            }
        }

        return types;
    }
}
182410
def _handle_single_tag_end(self):
        """"""
        stack = self._stack
        # We need to find the index of the TagCloseOpen token corresponding to
        # the TagOpenOpen token located at index 0:
        depth = 1
        for index, token in enumerate(stack[2:], 2):
            if isinstance(token, tokens.TagOpenOpen):
                depth += 1
            elif isinstance(token, tokens.TagCloseOpen):
                depth -= 1
                if depth == 0:
                    break
            elif isinstance(token, tokens.TagCloseSelfclose):
                depth -= 1
                if depth == 0:  # pragma: no cover (untestable/exceptional)
                    raise ParserError(
                        "_handle_single_tag_end() got an unexpected "
                        "TagCloseSelfclose")
        else:  # pragma: no cover (untestable/exceptional case)
            raise ParserError("_handle_single_tag_end() missed a TagCloseOpen")
        padding = stack[index].padding
        stack[index] = tokens.TagCloseSelfclose(padding=padding, implicit=True)
        return self._pop()
1238550
function _parseSelector(ctx) {
            var selector = "";

            // Skip over {
            TokenUtils.movePrevToken(ctx);

            while (true) {
                if (ctx.token.type !== "comment") {
                    // Stop once we've reached a {, }, or ;
                    if (/[\{\}\;]/.test(ctx.token.string)) {
                        break;
                    }

                    // Stop once we've reached a <style ...> tag
                    if (ctx.token.string === "style" && ctx.token.type === "tag") {
                        // Remove everything up to end-of-tag from selector
                        var eotIndex = selector.indexOf(">");
                        if (eotIndex !== -1) {
                            selector = selector.substring(eotIndex + 1);
                        }
                        break;
                    }

                    selector = ctx.token.string + selector;
                }
                if (!TokenUtils.movePrevToken(ctx)) {
                    break;
                }
            }

            return selector;
        }
9663
def parse_close(data):
    '''
    '''
    length = len(data)
    if length == 0:
        return 1005, ''
    elif length == 1:
        raise ProtocolError("Close frame too short")
    else:
        code, = unpack('!H', data[:2])
        if not (code in CLOSE_CODES or 3000 <= code < 5000):
            raise ProtocolError("Invalid status code for websocket")
        reason = data[2:].decode('utf-8')
        return code, reason
223931
function () {
  var parsers = require(PARSERS);
  
  var integerRegEx = /^[\-+]?[0-9]+$/;
  var numberRegEx = /^[\-+]?[0-9]*\.[0-9]+$/;
  var lengthRegEx = /^(0|[\-+]?[0-9]*\.?[0-9]+(in|cm|mm|pt|pc|px|em|ex|ch|rem|vh|vw|vmin|vmax))$/;
  var percentRegEx = /^[\-+]?[0-9]*\.?[0-9]+%$/;
  var urlRegEx = /^url\(\s*([^\)]*)\s*\)$/;
  var stringRegEx = /^(\"[^\"]*\"|\'[^\']*\')$/;
  var colorRegEx1 = /^#[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]([0-9a-fA-F][0-9a-fA-F][0-9a-fA-F])?$/;
  var colorRegEx2 = /^rgb\(([^\)]*)\)$/;
  var colorRegEx3 = /^rgba\(([^\)]*)\)$/;
  var angleRegEx = /^([\-+]?[0-9]*\.?[0-9]+)(deg|grad|rad)$/;

  parsers.valueType = function valueType(val) {
    var TYPES = parsers.TYPES;
    if (val === '' || val === null) return TYPES.NULL_OR_EMPTY_STR;
    if (typeof val === 'number') val = val.toString();
    if (typeof val !== 'string') return undefined;

    if (integerRegEx.test(val)) return TYPES.INTEGER;
    if (numberRegEx.test(val))  return TYPES.NUMBER;
    if (lengthRegEx.test(val))  return TYPES.LENGTH;
    if (percentRegEx.test(val)) return TYPES.PERCENT;
    if (urlRegEx.test(val))     return TYPES.URL;
    if (stringRegEx.test(val))  return TYPES.STRING;
    if (angleRegEx.test(val))   return TYPES.ANGLE;
    if (colorRegEx1.test(val))  return TYPES.COLOR;
    var res = colorRegEx2.exec(val);
    var parts;
    if (res !== null) {
      parts = res[1].split(/\s*,\s*/);
      if (parts.length !== 3) return undefined;
      if (parts.every(percentRegEx.test.bind(percentRegEx)) ||
          parts.every(integerRegEx.test.bind(integerRegEx))) return TYPES.COLOR;
      return undefined;
    }
    res = colorRegEx3.exec(val);
    if (res !== null) {
      parts = res[1].split(/\s*,\s*/);
      if (parts.length !== 4) return undefined;
      if (parts.slice(0, 3).every(percentRegEx.test.bind(percentRegEx)) ||
          parts.every(integerRegEx.test.bind(integerRegEx))) {
        if (numberRegEx.test(parts[3])) return TYPES.COLOR;
      }
      return undefined;
    }
    val = val.toLowerCase();
    switch (val) {
     case 'maroon':
     case 'red':
     case 'orange':
     case 'yellow':
     case 'olive':
     case 'purple':
     case 'fuchsia':
     case 'white':
     case 'lime':
     case 'green':
     case 'navy':
     case 'blue':
     case 'aqua':
     case 'teal':
     case 'black':
     case 'silver':
     case 'gray':
      // the following are deprecated in CSS3
     case 'activeborder':
     case 'activecaption':
     case 'appworkspace':
     case 'background':
     case 'buttonface':
     case 'buttonhighlight':
     case 'buttonshadow':
     case 'buttontext':
     case 'captiontext':
     case 'graytext':
     case 'highlight':
     case 'highlighttext':
     case 'inactiveborder':
     case 'inactivecaption':
     case 'inactivecaptiontext':
     case 'infobackground':
     case 'infotext':
     case 'menu':
     case 'menutext':
     case 'scrollbar':
     case 'threeddarkshadow':
     case 'threedface':
     case 'threedhighlight':
     case 'threedlightshadow':
     case 'threedshadow':
     case 'window':
     case 'windowframe':
     case 'windowtext':
      return TYPES.COLOR;
     default:
      return TYPES.KEYWORD;
    }
  };
}
434095
function parse(contents, retained, parser) {
    var errors = [], data = [], lines = 0;

    // optional parser
    if (!parser) parser = JSON;

    // process each line of the file
    contents.toString().split('\n').forEach(function(line) {
        if (!line) return;
        lines++;
        try {
            data.push(parser.parse(line));
        } catch (e) {
            e.line = line;
            errors.push(e);
        }
    });

    // if no errors/data, don't return an empty array
    var ret = {};
    if (errors.length) ret.errors = errors;
    if (data.length) ret.data = data;

    // if every line failed, probably not line-delimited
    if (errors.length == lines) ret.errors = retained;

    return ret;
}
610594
function parseResult(text, callback) {
  var errors = [], i = 0, l, errBlock, match, match2, lines;

  text = text.replace(/\r/g, '');
  lines = text.split('\n');

  match = skippingRegex.exec(lines[i]);
  if (match) {
    i++;
  }

  match = successRegex.exec(lines[i]);
  if (match) {
    callback(null, createParseSuccessObj(match));
    return;
  }

  for (l = lines.length; i < l; i++) {
    match = fileRegex.exec(lines[i]);
    if (match) {
      match2 = errorRegex.exec(lines[++i]);
      errBlock = createFailObj(match);
      for (var j = i; match2 && j < lines.length;) {
        errBlock.errors.push(createErrorObj(match2));
        match2 = errorRegex.exec(lines[++j]);
      }
      i = --j;
      errors.push(errBlock);
    } else {
      match = abstractRegex.exec(lines[i]);
      if (match) {
        callback(createErrorGJSLintFailed(match, errors));
        return;
      }
    }
  }
  callback(createParseErrorUnknown(lines));

}
1201035
function HTMLReactParser(html, options) {
  if (typeof html !== 'string') {
    throw new TypeError('First argument must be a string');
  }
  return domToReact(htmlToDOM(html, domParserOptions), options);
}