return line in _blanklines<EOL>

Determine whether a line is a legal end of RFC 2822 headers.

        You may override this method if your application wants to bend the
        rules, e.g. to strip trailing whitespace, or to recognize MH template
        separators ('--------').  For convenience (e.g. for code reading from
        sockets) a line consisting of \\r\\n also matches.


return False<EOL>

Determine whether a line should be skipped entirely.

        You may override this method in order to use Message parsing on tagged
        data in RFC 2822-like formats that support embedded comments or
        free-text data.


name = name.lower() + '<STR_LIT::>'<EOL>n = len(name)<EOL>lst = []<EOL>hit = <NUM_LIT:0><EOL>for line in self.headers:<EOL><INDENT>if line[:n].lower() == name:<EOL><INDENT>hit = <NUM_LIT:1><EOL><DEDENT>elif not line[:<NUM_LIT:1>].isspace():<EOL><INDENT>hit = <NUM_LIT:0><EOL><DEDENT>if hit:<EOL><INDENT>lst.append(line)<EOL><DEDENT><DEDENT>return lst<EOL>

Find all header lines matching a given header name.

        Look through the list of headers and find all lines matching a given
        header name (and their continuation lines).  A list of the lines is
        returned, without interpretation.  If the header does not occur, an
        empty list is returned.  If the header occurs multiple times, all
        occurrences are returned.  Case is not important in the header name.


name = name.lower() + '<STR_LIT::>'<EOL>n = len(name)<EOL>lst = []<EOL>hit = <NUM_LIT:0><EOL>for line in self.headers:<EOL><INDENT>if hit:<EOL><INDENT>if not line[:<NUM_LIT:1>].isspace():<EOL><INDENT>break<EOL><DEDENT><DEDENT>elif line[:n].lower() == name:<EOL><INDENT>hit = <NUM_LIT:1><EOL><DEDENT>if hit:<EOL><INDENT>lst.append(line)<EOL><DEDENT><DEDENT>return lst<EOL>

Get the first header line matching name.

        This is similar to getallmatchingheaders, but it returns only the
        first matching header (and its continuation lines).


lst = self.getfirstmatchingheader(name)<EOL>if not lst:<EOL><INDENT>return None<EOL><DEDENT>lst[<NUM_LIT:0>] = lst[<NUM_LIT:0>][len(name) + <NUM_LIT:1>:]<EOL>return '<STR_LIT>'.join(lst)<EOL>

A higher-level interface to getfirstmatchingheader().

        Return a string containing the literal text of the header but with the
        keyword stripped.  All leading, trailing and embedded whitespace is
        kept in the string, however.  Return None if the header does not
        occur.


def getheader(self, name, default=None):

return self.dict.get(name.lower(), default)<EOL>

Get the header value for a name.

        This is the normal interface: it returns a stripped version of the
        header value for a given header name, or None if it doesn't exist.
        This uses the dictionary version which finds the *last* such header.


result = []<EOL>current = '<STR_LIT>'<EOL>have_header = <NUM_LIT:0><EOL>for s in self.getallmatchingheaders(name):<EOL><INDENT>if s[<NUM_LIT:0>].isspace():<EOL><INDENT>if current:<EOL><INDENT>current = "<STR_LIT>" % (current, s.strip())<EOL><DEDENT>else:<EOL><INDENT>current = s.strip()<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if have_header:<EOL><INDENT>result.append(current)<EOL><DEDENT>current = s[s.find("<STR_LIT::>") + <NUM_LIT:1>:].strip()<EOL>have_header = <NUM_LIT:1><EOL><DEDENT><DEDENT>if have_header:<EOL><INDENT>result.append(current)<EOL><DEDENT>return result<EOL>

Get all values for a header.

        This returns a list of values for headers given more than once; each
        value in the result list is stripped in the same way as the result of
        getheader().  If the header is not given, return an empty list.


