desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'-self'
| @abstractmethod
def __neg__(self):
| raise NotImplementedError
|
'+self'
| @abstractmethod
def __pos__(self):
| raise NotImplementedError
|
'self - other'
| def __sub__(self, other):
| return (self + (- other))
|
'other - self'
| def __rsub__(self, other):
| return ((- self) + other)
|
'self * other'
| @abstractmethod
def __mul__(self, other):
| raise NotImplementedError
|
'other * self'
| @abstractmethod
def __rmul__(self, other):
| raise NotImplementedError
|
'self / other without __future__ division
May promote to float.'
| @abstractmethod
def __div__(self, other):
| raise NotImplementedError
|
'other / self without __future__ division'
| @abstractmethod
def __rdiv__(self, other):
| raise NotImplementedError
|
'self / other with __future__ division.
Should promote to float when necessary.'
| @abstractmethod
def __truediv__(self, other):
| raise NotImplementedError
|
'other / self with __future__ division'
| @abstractmethod
def __rtruediv__(self, other):
| raise NotImplementedError
|
'self**exponent; should promote to float or complex when necessary.'
| @abstractmethod
def __pow__(self, exponent):
| raise NotImplementedError
|
'base ** self'
| @abstractmethod
def __rpow__(self, base):
| raise NotImplementedError
|
'Returns the Real distance from 0. Called for abs(self).'
| @abstractmethod
def __abs__(self):
| raise NotImplementedError
|
'(x+y*i).conjugate() returns (x-y*i).'
| @abstractmethod
def conjugate(self):
| raise NotImplementedError
|
'self == other'
| @abstractmethod
def __eq__(self, other):
| raise NotImplementedError
|
'self != other'
| def __ne__(self, other):
| return (not (self == other))
|
'Any Real can be converted to a native float object.
Called for float(self).'
| @abstractmethod
def __float__(self):
| raise NotImplementedError
|
'trunc(self): Truncates self to an Integral.
Returns an Integral i such that:
* i>0 iff self>0;
* abs(i) <= abs(self);
* for any Integral j satisfying the first two conditions,
abs(i) >= abs(j) [i.e. i has "maximal" abs among those].
i.e. "truncate towards 0".'
| @abstractmethod
def __trunc__(self):
| raise NotImplementedError
|
'divmod(self, other): The pair (self // other, self % other).
Sometimes this can be computed faster than the pair of
operations.'
| def __divmod__(self, other):
| return ((self // other), (self % other))
|
'divmod(other, self): The pair (self // other, self % other).
Sometimes this can be computed faster than the pair of
operations.'
| def __rdivmod__(self, other):
| return ((other // self), (other % self))
|
'self // other: The floor() of self/other.'
| @abstractmethod
def __floordiv__(self, other):
| raise NotImplementedError
|
'other // self: The floor() of other/self.'
| @abstractmethod
def __rfloordiv__(self, other):
| raise NotImplementedError
|
'self % other'
| @abstractmethod
def __mod__(self, other):
| raise NotImplementedError
|
'other % self'
| @abstractmethod
def __rmod__(self, other):
| raise NotImplementedError
|
'self < other
< on Reals defines a total ordering, except perhaps for NaN.'
| @abstractmethod
def __lt__(self, other):
| raise NotImplementedError
|
'self <= other'
| @abstractmethod
def __le__(self, other):
| raise NotImplementedError
|
'complex(self) == complex(float(self), 0)'
| def __complex__(self):
| return complex(float(self))
|
'Real numbers are their real component.'
| @property
def real(self):
| return (+ self)
|
'Real numbers have no imaginary component.'
| @property
def imag(self):
| return 0
|
'Conjugate is a no-op for Reals.'
| def conjugate(self):
| return (+ self)
|
'float(self) = self.numerator / self.denominator
It\'s important that this conversion use the integer\'s "true"
division rather than casting one side to float before dividing
so that ratios of huge integers convert without overflowing.'
| def __float__(self):
| return (self.numerator / self.denominator)
|
'long(self)'
| @abstractmethod
def __long__(self):
| raise NotImplementedError
|
'index(self)'
| def __index__(self):
| return long(self)
|
'self ** exponent % modulus, but maybe faster.
Accept the modulus argument if you want to support the
3-argument version of pow(). Raise a TypeError if exponent < 0
or any argument isn\'t Integral. Otherwise, just implement the
2-argument version described in Complex.'
| @abstractmethod
def __pow__(self, exponent, modulus=None):
| raise NotImplementedError
|
'self << other'
| @abstractmethod
def __lshift__(self, other):
| raise NotImplementedError
|
'other << self'
| @abstractmethod
def __rlshift__(self, other):
| raise NotImplementedError
|
'self >> other'
| @abstractmethod
def __rshift__(self, other):
| raise NotImplementedError
|
'other >> self'
| @abstractmethod
def __rrshift__(self, other):
| raise NotImplementedError
|
'self & other'
| @abstractmethod
def __and__(self, other):
| raise NotImplementedError
|
'other & self'
| @abstractmethod
def __rand__(self, other):
| raise NotImplementedError
|
'self ^ other'
| @abstractmethod
def __xor__(self, other):
| raise NotImplementedError
|
'other ^ self'
| @abstractmethod
def __rxor__(self, other):
| raise NotImplementedError
|
'self | other'
| @abstractmethod
def __or__(self, other):
| raise NotImplementedError
|
'other | self'
| @abstractmethod
def __ror__(self, other):
| raise NotImplementedError
|
'~self'
| @abstractmethod
def __invert__(self):
| raise NotImplementedError
|
'float(self) == float(long(self))'
| def __float__(self):
| return float(long(self))
|
'Integers are their own numerators.'
| @property
def numerator(self):
| return (+ self)
|
'Integers have a denominator of 1.'
| @property
def denominator(self):
| return 1
|
'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 output is guaranteed to be str
objects with all incoming unicode ch... | def __init__(self, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None):
| self.skipkeys = skipkeys
self.ensure_ascii = ensure_ascii
self.check_circular = check_circular
self.allow_nan = allow_nan
self.sort_keys = sort_keys
self.indent = indent
if (separators is not None):
(self.item_separator, self.key_separator) = separators
if (default is not None):
... |
'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 l... | def default(self, o):
| raise TypeError((repr(o) + ' is not JSON serializable'))
|
'Return a JSON string representation of a Python data structure.
>>> JSONEncoder().encode({"foo": ["bar", "baz"]})
\'{"foo": ["bar", "baz"]}\''
| def encode(self, o):
| if isinstance(o, basestring):
if isinstance(o, str):
_encoding = self.encoding
if ((_encoding is not None) and (not (_encoding == 'utf-8'))):
o = o.decode(_encoding)
if self.ensure_ascii:
return encode_basestring_ascii(o)
else:
... |
'Encode the given object and yield each string
representation as available.
For example::
for chunk in JSONEncoder().iterencode(bigobject):
mysocket.write(chunk)'
| def iterencode(self, o, _one_shot=False):
| if self.check_circular:
markers = {}
else:
markers = None
if self.ensure_ascii:
_encoder = encode_basestring_ascii
else:
_encoder = encode_basestring
if (self.encoding != 'utf-8'):
def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):
i... |
'``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... | def __init__(self, encoding=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, strict=True, object_pairs_hook=None):
| self.encoding = encoding
self.object_hook = object_hook
self.object_pairs_hook = object_pairs_hook
self.parse_float = (parse_float or float)
self.parse_int = (parse_int or int)
self.parse_constant = (parse_constant or _CONSTANTS.__getitem__)
self.strict = strict
self.parse_object = JSONO... |
'Return the Python representation of ``s`` (a ``str`` or ``unicode``
instance containing a JSON document)'
| def decode(self, s, _w=WHITESPACE.match):
| (obj, end) = self.raw_decode(s, idx=_w(s, 0).end())
end = _w(s, end).end()
if (end != len(s)):
raise ValueError(errmsg('Extra data', s, end, len(s)))
return obj
|
'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.'
| def raw_decode(self, s, idx=0):
| try:
(obj, end) = self.scan_once(s, idx)
except StopIteration:
raise ValueError('No JSON object could be decoded')
return (obj, end)
|
'Create a new directory in the Directory table. There is a current component
at each point in time for the directory, which is either explicitly created
through start_component, or implicitly when files are added for the first
time. Files are added into the current component, and into the cab file.
To create a director... | def __init__(self, db, cab, basedir, physical, _logical, default, componentflags=None):
| index = 1
_logical = make_id(_logical)
logical = _logical
while (logical in _directories):
logical = ('%s%d' % (_logical, index))
index += 1
_directories.add(logical)
self.db = db
self.cab = cab
self.basedir = basedir
self.physical = physical
self.logical = logica... |
'Add an entry to the Component table, and make this component the current for this
directory. If no component name is given, the directory name is used. If no feature
is given, the current feature is used. If no flags are given, the directory\'s default
flags are used. If no keyfile is given, the KeyPath is left null i... | def start_component(self, component=None, feature=None, flags=None, keyfile=None, uuid=None):
| if (flags is None):
flags = self.componentflags
if (uuid is None):
uuid = gen_uuid()
else:
uuid = uuid.upper()
if (component is None):
component = self.logical
self.component = component
if Win64:
flags |= 256
if keyfile:
keyid = self.cab.gen_i... |
'Add a file to the current component of the directory, starting a new one
one if there is no current component. By default, the file name in the source
and the file table will be identical. If the src file is specified, it is
interpreted relative to the current directory. Optionally, a version and a
language can be spe... | def add_file(self, file, src=None, version=None, language=None):
| if (not self.component):
self.start_component(self.logical, current_feature, 0)
if (not src):
src = file
file = os.path.basename(file)
absolute = os.path.join(self.absolute, src)
assert (not re.search('[\\?|><:/*]"', file))
if (file in self.keyfiles):
logical = self.k... |
'Add a list of files to the current component as specified in the
glob pattern. Individual files can be excluded in the exclude list.'
| def glob(self, pattern, exclude=None):
| files = glob.glob1(self.absolute, pattern)
for f in files:
if (exclude and (f in exclude)):
continue
self.add_file(f)
return files
|
'Remove .pyc/.pyo files on uninstall'
| def remove_pyc(self):
| add_data(self.db, 'RemoveFile', [((self.component + 'c'), self.component, '*.pyc', self.logical, 2), ((self.component + 'o'), self.component, '*.pyo', self.logical, 2)])
|
'Getter for \'message\'; needed only to override deprecation in
BaseException.'
| def _get_message(self):
| return self.__message
|
'Setter for \'message\'; needed only to override deprecation in
BaseException.'
| def _set_message(self, value):
| self.__message = value
|
'Return a list of section names, excluding [DEFAULT]'
| def sections(self):
| return self._sections.keys()
|
'Create a new section in the configuration.
Raise DuplicateSectionError if a section by the specified name
already exists. Raise ValueError if name is DEFAULT or any of it\'s
case-insensitive variants.'
| def add_section(self, section):
| if (section.lower() == 'default'):
raise ValueError, ('Invalid section name: %s' % section)
if (section in self._sections):
raise DuplicateSectionError(section)
self._sections[section] = self._dict()
|
'Indicate whether the named section is present in the configuration.
The DEFAULT section is not acknowledged.'
| def has_section(self, section):
| return (section in self._sections)
|
'Return a list of option names for the given section name.'
| def options(self, section):
| try:
opts = self._sections[section].copy()
except KeyError:
raise NoSectionError(section)
opts.update(self._defaults)
if ('__name__' in opts):
del opts['__name__']
return opts.keys()
|
'Read and parse a filename or a list of filenames.
Files that cannot be opened are silently ignored; this is
designed so that you can specify a list of potential
configuration file locations (e.g. current directory, user\'s
home directory, systemwide directory), and all existing
configuration files in the list will be ... | def read(self, filenames):
| if isinstance(filenames, basestring):
filenames = [filenames]
read_ok = []
for filename in filenames:
try:
fp = open(filename)
except IOError:
continue
self._read(fp, filename)
fp.close()
read_ok.append(filename)
return read_ok
|
'Like read() but the argument must be a file-like object.
The `fp\' argument must have a `readline\' method. Optional
second argument is the `filename\', which if not given, is
taken from fp.name. If fp has no `name\' attribute, `<???>\' is
used.'
| def readfp(self, fp, filename=None):
| if (filename is None):
try:
filename = fp.name
except AttributeError:
filename = '<???>'
self._read(fp, filename)
|
'Check for the existence of a given option in a given section.'
| def has_option(self, section, option):
| if ((not section) or (section == DEFAULTSECT)):
option = self.optionxform(option)
return (option in self._defaults)
elif (section not in self._sections):
return False
else:
option = self.optionxform(option)
return ((option in self._sections[section]) or (option in sel... |
'Set an option.'
| def set(self, section, option, value=None):
| if ((not section) or (section == DEFAULTSECT)):
sectdict = self._defaults
else:
try:
sectdict = self._sections[section]
except KeyError:
raise NoSectionError(section)
sectdict[self.optionxform(option)] = value
|
'Write an .ini-format representation of the configuration state.'
| def write(self, fp):
| if self._defaults:
fp.write(('[%s]\n' % DEFAULTSECT))
for (key, value) in self._defaults.items():
fp.write(('%s = %s\n' % (key, str(value).replace('\n', '\n DCTB '))))
fp.write('\n')
for section in self._sections:
fp.write(('[%s]\n' % section))
for (key,... |
'Remove an option.'
| def remove_option(self, section, option):
| if ((not section) or (section == DEFAULTSECT)):
sectdict = self._defaults
else:
try:
sectdict = self._sections[section]
except KeyError:
raise NoSectionError(section)
option = self.optionxform(option)
existed = (option in sectdict)
if existed:
... |
'Remove a file section.'
| def remove_section(self, section):
| existed = (section in self._sections)
if existed:
del self._sections[section]
return existed
|
'Parse a sectioned setup file.
The sections in setup file contains a title line at the top,
indicated by a name in square brackets (`[]\'), plus key/value
options lines, indicated by `name: value\' format lines.
Continuations are represented by an embedded newline then
leading whitespace. Blank lines, lines beginning ... | def _read(self, fp, fpname):
| cursect = None
optname = None
lineno = 0
e = None
while True:
line = fp.readline()
if (not line):
break
lineno = (lineno + 1)
if ((line.strip() == '') or (line[0] in '#;')):
continue
if ((line.split(None, 1)[0].lower() == 'rem') and (li... |
'Get an option value for a given section.
If `vars\' is provided, it must be a dictionary. The option is looked up
in `vars\' (if provided), `section\', and in `defaults\' in that order.
All % interpolations are expanded in the return values, unless the
optional argument `raw\' is true. Values for interpolation keys ar... | def get(self, section, option, raw=False, vars=None):
| sectiondict = {}
try:
sectiondict = self._sections[section]
except KeyError:
if (section != DEFAULTSECT):
raise NoSectionError(section)
vardict = {}
if vars:
for (key, value) in vars.items():
vardict[self.optionxform(key)] = value
d = _Chainmap(var... |
'Return a list of tuples with (name, value) for each option
in the section.
All % interpolations are expanded in the return values, based on the
defaults passed into the constructor, unless the optional argument
`raw\' is true. Additional substitutions may be provided using the
`vars\' argument, which must be a dictio... | def items(self, section, raw=False, vars=None):
| d = self._defaults.copy()
try:
d.update(self._sections[section])
except KeyError:
if (section != DEFAULTSECT):
raise NoSectionError(section)
if vars:
for (key, value) in vars.items():
d[self.optionxform(key)] = value
options = d.keys()
if ('__name_... |
'Set an option. Extend ConfigParser.set: check for string values.'
| def set(self, section, option, value=None):
| if ((self._optcre is self.OPTCRE) or value):
if (not isinstance(value, basestring)):
raise TypeError('option values must be strings')
if (value is not None):
tmp_value = value.replace('%%', '')
tmp_value = self._interpvar_re.sub('', tmp_value)
if ('%' in t... |
'Override this abstract method to handle messages from the client.
peer is a tuple containing (ipaddr, port) of the client that made the
socket connection to our smtp port.
mailfrom is the raw address the client claims the message is coming
from.
rcpttos is a list of raw addresses the client wishes to deliver the
messa... | def process_message(self, peer, mailfrom, rcpttos, data):
| raise NotImplementedError
|
'Internal: raise an exception for unsupported operations.'
| def _unsupported(self, name):
| raise UnsupportedOperation((u'%s.%s() not supported' % (self.__class__.__name__, name)))
|
'Change stream position.
Change the stream position to byte offset offset. offset is
interpreted relative to the position indicated by whence. Values
for whence are:
* 0 -- start of stream (the default); offset should be zero or positive
* 1 -- current stream position; offset may be negative
* 2 -- end of stream; offs... | def seek(self, pos, whence=0):
| self._unsupported(u'seek')
|
'Return current stream position.'
| def tell(self):
| return self.seek(0, 1)
|
'Truncate file to size bytes.
Size defaults to the current IO position as reported by tell(). Return
the new size.'
| def truncate(self, pos=None):
| self._unsupported(u'truncate')
|
'Flush write buffers, if applicable.
This is not implemented for read-only and non-blocking streams.'
| def flush(self):
| self._checkClosed()
|
'Flush and close the IO object.
This method has no effect if the file is already closed.'
| def close(self):
| if (not self.__closed):
self.flush()
self.__closed = True
|
'Destructor. Calls close().'
| def __del__(self):
| try:
self.close()
except:
pass
|
'Return whether object supports random access.
If False, seek(), tell() and truncate() will raise IOError.
This method may need to do a test seek().'
| def seekable(self):
| return False
|
'Internal: raise an IOError if file is not seekable'
| def _checkSeekable(self, msg=None):
| if (not self.seekable()):
raise IOError((u'File or stream is not seekable.' if (msg is None) else msg))
|
'Return whether object was opened for reading.
If False, read() will raise IOError.'
| def readable(self):
| return False
|
'Internal: raise an IOError if file is not readable'
| def _checkReadable(self, msg=None):
| if (not self.readable()):
raise IOError((u'File or stream is not readable.' if (msg is None) else msg))
|
'Return whether object was opened for writing.
If False, write() and truncate() will raise IOError.'
| def writable(self):
| return False
|
'Internal: raise an IOError if file is not writable'
| def _checkWritable(self, msg=None):
| if (not self.writable()):
raise IOError((u'File or stream is not writable.' if (msg is None) else msg))
|
'closed: bool. True iff the file has been closed.
For backwards compatibility, this is a property, not a predicate.'
| @property
def closed(self):
| return self.__closed
|
'Internal: raise an ValueError if file is closed'
| def _checkClosed(self, msg=None):
| if self.closed:
raise ValueError((u'I/O operation on closed file.' if (msg is None) else msg))
|
'Context management protocol. Returns self.'
| def __enter__(self):
| self._checkClosed()
return self
|
'Context management protocol. Calls close()'
| def __exit__(self, *args):
| self.close()
|
'Returns underlying file descriptor if one exists.
An IOError is raised if the IO object does not use a file descriptor.'
| def fileno(self):
| self._unsupported(u'fileno')
|
'Return whether this is an \'interactive\' stream.
Return False if it can\'t be determined.'
| def isatty(self):
| self._checkClosed()
return False
|
'Read and return a line from the stream.
If limit is specified, at most limit bytes will be read.
The line terminator is always b\'\n\' for binary files; for text
files, the newlines argument to open can be used to select the line
terminator(s) recognized.'
| def readline(self, limit=(-1)):
| if hasattr(self, u'peek'):
def nreadahead():
readahead = self.peek(1)
if (not readahead):
return 1
n = ((readahead.find('\n') + 1) or len(readahead))
if (limit >= 0):
n = min(n, limit)
return n
else:
def ... |
'Return a list of lines from the stream.
hint can be specified to control the number of lines read: no more
lines will be read if the total size (in bytes/characters) of all
lines so far exceeds hint.'
| def readlines(self, hint=None):
| if ((hint is not None) and (not isinstance(hint, (int, long)))):
raise TypeError(u'integer or None expected')
if ((hint is None) or (hint <= 0)):
return list(self)
n = 0
lines = []
for line in self:
lines.append(line)
n += len(line)
if (n >= hint):
... |
'Read and return up to n bytes.
Returns an empty bytes object on EOF, or None if the object is
set not to block and has no data to read.'
| def read(self, n=(-1)):
| if (n is None):
n = (-1)
if (n < 0):
return self.readall()
b = bytearray(n.__index__())
n = self.readinto(b)
if (n is None):
return None
del b[n:]
return bytes(b)
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.