desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Hook method executed once when the cmdloop() method is about to
return.'
| def postloop(self):
| pass
|
'Parse the line into a command name and a string containing
the arguments. Returns a tuple containing (command, args, line).
\'command\' and \'args\' may be None if the line couldn\'t be parsed.'
| def parseline(self, line):
| line = line.strip()
if (not line):
return (None, None, line)
elif (line[0] == '?'):
line = ('help ' + line[1:])
elif (line[0] == '!'):
if hasattr(self, 'do_shell'):
line = ('shell ' + line[1:])
else:
return (None, None, line)
(i, n) = (0,... |
'Interpret the argument as though it had been typed in response
to the prompt.
This may be overridden, but should not normally need to be;
see the precmd() and postcmd() methods for useful execution hooks.
The return value is a flag indicating whether interpretation of
commands by the interpreter should stop.'
| def onecmd(self, line):
| (cmd, arg, line) = self.parseline(line)
if (not line):
return self.emptyline()
if (cmd is None):
return self.default(line)
self.lastcmd = line
if (cmd == ''):
return self.default(line)
else:
try:
func = getattr(self, ('do_' + cmd))
except Attri... |
'Called when an empty line is entered in response to the prompt.
If this method is not overridden, it repeats the last nonempty
command entered.'
| def emptyline(self):
| if self.lastcmd:
return self.onecmd(self.lastcmd)
|
'Called on an input line when the command prefix is not recognized.
If this method is not overridden, it prints an error message and
returns.'
| def default(self, line):
| self.stdout.write(('*** Unknown syntax: %s\n' % line))
|
'Method called to complete an input line when no command-specific
complete_*() method is available.
By default, it returns an empty list.'
| def completedefault(self, *ignored):
| return []
|
'Return the next possible completion for \'text\'.
If a command has not been entered, then complete against command list.
Otherwise try to call complete_<command> to get list of completions.'
| def complete(self, text, state):
| if (state == 0):
import readline
origline = readline.get_line_buffer()
line = origline.lstrip()
stripped = (len(origline) - len(line))
begidx = (readline.get_begidx() - stripped)
endidx = (readline.get_endidx() - stripped)
if (begidx > 0):
(cmd, ar... |
'Display a list of strings as a compact set of columns.
Each column is only as wide as necessary.
Columns are separated by two spaces (one was not legible enough).'
| def columnize(self, list, displaywidth=80):
| if (not list):
self.stdout.write('<empty>\n')
return
nonstrings = [i for i in range(len(list)) if (not isinstance(list[i], str))]
if nonstrings:
raise TypeError, ('list[i] not a string for i in %s' % ', '.join(map(str, nonstrings)))
size = len(list)
if... |
'Deprecated. Use the readPlist() function instead.'
| def fromFile(cls, pathOrFile):
| rootObject = readPlist(pathOrFile)
plist = cls()
plist.update(rootObject)
return plist
|
'Deprecated. Use the writePlist() function instead.'
| def write(self, pathOrFile):
| writePlist(self, pathOrFile)
|
'Send user name, return response
(should indicate password required).'
| def user(self, user):
| return self._shortcmd(('USER %s' % user))
|
'Send password, return response
(response includes message count, mailbox size).
NB: mailbox is locked by server from here to \'quit()\''
| def pass_(self, pswd):
| return self._shortcmd(('PASS %s' % pswd))
|
'Get mailbox status.
Result is tuple of 2 ints (message count, mailbox size)'
| def stat(self):
| retval = self._shortcmd('STAT')
rets = retval.split()
if self._debugging:
print '*stat*', repr(rets)
numMessages = int(rets[1])
sizeMessages = int(rets[2])
return (numMessages, sizeMessages)
|
'Request listing, return result.
Result without a message number argument is in form
[\'response\', [\'mesg_num octets\', ...], octets].
Result when a message number argument is given is a
single response: the "scan listing" for that message.'
| def list(self, which=None):
| if (which is not None):
return self._shortcmd(('LIST %s' % which))
return self._longcmd('LIST')
|
'Retrieve whole message number \'which\'.
Result is in form [\'response\', [\'line\', ...], octets].'
| def retr(self, which):
| return self._longcmd(('RETR %s' % which))
|
'Delete message number \'which\'.
Result is \'response\'.'
| def dele(self, which):
| return self._shortcmd(('DELE %s' % which))
|
'Does nothing.
One supposes the response indicates the server is alive.'
| def noop(self):
| return self._shortcmd('NOOP')
|
'Unmark all messages marked for deletion.'
| def rset(self):
| return self._shortcmd('RSET')
|
'Signoff: commit changes on server, unlock mailbox, close connection.'
| def quit(self):
| try:
resp = self._shortcmd('QUIT')
except error_proto as val:
resp = val
self.file.close()
self.sock.close()
del self.file, self.sock
return resp
|
'Not sure what this does.'
| def rpop(self, user):
| return self._shortcmd(('RPOP %s' % user))
|
'Authorisation
- only possible if server has supplied a timestamp in initial greeting.
Args:
user - mailbox user;
secret - secret shared between client and server.
NB: mailbox is locked by server from here to \'quit()\''
| def apop(self, user, secret):
| m = self.timestamp.match(self.welcome)
if (not m):
raise error_proto('-ERR APOP not supported by server')
import hashlib
digest = hashlib.md5((m.group(1) + secret)).digest()
digest = ''.join(map((lambda x: ('%02x' % ord(x))), digest))
return self._shortcmd(('APOP %s ... |
'Retrieve message header of message number \'which\'
and first \'howmuch\' lines of message body.
Result is in form [\'response\', [\'line\', ...], octets].'
| def top(self, which, howmuch):
| return self._longcmd(('TOP %s %s' % (which, howmuch)))
|
'Return message digest (unique id) list.
If \'which\', result contains unique id for that message
in the form \'response mesgnum uid\', otherwise result is
the list [\'response\', [\'mesgnum uid\', ...], octets]'
| def uidl(self, which=None):
| if (which is not None):
return self._shortcmd(('UIDL %s' % which))
return self._longcmd('UIDL')
|
'Set the input delimiter. Can be a fixed string of any length, an integer, or None'
| def set_terminator(self, term):
| self.terminator = term
|
'predicate for inclusion in the readable for select()'
| def readable(self):
| return 1
|
'predicate for inclusion in the writable for select()'
| def writable(self):
| return (self.producer_fifo or (not self.connected))
|
'automatically close this channel once the outgoing queue is empty'
| def close_when_done(self):
| self.producer_fifo.append(None)
|
'Create a UUID from either a string of 32 hexadecimal digits,
a string of 16 bytes as the \'bytes\' argument, a string of 16 bytes
in little-endian order as the \'bytes_le\' argument, a tuple of six
integers (32-bit time_low, 16-bit time_mid, 16-bit time_hi_version,
8-bit clock_seq_hi_variant, 8-bit clock_seq_low, 48-b... | def __init__(self, hex=None, bytes=None, bytes_le=None, fields=None, int=None, version=None):
| if ([hex, bytes, bytes_le, fields, int].count(None) != 4):
raise TypeError('need one of hex, bytes, bytes_le, fields, or int')
if (hex is not None):
hex = hex.replace('urn:', '').replace('uuid:', '')
hex = hex.strip('{}').replace('-', '')
if (len(hex) != 3... |
'Create a new completer for the command line.
Completer([namespace]) -> completer instance.
If unspecified, the default namespace where completions are performed
is __main__ (technically, __main__.__dict__). Namespaces should be
given as dictionaries.
Completer instances should be used as the completion mechanism of
re... | def __init__(self, namespace=None):
| if (namespace and (not isinstance(namespace, dict))):
raise TypeError, 'namespace must be a dictionary'
if (namespace is None):
self.use_main_ns = 1
else:
self.use_main_ns = 0
self.namespace = namespace
|
'Return the next possible completion for \'text\'.
This is called successively with state == 0, 1, 2, ... until it
returns None. The completion should begin with \'text\'.'
| def complete(self, text, state):
| if self.use_main_ns:
self.namespace = __main__.__dict__
if (state == 0):
if ('.' in text):
self.matches = self.attr_matches(text)
else:
self.matches = self.global_matches(text)
try:
return self.matches[state]
except IndexError:
return None
|
'Compute matches when text is a simple name.
Return a list of all keywords, built-in functions and names currently
defined in self.namespace that match.'
| def global_matches(self, text):
| import keyword
matches = []
n = len(text)
for word in keyword.kwlist:
if (word[:n] == text):
matches.append(word)
for nspace in [__builtin__.__dict__, self.namespace]:
for (word, val) in nspace.items():
if ((word[:n] == text) and (word != '__builtins__')):
... |
'Compute matches when text contains a dot.
Assuming the text is of the form NAME.NAME....[NAME], and is
evaluatable in self.namespace, it will be evaluated and its attributes
(as revealed by dir()) are used as possible completions. (For class
instances, class members are also considered.)
WARNING: this can still invok... | def attr_matches(self, text):
| import re
m = re.match('(\\w+(\\.\\w+)*)\\.(\\w*)', text)
if (not m):
return []
(expr, attr) = m.group(1, 3)
try:
thisobject = eval(expr, self.namespace)
except Exception:
return []
words = dir(thisobject)
if ('__builtins__' in words):
words.remove('__buil... |
'Initialize the class instance and read the headers.'
| def __init__(self, fp, seekable=1):
| if (seekable == 1):
try:
fp.tell()
except (AttributeError, IOError):
seekable = 0
self.fp = fp
self.seekable = seekable
self.startofheaders = None
self.startofbody = None
if self.seekable:
try:
self.startofheaders = self.fp.tell()
... |
'Rewind the file to the start of the body (if seekable).'
| def rewindbody(self):
| if (not self.seekable):
raise IOError, 'unseekable file'
self.fp.seek(self.startofbody)
|
'Read header lines.
Read header lines up to the entirely blank line that terminates them.
The (normally blank) line that ends the headers is skipped, but not
included in the returned list. If a non-header line ends the headers,
(which is an error), an attempt is made to backspace over it; it is
never included in the r... | def readheaders(self):
| self.dict = {}
self.unixfrom = ''
self.headers = lst = []
self.status = ''
headerseen = ''
firstline = 1
startofline = unread = tell = None
if hasattr(self.fp, 'unread'):
unread = self.fp.unread
elif self.seekable:
tell = self.fp.tell
while 1:
if tell:
... |
'Determine whether a given line is a legal header.
This method should return the header name, suitably canonicalized.
You may override this method in order to use Message parsing on tagged
data in RFC 2822-like formats with special header formats.'
| def isheader(self, line):
| i = line.find(':')
if (i > 0):
return line[:i].lower()
return None
|
'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
also matches.'
| def islast(self, line):
| return (line in _blanklines)
|
'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.'
| def iscomment(self, line):
| return False
|
'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, ... | def getallmatchingheaders(self, name):
| name = (name.lower() + ':')
n = len(name)
lst = []
hit = 0
for line in self.headers:
if (line[:n].lower() == name):
hit = 1
elif (not line[:1].isspace()):
hit = 0
if hit:
lst.append(line)
return lst
|
'Get the first header line matching name.
This is similar to getallmatchingheaders, but it returns only the
first matching header (and its continuation lines).'
| def getfirstmatchingheader(self, name):
| name = (name.lower() + ':')
n = len(name)
lst = []
hit = 0
for line in self.headers:
if hit:
if (not line[:1].isspace()):
break
elif (line[:n].lower() == name):
hit = 1
if hit:
lst.append(line)
return lst
|
'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 getrawheader(self, name):
| lst = self.getfirstmatchingheader(name)
if (not lst):
return None
lst[0] = lst[0][(len(name) + 1):]
return ''.join(lst)
|
'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.'
| def getheader(self, name, default=None):
| return self.dict.get(name.lower(), default)
|
'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.'
| def getheaders(self, name):
| result = []
current = ''
have_header = 0
for s in self.getallmatchingheaders(name):
if s[0].isspace():
if current:
current = ('%s\n %s' % (current, s.strip()))
else:
current = s.strip()
else:
if have_header:
... |
'Get a single address from a header, as a tuple.
An example return value:
(\'Guido van Rossum\', \'guido@cwi.nl\')'
| def getaddr(self, name):
| alist = self.getaddrlist(name)
if alist:
return alist[0]
else:
return (None, None)
|
'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.'
| def getaddrlist(self, name):
| raw = []
for h in self.getallmatchingheaders(name):
if (h[0] in ' DCTB '):
raw.append(h)
else:
if raw:
raw.append(', ')
i = h.find(':')
if (i > 0):
addr = h[(i + 1):]
raw.append(addr)
alladdrs ... |
'Retrieve a date field from a header.
Retrieves a date field from the named header, returning a tuple
compatible with time.mktime().'
| def getdate(self, name):
| try:
data = self[name]
except KeyError:
return None
return parsedate(data)
|
'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.'
| def getdate_tz(self, name):
| try:
data = self[name]
except KeyError:
return None
return parsedate_tz(data)
|
'Get the number of headers in a message.'
| def __len__(self):
| return len(self.dict)
|
'Get a specific header, as from a dictionary.'
| def __getitem__(self, name):
| return self.dict[name.lower()]
|
'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.'
| def __setitem__(self, name, value):
| del self[name]
self.dict[name.lower()] = value
text = ((name + ': ') + value)
for line in text.split('\n'):
self.headers.append((line + '\n'))
|
'Delete all occurrences of a specific header, if it is present.'
| def __delitem__(self, name):
| name = name.lower()
if (not (name in self.dict)):
return
del self.dict[name]
name = (name + ':')
n = len(name)
lst = []
hit = 0
for i in range(len(self.headers)):
line = self.headers[i]
if (line[:n].lower() == name):
hit = 1
elif (not line[:1].... |
'Determine whether a message contains the named header.'
| def has_key(self, name):
| return (name.lower() in self.dict)
|
'Determine whether a message contains the named header.'
| def __contains__(self, name):
| return (name.lower() in self.dict)
|
'Get all of a message\'s header field names.'
| def keys(self):
| return self.dict.keys()
|
'Get all of a message\'s header field values.'
| def values(self):
| return self.dict.values()
|
'Get all of a message\'s headers.
Returns a list of name, value tuples.'
| def items(self):
| return self.dict.items()
|
'Initialize a new instance.
`field\' is an unparsed address header field, containing one or more
addresses.'
| def __init__(self, field):
| self.specials = '()<>@,:;."[]'
self.pos = 0
self.LWS = ' DCTB '
self.CR = '\r\n'
self.atomends = ((self.specials + self.LWS) + self.CR)
self.phraseends = self.atomends.replace('.', '')
self.field = field
self.commentlist = []
|
'Parse up to the start of the next address.'
| def gotonext(self):
| while (self.pos < len(self.field)):
if (self.field[self.pos] in (self.LWS + '\n\r')):
self.pos = (self.pos + 1)
elif (self.field[self.pos] == '('):
self.commentlist.append(self.getcomment())
else:
break
|
'Parse all addresses.
Returns a list containing all of the addresses.'
| def getaddrlist(self):
| result = []
ad = self.getaddress()
while ad:
result += ad
ad = self.getaddress()
return result
|
'Parse the next address.'
| def getaddress(self):
| self.commentlist = []
self.gotonext()
oldpos = self.pos
oldcl = self.commentlist
plist = self.getphraselist()
self.gotonext()
returnlist = []
if (self.pos >= len(self.field)):
if plist:
returnlist = [(' '.join(self.commentlist), plist[0])]
elif (self.field[self... |
'Parse a route address (Return-path value).
This method just skips all the route stuff and returns the addrspec.'
| def getrouteaddr(self):
| if (self.field[self.pos] != '<'):
return
expectroute = 0
self.pos += 1
self.gotonext()
adlist = ''
while (self.pos < len(self.field)):
if expectroute:
self.getdomain()
expectroute = 0
elif (self.field[self.pos] == '>'):
self.pos += 1
... |
'Parse an RFC 2822 addr-spec.'
| def getaddrspec(self):
| aslist = []
self.gotonext()
while (self.pos < len(self.field)):
if (self.field[self.pos] == '.'):
aslist.append('.')
self.pos += 1
elif (self.field[self.pos] == '"'):
aslist.append(('"%s"' % self.getquote()))
elif (self.field[self.pos] in self.atom... |
'Get the complete domain name from an address.'
| def getdomain(self):
| sdlist = []
while (self.pos < len(self.field)):
if (self.field[self.pos] in self.LWS):
self.pos += 1
elif (self.field[self.pos] == '('):
self.commentlist.append(self.getcomment())
elif (self.field[self.pos] == '['):
sdlist.append(self.getdomainliteral(... |
'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 encounte... | def getdelimited(self, beginchar, endchars, allowcomments=1):
| if (self.field[self.pos] != beginchar):
return ''
slist = ['']
quote = 0
self.pos += 1
while (self.pos < len(self.field)):
if (quote == 1):
slist.append(self.field[self.pos])
quote = 0
elif (self.field[self.pos] in endchars):
self.pos += 1
... |
'Get a quote-delimited fragment from self\'s field.'
| def getquote(self):
| return self.getdelimited('"', '"\r', 0)
|
'Get a parenthesis-delimited fragment from self\'s field.'
| def getcomment(self):
| return self.getdelimited('(', ')\r', 1)
|
'Parse an RFC 2822 domain-literal.'
| def getdomainliteral(self):
| return ('[%s]' % self.getdelimited('[', ']\r', 0))
|
'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).'
| def getatom(self, atomends=None):
| atomlist = ['']
if (atomends is None):
atomends = self.atomends
while (self.pos < len(self.field)):
if (self.field[self.pos] in atomends):
break
else:
atomlist.append(self.field[self.pos])
self.pos += 1
return ''.join(atomlist)
|
'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.'
| def getphraselist(self):
| plist = []
while (self.pos < len(self.field)):
if (self.field[self.pos] in self.LWS):
self.pos += 1
elif (self.field[self.pos] == '"'):
plist.append(self.getquote())
elif (self.field[self.pos] == '('):
self.commentlist.append(self.getcomment())
... |
'This takes a file-like object for writing a pickle data stream.
The optional protocol argument tells the pickler to use the
given protocol; supported protocols are 0, 1, 2. The default
protocol is 0, to be backwards compatible. (Protocol 0 is the
only protocol that can be written to a file opened in text
mode and re... | def __init__(self, file, protocol=None):
| if (protocol is None):
protocol = 0
if (protocol < 0):
protocol = HIGHEST_PROTOCOL
elif (not (0 <= protocol <= HIGHEST_PROTOCOL)):
raise ValueError(('pickle protocol must be <= %d' % HIGHEST_PROTOCOL))
self.write = file.write
self.memo = {}
self.proto = int... |
'Clears the pickler\'s "memo".
The memo is the data structure that remembers which objects the
pickler has already seen, so that shared or recursive objects are
pickled by reference and not by value. This method is useful when
re-using picklers.'
| def clear_memo(self):
| self.memo.clear()
|
'Write a pickled representation of obj to the open file.'
| def dump(self, obj):
| if (self.proto >= 2):
self.write((PROTO + chr(self.proto)))
self.save(obj)
self.write(STOP)
|
'Store an object in the memo.'
| def memoize(self, obj):
| if self.fast:
return
assert (id(obj) not in self.memo)
memo_len = len(self.memo)
self.write(self.put(memo_len))
self.memo[id(obj)] = (memo_len, obj)
|
'This takes a file-like object for reading a pickle data stream.
The protocol version of the pickle is detected automatically, so no
proto argument is needed.
The file-like object must have two methods, a read() method that
takes an integer argument, and a readline() method that requires no
arguments. Both methods sho... | def __init__(self, file):
| self.readline = file.readline
self.read = file.read
self.memo = {}
|
'Read a pickled object representation from the open file.
Return the reconstituted object hierarchy specified in the file.'
| def load(self):
| self.mark = object()
self.stack = []
self.append = self.stack.append
read = self.read
dispatch = self.dispatch
try:
while 1:
key = read(1)
dispatch[key](self)
except _Stop as stopinst:
return stopinst.value
|
'Encodes the object input and returns a tuple (output
object, length consumed).
errors defines the error handling to apply. It defaults to
\'strict\' handling.
The method may not store state in the Codec instance. Use
StreamCodec for codecs which have to keep state in order to
make encoding/decoding efficient.
The enco... | def encode(self, input, errors='strict'):
| raise NotImplementedError
|
'Decodes the object input and returns a tuple (output
object, length consumed).
input must be an object which provides the bf_getreadbuf
buffer slot. Python strings, buffer objects and memory
mapped files are examples of objects providing this slot.
errors defines the error handling to apply. It defaults to
\'strict\' ... | def decode(self, input, errors='strict'):
| raise NotImplementedError
|
'Creates an IncrementalEncoder instance.
The IncrementalEncoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.'
| def __init__(self, errors='strict'):
| self.errors = errors
self.buffer = ''
|
'Encodes input and returns the resulting object.'
| def encode(self, input, final=False):
| raise NotImplementedError
|
'Return the current state of the encoder.'
| def getstate(self):
| return 0
|
'Creates a IncrementalDecoder instance.
The IncrementalDecoder may use different error handling schemes by
providing the errors keyword argument. See the module docstring
for a list of possible values.'
| def __init__(self, errors='strict'):
| self.errors = errors
|
'Decodes input and returns the resulting object.'
| def decode(self, input, final=False):
| raise NotImplementedError
|
'Return the current state of the decoder.
This must be a (buffered_input, additional_state_info) tuple.
buffered_input must be a bytes object containing bytes that
were passed to decode() that have not yet been converted.
additional_state_info must be a non-negative integer
representing the state of the decoder WITHOUT... | def getstate(self):
| return ('', 0)
|
'Creates a StreamWriter instance.
stream must be a file-like object open for writing
(binary) data.
The StreamWriter may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
\'strict\' - raise a ValueError (or a subclass)
\'ignore\' - ignore the character and c... | def __init__(self, stream, errors='strict'):
| self.stream = stream
self.errors = errors
|
'Writes the object\'s contents encoded to self.stream.'
| def write(self, object):
| (data, consumed) = self.encode(object, self.errors)
self.stream.write(data)
|
'Writes the concatenated list of strings to the stream
using .write().'
| def writelines(self, list):
| self.write(''.join(list))
|
'Flushes and resets the codec buffers used for keeping state.
Calling this method should ensure that the data on the
output is put into a clean state, that allows appending
of new fresh data without having to rescan the whole
stream to recover state.'
| def reset(self):
| pass
|
'Inherit all other methods from the underlying stream.'
| def __getattr__(self, name, getattr=getattr):
| return getattr(self.stream, name)
|
'Creates a StreamReader instance.
stream must be a file-like object open for reading
(binary) data.
The StreamReader may use different error handling
schemes by providing the errors keyword argument. These
parameters are predefined:
\'strict\' - raise a ValueError (or a subclass)
\'ignore\' - ignore the character and c... | def __init__(self, stream, errors='strict'):
| self.stream = stream
self.errors = errors
self.bytebuffer = ''
self.charbuffer = ''
self.linebuffer = None
|
'Decodes data from the stream self.stream and returns the
resulting object.
chars indicates the number of characters to read from the
stream. read() will never return more than chars
characters, but it might return less, if there are not enough
characters available.
size indicates the approximate maximum number of byte... | def read(self, size=(-1), chars=(-1), firstline=False):
| if self.linebuffer:
self.charbuffer = ''.join(self.linebuffer)
self.linebuffer = None
while True:
if (chars < 0):
if (size < 0):
if self.charbuffer:
break
elif (len(self.charbuffer) >= size):
break
elif (... |
'Read one line from the input stream and return the
decoded data.
size, if given, is passed as size argument to the
read() method.'
| def readline(self, size=None, keepends=True):
| if self.linebuffer:
line = self.linebuffer[0]
del self.linebuffer[0]
if (len(self.linebuffer) == 1):
self.charbuffer = self.linebuffer[0]
self.linebuffer = None
if (not keepends):
line = line.splitlines(False)[0]
return line
readsize = ... |
'Read all lines available on the input stream
and return them as list of lines.
Line breaks are implemented using the codec\'s decoder
method and are included in the list entries.
sizehint, if given, is ignored since there is no efficient
way to finding the true end-of-line.'
| def readlines(self, sizehint=None, keepends=True):
| data = self.read()
return data.splitlines(keepends)
|
'Resets the codec buffers used for keeping state.
Note that no stream repositioning should take place.
This method is primarily intended to be able to recover
from decoding errors.'
| def reset(self):
| self.bytebuffer = ''
self.charbuffer = u''
self.linebuffer = None
|
'Set the input stream\'s current position.
Resets the codec buffers used for keeping state.'
| def seek(self, offset, whence=0):
| self.stream.seek(offset, whence)
self.reset()
|
'Return the next decoded line from the input stream.'
| def next(self):
| line = self.readline()
if line:
return line
raise StopIteration
|
'Inherit all other methods from the underlying stream.'
| def __getattr__(self, name, getattr=getattr):
| return getattr(self.stream, name)
|
'Creates a StreamReaderWriter instance.
stream must be a Stream-like object.
Reader, Writer must be factory functions or classes
providing the StreamReader, StreamWriter interface resp.
Error handling is done in the same way as defined for the
StreamWriter/Readers.'
| def __init__(self, stream, Reader, Writer, errors='strict'):
| self.stream = stream
self.reader = Reader(stream, errors)
self.writer = Writer(stream, errors)
self.errors = errors
|
'Return the next decoded line from the input stream.'
| def next(self):
| return self.reader.next()
|
'Inherit all other methods from the underlying stream.'
| def __getattr__(self, name, getattr=getattr):
| return getattr(self.stream, name)
|
'Creates a StreamRecoder instance which implements a two-way
conversion: encode and decode work on the frontend (the
input to .read() and output of .write()) while
Reader and Writer work on the backend (reading and
writing to the stream).
You can use these objects to do transparent direct
recodings from e.g. latin-1 to... | def __init__(self, stream, encode, decode, Reader, Writer, errors='strict'):
| self.stream = stream
self.encode = encode
self.decode = decode
self.reader = Reader(stream, errors)
self.writer = Writer(stream, errors)
self.errors = errors
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.