<EOL>alist = self.getaddrlist(name)<EOL>if alist:<EOL><INDENT>return alist[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>return (None, None)<EOL><DEDENT>

Get a single address from a header, as a tuple.

        An example return value:
        ('Guido van Rossum', 'guido@cwi.nl')


raw = []<EOL>for h in self.getallmatchingheaders(name):<EOL><INDENT>if h[<NUM_LIT:0>] in '<STR_LIT>':<EOL><INDENT>raw.append(h)<EOL><DEDENT>else:<EOL><INDENT>if raw:<EOL><INDENT>raw.append('<STR_LIT:U+002CU+0020>')<EOL><DEDENT>i = h.find('<STR_LIT::>')<EOL>if i > <NUM_LIT:0>:<EOL><INDENT>addr = h[i+<NUM_LIT:1>:]<EOL><DEDENT>raw.append(addr)<EOL><DEDENT><DEDENT>alladdrs = '<STR_LIT>'.join(raw)<EOL>a = AddressList(alladdrs)<EOL>return a.addresslist<EOL>

Get a list of addresses from a header.

        Retrieves a list of addresses from a header, where each address is a
        tuple as returned by getaddr().  Scans all named headers, so it works
        properly with multiple To: or Cc: headers for example.


try:<EOL><INDENT>data = self[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>return None<EOL><DEDENT>return parsedate(data)<EOL>

Retrieve a date field from a header.

        Retrieves a date field from the named header, returning a tuple
        compatible with time.mktime().


try:<EOL><INDENT>data = self[name]<EOL><DEDENT>except KeyError:<EOL><INDENT>return None<EOL><DEDENT>return parsedate_tz(data)<EOL>

Retrieve a date field from a header as a 10-tuple.

        The first 9 elements make up a tuple compatible with time.mktime(),
        and the 10th is the offset of the poster's time zone from GMT/UTC.


return len(self.dict)<EOL>


return self.dict[name.lower()]<EOL>

Get a specific header, as from a dictionary.


del self[name] <EOL>self.dict[name.lower()] = value<EOL>text = name + "<STR_LIT>" + value<EOL>for line in text.split("<STR_LIT:\n>"):<EOL><INDENT>self.headers.append(line + "<STR_LIT:\n>")<EOL><DEDENT>

Set the value of a header.

        Note: This is not a perfect inversion of __getitem__, because any
        changed headers get stuck at the end of the raw-headers list rather
        than where the altered header was.


name = name.lower()<EOL>if not name in self.dict:<EOL><INDENT>return<EOL><DEDENT>del self.dict[name]<EOL>name = name + '<STR_LIT::>'<EOL>n = len(name)<EOL>lst = []<EOL>hit = <NUM_LIT:0><EOL>for i in range(len(self.headers)):<EOL><INDENT>line = self.headers[i]<EOL>if line[:n].lower() == name:<EOL><INDENT>hit = <NUM_LIT:1><EOL><DEDENT>elif not line[:<NUM_LIT:1>].isspace():<EOL><INDENT>hit = <NUM_LIT:0><EOL><DEDENT>if hit:<EOL><INDENT>lst.append(i)<EOL><DEDENT><DEDENT>for i in reversed(lst):<EOL><INDENT>del self.headers[i]<EOL><DEDENT>

Delete all occurrences of a specific header, if it is present.


return name.lower() in self.dict<EOL>

Determine whether a message contains the named header.


return name.lower() in self.dict<EOL>


return list(self.dict.keys())<EOL>

Get all of a message's header field names.


return list(self.dict.values())<EOL>

Get all of a message's header field values.


return list(self.dict.items())<EOL>

Get all of a message's headers.

        Returns a list of name, value tuples.


self.specials = '<STR_LIT>'<EOL>self.pos = <NUM_LIT:0><EOL>self.LWS = '<STR_LIT>'<EOL>self.CR = '<STR_LIT:\r\n>'<EOL>self.atomends = self.specials + self.LWS + self.CR<EOL>self.phraseends = self.atomends.replace('<STR_LIT:.>', '<STR_LIT>')<EOL>self.field = field<EOL>self.commentlist = []<EOL>

Initialize a new instance.

        `field' is an unparsed address header field, containing one or more
        addresses.


while self.pos < len(self.field):<EOL><INDENT>if self.field[self.pos] in self.LWS + '<STR_LIT>':<EOL><INDENT>self.pos = self.pos + <NUM_LIT:1><EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:(>':<EOL><INDENT>self.commentlist.append(self.getcomment())<EOL><DEDENT>else: break<EOL><DEDENT>

Parse up to the start of the next address.


result = []<EOL>ad = self.getaddress()<EOL>while ad:<EOL><INDENT>result += ad<EOL>ad = self.getaddress()<EOL><DEDENT>return result<EOL>

Parse all addresses.

        Returns a list containing all of the addresses.


self.commentlist = []<EOL>self.gotonext()<EOL>oldpos = self.pos<EOL>oldcl = self.commentlist<EOL>plist = self.getphraselist()<EOL>self.gotonext()<EOL>returnlist = []<EOL>if self.pos >= len(self.field):<EOL><INDENT>if plist:<EOL><INDENT>returnlist = [('<STR_LIT:U+0020>'.join(self.commentlist), plist[<NUM_LIT:0>])]<EOL><DEDENT><DEDENT>elif self.field[self.pos] in '<STR_LIT>':<EOL><INDENT>self.pos = oldpos<EOL>self.commentlist = oldcl<EOL>addrspec = self.getaddrspec()<EOL>returnlist = [('<STR_LIT:U+0020>'.join(self.commentlist), addrspec)]<EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT::>':<EOL><INDENT>returnlist = []<EOL>fieldlen = len(self.field)<EOL>self.pos += <NUM_LIT:1><EOL>while self.pos < len(self.field):<EOL><INDENT>self.gotonext()<EOL>if self.pos < fieldlen and self.field[self.pos] == '<STR_LIT:;>':<EOL><INDENT>self.pos += <NUM_LIT:1><EOL>break<EOL><DEDENT>returnlist = returnlist + self.getaddress()<EOL><DEDENT><DEDENT>elif self.field[self.pos] == '<STR_LIT:<>':<EOL><INDENT>routeaddr = self.getrouteaddr()<EOL>if self.commentlist:<EOL><INDENT>returnlist = [('<STR_LIT:U+0020>'.join(plist) + '<STR_LIT>' +'<STR_LIT:U+0020>'.join(self.commentlist) + '<STR_LIT:)>', routeaddr)]<EOL><DEDENT>else: returnlist = [('<STR_LIT:U+0020>'.join(plist), routeaddr)]<EOL><DEDENT>else:<EOL><INDENT>if plist:<EOL><INDENT>returnlist = [('<STR_LIT:U+0020>'.join(self.commentlist), plist[<NUM_LIT:0>])]<EOL><DEDENT>elif self.field[self.pos] in self.specials:<EOL><INDENT>self.pos += <NUM_LIT:1><EOL><DEDENT><DEDENT>self.gotonext()<EOL>if self.pos < len(self.field) and self.field[self.pos] == '<STR_LIT:U+002C>':<EOL><INDENT>self.pos += <NUM_LIT:1><EOL><DEDENT>return returnlist<EOL>


if self.field[self.pos] != '<STR_LIT:<>':<EOL><INDENT>return<EOL><DEDENT>expectroute = <NUM_LIT:0><EOL>self.pos += <NUM_LIT:1><EOL>self.gotonext()<EOL>adlist = "<STR_LIT>"<EOL>while self.pos < len(self.field):<EOL><INDENT>if expectroute:<EOL><INDENT>self.getdomain()<EOL>expectroute = <NUM_LIT:0><EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:>>':<EOL><INDENT>self.pos += <NUM_LIT:1><EOL>break<EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:@>':<EOL><INDENT>self.pos += <NUM_LIT:1><EOL>expectroute = <NUM_LIT:1><EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT::>':<EOL><INDENT>self.pos += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>adlist = self.getaddrspec()<EOL>self.pos += <NUM_LIT:1><EOL>break<EOL><DEDENT>self.gotonext()<EOL><DEDENT>return adlist<EOL>

Parse a route address (Return-path value).

        This method just skips all the route stuff and returns the addrspec.


aslist = []<EOL>self.gotonext()<EOL>while self.pos < len(self.field):<EOL><INDENT>if self.field[self.pos] == '<STR_LIT:.>':<EOL><INDENT>aslist.append('<STR_LIT:.>')<EOL>self.pos += <NUM_LIT:1><EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:">':<EOL><INDENT>aslist.append('<STR_LIT>' % self.getquote())<EOL><DEDENT>elif self.field[self.pos] in self.atomends:<EOL><INDENT>break<EOL><DEDENT>else: aslist.append(self.getatom())<EOL>self.gotonext()<EOL><DEDENT>if self.pos >= len(self.field) or self.field[self.pos] != '<STR_LIT:@>':<EOL><INDENT>return '<STR_LIT>'.join(aslist)<EOL><DEDENT>aslist.append('<STR_LIT:@>')<EOL>self.pos += <NUM_LIT:1><EOL>self.gotonext()<EOL>return '<STR_LIT>'.join(aslist) + self.getdomain()<EOL>


sdlist = []<EOL>while self.pos < len(self.field):<EOL><INDENT>if self.field[self.pos] in self.LWS:<EOL><INDENT>self.pos += <NUM_LIT:1><EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:(>':<EOL><INDENT>self.commentlist.append(self.getcomment())<EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:[>':<EOL><INDENT>sdlist.append(self.getdomainliteral())<EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:.>':<EOL><INDENT>self.pos += <NUM_LIT:1><EOL>sdlist.append('<STR_LIT:.>')<EOL><DEDENT>elif self.field[self.pos] in self.atomends:<EOL><INDENT>break<EOL><DEDENT>else: sdlist.append(self.getatom())<EOL><DEDENT>return '<STR_LIT>'.join(sdlist)<EOL>

Get the complete domain name from an address.


def getdelimited(self, beginchar, endchars, allowcomments = <NUM_LIT:1>):

if self.field[self.pos] != beginchar:<EOL><INDENT>return '<STR_LIT>'<EOL><DEDENT>slist = ['<STR_LIT>']<EOL>quote = <NUM_LIT:0><EOL>self.pos += <NUM_LIT:1><EOL>while self.pos < len(self.field):<EOL><INDENT>if quote == <NUM_LIT:1>:<EOL><INDENT>slist.append(self.field[self.pos])<EOL>quote = <NUM_LIT:0><EOL><DEDENT>elif self.field[self.pos] in endchars:<EOL><INDENT>self.pos += <NUM_LIT:1><EOL>break<EOL><DEDENT>elif allowcomments and self.field[self.pos] == '<STR_LIT:(>':<EOL><INDENT>slist.append(self.getcomment())<EOL>continue        <EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:\\>':<EOL><INDENT>quote = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>slist.append(self.field[self.pos])<EOL><DEDENT>self.pos += <NUM_LIT:1><EOL><DEDENT>return '<STR_LIT>'.join(slist)<EOL>

Parse a header fragment delimited by special characters.

        `beginchar' is the start character for the fragment.  If self is not
        looking at an instance of `beginchar' then getdelimited returns the
        empty string.

        `endchars' is a sequence of allowable end-delimiting characters.
        Parsing stops when one of these is encountered.

        If `allowcomments' is non-zero, embedded RFC 2822 comments are allowed
        within the parsed fragment.


return self.getdelimited('<STR_LIT:">', '<STR_LIT>', <NUM_LIT:0>)<EOL>

Get a quote-delimited fragment from self's field.


return self.getdelimited('<STR_LIT:(>', '<STR_LIT>', <NUM_LIT:1>)<EOL>

Get a parenthesis-delimited fragment from self's field.


return '<STR_LIT>' % self.getdelimited('<STR_LIT:[>', '<STR_LIT>', <NUM_LIT:0>)<EOL>


atomlist = ['<STR_LIT>']<EOL>if atomends is None:<EOL><INDENT>atomends = self.atomends<EOL><DEDENT>while self.pos < len(self.field):<EOL><INDENT>if self.field[self.pos] in atomends:<EOL><INDENT>break<EOL><DEDENT>else: atomlist.append(self.field[self.pos])<EOL>self.pos += <NUM_LIT:1><EOL><DEDENT>return '<STR_LIT>'.join(atomlist)<EOL>

Parse an RFC 2822 atom.

        Optional atomends specifies a different set of end token delimiters
        (the default is to use self.atomends).  This is used e.g. in
        getphraselist() since phrase endings must not include the `.' (which
        is legal in phrases).


plist = []<EOL>while self.pos < len(self.field):<EOL><INDENT>if self.field[self.pos] in self.LWS:<EOL><INDENT>self.pos += <NUM_LIT:1><EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:">':<EOL><INDENT>plist.append(self.getquote())<EOL><DEDENT>elif self.field[self.pos] == '<STR_LIT:(>':<EOL><INDENT>self.commentlist.append(self.getcomment())<EOL><DEDENT>elif self.field[self.pos] in self.phraseends:<EOL><INDENT>break<EOL><DEDENT>else:<EOL><INDENT>plist.append(self.getatom(self.phraseends))<EOL><DEDENT><DEDENT>return plist<EOL>

Parse a sequence of RFC 2822 phrases.

        A phrase is a sequence of words, which are in turn either RFC 2822
        atoms or quoted-strings.  Phrases are canonicalized by squeezing all
        runs of continuous whitespace into one space.


_complain_ifclosed(self.closed)<EOL>r = self.readline()<EOL>if not r:<EOL><INDENT>raise StopIteration<EOL><DEDENT>return r<EOL>

A file object is its own iterator, for example iter(f) returns f
        (unless f is closed). When a file is used as an iterator, typically
        in a for loop (for example, for line in f: print line), the next()
        method is called repeatedly. This method returns the next input line,
        or raises StopIteration when EOF is hit.


if not self.closed:<EOL><INDENT>self.closed = True<EOL>del self.buf, self.pos<EOL><DEDENT>


_complain_ifclosed(self.closed)<EOL>return False<EOL>

Returns False because StringIO objects are not connected to a
        tty-like device.


def seek(self, pos, mode = <NUM_LIT:0>):

_complain_ifclosed(self.closed)<EOL>if self.buflist:<EOL><INDENT>self.buf += '<STR_LIT>'.join(self.buflist)<EOL>self.buflist = []<EOL><DEDENT>if mode == <NUM_LIT:1>:<EOL><INDENT>pos += self.pos<EOL><DEDENT>elif mode == <NUM_LIT:2>:<EOL><INDENT>pos += self.len<EOL><DEDENT>self.pos = max(<NUM_LIT:0>, pos)<EOL>

Set the file's current position.

        The mode argument is optional and defaults to 0 (absolute file
        positioning); other values are 1 (seek relative to the current
        position) and 2 (seek relative to the file's end).

        There is no return value.


_complain_ifclosed(self.closed)<EOL>return self.pos<EOL>


_complain_ifclosed(self.closed)<EOL>if self.buflist:<EOL><INDENT>self.buf += '<STR_LIT>'.join(self.buflist)<EOL>self.buflist = []<EOL><DEDENT>if n is None or n < <NUM_LIT:0>:<EOL><INDENT>newpos = self.len<EOL><DEDENT>else:<EOL><INDENT>newpos = min(self.pos+n, self.len)<EOL><DEDENT>r = self.buf[self.pos:newpos]<EOL>self.pos = newpos<EOL>return r<EOL>

Read at most size bytes from the file
        (less if the read hits EOF before obtaining size bytes).

        If the size argument is negative or omitted, read all data until EOF
        is reached. The bytes are returned as a string object. An empty
        string is returned when EOF is encountered immediately.


_complain_ifclosed(self.closed)<EOL>if self.buflist:<EOL><INDENT>self.buf += '<STR_LIT>'.join(self.buflist)<EOL>self.buflist = []<EOL><DEDENT>i = self.buf.find('<STR_LIT:\n>', self.pos)<EOL>if i < <NUM_LIT:0>:<EOL><INDENT>newpos = self.len<EOL><DEDENT>else:<EOL><INDENT>newpos = i+<NUM_LIT:1><EOL><DEDENT>if length is not None and length >= <NUM_LIT:0>:<EOL><INDENT>if self.pos + length < newpos:<EOL><INDENT>newpos = self.pos + length<EOL><DEDENT><DEDENT>r = self.buf[self.pos:newpos]<EOL>self.pos = newpos<EOL>return r<EOL>

r"""Read one entire line from the file.

        A trailing newline character is kept in the string (but may be absent
        when a file ends with an incomplete line). If the size argument is
        present and non-negative, it is a maximum byte count (including the
        trailing newline) and an incomplete line may be returned.

        An empty string is returned only when EOF is encountered immediately.

        Note: Unlike stdio's fgets(), the returned string contains null
        characters ('\0') if they occurred in the input.


def readlines(self, sizehint = <NUM_LIT:0>):

total = <NUM_LIT:0><EOL>lines = []<EOL>line = self.readline()<EOL>while line:<EOL><INDENT>lines.append(line)<EOL>total += len(line)<EOL>if <NUM_LIT:0> < sizehint <= total:<EOL><INDENT>break<EOL><DEDENT>line = self.readline()<EOL><DEDENT>return lines<EOL>

Read until EOF using readline() and return a list containing the
        lines thus read.

        If the optional sizehint argument is present, instead of reading up
        to EOF, whole lines totalling approximately sizehint bytes (or more
        to accommodate a final whole line).


_complain_ifclosed(self.closed)<EOL>if size is None:<EOL><INDENT>size = self.pos<EOL><DEDENT>elif size < <NUM_LIT:0>:<EOL><INDENT>raise IOError(EINVAL, "<STR_LIT>")<EOL><DEDENT>elif size < self.pos:<EOL><INDENT>self.pos = size<EOL><DEDENT>self.buf = self.getvalue()[:size]<EOL>self.len = size<EOL>

Truncate the file's size.

        If the optional size argument is present, the file is truncated to
        (at most) that size. The size defaults to the current position.
        The current file position is not changed unless the position
        is beyond the new file size.

        If the specified size exceeds the file's current size, the
        file remains unchanged.


_complain_ifclosed(self.closed)<EOL>if not s: return<EOL>if not isinstance(s, str):<EOL><INDENT>s = str(s)<EOL><DEDENT>spos = self.pos<EOL>slen = self.len<EOL>if spos == slen:<EOL><INDENT>self.buflist.append(s)<EOL>self.len = self.pos = spos + len(s)<EOL>return<EOL><DEDENT>if spos > slen:<EOL><INDENT>self.buflist.append('<STR_LIT>'*(spos - slen))<EOL>slen = spos<EOL><DEDENT>newpos = spos + len(s)<EOL>if spos < slen:<EOL><INDENT>if self.buflist:<EOL><INDENT>self.buf += '<STR_LIT>'.join(self.buflist)<EOL><DEDENT>self.buflist = [self.buf[:spos], s, self.buf[newpos:]]<EOL>self.buf = '<STR_LIT>'<EOL>if newpos > slen:<EOL><INDENT>slen = newpos<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.buflist.append(s)<EOL>slen = newpos<EOL><DEDENT>self.len = slen<EOL>self.pos = newpos<EOL>

Write a string to the file.

        There is no return value.


write = self.write<EOL>for line in iterable:<EOL><INDENT>write(line)<EOL><DEDENT>

Write a sequence of strings to the file. The sequence can be any
        iterable object producing strings, typically a list of strings. There
        is no return value.

        (The name is intended to match readlines(); writelines() does not add
        line separators.)


_complain_ifclosed(self.closed)<EOL>if self.buflist:<EOL><INDENT>self.buf += '<STR_LIT>'.join(self.buflist)<EOL>self.buflist = []<EOL><DEDENT>return self.buf<EOL>

Retrieve the entire contents of the "file" at any time before
the StringIO object's close() method is called.

The StringIO object can accept either Unicode or 8-bit strings,
but mixing the two may take some care. If both are used, 8-bit
strings that cannot be interpreted as 7-bit ASCII (that use the
8th bit) will cause a UnicodeError to be raised when getvalue()
is called.


def sniff(self, sample, delimiters=None):

quotechar, doublequote, delimiter, skipinitialspace =self._guess_quote_and_delimiter(sample, delimiters)<EOL>if not delimiter:<EOL><INDENT>delimiter, skipinitialspace = self._guess_delimiter(sample,<EOL>delimiters)<EOL><DEDENT>if not delimiter:<EOL><INDENT>raise Error("<STR_LIT>")<EOL><DEDENT>class dialect(Dialect):<EOL><INDENT>_name = "<STR_LIT>"<EOL>lineterminator = '<STR_LIT:\r\n>'<EOL>quoting = QUOTE_MINIMAL<EOL><DEDENT>dialect.doublequote = doublequote<EOL>dialect.delimiter = delimiter<EOL>dialect.quotechar = quotechar or '<STR_LIT:">'<EOL>dialect.skipinitialspace = skipinitialspace<EOL>return dialect<EOL>

Returns a dialect (or None) corresponding to the sample


def _guess_quote_and_delimiter(self, data, delimiters):

matches = []<EOL>for restr in ('<STR_LIT>', <EOL>'<STR_LIT>',   <EOL>'<STR_LIT>',  <EOL>'<STR_LIT>'):                            <EOL><INDENT>regexp = re.compile(restr, re.DOTALL | re.MULTILINE)<EOL>matches = regexp.findall(data)<EOL>if matches:<EOL><INDENT>break<EOL><DEDENT><DEDENT>if not matches:<EOL><INDENT>return ('<STR_LIT>', False, None, <NUM_LIT:0>)<EOL><DEDENT>quotes = {}<EOL>delims = {}<EOL>spaces = <NUM_LIT:0><EOL>for m in matches:<EOL><INDENT>n = regexp.groupindex['<STR_LIT>'] - <NUM_LIT:1><EOL>key = m[n]<EOL>if key:<EOL><INDENT>quotes[key] = quotes.get(key, <NUM_LIT:0>) + <NUM_LIT:1><EOL><DEDENT>try:<EOL><INDENT>n = regexp.groupindex['<STR_LIT>'] - <NUM_LIT:1><EOL>key = m[n]<EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>if key and (delimiters is None or key in delimiters):<EOL><INDENT>delims[key] = delims.get(key, <NUM_LIT:0>) + <NUM_LIT:1><EOL><DEDENT>try:<EOL><INDENT>n = regexp.groupindex['<STR_LIT>'] - <NUM_LIT:1><EOL><DEDENT>except KeyError:<EOL><INDENT>continue<EOL><DEDENT>if m[n]:<EOL><INDENT>spaces += <NUM_LIT:1><EOL><DEDENT><DEDENT>quotechar = reduce(lambda a, b, quotes = quotes:<EOL>(quotes[a] > quotes[b]) and a or b, list(quotes.keys()))<EOL>if delims:<EOL><INDENT>delim = reduce(lambda a, b, delims = delims:<EOL>(delims[a] > delims[b]) and a or b, list(delims.keys()))<EOL>skipinitialspace = delims[delim] == spaces<EOL>if delim == '<STR_LIT:\n>': <EOL><INDENT>delim = '<STR_LIT>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>delim = '<STR_LIT>'<EOL>skipinitialspace = <NUM_LIT:0><EOL><DEDENT>dq_regexp = re.compile(<EOL>r"<STR_LIT>" %{'<STR_LIT>':re.escape(delim), '<STR_LIT>':quotechar}, re.MULTILINE)<EOL>if dq_regexp.search(data):<EOL><INDENT>doublequote = True<EOL><DEDENT>else:<EOL><INDENT>doublequote = False<EOL><DEDENT>return (quotechar, doublequote, delim, skipinitialspace)<EOL>

Looks for text enclosed between two identical quotes
(the probable quotechar) which are preceded and followed
by the same character (the probable delimiter).
For example:
                 ,'some text',
The quote with the most wins, same with the delimiter.
If there is no quotechar the delimiter can't be determined
this way.


def _guess_delimiter(self, data, delimiters):

data = [_f for _f in data.split('<STR_LIT:\n>') if _f]<EOL>ascii = [chr(c) for c in range(<NUM_LIT>)] <EOL>chunkLength = min(<NUM_LIT:10>, len(data))<EOL>iteration = <NUM_LIT:0><EOL>charFrequency = {}<EOL>modes = {}<EOL>delims = {}<EOL>start, end = <NUM_LIT:0>, min(chunkLength, len(data))<EOL>while start < len(data):<EOL><INDENT>iteration += <NUM_LIT:1><EOL>for line in data[start:end]:<EOL><INDENT>for char in ascii:<EOL><INDENT>metaFrequency = charFrequency.get(char, {})<EOL>freq = line.count(char)<EOL>metaFrequency[freq] = metaFrequency.get(freq, <NUM_LIT:0>) + <NUM_LIT:1><EOL>charFrequency[char] = metaFrequency<EOL><DEDENT><DEDENT>for char in list(charFrequency.keys()):<EOL><INDENT>items = list(charFrequency[char].items())<EOL>if len(items) == <NUM_LIT:1> and items[<NUM_LIT:0>][<NUM_LIT:0>] == <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>if len(items) > <NUM_LIT:1>:<EOL><INDENT>modes[char] = reduce(lambda a, b: a[<NUM_LIT:1>] > b[<NUM_LIT:1>] and a or b,<EOL>items)<EOL>items.remove(modes[char])<EOL>modes[char] = (modes[char][<NUM_LIT:0>], modes[char][<NUM_LIT:1>]<EOL>- reduce(lambda a, b: (<NUM_LIT:0>, a[<NUM_LIT:1>] + b[<NUM_LIT:1>]),<EOL>items)[<NUM_LIT:1>])<EOL><DEDENT>else:<EOL><INDENT>modes[char] = items[<NUM_LIT:0>]<EOL><DEDENT><DEDENT>modeList = list(modes.items())<EOL>total = float(chunkLength * iteration)<EOL>consistency = <NUM_LIT:1.0><EOL>threshold = <NUM_LIT><EOL>while len(delims) == <NUM_LIT:0> and consistency >= threshold:<EOL><INDENT>for k, v in modeList:<EOL><INDENT>if v[<NUM_LIT:0>] > <NUM_LIT:0> and v[<NUM_LIT:1>] > <NUM_LIT:0>:<EOL><INDENT>if ((v[<NUM_LIT:1>]/total) >= consistency and<EOL>(delimiters is None or k in delimiters)):<EOL><INDENT>delims[k] = v<EOL><DEDENT><DEDENT><DEDENT>consistency -= <NUM_LIT><EOL><DEDENT>if len(delims) == <NUM_LIT:1>:<EOL><INDENT>delim = list(delims.keys())[<NUM_LIT:0>]<EOL>skipinitialspace = (data[<NUM_LIT:0>].count(delim) ==<EOL>data[<NUM_LIT:0>].count("<STR_LIT>" % delim))<EOL>return (delim, skipinitialspace)<EOL><DEDENT>start = end<EOL>end += chunkLength<EOL><DEDENT>if not delims:<EOL><INDENT>return ('<STR_LIT>', <NUM_LIT:0>)<EOL><DEDENT>if len(delims) > <NUM_LIT:1>:<EOL><INDENT>for d in self.preferred:<EOL><INDENT>if d in list(delims.keys()):<EOL><INDENT>skipinitialspace = (data[<NUM_LIT:0>].count(d) ==<EOL>data[<NUM_LIT:0>].count("<STR_LIT>" % d))<EOL>return (d, skipinitialspace)<EOL><DEDENT><DEDENT><DEDENT>items = [(v,k) for (k,v) in list(delims.items())]<EOL>items.sort()<EOL>delim = items[-<NUM_LIT:1>][<NUM_LIT:1>]<EOL>skipinitialspace = (data[<NUM_LIT:0>].count(delim) ==<EOL>data[<NUM_LIT:0>].count("<STR_LIT>" % delim))<EOL>return (delim, skipinitialspace)<EOL>

The delimiter /should/ occur the same number of times on
each row. However, due to malformed data, it may not. We don't want
an all or nothing approach, so we allow for small variations in this
number.
  1) build a table of the frequency of each character on every line.
  2) build a table of frequencies of this frequency (meta-frequency?),
     e.g.  'x occurred 5 times in 10 rows, 6 times in 1000 rows,
     7 times in 2 rows'
  3) use the mode of the meta-frequency to determine the /expected/
     frequency for that character
  4) find out how often the character actually meets that goal
  5) the character that best meets its goal is the delimiter
For performance reasons, the data is evaluated in chunks, so it can
try and evaluate the smallest portion of the data possible, evaluating
additional chunks as necessary.


global cache<EOL>cache = {}<EOL>


try:<EOL><INDENT>cached_mtime, list = cache[path]<EOL>del cache[path]<EOL><DEDENT>except KeyError:<EOL><INDENT>cached_mtime, list = -<NUM_LIT:1>, []<EOL><DEDENT>mtime = os.stat(path).st_mtime<EOL>if mtime != cached_mtime:<EOL><INDENT>list = os.listdir(path)<EOL>list.sort()<EOL><DEDENT>cache[path] = mtime, list<EOL>return list<EOL>


for i in range(len(list)):<EOL><INDENT>if os.path.isdir(os.path.join(head, list[i])):<EOL><INDENT>list[i] = list[i] + '<STR_LIT:/>'<EOL><DEDENT><DEDENT>


return list(iglob(pathname))<EOL>

Return a list of paths matching a pathname pattern.

    The pattern may contain simple shell-style wildcards a la
    fnmatch. However, unlike fnmatch, filenames starting with a
    dot are special cases that are not matched by '*' and '?'
    patterns.


dirname, basename = os.path.split(pathname)<EOL>if not has_magic(pathname):<EOL><INDENT>if basename:<EOL><INDENT>if os.path.lexists(pathname):<EOL><INDENT>yield pathname<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if os.path.isdir(dirname):<EOL><INDENT>yield pathname<EOL><DEDENT><DEDENT>return<EOL><DEDENT>if not dirname:<EOL><INDENT>for name in glob1(os.curdir, basename):<EOL><INDENT>yield name<EOL><DEDENT>return<EOL><DEDENT>if dirname != pathname and has_magic(dirname):<EOL><INDENT>dirs = iglob(dirname)<EOL><DEDENT>else:<EOL><INDENT>dirs = [dirname]<EOL><DEDENT>if has_magic(basename):<EOL><INDENT>glob_in_dir = glob1<EOL><DEDENT>else:<EOL><INDENT>glob_in_dir = glob0<EOL><DEDENT>for dirname in dirs:<EOL><INDENT>for name in glob_in_dir(dirname, basename):<EOL><INDENT>yield os.path.join(dirname, name)<EOL><DEDENT><DEDENT>

Return an iterator which yields the paths matching a pathname pattern.

    The pattern may contain simple shell-style wildcards a la
    fnmatch. However, unlike fnmatch, filenames starting with a
    dot are special cases that are not matched by '*' and '?'
    patterns.


try:<EOL><INDENT>os.stat(path)<EOL><DEDENT>except os.error:<EOL><INDENT>return False<EOL><DEDENT>return True<EOL>

Test whether a path exists.  Returns False for broken symbolic links


try:<EOL><INDENT>st = os.stat(path)<EOL><DEDENT>except os.error:<EOL><INDENT>return False<EOL><DEDENT>return stat.S_ISREG(st.st_mode)<EOL>


try:<EOL><INDENT>st = os.stat(s)<EOL><DEDENT>except os.error:<EOL><INDENT>return False<EOL><DEDENT>return stat.S_ISDIR(st.st_mode)<EOL>

Return true if the pathname refers to an existing directory.


return os.stat(filename).st_size<EOL>

Return the size of a file, reported by os.stat().


return os.stat(filename).st_mtime<EOL>

Return the last modification time of a file, reported by os.stat().


return os.stat(filename).st_atime<EOL>

Return the last access time of a file, reported by os.stat().


return os.stat(filename).st_ctime<EOL>

Return the metadata change time of a file, reported by os.stat().


if not m: return '<STR_LIT>'<EOL>s1 = min(m)<EOL>s2 = max(m)<EOL>for i, c in enumerate(s1):<EOL><INDENT>if c != s2[i]:<EOL><INDENT>return s1[:i]<EOL><DEDENT><DEDENT>return s1<EOL>

Given a list of pathnames, returns the longest common leading component


sepIndex = p.rfind(sep)<EOL>if altsep:<EOL><INDENT>altsepIndex = p.rfind(altsep)<EOL>sepIndex = max(sepIndex, altsepIndex)<EOL><DEDENT>dotIndex = p.rfind(extsep)<EOL>if dotIndex > sepIndex:<EOL><INDENT>filenameIndex = sepIndex + <NUM_LIT:1><EOL>while filenameIndex < dotIndex:<EOL><INDENT>if p[filenameIndex] != extsep:<EOL><INDENT>return p[:dotIndex], p[dotIndex:]<EOL><DEDENT>filenameIndex += <NUM_LIT:1><EOL><DEDENT><DEDENT>return p, '<STR_LIT>'<EOL>

Split the extension from a pathname.

    Extension is everything from the last dot to the end, ignoring
    leading dots.  Returns "(root, ext)"; ext may be empty.


def start_new_thread(function, args, kwargs={}):

if type(args) != type(tuple()):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>if type(kwargs) != type(dict()):<EOL><INDENT>raise TypeError("<STR_LIT>")<EOL><DEDENT>global _main<EOL>_main = False<EOL>try:<EOL><INDENT>function(*args, **kwargs)<EOL><DEDENT>except SystemExit:<EOL><INDENT>pass<EOL><DEDENT>except:<EOL><INDENT>_traceback.print_exc()<EOL><DEDENT>_main = True<EOL>global _interrupt<EOL>if _interrupt:<EOL><INDENT>_interrupt = False<EOL>raise KeyboardInterrupt<EOL><DEDENT>

Dummy implementation of thread.start_new_thread().

    Compatibility is maintained by making sure that ``args`` is a
    tuple and ``kwargs`` is a dictionary.  If an exception is raised
    and it is SystemExit (which can be done by thread.exit()) it is
    caught and nothing is done; all other exceptions are printed out
    by using traceback.print_exc().

    If the executed function calls interrupt_main the KeyboardInterrupt will be
    raised when the function returns.


raise SystemExit<EOL>


return -<NUM_LIT:1><EOL>

Dummy implementation of thread.get_ident().

    Since this module should only be used when threadmodule is not
    available, it is safe to assume that the current process is the
    only thread.  Thus a constant can be safely returned.


return LockType()<EOL>

Dummy implementation of thread.allocate_lock().


if size is not None:<EOL><INDENT>raise error("<STR_LIT>")<EOL><DEDENT>return <NUM_LIT:0><EOL>

Dummy implementation of thread.stack_size().


if _main:<EOL><INDENT>raise KeyboardInterrupt<EOL><DEDENT>else:<EOL><INDENT>global _interrupt<EOL>_interrupt = True<EOL><DEDENT>

Set _interrupt flag to True to have start_new_thread raise
    KeyboardInterrupt upon exiting.


if waitflag is None or waitflag:<EOL><INDENT>self.locked_status = True<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>if not self.locked_status:<EOL><INDENT>self.locked_status = True<EOL>return True<EOL><DEDENT>else:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>

Dummy implementation of acquire().

        For blocking calls, self.locked_status is automatically set to
        True and returned appropriately based on value of
        ``waitflag``.  If it is non-blocking, then the value is
        actually checked and not set if it is already acquired.  This
        is all done so that threading.Condition's assert statements
        aren't triggered and throw a little fit.


<EOL>if not self.locked_status:<EOL><INDENT>raise error<EOL><DEDENT>self.locked_status = False<EOL>return True<EOL>


for test in self:<EOL><INDENT>test.debug()<EOL><DEDENT>

Run the tests without collecting errors in a TestResult


debug = _DebugResult()<EOL>self.run(debug, True)<EOL>


Called once before any tests are executed.

        See startTest for a method called before each test.


Called once after all tests are executed.

        See stopTest for a method called after each test.


return len(self.failures) == len(self.errors) == <NUM_LIT:0><EOL>

Tells whether or not this result was a success


self.shouldStop = True<EOL>

Indicates that the tests should be aborted


def update_wrapper(wrapper,<EOL>wrapped,<EOL>assigned = WRAPPER_ASSIGNMENTS,<EOL>updated = WRAPPER_UPDATES):

for attr in assigned:<EOL><INDENT>setattr(wrapper, attr, getattr(wrapped, attr))<EOL><DEDENT>for attr in updated:<EOL><INDENT>getattr(wrapper, attr).update(getattr(wrapped, attr, {}))<EOL><DEDENT>return wrapper<EOL>

Update a wrapper function to look like the wrapped function

       wrapper is the function to be updated
       wrapped is the original function
       assigned is a tuple naming the attributes assigned directly
       from the wrapped function to the wrapper function (defaults to
       functools.WRAPPER_ASSIGNMENTS)
       updated is a tuple naming the attributes of the wrapper that
       are updated with the corresponding attribute from the wrapped
       function (defaults to functools.WRAPPER_UPDATES)


def wraps(wrapped,<EOL>assigned = WRAPPER_ASSIGNMENTS,<EOL>updated = WRAPPER_UPDATES):

return partial(update_wrapper, wrapped=wrapped,<EOL>assigned=assigned, updated=updated)<EOL>

Decorator factory to apply update_wrapper() to a wrapper function

       Returns a decorator that invokes update_wrapper() with the decorated
       function as the wrapper argument and the arguments to wraps() as the
       remaining arguments. Default arguments are as for update_wrapper().
       This is a convenience function to simplify applying partial() to
       update_wrapper().


convert = {<EOL>'<STR_LIT>': [('<STR_LIT>', lambda self, other: not (self < other or self == other)),<EOL>('<STR_LIT>', lambda self, other: self < other or self == other),<EOL>('<STR_LIT>', lambda self, other: not self < other)],<EOL>'<STR_LIT>': [('<STR_LIT>', lambda self, other: not self <= other or self == other),<EOL>('<STR_LIT>', lambda self, other: self <= other and not self == other),<EOL>('<STR_LIT>', lambda self, other: not self <= other)],<EOL>'<STR_LIT>': [('<STR_LIT>', lambda self, other: not (self > other or self == other)),<EOL>('<STR_LIT>', lambda self, other: self > other or self == other),<EOL>('<STR_LIT>', lambda self, other: not self > other)],<EOL>'<STR_LIT>': [('<STR_LIT>', lambda self, other: (not self >= other) or self == other),<EOL>('<STR_LIT>', lambda self, other: self >= other and not self == other),<EOL>('<STR_LIT>', lambda self, other: not self >= other)]<EOL>}<EOL>roots = set(dir(cls)) & set(convert)<EOL>if not roots:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>root = max(roots)       <EOL>for opname, opfunc in convert[root]:<EOL><INDENT>if opname not in roots:<EOL><INDENT>opfunc.__name__ = opname<EOL>opfunc.__doc__ = getattr(int, opname).__doc__<EOL>setattr(cls, opname, opfunc)<EOL><DEDENT><DEDENT>return cls<EOL>

Class decorator that fills in missing ordering methods


class K(object):<EOL><INDENT>__slots__ = ['<STR_LIT>']<EOL>def __init__(self, obj, *args):<EOL><INDENT>self.obj = obj<EOL><DEDENT>def __lt__(self, other):<EOL><INDENT>return mycmp(self.obj, other.obj) < <NUM_LIT:0><EOL><DEDENT>def __gt__(self, other):<EOL><INDENT>return mycmp(self.obj, other.obj) > <NUM_LIT:0><EOL><DEDENT>def __eq__(self, other):<EOL><INDENT>return mycmp(self.obj, other.obj) == <NUM_LIT:0><EOL><DEDENT>def __le__(self, other):<EOL><INDENT>return mycmp(self.obj, other.obj) <= <NUM_LIT:0><EOL><DEDENT>def __ge__(self, other):<EOL><INDENT>return mycmp(self.obj, other.obj) >= <NUM_LIT:0><EOL><DEDENT>def __ne__(self, other):<EOL><INDENT>return mycmp(self.obj, other.obj) != <NUM_LIT:0><EOL><DEDENT>def __hash__(self):<EOL><INDENT>raise TypeError('<STR_LIT>')<EOL><DEDENT><DEDENT>return K<EOL>

Convert a cmp= function into a key= function


raise StopIteration<EOL>

Return the next item from the iterator. When exhausted, raise StopIteration


return cls(it)<EOL>

Construct an instance of the class from any iterable input.

        Must override this method if the class constructor signature
        does not accept an iterable for an input.


for value in other:<EOL><INDENT>if value in self:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>return True<EOL>

Return True if two sets have a null intersection.


MAX = sys.maxint<EOL>MASK = <NUM_LIT:2> * MAX + <NUM_LIT:1><EOL>n = len(self)<EOL>h = <NUM_LIT> * (n + <NUM_LIT:1>)<EOL>h &= MASK<EOL>for x in self:<EOL><INDENT>hx = hash(x)<EOL>h ^= (hx ^ (hx << <NUM_LIT:16>) ^ <NUM_LIT>)  * <NUM_LIT><EOL>h &= MASK<EOL><DEDENT>h = h * <NUM_LIT> + <NUM_LIT><EOL>h &= MASK<EOL>if h > MAX:<EOL><INDENT>h -= MASK + <NUM_LIT:1><EOL><DEDENT>if h == -<NUM_LIT:1>:<EOL><INDENT>h = <NUM_LIT><EOL><DEDENT>return h<EOL>

Compute the hash value of a set.

        Note that we don't define __hash__: not all sets are hashable.
        But if you define a hashable set type, its __hash__ should
        call this function.

        This must be compatible __eq__.

        All sets ought to compare equal if they contain the same
        elements, regardless of how they are implemented, and
        regardless of the order of the elements; so there's not much
        freedom for __eq__ or __hash__.  We match the algorithm used
        by the built-in frozenset type.


raise NotImplementedError<EOL>


raise NotImplementedError<EOL>

Remove an element.  Do not raise an exception if absent.


if value not in self:<EOL><INDENT>raise KeyError(value)<EOL><DEDENT>self.discard(value)<EOL>

Remove an element. If not a member, raise a KeyError.


it = iter(self)<EOL>try:<EOL><INDENT>value = next(it)<EOL><DEDENT>except StopIteration:<EOL><INDENT>raise KeyError<EOL><DEDENT>self.discard(value)<EOL>return value<EOL>

Return the popped value.  Raise KeyError if empty.


try:<EOL><INDENT>while True:<EOL><INDENT>self.pop()<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>

This is slow (creates N new iterators!) but effective.


try:<EOL><INDENT>return self[key]<EOL><DEDENT>except KeyError:<EOL><INDENT>return default<EOL><DEDENT>

D.get(k[,d]) -> D[k] if k in D, else d.  d defaults to None.


return iter(self)<EOL>

D.iterkeys() -> an iterator over the keys of D


for key in self:<EOL><INDENT>yield self[key]<EOL><DEDENT>

D.itervalues() -> an iterator over the values of D


for key in self:<EOL><INDENT>yield (key, self[key])<EOL><DEDENT>

D.iteritems() -> an iterator over the (key, value) items of D


return list(self)<EOL>


return [(key, self[key]) for key in self]<EOL>

D.items() -> list of D's (key, value) pairs, as 2-tuples


return [self[key] for key in self]<EOL>


try:<EOL><INDENT>value = self[key]<EOL><DEDENT>except KeyError:<EOL><INDENT>if default is self.__marker:<EOL><INDENT>raise<EOL><DEDENT>return default<EOL><DEDENT>else:<EOL><INDENT>del self[key]<EOL>return value<EOL><DEDENT>

D.pop(k[,d]) -> v, remove specified key and return the corresponding value.
          If key is not found, d is returned if given, otherwise KeyError is raised.


try:<EOL><INDENT>key = next(iter(self))<EOL><DEDENT>except StopIteration:<EOL><INDENT>raise KeyError<EOL><DEDENT>value = self[key]<EOL>del self[key]<EOL>return key, value<EOL>

D.popitem() -> (k, v), remove and return some (key, value) pair
           as a 2-tuple; but raise KeyError if D is empty.


try:<EOL><INDENT>while True:<EOL><INDENT>self.popitem()<EOL><DEDENT><DEDENT>except KeyError:<EOL><INDENT>pass<EOL><DEDENT>

D.clear() -> None.  Remove all items from D.


if not args:<EOL><INDENT>raise TypeError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>self = args[<NUM_LIT:0>]<EOL>args = args[<NUM_LIT:1>:]<EOL>if len(args) > <NUM_LIT:1>:<EOL><INDENT>raise TypeError('<STR_LIT>' %<EOL>len(args))<EOL><DEDENT>if args:<EOL><INDENT>other = args[<NUM_LIT:0>]<EOL>if isinstance(other, Mapping):<EOL><INDENT>for key in other:<EOL><INDENT>self[key] = other[key]<EOL><DEDENT><DEDENT>elif hasattr(other, "<STR_LIT>"):<EOL><INDENT>for key in other.keys():<EOL><INDENT>self[key] = other[key]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for key, value in other:<EOL><INDENT>self[key] = value<EOL><DEDENT><DEDENT><DEDENT>for key, value in kwds.items():<EOL><INDENT>self[key] = value<EOL><DEDENT>

D.update([E, ]**F) -> None.  Update D from mapping/iterable E and F.
            If E present and has a .keys() method, does:     for k in E: D[k] = E[k]
            If E present and lacks .keys() method, does:     for (k, v) in E: D[k] = v
            In either case, this is followed by: for k, v in F.items(): D[k] = v


def setdefault(self, key, default=None):

try:<EOL><INDENT>return self[key]<EOL><DEDENT>except KeyError:<EOL><INDENT>self[key] = default<EOL><DEDENT>return default<EOL>

D.setdefault(k[,d]) -> D.get(k,d), also set D[k]=d if k not in D


for i, v in enumerate(self):<EOL><INDENT>if v == value:<EOL><INDENT>return i<EOL><DEDENT><DEDENT>raise ValueError<EOL>

S.index(value) -> integer -- return first index of value.
           Raises ValueError if the value is not present.


return sum(<NUM_LIT:1> for v in self if v == value)<EOL>

S.count(value) -> integer -- return number of occurrences of value


@abstractmethod<EOL><INDENT>def insert(self, index, value):<DEDENT>

raise IndexError<EOL>

S.insert(index, object) -- insert object before index


self.insert(len(self), value)<EOL>

S.append(object) -- append object to the end of the sequence


n = len(self)<EOL>for i in range(n//<NUM_LIT:2>):<EOL><INDENT>self[i], self[n-i-<NUM_LIT:1>] = self[n-i-<NUM_LIT:1>], self[i]<EOL><DEDENT>


for v in values:<EOL><INDENT>self.append(v)<EOL><DEDENT>

S.extend(iterable) -- extend sequence by appending elements from the iterable


v = self[index]<EOL>del self[index]<EOL>return v<EOL>

S.pop([index]) -> item -- remove and return item at index (default last).
           Raise IndexError if list is empty or index is out of range.


del self[self.index(value)]<EOL>

S.remove(value) -- remove first occurrence of value.
           Raise ValueError if the value is not present.


self.seed(x)<EOL>self.gauss_next = None<EOL>

Initialize an instance.

        Optional argument x controls seeding, as for Random.seed().


super(Random, self).seed(a)<EOL>self.gauss_next = None<EOL>

Initialize internal state of the random number generator.

        None or no argument seeds from current time or from an operating
        system specific randomness source if available.

        If a is not None or is an int or long, hash(a) is used instead.
        Hash values for some types are nondeterministic when the
        PYTHONHASHSEED environment variable is enabled.


def randrange(self, start, stop=None, step=<NUM_LIT:1>, _int=int, _maxwidth=<NUM_LIT:1><<BPF):

<EOL>istart = _int(start)<EOL>if istart != start:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if stop is None:<EOL><INDENT>if istart > <NUM_LIT:0>:<EOL><INDENT>if istart >= _maxwidth:<EOL><INDENT>return self._randbelow(istart)<EOL><DEDENT>return _int(self.random() * istart)<EOL><DEDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>istop = _int(stop)<EOL>if istop != stop:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>width = istop - istart<EOL>if step == <NUM_LIT:1> and width > <NUM_LIT:0>:<EOL><INDENT>if width >= _maxwidth:<EOL><INDENT>return _int(istart + self._randbelow(width))<EOL><DEDENT>return _int(istart + _int(self.random()*width))<EOL><DEDENT>if step == <NUM_LIT:1>:<EOL><INDENT>raise ValueError("<STR_LIT>" % (istart, istop, width))<EOL><DEDENT>istep = _int(step)<EOL>if istep != step:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if istep > <NUM_LIT:0>:<EOL><INDENT>n = (width + istep - <NUM_LIT:1>) // istep<EOL><DEDENT>elif istep < <NUM_LIT:0>:<EOL><INDENT>n = (width + istep + <NUM_LIT:1>) // istep<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n <= <NUM_LIT:0>:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if n >= _maxwidth:<EOL><INDENT>return istart + istep*self._randbelow(n)<EOL><DEDENT>return istart + istep*_int(self.random() * n)<EOL>

Choose a random item from range(start, stop[, step]).

        This fixes the problem with randint() which includes the
        endpoint; in Python this is usually not what you want.


return self.randrange(a, b+<NUM_LIT:1>)<EOL>

Return random integer in range [a, b], including both end points.


return seq[int(self.random() * len(seq))]<EOL>

Choose a random element from a non-empty sequence.


if random is None:<EOL><INDENT>random = self.random<EOL><DEDENT>_int = int<EOL>for i in reversed(range(<NUM_LIT:1>, len(x))):<EOL><INDENT>j = _int(random() * (i+<NUM_LIT:1>))<EOL>x[i], x[j] = x[j], x[i]<EOL><DEDENT>

x, random=random.random -> shuffle list x in place; return None.

        Optional arg random is a 0-argument function returning a random
        float in [0.0, 1.0); by default, the standard random.random.


return a + (b-a) * self.random()<EOL>

Get a random number in the range [a, b) or [a, b] depending on rounding.


def match(pattern, string, flags=<NUM_LIT:0>):

return _compile(pattern, flags).match(string)<EOL>

Try to apply the pattern at the start of the string, returning
    a match object, or None if no match was found.


def search(pattern, string, flags=<NUM_LIT:0>):

return _compile(pattern, flags).search(string)<EOL>

Scan through string looking for a match to the pattern, returning
    a match object, or None if no match was found.


def sub(pattern, repl, string, count=<NUM_LIT:0>, flags=<NUM_LIT:0>):

return _compile(pattern, flags).sub(repl, string, count)<EOL>

Return the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in string by the
    replacement repl.  repl can be either a string or a callable;
    if a string, backslash escapes in it are processed.  If it is
    a callable, it's passed the match object and must return
    a replacement string to be used.


def subn(pattern, repl, string, count=<NUM_LIT:0>, flags=<NUM_LIT:0>):

return _compile(pattern, flags).subn(repl, string, count)<EOL>

Return a 2-tuple containing (new_string, number).
    new_string is the string obtained by replacing the leftmost
    non-overlapping occurrences of the pattern in the source
    string by the replacement repl.  number is the number of
    substitutions that were made. repl can be either a string or a
    callable; if a string, backslash escapes in it are processed.
    If it is a callable, it's passed the match object and must
    return a replacement string to be used.


def split(pattern, string, maxsplit=<NUM_LIT:0>, flags=<NUM_LIT:0>):

return _compile(pattern, flags).split(string, maxsplit)<EOL>

Split the source string by the occurrences of the pattern,
    returning a list containing the resulting substrings.


def findall(pattern, string, flags=<NUM_LIT:0>):

return _compile(pattern, flags).findall(string)<EOL>def finditer(pattern, string, flags=<NUM_LIT:0>):<EOL><INDENT>"""<STR_LIT>"""<EOL>return _compile(pattern, flags).finditer(string)<EOL><DEDENT>

Return a list of all non-overlapping matches in the string.

    If one or more groups are present in the pattern, return a
    list of groups; this will be a list of tuples if the pattern
    has more than one group.

    Empty matches are included in the result.


return _compile(pattern, flags)<EOL>

Compile a regular expression pattern, returning a pattern object.


_cache.clear()<EOL>_cache_repl.clear()<EOL>


return _compile(pattern, flags|T)<EOL>

Compile a template pattern, returning a pattern object


s = list(pattern)<EOL>alphanum = _alphanum<EOL>for i, c in enumerate(pattern):<EOL><INDENT>if c not in alphanum:<EOL><INDENT>if c == "<STR_LIT>":<EOL><INDENT>s[i] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>s[i] = "<STR_LIT:\\>" + c<EOL><DEDENT><DEDENT><DEDENT>return pattern[:<NUM_LIT:0>].join(s)<EOL>

Escape all non-alphanumeric characters in pattern.


def add_argument(self, *args, **kwargs):

<EOL>chars = self.prefix_chars<EOL>if not args or len(args) == <NUM_LIT:1> and args[<NUM_LIT:0>][<NUM_LIT:0>] not in chars:<EOL><INDENT>if args and '<STR_LIT>' in kwargs:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>kwargs = self._get_positional_kwargs(*args, **kwargs)<EOL><DEDENT>else:<EOL><INDENT>kwargs = self._get_optional_kwargs(*args, **kwargs)<EOL><DEDENT>if '<STR_LIT:default>' not in kwargs:<EOL><INDENT>dest = kwargs['<STR_LIT>']<EOL>if dest in self._defaults:<EOL><INDENT>kwargs['<STR_LIT:default>'] = self._defaults[dest]<EOL><DEDENT>elif self.argument_default is not None:<EOL><INDENT>kwargs['<STR_LIT:default>'] = self.argument_default<EOL><DEDENT><DEDENT>action_class = self._pop_action_class(kwargs)<EOL>if not _callable(action_class):<EOL><INDENT>raise ValueError('<STR_LIT>' % (action_class,))<EOL><DEDENT>action = action_class(**kwargs)<EOL>type_func = self._registry_get('<STR_LIT:type>', action.type, action.type)<EOL>if not _callable(type_func):<EOL><INDENT>raise ValueError('<STR_LIT>' % (type_func,))<EOL><DEDENT>if hasattr(self, "<STR_LIT>"):<EOL><INDENT>try:<EOL><INDENT>self._get_formatter()._format_args(action, None)<EOL><DEDENT>except TypeError:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT><DEDENT>return self._add_action(action)<EOL>

add_argument(dest, ..., name=value, ...)
add_argument(option_string, option_string, ..., name=value, ...)


self.print_usage(_sys.stderr)<EOL>self.exit(<NUM_LIT:2>, _('<STR_LIT>') % (self.prog, message))<EOL>

error(message: string)

        Prints a usage message incorporating the message to stderr and
        exits.

        If you override this in a subclass, it should not return -- it
        should either exit or raise an exception.


def replace(match):<EOL><INDENT>return ESCAPE_DCT[match.group(<NUM_LIT:0>)]<EOL><DEDENT>return '<STR_LIT:">' + ESCAPE.sub(replace, s) + '<STR_LIT:">'<EOL>

Return a JSON representation of a Python string


if isinstance(s, str) and HAS_UTF8.search(s) is not None:<EOL><INDENT>s = s.decode('<STR_LIT:utf-8>')<EOL><DEDENT>def replace(match):<EOL><INDENT>s = match.group(<NUM_LIT:0>)<EOL>try:<EOL><INDENT>return ESCAPE_DCT[s]<EOL><DEDENT>except KeyError:<EOL><INDENT>n = ord(s)<EOL>if n < <NUM_LIT>:<EOL><INDENT>return '<STR_LIT>' + x4(n)<EOL><DEDENT>else:<EOL><INDENT>n -= <NUM_LIT><EOL>s1 = <NUM_LIT> | ((n >> <NUM_LIT:10>) & <NUM_LIT>)<EOL>s2 = <NUM_LIT> | (n & <NUM_LIT>)<EOL>return '<STR_LIT>' + x4(s1) + '<STR_LIT>' + x4(s2)<EOL><DEDENT><DEDENT><DEDENT>return '<STR_LIT:">' + str(ESCAPE_ASCII.sub(replace, s)) + '<STR_LIT:">'<EOL>

Return an ASCII-only JSON representation of a Python string


def __init__(self, skipkeys=False, ensure_ascii=True,<EOL>check_circular=True, allow_nan=True, sort_keys=False,<EOL>indent=None, separators=None, encoding='<STR_LIT:utf-8>', default=None):

self.skipkeys = skipkeys<EOL>self.ensure_ascii = ensure_ascii<EOL>self.check_circular = check_circular<EOL>self.allow_nan = allow_nan<EOL>self.sort_keys = sort_keys<EOL>self.indent = indent<EOL>if separators is not None:<EOL><INDENT>self.item_separator, self.key_separator = separators<EOL><DEDENT>if default is not None:<EOL><INDENT>self.default = default<EOL><DEDENT>self.encoding = encoding<EOL>

Constructor for JSONEncoder, with sensible defaults.

        If skipkeys is false, then it is a TypeError to attempt
        encoding of keys that are not str, int, long, float or None.  If
        skipkeys is True, such items are simply skipped.

        If *ensure_ascii* is true (the default), all non-ASCII
        characters in the output are escaped with \\uXXXX sequences,
        and the results are str instances consisting of ASCII
        characters only.  If ensure_ascii is False, a result may be a
        unicode instance.  This usually happens if the input contains
        unicode strings or the *encoding* parameter is used.

        If check_circular is true, then lists, dicts, and custom encoded
        objects will be checked for circular references during encoding to
        prevent an infinite recursion (which would cause an OverflowError).
        Otherwise, no such check takes place.

        If allow_nan is true, then NaN, Infinity, and -Infinity will be
        encoded as such.  This behavior is not JSON specification compliant,
        but is consistent with most JavaScript based encoders and decoders.
        Otherwise, it will be a ValueError to encode such floats.

        If sort_keys is true, then the output of dictionaries will be
        sorted by key; this is useful for regression tests to ensure
        that JSON serializations can be compared on a day-to-day basis.

        If indent is a non-negative integer, then JSON array
        elements and object members will be pretty-printed with that
        indent level.  An indent level of 0 will only insert newlines.
        None is the most compact representation.  Since the default
        item separator is ', ',  the output might include trailing
        whitespace when indent is specified.  You can use
        separators=(',', ': ') to avoid this.

        If specified, separators should be a (item_separator, key_separator)
        tuple.  The default is (', ', ': ').  To get the most compact JSON
        representation you should specify (',', ':') to eliminate whitespace.

        If specified, default is a function that gets called for objects
        that can't otherwise be serialized.  It should return a JSON encodable
        version of the object or raise a ``TypeError``.

        If encoding is not None, then all input strings will be
        transformed into unicode using that encoding prior to JSON-encoding.
        The default is UTF-8.


raise TypeError(repr(o) + "<STR_LIT>")<EOL>

Implement this method in a subclass such that it returns
        a serializable object for ``o``, or calls the base implementation
        (to raise a ``TypeError``).

        For example, to support arbitrary iterators, you could
        implement default like this::

            def default(self, o):
                try:
                    iterable = iter(o)
                except TypeError:
                    pass
                else:
                    return list(iterable)
                # Let the base class default method raise the TypeError
                return JSONEncoder.default(self, o)


<EOL>if isinstance(o, str):<EOL><INDENT>if isinstance(o, str):<EOL><INDENT>_encoding = self.encoding<EOL>if (_encoding is not None<EOL>and not (_encoding == '<STR_LIT:utf-8>')):<EOL><INDENT>o = o.decode(_encoding)<EOL><DEDENT><DEDENT>if self.ensure_ascii:<EOL><INDENT>return encode_basestring_ascii(o)<EOL><DEDENT>else:<EOL><INDENT>return encode_basestring(o)<EOL><DEDENT><DEDENT>chunks = self.iterencode(o, _one_shot=True)<EOL>if not isinstance(chunks, (list, tuple)):<EOL><INDENT>chunks = list(chunks)<EOL><DEDENT>return '<STR_LIT>'.join(chunks)<EOL>

Return a JSON string representation of a Python data structure.

        >>> JSONEncoder().encode({"foo": ["bar", "baz"]})
        '{"foo": ["bar", "baz"]}'


def iterencode(self, o, _one_shot=False):

if self.check_circular:<EOL><INDENT>markers = {}<EOL><DEDENT>else:<EOL><INDENT>markers = None<EOL><DEDENT>if self.ensure_ascii:<EOL><INDENT>_encoder = encode_basestring_ascii<EOL><DEDENT>else:<EOL><INDENT>_encoder = encode_basestring<EOL><DEDENT>if self.encoding != '<STR_LIT:utf-8>':<EOL><INDENT>def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):<EOL><INDENT>if isinstance(o, str):<EOL><INDENT>o = o.decode(_encoding)<EOL><DEDENT>return _orig_encoder(o)<EOL><DEDENT><DEDENT>def floatstr(o, allow_nan=self.allow_nan,<EOL>_repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):<EOL><INDENT>if o != o:<EOL><INDENT>text = '<STR_LIT>'<EOL><DEDENT>elif o == _inf:<EOL><INDENT>text = '<STR_LIT>'<EOL><DEDENT>elif o == _neginf:<EOL><INDENT>text = '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>return _repr(o)<EOL><DEDENT>if not allow_nan:<EOL><INDENT>raise ValueError(<EOL>"<STR_LIT>" +<EOL>repr(o))<EOL><DEDENT>return text<EOL><DEDENT>if (_one_shot and c_make_encoder is not None<EOL>and self.indent is None and not self.sort_keys):<EOL><INDENT>_iterencode = c_make_encoder(<EOL>markers, self.default, _encoder, self.indent,<EOL>self.key_separator, self.item_separator, self.sort_keys,<EOL>self.skipkeys, self.allow_nan)<EOL><DEDENT>else:<EOL><INDENT>_iterencode = _make_iterencode(<EOL>markers, self.default, _encoder, self.indent, floatstr,<EOL>self.key_separator, self.item_separator, self.sort_keys,<EOL>self.skipkeys, _one_shot)<EOL><DEDENT>return _iterencode(o, <NUM_LIT:0>)<EOL>

Encode the given object and yield each string
        representation as available.

        For example::

            for chunk in JSONEncoder().iterencode(bigobject):
                mysocket.write(chunk)


def dump(obj, fp, skipkeys=False, ensure_ascii=True, check_circular=True,<EOL>allow_nan=True, cls=None, indent=None, separators=None,<EOL>encoding='<STR_LIT:utf-8>', default=None, sort_keys=False, **kw):

<EOL>if (not skipkeys and ensure_ascii and<EOL>check_circular and allow_nan and<EOL>cls is None and indent is None and separators is None and<EOL>encoding == '<STR_LIT:utf-8>' and default is None and not sort_keys and not kw):<EOL><INDENT>iterable = _default_encoder.iterencode(obj)<EOL><DEDENT>else:<EOL><INDENT>if cls is None:<EOL><INDENT>cls = JSONEncoder<EOL><DEDENT>iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,<EOL>check_circular=check_circular, allow_nan=allow_nan, indent=indent,<EOL>separators=separators, encoding=encoding,<EOL>default=default, sort_keys=sort_keys, **kw).iterencode(obj)<EOL><DEDENT>for chunk in iterable:<EOL><INDENT>fp.write(chunk)<EOL><DEDENT>

Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
    ``.write()``-supporting file-like object).

    If ``skipkeys`` is true then ``dict`` keys that are not basic types
    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
    will be skipped instead of raising a ``TypeError``.

    If ``ensure_ascii`` is true (the default), all non-ASCII characters in the
    output are escaped with ``\\uXXXX`` sequences, and the result is a ``str``
    instance consisting of ASCII characters only.  If ``ensure_ascii`` is
    ``False``, some chunks written to ``fp`` may be ``unicode`` instances.
    This usually happens because the input contains unicode strings or the
    ``encoding`` parameter is used. Unless ``fp.write()`` explicitly
    understands ``unicode`` (as in ``codecs.getwriter``) this is likely to
    cause an error.

    If ``check_circular`` is false, then the circular reference check
    for container types will be skipped and a circular reference will
    result in an ``OverflowError`` (or worse).

    If ``allow_nan`` is false, then it will be a ``ValueError`` to
    serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
    in strict compliance of the JSON specification, instead of using the
    JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).

    If ``indent`` is a non-negative integer, then JSON array elements and
    object members will be pretty-printed with that indent level. An indent
    level of 0 will only insert newlines. ``None`` is the most compact
    representation.  Since the default item separator is ``', '``,  the
    output might include trailing whitespace when ``indent`` is specified.
    You can use ``separators=(',', ': ')`` to avoid this.

    If ``separators`` is an ``(item_separator, dict_separator)`` tuple
    then it will be used instead of the default ``(', ', ': ')`` separators.
    ``(',', ':')`` is the most compact JSON representation.

    ``encoding`` is the character encoding for str instances, default is UTF-8.

    ``default(obj)`` is a function that should return a serializable version
    of obj or raise TypeError. The default simply raises TypeError.

    If *sort_keys* is ``True`` (default: ``False``), then the output of
    dictionaries will be sorted by key.

    To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
    ``.default()`` method to serialize additional types), specify it with
    the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.


def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,<EOL>allow_nan=True, cls=None, indent=None, separators=None,<EOL>encoding='<STR_LIT:utf-8>', default=None, sort_keys=False, **kw):

<EOL>if (not skipkeys and ensure_ascii and<EOL>check_circular and allow_nan and<EOL>cls is None and indent is None and separators is None and<EOL>encoding == '<STR_LIT:utf-8>' and default is None and not sort_keys and not kw):<EOL><INDENT>return _default_encoder.encode(obj)<EOL><DEDENT>if cls is None:<EOL><INDENT>cls = JSONEncoder<EOL><DEDENT>return cls(<EOL>skipkeys=skipkeys, ensure_ascii=ensure_ascii,<EOL>check_circular=check_circular, allow_nan=allow_nan, indent=indent,<EOL>separators=separators, encoding=encoding, default=default,<EOL>sort_keys=sort_keys, **kw).encode(obj)<EOL>

Serialize ``obj`` to a JSON formatted ``str``.

    If ``skipkeys`` is true then ``dict`` keys that are not basic types
    (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
    will be skipped instead of raising a ``TypeError``.

    If ``ensure_ascii`` is false, all non-ASCII characters are not escaped, and
    the return value may be a ``unicode`` instance. See ``dump`` for details.

    If ``check_circular`` is false, then the circular reference check
    for container types will be skipped and a circular reference will
    result in an ``OverflowError`` (or worse).

    If ``allow_nan`` is false, then it will be a ``ValueError`` to
    serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
    strict compliance of the JSON specification, instead of using the
    JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).

    If ``indent`` is a non-negative integer, then JSON array elements and
    object members will be pretty-printed with that indent level. An indent
    level of 0 will only insert newlines. ``None`` is the most compact
    representation.  Since the default item separator is ``', '``,  the
    output might include trailing whitespace when ``indent`` is specified.
    You can use ``separators=(',', ': ')`` to avoid this.

    If ``separators`` is an ``(item_separator, dict_separator)`` tuple
    then it will be used instead of the default ``(', ', ': ')`` separators.
    ``(',', ':')`` is the most compact JSON representation.

    ``encoding`` is the character encoding for str instances, default is UTF-8.

    ``default(obj)`` is a function that should return a serializable version
    of obj or raise TypeError. The default simply raises TypeError.

    If *sort_keys* is ``True`` (default: ``False``), then the output of
    dictionaries will be sorted by key.

    To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
    ``.default()`` method to serialize additional types), specify it with
    the ``cls`` kwarg; otherwise ``JSONEncoder`` is used.


def load(fp, encoding=None, cls=None, object_hook=None, parse_float=None,<EOL>parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):

return loads(fp.read(),<EOL>encoding=encoding, cls=cls, object_hook=object_hook,<EOL>parse_float=parse_float, parse_int=parse_int,<EOL>parse_constant=parse_constant, object_pairs_hook=object_pairs_hook,<EOL>**kw)<EOL>

Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
    a JSON document) to a Python object.

    If the contents of ``fp`` is encoded with an ASCII based encoding other
    than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
    be specified. Encodings that are not ASCII based (such as UCS-2) are
    not allowed, and should be wrapped with
    ``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
    object and passed to ``loads()``

    ``object_hook`` is an optional function that will be called with the
    result of any object literal decode (a ``dict``). The return value of
    ``object_hook`` will be used instead of the ``dict``. This feature
    can be used to implement custom decoders (e.g. JSON-RPC class hinting).

    ``object_pairs_hook`` is an optional function that will be called with the
    result of any object literal decoded with an ordered list of pairs.  The
    return value of ``object_pairs_hook`` will be used instead of the ``dict``.
    This feature can be used to implement custom decoders that rely on the
    order that the key and value pairs are decoded (for example,
    collections.OrderedDict will remember the order of insertion). If
    ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.

    To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
    kwarg; otherwise ``JSONDecoder`` is used.


def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,<EOL>parse_int=None, parse_constant=None, object_pairs_hook=None, **kw):

if (cls is None and encoding is None and object_hook is None and<EOL>parse_int is None and parse_float is None and<EOL>parse_constant is None and object_pairs_hook is None and not kw):<EOL><INDENT>return _default_decoder.decode(s)<EOL><DEDENT>if cls is None:<EOL><INDENT>cls = JSONDecoder<EOL><DEDENT>if object_hook is not None:<EOL><INDENT>kw['<STR_LIT>'] = object_hook<EOL><DEDENT>if object_pairs_hook is not None:<EOL><INDENT>kw['<STR_LIT>'] = object_pairs_hook<EOL><DEDENT>if parse_float is not None:<EOL><INDENT>kw['<STR_LIT>'] = parse_float<EOL><DEDENT>if parse_int is not None:<EOL><INDENT>kw['<STR_LIT>'] = parse_int<EOL><DEDENT>if parse_constant is not None:<EOL><INDENT>kw['<STR_LIT>'] = parse_constant<EOL><DEDENT>return cls(encoding=encoding, **kw).decode(s)<EOL>

Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
    document) to a Python object.

    If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
    other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
    must be specified. Encodings that are not ASCII based (such as UCS-2)
    are not allowed and should be decoded to ``unicode`` first.

    ``object_hook`` is an optional function that will be called with the
    result of any object literal decode (a ``dict``). The return value of
    ``object_hook`` will be used instead of the ``dict``. This feature
    can be used to implement custom decoders (e.g. JSON-RPC class hinting).

    ``object_pairs_hook`` is an optional function that will be called with the
    result of any object literal decoded with an ordered list of pairs.  The
    return value of ``object_pairs_hook`` will be used instead of the ``dict``.
    This feature can be used to implement custom decoders that rely on the
    order that the key and value pairs are decoded (for example,
    collections.OrderedDict will remember the order of insertion). If
    ``object_hook`` is also defined, the ``object_pairs_hook`` takes priority.

    ``parse_float``, if specified, will be called with the string
    of every JSON float to be decoded. By default this is equivalent to
    float(num_str). This can be used to use another datatype or parser
    for JSON floats (e.g. decimal.Decimal).

    ``parse_int``, if specified, will be called with the string
    of every JSON int to be decoded. By default this is equivalent to
    int(num_str). This can be used to use another datatype or parser
    for JSON integers (e.g. float).

    ``parse_constant``, if specified, will be called with one of the
    following strings: -Infinity, Infinity, NaN, null, true, false.
    This can be used to raise an exception if invalid JSON numbers
    are encountered.

    To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
    kwarg; otherwise ``JSONDecoder`` is used.


def py_scanstring(s, end, encoding=None, strict=True,<EOL>_b=BACKSLASH, _m=STRINGCHUNK.match):

if encoding is None:<EOL><INDENT>encoding = DEFAULT_ENCODING<EOL><DEDENT>chunks = []<EOL>_append = chunks.append<EOL>begin = end - <NUM_LIT:1><EOL>while <NUM_LIT:1>:<EOL><INDENT>chunk = _m(s, end)<EOL>if chunk is None:<EOL><INDENT>raise ValueError(<EOL>errmsg("<STR_LIT>", s, begin))<EOL><DEDENT>end = chunk.end()<EOL>content, terminator = chunk.groups()<EOL>if content:<EOL><INDENT>if not isinstance(content, unicode):<EOL><INDENT>content = unicode(content, encoding)<EOL><DEDENT>_append(content)<EOL><DEDENT>if terminator == '<STR_LIT:">':<EOL><INDENT>break<EOL><DEDENT>elif terminator != '<STR_LIT:\\>':<EOL><INDENT>if strict:<EOL><INDENT>msg = "<STR_LIT>" % (terminator,)<EOL>raise ValueError(errmsg(msg, s, end))<EOL><DEDENT>else:<EOL><INDENT>_append(terminator)<EOL>continue<EOL><DEDENT><DEDENT>try:<EOL><INDENT>esc = s[end]<EOL><DEDENT>except IndexError:<EOL><INDENT>raise ValueError(<EOL>errmsg("<STR_LIT>", s, begin))<EOL><DEDENT>if esc != '<STR_LIT:u>':<EOL><INDENT>try:<EOL><INDENT>char = _b[esc]<EOL><DEDENT>except KeyError:<EOL><INDENT>msg = "<STR_LIT>" + repr(esc)<EOL>raise ValueError(errmsg(msg, s, end))<EOL><DEDENT>end += <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>uni = _decode_uXXXX(s, end)<EOL>end += <NUM_LIT:5><EOL>if sys.maxunicode > <NUM_LIT> and<NUM_LIT> <= uni <= <NUM_LIT> and s[end:end + <NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>uni2 = _decode_uXXXX(s, end + <NUM_LIT:1>)<EOL>if <NUM_LIT> <= uni2 <= <NUM_LIT>:<EOL><INDENT>uni = <NUM_LIT> + (((uni - <NUM_LIT>) << <NUM_LIT:10>) | (uni2 - <NUM_LIT>))<EOL>end += <NUM_LIT:6><EOL><DEDENT><DEDENT>char = unichr(uni)<EOL><DEDENT>_append(char)<EOL><DEDENT>return u'<STR_LIT>'.join(chunks), end<EOL>

Scan the string s for a JSON string. End is the index of the
    character in s after the quote that started the JSON string.
    Unescapes all valid JSON string escape sequences and raises ValueError
    on attempt to decode an invalid string. If strict is False then literal
    control characters are allowed in the string.

    Returns a tuple of the decoded string and the index of the character in s
    after the end quote.


def __init__(self, encoding=None, object_hook=None, parse_float=None,<EOL>parse_int=None, parse_constant=None, strict=True,<EOL>object_pairs_hook=None):

self.encoding = encoding<EOL>self.object_hook = object_hook<EOL>self.object_pairs_hook = object_pairs_hook<EOL>self.parse_float = parse_float or float<EOL>self.parse_int = parse_int or int<EOL>self.parse_constant = parse_constant or _CONSTANTS.__getitem__<EOL>self.strict = strict<EOL>self.parse_object = JSONObject<EOL>self.parse_array = JSONArray<EOL>self.parse_string = scanstring<EOL>self.scan_once = scanner.make_scanner(self)<EOL>

``encoding`` determines the encoding used to interpret any ``str``
        objects decoded by this instance (utf-8 by default).  It has no
        effect when decoding ``unicode`` objects.

        Note that currently only encodings that are a superset of ASCII work,
        strings of other encodings should be passed in as ``unicode``.

        ``object_hook``, if specified, will be called with the result
        of every JSON object decoded and its return value will be used in
        place of the given ``dict``.  This can be used to provide custom
        deserializations (e.g. to support JSON-RPC class hinting).

        ``object_pairs_hook``, if specified will be called with the result of
        every JSON object decoded with an ordered list of pairs.  The return
        value of ``object_pairs_hook`` will be used instead of the ``dict``.
        This feature can be used to implement custom decoders that rely on the
        order that the key and value pairs are decoded (for example,
        collections.OrderedDict will remember the order of insertion). If
        ``object_hook`` is also defined, the ``object_pairs_hook`` takes
        priority.

        ``parse_float``, if specified, will be called with the string
        of every JSON float to be decoded. By default this is equivalent to
        float(num_str). This can be used to use another datatype or parser
        for JSON floats (e.g. decimal.Decimal).

        ``parse_int``, if specified, will be called with the string
        of every JSON int to be decoded. By default this is equivalent to
        int(num_str). This can be used to use another datatype or parser
        for JSON integers (e.g. float).

        ``parse_constant``, if specified, will be called with one of the
        following strings: -Infinity, Infinity, NaN.
        This can be used to raise an exception if invalid JSON numbers
        are encountered.

        If ``strict`` is false (true is the default), then control
        characters will be allowed inside strings.  Control characters in
        this context are those with character codes in the 0-31 range,
        including ``'\\t'`` (tab), ``'\\n'``, ``'\\r'`` and ``'\\0'``.


def decode(self, s, _w=WHITESPACE.match):

obj, end = self.raw_decode(s, idx=_w(s, <NUM_LIT:0>).end())<EOL>end = _w(s, end).end()<EOL>if end != len(s):<EOL><INDENT>raise ValueError(errmsg("<STR_LIT>", s, end, len(s)))<EOL><DEDENT>return obj<EOL>

Return the Python representation of ``s`` (a ``str`` or ``unicode``
        instance containing a JSON document)


def raw_decode(self, s, idx=<NUM_LIT:0>):

try:<EOL><INDENT>obj, end = self.scan_once(s, idx)<EOL><DEDENT>except StopIteration:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>return obj, end<EOL>

Decode a JSON document from ``s`` (a ``str`` or ``unicode``
        beginning with a JSON document) and return a 2-tuple of the Python
        representation and the index in ``s`` where the document ended.

        This can be used to decode a JSON document from a string that may
        have extraneous data at the end.


res = decoder.match(s)<EOL>if res is None: raise NotANumber(s)<EOL>sign, intpart, fraction, exppart = res.group(<NUM_LIT:1>,<NUM_LIT:2>,<NUM_LIT:3>,<NUM_LIT:4>)<EOL>if sign == '<STR_LIT:+>': sign = '<STR_LIT>'<EOL>if fraction: fraction = fraction[<NUM_LIT:1>:]<EOL>if exppart: expo = int(exppart[<NUM_LIT:1>:])<EOL>else: expo = <NUM_LIT:0><EOL>return sign, intpart, fraction, expo<EOL>

Return (sign, intpart, fraction, expo) or raise an exception:
    sign is '+' or '-'
    intpart is 0 or more digits beginning with a nonzero
    fraction is 0 or more digits
    expo is an integer


if expo > <NUM_LIT:0>: <EOL><INDENT>f = len(fraction)<EOL>intpart, fraction = intpart + fraction[:expo], fraction[expo:]<EOL>if expo > f:<EOL><INDENT>intpart = intpart + '<STR_LIT:0>'*(expo-f)<EOL><DEDENT><DEDENT>elif expo < <NUM_LIT:0>: <EOL><INDENT>i = len(intpart)<EOL>intpart, fraction = intpart[:expo], intpart[expo:] + fraction<EOL>if expo < -i:<EOL><INDENT>fraction = '<STR_LIT:0>'*(-expo-i) + fraction<EOL><DEDENT><DEDENT>return intpart, fraction<EOL>

Remove the exponent by changing intpart and fraction.


f = len(fraction)<EOL>if f <= digs:<EOL><INDENT>return intpart, fraction + '<STR_LIT:0>'*(digs-f)<EOL><DEDENT>i = len(intpart)<EOL>if i+digs < <NUM_LIT:0>:<EOL><INDENT>return '<STR_LIT:0>'*-digs, '<STR_LIT>'<EOL><DEDENT>total = intpart + fraction<EOL>nextdigit = total[i+digs]<EOL>if nextdigit >= '<STR_LIT:5>': <EOL><INDENT>n = i + digs - <NUM_LIT:1><EOL>while n >= <NUM_LIT:0>:<EOL><INDENT>if total[n] != '<STR_LIT>': break<EOL>n = n-<NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>total = '<STR_LIT:0>' + total<EOL>i = i+<NUM_LIT:1><EOL>n = <NUM_LIT:0><EOL><DEDENT>total = total[:n] + chr(ord(total[n]) + <NUM_LIT:1>) + '<STR_LIT:0>'*(len(total)-n-<NUM_LIT:1>)<EOL>intpart, fraction = total[:i], total[i:]<EOL><DEDENT>if digs >= <NUM_LIT:0>:<EOL><INDENT>return intpart, fraction[:digs]<EOL><DEDENT>else:<EOL><INDENT>return intpart[:digs] + '<STR_LIT:0>'*-digs, '<STR_LIT>'<EOL><DEDENT>

Round or extend the fraction to size digs.


if type(x) != type('<STR_LIT>'): x = repr(x)<EOL>try:<EOL><INDENT>sign, intpart, fraction, expo = extract(x)<EOL><DEDENT>except NotANumber:<EOL><INDENT>return x<EOL><DEDENT>intpart, fraction = unexpo(intpart, fraction, expo)<EOL>intpart, fraction = roundfrac(intpart, fraction, digs)<EOL>while intpart and intpart[<NUM_LIT:0>] == '<STR_LIT:0>': intpart = intpart[<NUM_LIT:1>:]<EOL>if intpart == '<STR_LIT>': intpart = '<STR_LIT:0>'<EOL>if digs > <NUM_LIT:0>: return sign + intpart + '<STR_LIT:.>' + fraction<EOL>else: return sign + intpart<EOL>

Format x as [-]ddd.ddd with 'digs' digits after the point
    and at least one digit before.
    If digs <= 0, the point is suppressed.


if type(x) != type('<STR_LIT>'): x = repr(x)<EOL>sign, intpart, fraction, expo = extract(x)<EOL>if not intpart:<EOL><INDENT>while fraction and fraction[<NUM_LIT:0>] == '<STR_LIT:0>':<EOL><INDENT>fraction = fraction[<NUM_LIT:1>:]<EOL>expo = expo - <NUM_LIT:1><EOL><DEDENT>if fraction:<EOL><INDENT>intpart, fraction = fraction[<NUM_LIT:0>], fraction[<NUM_LIT:1>:]<EOL>expo = expo - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>intpart = '<STR_LIT:0>'<EOL><DEDENT><DEDENT>else:<EOL><INDENT>expo = expo + len(intpart) - <NUM_LIT:1><EOL>intpart, fraction = intpart[<NUM_LIT:0>], intpart[<NUM_LIT:1>:] + fraction<EOL><DEDENT>digs = max(<NUM_LIT:0>, digs)<EOL>intpart, fraction = roundfrac(intpart, fraction, digs)<EOL>if len(intpart) > <NUM_LIT:1>:<EOL><INDENT>intpart, fraction, expo =intpart[<NUM_LIT:0>], intpart[<NUM_LIT:1>:] + fraction[:-<NUM_LIT:1>],expo + len(intpart) - <NUM_LIT:1><EOL><DEDENT>s = sign + intpart<EOL>if digs > <NUM_LIT:0>: s = s + '<STR_LIT:.>' + fraction<EOL>e = repr(abs(expo))<EOL>e = '<STR_LIT:0>'*(<NUM_LIT:3>-len(e)) + e<EOL>if expo < <NUM_LIT:0>: e = '<STR_LIT:->' + e<EOL>else: e = '<STR_LIT:+>' + e<EOL>return s + '<STR_LIT:e>' + e<EOL>

Format x as [-]d.dddE[+-]ddd with 'digs' digits after the point
    and exactly one digit before.
    If digs is <= 0, one digit is kept and the point is suppressed.


def warnpy3k(message, category=None, stacklevel=<NUM_LIT:1>):

if sys.py3kwarning:<EOL><INDENT>if category is None:<EOL><INDENT>category = DeprecationWarning<EOL><DEDENT>warn(message, category, stacklevel+<NUM_LIT:1>)<EOL><DEDENT>

Issue a deprecation warning for Python 3.x related changes.

    Warnings are omitted unless Python is started with the -3 option.


def _show_warning(message, category, filename, lineno, file=None, line=None):

if file is None:<EOL><INDENT>file = sys.stderr<EOL>if file is None:<EOL><INDENT>return<EOL><DEDENT><DEDENT>try:<EOL><INDENT>file.write(formatwarning(message, category, filename, lineno, line))<EOL><DEDENT>except (IOError, UnicodeError):<EOL><INDENT>pass <EOL><DEDENT>

Hook to write a warning to a file; replace if you like.


def formatwarning(message, category, filename, lineno, line=None):

try:<EOL><INDENT>unicodetype = str<EOL><DEDENT>except NameError:<EOL><INDENT>unicodetype = ()<EOL><DEDENT>try:<EOL><INDENT>message = str(message)<EOL><DEDENT>except UnicodeEncodeError:<EOL><INDENT>pass<EOL><DEDENT>s =  "<STR_LIT>" % (lineno, category.__name__, message)<EOL>line = linecache.getline(filename, lineno) if line is None else line<EOL>if line:<EOL><INDENT>line = line.strip()<EOL>if isinstance(s, unicodetype) and isinstance(line, str):<EOL><INDENT>line = str(line, '<STR_LIT>')<EOL><DEDENT>s += "<STR_LIT>" % line<EOL><DEDENT>if isinstance(s, unicodetype) and isinstance(filename, str):<EOL><INDENT>enc = sys.getfilesystemencoding()<EOL>if enc:<EOL><INDENT>try:<EOL><INDENT>filename = str(filename, enc)<EOL><DEDENT>except UnicodeDecodeError:<EOL><INDENT>pass<EOL><DEDENT><DEDENT><DEDENT>s = "<STR_LIT>" % (filename, s)<EOL>return s<EOL>

Function to format a warning the standard way.


def filterwarnings(action, message="<STR_LIT>", category=Warning, module="<STR_LIT>", lineno=<NUM_LIT:0>,<EOL>append=<NUM_LIT:0>):

assert action in ("<STR_LIT:error>", "<STR_LIT:ignore>", "<STR_LIT>", "<STR_LIT:default>", "<STR_LIT>",<EOL>"<STR_LIT>"), "<STR_LIT>" % (action,)<EOL>assert isinstance(message, str), "<STR_LIT>"<EOL>assert isinstance(category, type), "<STR_LIT>"<EOL>assert issubclass(category, Warning), "<STR_LIT>"<EOL>assert isinstance(module, str), "<STR_LIT>"<EOL>assert isinstance(lineno, int) and lineno >= <NUM_LIT:0>,"<STR_LIT>"<EOL>item = (action, re.compile(message, re.I), category,<EOL>re.compile(module), lineno)<EOL>if append:<EOL><INDENT>filters.append(item)<EOL><DEDENT>else:<EOL><INDENT>filters.insert(<NUM_LIT:0>, item)<EOL><DEDENT>

Insert an entry into the list of warnings filters (at the front).

    'action' -- one of "error", "ignore", "always", "default", "module",
                or "once"
    'message' -- a regex that the warning message must match
    'category' -- a class that the warning must be a subclass of
    'module' -- a regex that the module name must match
    'lineno' -- an integer line number, 0 matches all warnings
    'append' -- if true, append to the list of filters


def simplefilter(action, category=Warning, lineno=<NUM_LIT:0>, append=<NUM_LIT:0>):

assert action in ("<STR_LIT:error>", "<STR_LIT:ignore>", "<STR_LIT>", "<STR_LIT:default>", "<STR_LIT>",<EOL>"<STR_LIT>"), "<STR_LIT>" % (action,)<EOL>assert isinstance(lineno, int) and lineno >= <NUM_LIT:0>,"<STR_LIT>"<EOL>item = (action, None, category, None, lineno)<EOL>if append:<EOL><INDENT>filters.append(item)<EOL><DEDENT>else:<EOL><INDENT>filters.insert(<NUM_LIT:0>, item)<EOL><DEDENT>

Insert a simple entry into the list of warnings filters (at the front).

    A simple filter matches all modules and messages.
    'action' -- one of "error", "ignore", "always", "default", "module",
                or "once"
    'category' -- a class that the warning must be a subclass of
    'lineno' -- an integer line number, 0 matches all warnings
    'append' -- if true, append to the list of filters


filters[:] = []<EOL>

Clear the list of warning filters, so that no filters are active.


def warn(message, category=None, stacklevel=<NUM_LIT:1>):

<EOL>if isinstance(message, Warning):<EOL><INDENT>category = message.__class__<EOL><DEDENT>if category is None:<EOL><INDENT>category = UserWarning<EOL><DEDENT>assert issubclass(category, Warning)<EOL>try:<EOL><INDENT>caller = sys._getframe(stacklevel)<EOL><DEDENT>except ValueError:<EOL><INDENT>globals = sys.__dict__<EOL>lineno = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>globals = caller.f_globals<EOL>lineno = caller.f_lineno<EOL><DEDENT>if '<STR_LIT>' in globals:<EOL><INDENT>module = globals['<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>module = "<STR_LIT>"<EOL><DEDENT>filename = globals.get('<STR_LIT>')<EOL>if filename:<EOL><INDENT>fnl = filename.lower()<EOL>if fnl.endswith(("<STR_LIT>", "<STR_LIT>")):<EOL><INDENT>filename = filename[:-<NUM_LIT:1>]<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if module == "<STR_LIT:__main__>":<EOL><INDENT>try:<EOL><INDENT>filename = sys.argv[<NUM_LIT:0>]<EOL><DEDENT>except AttributeError:<EOL><INDENT>filename = '<STR_LIT:__main__>'<EOL><DEDENT><DEDENT>if not filename:<EOL><INDENT>filename = module<EOL><DEDENT><DEDENT>registry = globals.setdefault("<STR_LIT>", {})<EOL>warn_explicit(message, category, filename, lineno, module, registry,<EOL>globals)<EOL>

Issue a warning, or maybe ignore it or raise an exception.


def __init__(self, record=False, module=None):

self._record = record<EOL>self._module = sys.modules['<STR_LIT>'] if module is None else module<EOL>self._entered = False<EOL>

Specify whether to record warnings and if an alternative module
        should be used other than sys.modules['warnings'].

        For compatibility with Python 3.0, please consider all arguments to be
        keyword-only.


def getopt(args, shortopts, longopts = []):

opts = []<EOL>if type(longopts) == type("<STR_LIT>"):<EOL><INDENT>longopts = [longopts]<EOL><DEDENT>else:<EOL><INDENT>longopts = list(longopts)<EOL><DEDENT>while args and args[<NUM_LIT:0>].startswith('<STR_LIT:->') and args[<NUM_LIT:0>] != '<STR_LIT:->':<EOL><INDENT>if args[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>args = args[<NUM_LIT:1>:]<EOL>break<EOL><DEDENT>if args[<NUM_LIT:0>].startswith('<STR_LIT>'):<EOL><INDENT>opts, args = do_longs(opts, args[<NUM_LIT:0>][<NUM_LIT:2>:], longopts, args[<NUM_LIT:1>:])<EOL><DEDENT>else:<EOL><INDENT>opts, args = do_shorts(opts, args[<NUM_LIT:0>][<NUM_LIT:1>:], shortopts, args[<NUM_LIT:1>:])<EOL><DEDENT><DEDENT>return opts, args<EOL>

getopt(args, options[, long_options]) -> opts, args

    Parses command line options and parameter list.  args is the
    argument list to be parsed, without the leading reference to the
    running program.  Typically, this means "sys.argv[1:]".  shortopts
    is the string of option letters that the script wants to
    recognize, with options that require an argument followed by a
    colon (i.e., the same format that Unix getopt() uses).  If
    specified, longopts is a list of strings with the names of the
    long options which should be supported.  The leading '--'
    characters should not be included in the option name.  Options
    which require an argument should be followed by an equal sign
    ('=').

    The return value consists of two elements: the first is a list of
    (option, value) pairs; the second is the list of program arguments
    left after the option list was stripped (this is a trailing slice
    of the first argument).  Each option-and-value pair returned has
    the option as its first element, prefixed with a hyphen (e.g.,
    '-x'), and the option argument as its second element, or an empty
    string if the option has no argument.  The options occur in the
    list in the same order in which they were found, thus allowing
    multiple occurrences.  Long and short options may be mixed.


def gnu_getopt(args, shortopts, longopts = []):

opts = []<EOL>prog_args = []<EOL>if isinstance(longopts, str):<EOL><INDENT>longopts = [longopts]<EOL><DEDENT>else:<EOL><INDENT>longopts = list(longopts)<EOL><DEDENT>if shortopts.startswith('<STR_LIT:+>'):<EOL><INDENT>shortopts = shortopts[<NUM_LIT:1>:]<EOL>all_options_first = True<EOL><DEDENT>elif os.environ.get("<STR_LIT>"):<EOL><INDENT>all_options_first = True<EOL><DEDENT>else:<EOL><INDENT>all_options_first = False<EOL><DEDENT>while args:<EOL><INDENT>if args[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>prog_args += args[<NUM_LIT:1>:]<EOL>break<EOL><DEDENT>if args[<NUM_LIT:0>][:<NUM_LIT:2>] == '<STR_LIT>':<EOL><INDENT>opts, args = do_longs(opts, args[<NUM_LIT:0>][<NUM_LIT:2>:], longopts, args[<NUM_LIT:1>:])<EOL><DEDENT>elif args[<NUM_LIT:0>][:<NUM_LIT:1>] == '<STR_LIT:->' and args[<NUM_LIT:0>] != '<STR_LIT:->':<EOL><INDENT>opts, args = do_shorts(opts, args[<NUM_LIT:0>][<NUM_LIT:1>:], shortopts, args[<NUM_LIT:1>:])<EOL><DEDENT>else:<EOL><INDENT>if all_options_first:<EOL><INDENT>prog_args += args<EOL>break<EOL><DEDENT>else:<EOL><INDENT>prog_args.append(args[<NUM_LIT:0>])<EOL>args = args[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT><DEDENT>return opts, prog_args<EOL>

getopt(args, options[, long_options]) -> opts, args

    This function works like getopt(), except that GNU style scanning
    mode is used by default. This means that option and non-option
    arguments may be intermixed. The getopt() function stops
    processing options as soon as a non-option argument is
    encountered.

    If the first character of the option string is `+', or if the
    environment variable POSIXLY_CORRECT is set, then option
    processing stops as soon as a non-option argument is encountered.


<EOL>globals()['<STR_LIT>'] = {}<EOL>


<EOL>return fnmatchcase(name, pat)<EOL>

Test whether FILENAME matches PATTERN.

    Patterns are Unix shell style:

    *       matches everything
    ?       matches any single character
    [seq]   matches any character in seq
    [!seq]  matches any char not in seq

    An initial period in FILENAME is not special.
    Both FILENAME and PATTERN are first case-normalized
    if the operating system requires it.
    If you don't want this, use fnmatchcase(FILENAME, PATTERN).


import os<EOL>result=[]<EOL>try:<EOL><INDENT>re_pat = _cache[pat]<EOL><DEDENT>except KeyError:<EOL><INDENT>res = translate(pat)<EOL>if len(_cache) >= _MAXCACHE:<EOL><INDENT>globals()['<STR_LIT>'] = {}<EOL><DEDENT>_cache[pat] = re_pat = re.compile(res)<EOL><DEDENT>match = re_pat.match<EOL>if <NUM_LIT:1>:<EOL><INDENT>for name in names:<EOL><INDENT>if match(name):<EOL><INDENT>result.append(name)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>for name in names:<EOL><INDENT>if match(os.path.normcase(name)):<EOL><INDENT>result.append(name)<EOL><DEDENT><DEDENT><DEDENT>return result<EOL>

Return the subset of the list NAMES that match PAT


try:<EOL><INDENT>re_pat = _cache[pat]<EOL><DEDENT>except KeyError:<EOL><INDENT>res = translate(pat)<EOL>if len(_cache) >= _MAXCACHE:<EOL><INDENT>globals()['<STR_LIT>'] = {}<EOL><DEDENT>_cache[pat] = re_pat = re.compile(res)<EOL><DEDENT>return re_pat.match(name) is not None<EOL>

Test whether FILENAME matches PATTERN, including case.

    This is a version of fnmatch() which doesn't case-normalize
    its arguments.


i, n = <NUM_LIT:0>, len(pat)<EOL>res = '<STR_LIT>'<EOL>while i < n:<EOL><INDENT>c = pat[i]<EOL>i = i+<NUM_LIT:1><EOL>if c == '<STR_LIT:*>':<EOL><INDENT>res = res + '<STR_LIT>'<EOL><DEDENT>elif c == '<STR_LIT:?>':<EOL><INDENT>res = res + '<STR_LIT:.>'<EOL><DEDENT>elif c == '<STR_LIT:[>':<EOL><INDENT>j = i<EOL>if j < n and pat[j] == '<STR_LIT:!>':<EOL><INDENT>j = j+<NUM_LIT:1><EOL><DEDENT>if j < n and pat[j] == '<STR_LIT:]>':<EOL><INDENT>j = j+<NUM_LIT:1><EOL><DEDENT>while j < n and pat[j] != '<STR_LIT:]>':<EOL><INDENT>j = j+<NUM_LIT:1><EOL><DEDENT>if j >= n:<EOL><INDENT>res = res + '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>stuff = pat[i:j].replace('<STR_LIT:\\>','<STR_LIT>')<EOL>i = j+<NUM_LIT:1><EOL>if stuff[<NUM_LIT:0>] == '<STR_LIT:!>':<EOL><INDENT>stuff = '<STR_LIT>' + stuff[<NUM_LIT:1>:]<EOL><DEDENT>elif stuff[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>stuff = '<STR_LIT:\\>' + stuff<EOL><DEDENT>res = '<STR_LIT>' % (res, stuff)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>res = res + re.escape(c)<EOL><DEDENT><DEDENT>return res + '<STR_LIT>'<EOL>

Translate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.


int_part = int(x)<EOL>frac_part = x - int_part<EOL>if frac_part > <NUM_LIT:0.5> or frac_part == <NUM_LIT:0.5> and int_part & <NUM_LIT:1> == <NUM_LIT:1>:<EOL><INDENT>int_part += <NUM_LIT:1><EOL><DEDENT>return int_part<EOL>

Python 3 style round:  round a float x to the nearest int, but
    unlike the builtin Python 2.x round function:

      - return an int, not a float
      - do round-half-to-even, not round-half-away-from-zero.

    We assume that x is finite and nonnegative; except wrong results
    if you use this for negative x.


if size == <NUM_LIT:8>:<EOL><INDENT>MIN_EXP = -<NUM_LIT>  <EOL>MAX_EXP = <NUM_LIT>   <EOL>MANT_DIG = <NUM_LIT>    <EOL>BITS = <NUM_LIT:64><EOL><DEDENT>elif size == <NUM_LIT:4>:<EOL><INDENT>MIN_EXP = -<NUM_LIT>   <EOL>MAX_EXP = <NUM_LIT>    <EOL>MANT_DIG = <NUM_LIT>    <EOL>BITS = <NUM_LIT:32><EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if Q >> BITS:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>sign = Q >> BITS - <NUM_LIT:1><EOL>exp = (Q & ((<NUM_LIT:1> << BITS - <NUM_LIT:1>) - (<NUM_LIT:1> << MANT_DIG - <NUM_LIT:1>))) >> MANT_DIG - <NUM_LIT:1><EOL>mant = Q & ((<NUM_LIT:1> << MANT_DIG - <NUM_LIT:1>) - <NUM_LIT:1>)<EOL>if exp == MAX_EXP - MIN_EXP + <NUM_LIT:2>:<EOL><INDENT>result = float('<STR_LIT>') if mant else float('<STR_LIT>')<EOL><DEDENT>elif exp == <NUM_LIT:0>:<EOL><INDENT>result = math.ldexp(float(mant), MIN_EXP - MANT_DIG)<EOL><DEDENT>else:<EOL><INDENT>mant += <NUM_LIT:1> << MANT_DIG - <NUM_LIT:1><EOL>result = math.ldexp(float(mant), exp + MIN_EXP - MANT_DIG - <NUM_LIT:1>)<EOL><DEDENT>return -result if sign else result<EOL>

Convert a 32-bit or 64-bit integer created
    by float_pack into a Python float.


if size == <NUM_LIT:8>:<EOL><INDENT>MIN_EXP = -<NUM_LIT>  <EOL>MAX_EXP = <NUM_LIT>   <EOL>MANT_DIG = <NUM_LIT>    <EOL>BITS = <NUM_LIT:64><EOL><DEDENT>elif size == <NUM_LIT:4>:<EOL><INDENT>MIN_EXP = -<NUM_LIT>   <EOL>MAX_EXP = <NUM_LIT>    <EOL>MANT_DIG = <NUM_LIT>    <EOL>BITS = <NUM_LIT:32><EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>sign = math.copysign(<NUM_LIT:1.0>, x) < <NUM_LIT:0.0><EOL>if math.isinf(x):<EOL><INDENT>mant = <NUM_LIT:0><EOL>exp = MAX_EXP - MIN_EXP + <NUM_LIT:2><EOL><DEDENT>elif math.isnan(x):<EOL><INDENT>mant = <NUM_LIT:1> << (MANT_DIG - <NUM_LIT:2>)  <EOL>exp = MAX_EXP - MIN_EXP + <NUM_LIT:2><EOL><DEDENT>elif x == <NUM_LIT:0.0>:<EOL><INDENT>mant = <NUM_LIT:0><EOL>exp = <NUM_LIT:0><EOL><DEDENT>else:<EOL><INDENT>m, e = math.frexp(abs(x))  <EOL>exp = e - (MIN_EXP - <NUM_LIT:1>)<EOL>if exp > <NUM_LIT:0>:<EOL><INDENT>mant = round_to_nearest(m * (<NUM_LIT:1> << MANT_DIG))<EOL>mant -= <NUM_LIT:1> << MANT_DIG - <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>if exp + MANT_DIG - <NUM_LIT:1> >= <NUM_LIT:0>:<EOL><INDENT>mant = round_to_nearest(m * (<NUM_LIT:1> << exp + MANT_DIG - <NUM_LIT:1>))<EOL><DEDENT>else:<EOL><INDENT>mant = <NUM_LIT:0><EOL><DEDENT>exp = <NUM_LIT:0><EOL><DEDENT>assert <NUM_LIT:0> <= mant <= <NUM_LIT:1> << MANT_DIG - <NUM_LIT:1><EOL>if mant == <NUM_LIT:1> << MANT_DIG - <NUM_LIT:1>:<EOL><INDENT>mant = <NUM_LIT:0><EOL>exp += <NUM_LIT:1><EOL><DEDENT>if exp >= MAX_EXP - MIN_EXP + <NUM_LIT:2>:<EOL><INDENT>raise OverflowError("<STR_LIT>")<EOL><DEDENT><DEDENT>assert <NUM_LIT:0> <= mant < <NUM_LIT:1> << MANT_DIG - <NUM_LIT:1><EOL>assert <NUM_LIT:0> <= exp <= MAX_EXP - MIN_EXP + <NUM_LIT:2><EOL>assert <NUM_LIT:0> <= sign <= <NUM_LIT:1><EOL>return ((sign << BITS - <NUM_LIT:1>) | (exp << MANT_DIG - <NUM_LIT:1>)) | mant<EOL>

Convert a Python float x into a 64-bit unsigned integer
    with the same byte representation.


formatdef, endianness, i = getmode(fmt)<EOL>num = <NUM_LIT:0><EOL>result = <NUM_LIT:0><EOL>while i < len(fmt):<EOL><INDENT>num, i = getNum(fmt, i)<EOL>cur = fmt[i]<EOL>try:<EOL><INDENT>format = formatdef[cur]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise StructError("<STR_LIT>" % cur)<EOL><DEDENT>if num != None:<EOL><INDENT>result += num * format['<STR_LIT:size>']<EOL><DEDENT>else:<EOL><INDENT>result += format['<STR_LIT:size>']<EOL><DEDENT>num = <NUM_LIT:0><EOL>i += <NUM_LIT:1><EOL><DEDENT>return result<EOL>

calcsize(fmt) -> int
    Return size of C struct described by format string fmt.
    See struct.__doc__ for more on format strings.


formatdef, endianness, i = getmode(fmt)<EOL>args = list(args)<EOL>n_args = len(args)<EOL>result = []<EOL>while i < len(fmt):<EOL><INDENT>num, i = getNum(fmt, i)<EOL>cur = fmt[i]<EOL>try:<EOL><INDENT>format = formatdef[cur]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise StructError("<STR_LIT>" % cur)<EOL><DEDENT>if num == None:<EOL><INDENT>num_s = <NUM_LIT:0><EOL>num = <NUM_LIT:1><EOL><DEDENT>else:<EOL><INDENT>num_s = num<EOL><DEDENT>if cur == '<STR_LIT:x>':<EOL><INDENT>result += [b'<STR_LIT>' * num]<EOL><DEDENT>elif cur == '<STR_LIT:s>':<EOL><INDENT>if isinstance(args[<NUM_LIT:0>], bytes):<EOL><INDENT>padding = num - len(args[<NUM_LIT:0>])<EOL>result += [args[<NUM_LIT:0>][:num] + b'<STR_LIT>' * padding]<EOL>args.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>raise StructError("<STR_LIT>")<EOL><DEDENT><DEDENT>elif cur == '<STR_LIT:p>':<EOL><INDENT>if isinstance(args[<NUM_LIT:0>], bytes):<EOL><INDENT>padding = num - len(args[<NUM_LIT:0>]) - <NUM_LIT:1><EOL>if padding > <NUM_LIT:0>:<EOL><INDENT>result += [bytes([len(args[<NUM_LIT:0>])]) + args[<NUM_LIT:0>]<EOL>[:num - <NUM_LIT:1>] + b'<STR_LIT>' * padding]<EOL><DEDENT>else:<EOL><INDENT>if num < <NUM_LIT:255>:<EOL><INDENT>result += [bytes([num - <NUM_LIT:1>]) + args[<NUM_LIT:0>][:num - <NUM_LIT:1>]]<EOL><DEDENT>else:<EOL><INDENT>result += [bytes([<NUM_LIT:255>]) + args[<NUM_LIT:0>][:num - <NUM_LIT:1>]]<EOL><DEDENT><DEDENT>args.pop(<NUM_LIT:0>)<EOL><DEDENT>else:<EOL><INDENT>raise StructError("<STR_LIT>")<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if len(args) < num:<EOL><INDENT>raise StructError("<STR_LIT>")<EOL><DEDENT>for var in args[:num]:<EOL><INDENT>result += [format['<STR_LIT>'](var, format['<STR_LIT:size>'], endianness)]<EOL><DEDENT>args = args[num:]<EOL><DEDENT>num = None<EOL>i += <NUM_LIT:1><EOL><DEDENT>if len(args) != <NUM_LIT:0>:<EOL><INDENT>raise StructError("<STR_LIT>")<EOL><DEDENT>return b'<STR_LIT>'.join(result)<EOL>

pack(fmt, v1, v2, ...) -> string
       Return string containing values v1, v2, ... packed according to fmt.
       See struct.__doc__ for more on format strings.


formatdef, endianness, i = getmode(fmt)<EOL>j = <NUM_LIT:0><EOL>num = <NUM_LIT:0><EOL>result = []<EOL>length = calcsize(fmt)<EOL>if length != len(data):<EOL><INDENT>raise StructError("<STR_LIT>")<EOL><DEDENT>while i < len(fmt):<EOL><INDENT>num, i = getNum(fmt, i)<EOL>cur = fmt[i]<EOL>i += <NUM_LIT:1><EOL>try:<EOL><INDENT>format = formatdef[cur]<EOL><DEDENT>except KeyError:<EOL><INDENT>raise StructError("<STR_LIT>" % cur)<EOL><DEDENT>if not num:<EOL><INDENT>num = <NUM_LIT:1><EOL><DEDENT>if cur == '<STR_LIT:x>':<EOL><INDENT>j += num<EOL><DEDENT>elif cur == '<STR_LIT:s>':<EOL><INDENT>result.append(data[j:j + num])<EOL>j += num<EOL><DEDENT>elif cur == '<STR_LIT:p>':<EOL><INDENT>n = data[j]<EOL>if n >= num:<EOL><INDENT>n = num - <NUM_LIT:1><EOL><DEDENT>result.append(data[j + <NUM_LIT:1>:j + n + <NUM_LIT:1>])<EOL>j += num<EOL><DEDENT>else:<EOL><INDENT>for n in range(num):<EOL><INDENT>result += [format['<STR_LIT>'](data, j, format['<STR_LIT:size>'], endianness)]<EOL>j += format['<STR_LIT:size>']<EOL><DEDENT><DEDENT><DEDENT>return tuple(result)<EOL>

unpack(fmt, string) -> (v1, v2, ...)
       Unpack the string, containing packed C structure data, according
       to fmt.  Requires len(string)==calcsize(fmt).
       See struct.__doc__ for more on format strings.


<EOL>