def inferheader(lines, comments=None, metadata=None,<EOL>verbosity=DEFAULT_VERBOSITY):
if ((comments is None) and metadata and ('<STR_LIT>' in list(metadata.keys()))):<EOL><INDENT>comments = metadata['<STR_LIT>']<EOL><DEDENT>if (comments is None):<EOL><INDENT>comments = '<STR_LIT:#>'  <EOL><DEDENT>if ('<STR_LIT>' in list(metadata.keys())):<EOL><INDENT>mmd = metadata['<STR_LIT>']<EOL>cc = <NUM_LIT:1> + max([v if isinstance(v, int) else max(v) <EOL>for v in list(mmd.values())])<EOL><DEDENT>else:<EOL><INDENT>cc = <NUM_LIT:0><EOL><DEDENT>if (comments != '<STR_LIT>'):<EOL><INDENT>if (cc < len(lines)):<EOL><INDENT>for l in range(cc,len(lines)):<EOL><INDENT>if not lines[l].startswith(comments):<EOL><INDENT>break<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>l = cc<EOL><DEDENT><DEDENT>if (l > <NUM_LIT:0>):<EOL><INDENT>return l<EOL><DEDENT>else:<EOL><INDENT>for j in range(min(<NUM_LIT:1000>, len(lines))):<EOL><INDENT>hasheader = '<STR_LIT>'<EOL>for k in [<NUM_LIT:100>, <NUM_LIT:200>, <NUM_LIT>, <NUM_LIT>, <NUM_LIT>]:<EOL><INDENT>F = '<STR_LIT:\n>'.join(lines[j:(j+k)])<EOL>try:<EOL><INDENT>hasheader = csv.Sniffer().has_header(F)<EOL><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not hasheader:<EOL><INDENT>return j<EOL><DEDENT><DEDENT><DEDENT>
Infers header from a CSV or other tab-delimited file.

This is essentially small extension of the csv.Sniffer.has_header algorithm.
provided in the Python csv module.   First, it checks to see whether a 
metametadata dictionary is present, specifiying the lines numbers of 
metadata lines in the header, and if so, sets the header lines to include
at least those lines.  Then iookms to see if a comments character is 
present, and if so, includes those lines as well.  If either of the above 
returns a nono-zero number of headerlines, the function returns that 
number; otherwise, it uses the csv.Sniffer module, checking each line in 
succession, and stopping at the first line where the sniffer module finds no 
evidence of a header, and returning that line numner.

**Parameters** 

    **lines** : line of strings 

        The list of lines representing lines in the file

    **comments** : single-character string, optional

        Comments character  specification. 

    **metadata** : metadata dictionary, optional

        Used to determine a comments character and metametadata dicationary, 
        if present.

**Returns**

    Integer, representing the number of (inferred) header lines at the top 
    of the file.