code string | signature string | docstring string | loss_without_docstring float64 | loss_with_docstring float64 | factor float64 |
|---|---|---|---|---|---|
container = self._container_factory(**options)
if not content or content is None:
return container()
options = self._load_options(container, **options)
return self.load_from_string(content, container, **options) | def loads(self, content, **options) | Load config from given string 'content' after some checks.
:param content: Config file content
:param options:
options will be passed to backend specific loading functions.
please note that options have to be sanitized w/
:func:`anyconfig.utils.filter_options` later... | 4.888038 | 6.425478 | 0.760728 |
container = self._container_factory(**options)
options = self._load_options(container, **options)
if not ioi:
return container()
if anyconfig.utils.is_stream_ioinfo(ioi):
cnf = self.load_from_stream(ioi.src, container, **options)
else:
... | def load(self, ioi, ac_ignore_missing=False, **options) | Load config from a file path or a file / file-like object which 'ioi'
refering after some checks.
:param ioi:
'anyconfig.globals.IOInfo' namedtuple object provides various info
of input object to load data from
:param ac_ignore_missing:
Ignore and just retur... | 3.560462 | 3.297995 | 1.079584 |
_not_implemented(self, cnf, filepath, **kwargs) | def dump_to_path(self, cnf, filepath, **kwargs) | Dump config 'cnf' to a file 'filepath'.
:param cnf: Configuration data to dump
:param filepath: Config file path
:param kwargs: optional keyword parameters to be sanitized :: dict | 9.581933 | 10.594787 | 0.904401 |
_not_implemented(self, cnf, stream, **kwargs) | def dump_to_stream(self, cnf, stream, **kwargs) | Dump config 'cnf' to a file-like object 'stream'.
TODO: How to process socket objects same as file objects ?
:param cnf: Configuration data to dump
:param stream: Config file or file like object
:param kwargs: optional keyword parameters to be sanitized :: dict | 9.376679 | 10.121011 | 0.926457 |
kwargs = anyconfig.utils.filter_options(self._dump_opts, kwargs)
return self.dump_to_string(cnf, **kwargs) | def dumps(self, cnf, **kwargs) | Dump config 'cnf' to a string.
:param cnf: Configuration data to dump
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: string represents the configuration | 6.818774 | 10.799241 | 0.631412 |
kwargs = anyconfig.utils.filter_options(self._dump_opts, kwargs)
if anyconfig.utils.is_stream_ioinfo(ioi):
self.dump_to_stream(cnf, ioi.src, **kwargs)
else:
ensure_outdir_exists(ioi.path)
self.dump_to_path(cnf, ioi.path, **kwargs) | def dump(self, cnf, ioi, **kwargs) | Dump config 'cnf' to output object of which 'ioi' refering.
:param cnf: Configuration data to dump
:param ioi:
an 'anyconfig.globals.IOInfo' namedtuple object provides various
info of input object to load data from
:param kwargs: optional keyword parameters to be saniti... | 3.954359 | 3.980794 | 0.993359 |
return self.load_from_string(stream.read(), container, **kwargs) | def load_from_stream(self, stream, container, **kwargs) | Load config from given stream 'stream'.
:param stream: Config file or file-like object
:param container: callble to make a container object later
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: Dict-like object holding config parameters | 3.571828 | 6.569494 | 0.543699 |
with self.ropen(filepath) as inp:
return self.load_from_stream(inp, container, **kwargs) | def load_from_path(self, filepath, container, **kwargs) | Load config from given file path 'filepath'.
:param filepath: Config file path
:param container: callble to make a container object later
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: Dict-like object holding config parameters | 5.134552 | 9.140392 | 0.561743 |
return self.load_from_stream(anyconfig.compat.StringIO(content),
container, **kwargs) | def load_from_string(self, content, container, **kwargs) | Load config from given string 'cnf_content'.
:param content: Config content string
:param container: callble to make a container object later
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: Dict-like object holding config parameters | 5.352719 | 9.158331 | 0.584464 |
with self.wopen(filepath) as out:
out.write(self.dump_to_string(cnf, **kwargs)) | def dump_to_path(self, cnf, filepath, **kwargs) | Dump config 'cnf' to a file 'filepath'.
:param cnf: Configuration data to dump
:param filepath: Config file path
:param kwargs: optional keyword parameters to be sanitized :: dict | 4.717131 | 8.04352 | 0.586451 |
stream.write(self.dump_to_string(cnf, **kwargs)) | def dump_to_stream(self, cnf, stream, **kwargs) | Dump config 'cnf' to a file-like object 'stream'.
TODO: How to process socket objects same as file objects ?
:param cnf: Configuration data to dump
:param stream: Config file or file like object
:param kwargs: optional keyword parameters to be sanitized :: dict | 4.178791 | 5.50194 | 0.759512 |
stream = anyconfig.compat.StringIO()
self.dump_to_stream(cnf, stream, **kwargs)
return stream.getvalue() | def dump_to_string(self, cnf, **kwargs) | Dump config 'cnf' to a string.
:param cnf: Configuration data to dump
:param kwargs: optional keyword parameters to be sanitized :: dict
:return: Dict-like object holding config parameters | 4.283532 | 6.606283 | 0.648403 |
with self.wopen(filepath) as out:
self.dump_to_stream(cnf, out, **kwargs) | def dump_to_path(self, cnf, filepath, **kwargs) | Dump config 'cnf' to a file 'filepath`.
:param cnf: Configuration data to dump
:param filepath: Config file path
:param kwargs: optional keyword parameters to be sanitized :: dict | 4.989728 | 9.133993 | 0.546281 |
return load_with_fn(self._load_from_string_fn, content, container,
allow_primitives=self.allow_primitives(),
**options) | def load_from_string(self, content, container, **options) | Load configuration data from given string 'content'.
:param content: Configuration string
:param container: callble to make a container object
:param options: keyword options passed to '_load_from_string_fn'
:return: container object holding the configuration data | 7.624712 | 8.654342 | 0.881027 |
return load_with_fn(self._load_from_stream_fn, stream, container,
allow_primitives=self.allow_primitives(),
**options) | def load_from_stream(self, stream, container, **options) | Load data from given stream 'stream'.
:param stream: Stream provides configuration data
:param container: callble to make a container object
:param options: keyword options passed to '_load_from_stream_fn'
:return: container object holding the configuration data | 7.177563 | 8.545215 | 0.839951 |
dump_with_fn(self._dump_to_stream_fn, cnf, stream, **kwargs) | def dump_to_stream(self, cnf, stream, **kwargs) | Dump config 'cnf' to a file-like object 'stream'.
TODO: How to process socket objects same as file objects ?
:param cnf: Configuration data to dump
:param stream: Config file or file like object
:param kwargs: optional keyword parameters to be sanitized :: dict | 5.980629 | 10.612025 | 0.563571 |
if obj is None:
return IOI_NONE
if anyconfig.utils.is_path(obj):
return IOI_PATH_STR
if anyconfig.utils.is_path_obj(obj):
return IOI_PATH_OBJ
if anyconfig.utils.is_file_stream(obj):
return IOI_STREAM
raise ValueError("Unknown I/O type object: %r" % obj) | def guess_io_type(obj) | Guess input or output type of 'obj'.
:param obj: a path string, a pathlib.Path or a file / file-like object
:return: IOInfo type defined in anyconfig.globals.IOI_TYPES
>>> apath = "/path/to/a_conf.ext"
>>> assert guess_io_type(apath) == IOI_PATH_STR
>>> from anyconfig.compat import pathlib
>>... | 3.451464 | 2.313337 | 1.491985 |
itype = guess_io_type(obj)
if itype == IOI_PATH_STR:
ipath = anyconfig.utils.normpath(obj)
ext = anyconfig.utils.get_file_extension(ipath)
opener = open
elif itype == IOI_PATH_OBJ:
ipath = anyconfig.utils.normpath(obj.as_posix())
ext = anyconfig.utils.get_file_e... | def inspect_io_obj(obj) | :param obj: a path string, a pathlib.Path or a file / file-like object
:return: A tuple of (objtype, objpath, objopener)
:raises: UnknownFileTypeError | 2.614075 | 2.318195 | 1.127634 |
if anyconfig.utils.is_ioinfo(obj):
return obj
(itype, ipath, opener, ext) = inspect_io_obj(obj)
return IOInfo(src=obj, type=itype, path=ipath, opener=opener,
extension=ext) | def make(obj) | :param obj: a path string, a pathlib.Path or a file / file-like object
:return:
Namedtuple object represents a kind of input object such as a file /
file-like object, path string or pathlib.Path object
:raises: ValueError, UnknownProcessorTypeError, UnknownFileTypeError | 7.514824 | 7.81884 | 0.961118 |
match = re.match(r"^\s*(export)?\s*(\S+)=(?:(?:"
r"(?:\"(.*[^\\])\")|(?:'(.*[^\\])')|"
r"(?:([^\"'#\s]+)))?)\s*#*", line)
if not match:
LOGGER.warning("Invalid line found: %s", line)
return (None, None)
tpl = match.groups()
vals = list(iter... | def _parseline(line) | Parse a line contains shell variable definition.
:param line: A string to parse, must not start with '#' (comment)
:return: A tuple of (key, value), both key and value may be None
>>> _parseline("aaa=")
('aaa', '')
>>> _parseline("aaa=bbb")
('aaa', 'bbb')
>>> _parseline("aaa='bb b'")
(... | 4.386787 | 4.122356 | 1.064146 |
ret = container()
for line in stream.readlines():
line = line.rstrip()
if line is None or not line:
continue
(key, val) = _parseline(line)
if key is None:
LOGGER.warning("Empty val in the line: %s", line)
continue
ret[key] = val... | def load(stream, container=dict) | Load and parse a file or file-like object 'stream' provides simple shell
variables' definitions.
:param stream: A file or file like object
:param container:
Factory function to create a dict-like object to store properties
:return: Dict-like object holding shell variables' definitions
>>> ... | 3.758975 | 5.045121 | 0.745071 |
for key, val in anyconfig.compat.iteritems(cnf):
stream.write("%s='%s'%s" % (key, val, os.linesep)) | def dump_to_stream(self, cnf, stream, **kwargs) | Dump config 'cnf' to a file or file-like object 'stream'.
:param cnf: Shell variables data to dump
:param stream: Shell script file or file like object
:param kwargs: backend-specific optional keyword parameters :: dict | 4.834301 | 6.984382 | 0.692159 |
return Color("cmyk", c, m, y, k) | def cmyk(c, m, y, k) | Create a spectra.Color object in the CMYK color space.
:param float c: c coordinate.
:param float m: m coordinate.
:param float y: y coordinate.
:param float k: k coordinate.
:rtype: Color
:returns: A spectra.Color object in the CMYK color space. | 4.743866 | 8.187755 | 0.579385 |
'''Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],
s[0...... | def RgbToHsl(r, g, b) | Convert the color from RGB coordinates to HSL.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, l) tuple in the range:
h[0...360],
s[0...1],
... | 2.037763 | 1.54448 | 1.319384 |
'''Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
... | def HslToRgb(h, s, l) | Convert the color from HSL coordinates to RGB.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0..... | 2.307095 | 1.587365 | 1.453412 |
'''Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],
s[0...... | def RgbToHsv(r, g, b) | Convert the color from RGB coordinates to HSV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (h, s, v) tuple in the range:
h[0...360],
s[0...1],
... | 2.186405 | 1.5564 | 1.404784 |
'''Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1]... | def HsvToRgb(h, s, v) | Convert the color from RGB coordinates to HSV.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
... | 2.36299 | 1.485142 | 1.591087 |
'''Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],
q[0.... | def RgbToYiq(r, g, b) | Convert the color from RGB to YIQ.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, i, q) tuple in the range:
y[0...1],
i[0...1],
q[0...1]
... | 2.920139 | 1.771748 | 1.648168 |
'''Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b... | def YiqToRgb(y, i, q) | Convert the color from YIQ coordinates to RGB.
Parameters:
:y:
Tte Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]... | 3.334773 | 1.42603 | 2.338501 |
'''Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
u[-0.436... | def RgbToYuv(r, g, b) | Convert the color from RGB coordinates to YUV.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (y, u, v) tuple in the range:
y[0...1],
u[-0.436...0.43... | 2.270073 | 1.276597 | 1.778222 |
'''Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
... | def YuvToRgb(y, u, v) | Convert the color from YUV coordinates to RGB.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...... | 2.761265 | 1.260745 | 2.190184 |
'''Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...1]
:g:
... | def RgbToXyz(r, g, b) | Convert the color from sRGB to CIE XYZ.
The methods assumes that the RGB coordinates are given in the sRGB
colorspace (D65).
.. note::
Compensation for the sRGB gamma correction is applied before converting.
Parameters:
:r:
The Red component value [0...1]
:g:
The G... | 2.371046 | 1.279468 | 1.853149 |
'''Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
Ret... | def XyzToRgb(x, y, z) | Convert the color from CIE XYZ coordinates to sRGB.
.. note::
Compensation for sRGB gamma correction is applied before converting.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
Returns:
... | 2.99118 | 1.665778 | 1.795665 |
'''Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (L, ... | def XyzToLab(x, y, z, wref=_DEFAULT_WREF) | Convert the color from CIE XYZ to CIE L*a*b*.
Parameters:
:x:
The X component value [0...1]
:y:
The Y component value [0...1]
:z:
The Z component value [0...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (L, a, b) t... | 3.115166 | 1.640506 | 1.898906 |
'''Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (x, y, z) tup... | def LabToXyz(l, a, b, wref=_DEFAULT_WREF) | Convert the color from CIE L*a*b* to CIE 1931 XYZ.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:wref:
The whitepoint reference, default is 2° D65.
Returns:
The color as an (x, y, z) tuple in t... | 3.652744 | 1.558652 | 2.343528 |
'''Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
The color as an (c... | def CmykToCmy(c, m, y, k) | Convert the color from CMYK coordinates to CMY.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
Returns:
The color as an (c, m, y)... | 2.852116 | 1.390321 | 2.051408 |
'''Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c[0...1],
... | def CmyToCmyk(c, m, y) | Convert the color from CMY coordinates to CMYK.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
Returns:
The color as an (c, m, y, k) tuple in the range:
c[0...1],
m[0...... | 2.613049 | 1.450911 | 1.800971 |
'''Convert the color from (r, g, b) to an int tuple.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...255],
g[0... | def RgbToIntTuple(r, g, b) | Convert the color from (r, g, b) to an int tuple.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
r[0...255],
g[0...2551... | 2.770406 | 1.317938 | 2.102076 |
'''Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> Color.RgbToHtml(... | def RgbToHtml(r, g, b) | Convert the color from (r, g, b) to #RRGGBB.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A CSS string representation of this color (#RRGGBB).
>>> Color.RgbToHtml(1, 0.5,... | 2.687254 | 1.45002 | 1.853252 |
'''Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neithe... | def HtmlToRgb(html) | Convert the HTML color to (r, g, b).
Parameters:
:html:
the HTML definition of the color (#RRGGBB or #RGB or a color name).
Returns:
The color as an (r, g, b) tuple in the range:
r[0...1],
g[0...1],
b[0...1]
Throws:
:ValueError:
If html is neither a kno... | 2.331407 | 1.413266 | 1.649658 |
'''Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x' % Color.RgbT... | def RgbToPil(r, g, b) | Convert the color from RGB to a PIL-compatible integer.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
A PIL compatible integer (0xBBGGRR).
>>> '0x%06x' % Color.RgbToPil(1,... | 2.904355 | 1.446145 | 2.008343 |
'''Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % Color.PilToRgb(0x0080... | def PilToRgb(pil) | Convert the color from a PIL-compatible integer to RGB.
Parameters:
pil: a PIL compatible color representation (0xBBGGRR)
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r: [0...1]
g: [0...1]
b: [0...1]
>>> '(%g, %g, %g)' % Color.PilToRgb(0x0080ff)
... | 3.765743 | 1.417972 | 2.655725 |
'''Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value.
'''
# This sucks, but floating po... | def _WebSafeComponent(c, alt=False) | Convert a color component to its web safe equivalent.
Parameters:
:c:
The component value [0...1]
:alt:
If True, return the alternative value instead of the nearest one.
Returns:
The web safe equivalent of the component value. | 5.195755 | 3.934726 | 1.320487 |
'''Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of the nearest one.
Can be ... | def RgbToWebSafe(r, g, b, alt=False) | Convert the color from RGB to 'web safe' RGB
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alt:
If True, use the alternative color instead of the nearest one.
Can be used fo... | 3.898693 | 1.492404 | 2.612358 |
'''Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
the range:
... | def RgbToGreyscale(r, g, b) | Convert the color from RGB to its greyscale equivalent
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
Returns:
The color as an (r, g, b) tuple in the range:
the range:
r[0...... | 3.116332 | 1.326354 | 2.349547 |
'''Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> Color.RgbToRyb(15)
26.0
'''
d = hue % 15
i = int(hue / 15)
x0 = _... | def RgbToRyb(hue) | Maps a hue on the RGB color wheel to Itten's RYB wheel.
Parameters:
:hue:
The hue on the RGB color wheel [0...360]
Returns:
An approximation of the corresponding hue on Itten's RYB wheel.
>>> Color.RgbToRyb(15)
26.0 | 4.828063 | 2.02416 | 2.385218 |
'''Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> Color.RybToRgb(15)
8.0
'''
d = hue % 15
i = int(hue... | def RybToRgb(hue) | Maps a hue on Itten's RYB color wheel to the standard RGB wheel.
Parameters:
:hue:
The hue on Itten's RYB color wheel [0...360]
Returns:
An approximation of the corresponding hue on the standard RGB wheel.
>>> Color.RybToRgb(15)
8.0 | 5.492454 | 2.119704 | 2.591141 |
'''Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | def NewFromRgb(r, g, b, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed RGB values.
Parameters:
:r:
The Red component value [0...1]
:g:
The Green component value [0...1]
:b:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
T... | 2.342365 | 1.264838 | 1.851909 |
'''Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
... | def NewFromHsl(h, s, l, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed HSL values.
Parameters:
:h:
The Hue component value [0...1]
:s:
The Saturation component value [0...1]
:l:
The Lightness component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:... | 2.452529 | 1.27791 | 1.919173 |
'''Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | def NewFromHsv(h, s, v, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed HSV values.
Parameters:
:h:
The Hus component value [0...1]
:s:
The Saturation component value [0...1]
:v:
The Value component [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
T... | 2.991392 | 1.45758 | 2.052301 |
'''Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The... | def NewFromYiq(y, i, q, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed YIQ values.
Parameters:
:y:
The Y component value [0...1]
:i:
The I component value [0...1]
:q:
The Q component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitep... | 2.889098 | 1.231822 | 2.345386 |
'''Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
The color transparency [0...1], default is opaque
... | def NewFromYuv(y, u, v, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed YUV values.
Parameters:
:y:
The Y component value [0...1]
:u:
The U component value [-0.436...0.436]
:v:
The V component value [-0.615...0.615]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | 2.786368 | 1.219413 | 2.285008 |
'''Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref... | def NewFromXyz(x, y, z, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed CIE-XYZ values.
Parameters:
:x:
The Red component value [0...1]
:y:
The Green component value [0...1]
:z:
The Blue component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | 2.938586 | 1.257287 | 2.337244 |
'''Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoin... | def NewFromLab(l, a, b, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed CIE-LAB values.
Parameters:
:l:
The L component [0...100]
:a:
The a component [-1...1]
:b:
The a component [-1...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint refer... | 2.557651 | 1.18821 | 2.152524 |
'''Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wre... | def NewFromCmy(c, m, y, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed CMY values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:alpha:
The color transparency [0...1], default is opaque
:wref:
... | 2.618972 | 1.321325 | 1.982081 |
'''Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
:alpha:
The col... | def NewFromCmyk(c, m, y, k, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed CMYK values.
Parameters:
:c:
The Cyan component value [0...1]
:m:
The Magenta component value [0...1]
:y:
The Yellow component value [0...1]
:k:
The Black component value [0...1]
:alpha:
The color tran... | 2.542444 | 1.347453 | 1.886851 |
'''Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
The whitepoint reference, default is 2° D65.
... | def NewFromHtml(html, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed HTML color definition.
Parameters:
:html:
The HTML definition of the color (#RRGGBB or #RGB or a color name).
:alpha:
The color transparency [0...1], default is opaque.
:wref:
The whitepoint reference, default is 2° D65.
Ret... | 2.401185 | 1.211646 | 1.981755 |
'''Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, default is 2° D65.
Returns:
A grapefruit.C... | def NewFromPil(pil, alpha=1.0, wref=_DEFAULT_WREF) | Create a new instance based on the specifed PIL color.
Parameters:
:pil:
A PIL compatible color representation (0xBBGGRR)
:alpha:
The color transparency [0...1], default is opaque
:wref:
The whitepoint reference, default is 2° D65.
Returns:
A grapefruit.Color in... | 3.901101 | 1.386219 | 2.814202 |
'''Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwise, the RGB values are used as reference.
Re... | def ColorWithWhiteRef(self, wref, labAsRef=False) | Create a new instance based on this one with a new white reference.
Parameters:
:wref:
The whitepoint reference.
:labAsRef:
If True, the L*a*b* values of the current instance are used as reference
for the new color; otherwise, the RGB values are used as reference.
Returns:
... | 2.887632 | 1.241519 | 2.325886 |
'''Create a new instance based on this one with a new hue.
Parameters:
:hue:
The hue of the new color [0...360].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithHue(60)
(1.0, 1.0, 0.0, 1.0)
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithHue(60).h... | def ColorWithHue(self, hue) | Create a new instance based on this one with a new hue.
Parameters:
:hue:
The hue of the new color [0...360].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithHue(60)
(1.0, 1.0, 0.0, 1.0)
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithHue(60).hsl
... | 3.571657 | 1.644838 | 2.171435 |
'''Create a new instance based on this one with a new saturation value.
.. note::
The saturation is defined for the HSL mode.
Parameters:
:saturation:
The saturation of the new color [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).Color... | def ColorWithSaturation(self, saturation) | Create a new instance based on this one with a new saturation value.
.. note::
The saturation is defined for the HSL mode.
Parameters:
:saturation:
The saturation of the new color [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithSat... | 3.519031 | 1.537316 | 2.289075 |
'''Create a new instance based on this one with a new lightness value.
Parameters:
:lightness:
The lightness of the new color [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithLightness(0.25)
(0.5, 0.25, 0.0, 1.0)
>>> Color.NewFromHsl... | def ColorWithLightness(self, lightness) | Create a new instance based on this one with a new lightness value.
Parameters:
:lightness:
The lightness of the new color [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ColorWithLightness(0.25)
(0.5, 0.25, 0.0, 1.0)
>>> Color.NewFromHsl(30, 1,... | 3.261102 | 1.597862 | 2.040916 |
'''Create a new instance based on this one but lighter.
Parameters:
:level:
The amount by which the color should be lightened to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).LighterColor(0.25)
(1.0, 0.75, 0.5, 1.0)... | def LighterColor(self, level) | Create a new instance based on this one but lighter.
Parameters:
:level:
The amount by which the color should be lightened to produce
the new one [0...1].
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).LighterColor(0.25)
(1.0, 0.75, 0.5, 1.0)
>>... | 3.55576 | 1.591718 | 2.233913 |
'''Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.NewFromRgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.WebSafeDither()
>>> str(c1)
'(1, 0.4, 0, 1)'
>>> str(c2)
'(1,... | def WebSafeDither(self) | Return the two websafe colors nearest to this one.
Returns:
A tuple of two grapefruit.Color instances which are the two
web safe colors closest this one.
>>> c = Color.NewFromRgb(1.0, 0.45, 0.0)
>>> c1, c2 = c.WebSafeDither()
>>> str(c1)
'(1, 0.4, 0, 1)'
>>> str(c2)
'(1, 0.6, 0... | 4.500936 | 2.041766 | 2.204433 |
'''Create a list with the gradient colors between this and the other color.
Parameters:
:target:
The grapefruit.Color at the other end of the gradient.
:steps:
The number of gradients steps to create.
Returns:
A list of grapefruit.Color instances.
>>> c1 = Color.New... | def Gradient(self, target, steps=100) | Create a list with the gradient colors between this and the other color.
Parameters:
:target:
The grapefruit.Color at the other end of the gradient.
:steps:
The number of gradients steps to create.
Returns:
A list of grapefruit.Color instances.
>>> c1 = Color.NewFromRgb... | 2.464075 | 1.499947 | 1.642775 |
'''Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ComplementaryColor(mode='rgb')
(0.0, 0.5, 1.0, 1.0)
... | def ComplementaryColor(self, mode='ryb') | Create a new instance which is the complementary color of this one.
Parameters:
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A grapefruit.Color instance.
>>> Color.NewFromHsl(30, 1, 0.5).ComplementaryColor(mode='rgb')
(0.0, 0.5, 1.0, 1.0)
>>> ... | 3.547318 | 1.695795 | 2.091832 |
'''Return 4 colors in the same hue with varying saturation/lightness.
Returns:
A tuple of 4 grapefruit.Color in the same hue as this one,
with varying saturation/lightness.
>>> c = Color.NewFromHsl(30, 0.5, 0.5)
>>> ['(%g, %g, %g)' % clr.hsl for clr in c.MonochromeScheme()]
['(30, 0.2,... | def MonochromeScheme(self) | Return 4 colors in the same hue with varying saturation/lightness.
Returns:
A tuple of 4 grapefruit.Color in the same hue as this one,
with varying saturation/lightness.
>>> c = Color.NewFromHsl(30, 0.5, 0.5)
>>> ['(%g, %g, %g)' % clr.hsl for clr in c.MonochromeScheme()]
['(30, 0.2, 0.8)',... | 2.673347 | 1.80443 | 1.481546 |
'''Return two colors forming a triad or a split complementary with this one.
Parameters:
:angle:
The angle between the hues of the created colors.
The default value makes a triad.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tupl... | def TriadicScheme(self, angle=120, mode='ryb') | Return two colors forming a triad or a split complementary with this one.
Parameters:
:angle:
The angle between the hues of the created colors.
The default value makes a triad.
:mode:
Select which color wheel to use for the generation (ryb/rgb).
Returns:
A tuple of tw... | 3.149694 | 1.54467 | 2.039073 |
rgb = GC.NewFromHtml(html_string).rgb
return cls("rgb", *rgb) | def from_html(cls, html_string) | Create sRGB color from a web-color name or hexcode.
:param str html_string: Web-color name or hexcode.
:rtype: Color
:returns: A spectra.Color in the sRGB color space. | 30.601519 | 44.555706 | 0.686815 |
if space == self.space: return self
new_color = convert_color(self.color_object, COLOR_SPACES[space])
return self.__class__(space, *new_color.get_value_tuple()) | def to(self, space) | Convert color to a different color space.
:param str space: Name of the color space.
:rtype: Color
:returns: A new spectra.Color in the given color space. | 6.931212 | 6.274456 | 1.104672 |
keep = 1.0 - ratio
if not self.space == other.space:
raise Exception("Colors must belong to the same color space.")
values = tuple(((u * keep) + (v * ratio)
for u, v in zip(self.values, other.values)))
return self.__class__(self.space, *values) | def blend(self, other, ratio=0.5) | Blend this color with another color in the same color space.
By default, blends the colors half-and-half (ratio: 0.5).
:param Color other: The color to blend.
:param float ratio: How much to blend (0 -> 1).
:rtype: Color
:returns: A new spectra.Color | 4.515359 | 4.940555 | 0.913938 |
lch = self.to("lch")
l, c, h = lch.values
new_lch = self.__class__("lch", l + amount, c, h)
return new_lch.to(self.space) | def brighten(self, amount=10) | Brighten this color by `amount` luminance.
Converts this color to the LCH color space, and then
increases the `L` parameter by `amount`.
:param float amount: Amount to increase the luminance.
:rtype: Color
:returns: A new spectra.Color | 4.223915 | 4.5235 | 0.933771 |
new_colors = [ c.to(space) for c in self.colors ]
return self.__class__(new_colors, self._domain) | def colorspace(self, space) | Create a new scale in the given color space.
:param str space: The new color space.
:rtype: Scale
:returns: A new color.Scale object. | 5.590292 | 8.106457 | 0.68961 |
if count <= 1:
raise ValueError("Range size must be greater than 1.")
dom = self._domain
distance = dom[-1] - dom[0]
props = [ self(dom[0] + distance * float(x)/(count-1))
for x in range(count) ]
return props | def range(self, count) | Create a list of colors evenly spaced along this scale's domain.
:param int count: The number of colors to return.
:rtype: list
:returns: A list of spectra.Color objects. | 5.171056 | 4.817567 | 1.073375 |
root_order = ["jsonrpc", "result", "error", "id"]
error_order = ["code", "message", "data"]
req = OrderedDict(sorted(response.items(), key=lambda k: root_order.index(k[0])))
if "error" in response:
req["error"] = OrderedDict(
sorted(response["error"].items(), key=lambda k: error... | def sort_response(response: Dict[str, Any]) -> OrderedDict | Sort the keys in a JSON-RPC response object.
This has no effect other than making it nicer to read. Useful in Python 3.5 only,
dictionaries are already sorted in newer Python versions.
Example::
>>> json.dumps(sort_response({'id': 2, 'result': 5, 'jsonrpc': '2.0'}))
{"jsonrpc": "2.0", "re... | 2.284276 | 2.455446 | 0.93029 |
if isinstance(data, list):
return sum([1 for d in data if d.ok == ok])
elif isinstance(data, JSONRPCResponse):
return int(data.ok == ok)
return 0 | def total_results(
data: Union[List[JSONRPCResponse], JSONRPCResponse, None], *, ok: bool = True
) -> int | Returns the total parsed responses, given the return value from parse(). | 2.635535 | 2.487683 | 1.059434 |
with async_timeout.timeout(self.timeout):
async with self.session.post(
self.endpoint, data=request, ssl=self.ssl
) as response:
response_text = await response.text()
return Response(response_text, raw=response) | async def send_message(
self, request: str, response_expected: bool, **kwargs: Any
) -> Response | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | 3.002851 | 3.143195 | 0.95535 |
await self.socket.send(request)
if response_expected:
response_text = await self.socket.recv()
return Response(response_text)
return Response("") | async def send_message(
self, request: str, response_expected: bool, **kwargs: Any
) -> Response | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | 3.260062 | 3.704261 | 0.880085 |
module = path[: path.rindex(".")]
callable_name = path[path.rindex(".") + 1 :]
callable_ = getattr(importlib.import_module(module), callable_name)
return callable_() | def parse_callable(path: str) -> Iterator | ConfigParser converter.
Calls the specified object, e.g. Option "id_generators.decimal" returns
`id_generators.decimal()`. | 3.299876 | 3.440781 | 0.959048 |
while True:
yield "".join([choice(chars) for _ in range(length)]) | def random(length: int = 8, chars: str = digits + ascii_lowercase) -> Iterator[str] | A random string.
Not unique, but has around 1 in a million chance of collision (with the default 8
character length). e.g. 'fubui5e6'
Args:
length: Length of the random string.
chars: The characters to randomly choose from. | 2.941629 | 4.816555 | 0.610733 |
if "error" in response:
return ErrorResponse(**response)
return SuccessResponse(**response) | def get_response(response: Dict[str, Any]) -> JSONRPCResponse | Converts a deserialized response into a JSONRPCResponse object.
The dictionary be either an error or success response, never a notification.
Args:
response: Deserialized response dictionary. We can assume the response is valid
JSON-RPC here, since it passed the jsonschema validation. | 5.456021 | 7.667003 | 0.711624 |
# If the response is empty, we can't deserialize it; an empty string is valid
# JSON-RPC, but not valid JSON.
if not response_text:
if batch:
# An empty string is a valid response to a batch request, when there were
# only notifications in the batch.
return [... | def parse(
response_text: str, *, batch: bool, validate_against_schema: bool = True
) -> Union[JSONRPCResponse, List[JSONRPCResponse]] | Parses response text, returning JSONRPCResponse objects.
Args:
response_text: JSON-RPC response string.
batch: If the response_text is an empty string, this determines how to parse.
validate_against_schema: Validate against the json-rpc schema.
Returns:
Either a JSONRPCResponse... | 4.414981 | 4.308304 | 1.024761 |
# We need both the serialized and deserialized version of the request
if isinstance(request, str):
request_text = request
request_deserialized = deserialize(request)
else:
request_text = serialize(request)
request_deserialized = request
... | async def send(
self,
request: Union[str, Dict, List],
trim_log_values: bool = False,
validate_against_schema: bool = True,
**kwargs: Any
) -> Response | Async version of Client.send. | 2.956934 | 2.912565 | 1.015234 |
headers = dict(self.DEFAULT_HEADERS)
headers.update(kwargs.pop("headers", {}))
response = await self.client.fetch(
self.endpoint, method="POST", body=request, headers=headers, **kwargs
)
return Response(response.body.decode(), raw=response) | async def send_message( # type: ignore
self, request: str, response_expected: bool, **kwargs: Any
) -> Response | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | 3.326962 | 3.463773 | 0.960502 |
exit_status = 0
# Extract the jsonrpc arguments
positional = [a for a in context.args if "=" not in a]
named = {a.split("=")[0]: a.split("=")[1] for a in context.args if "=" in a}
# Create the request
if request_type == "notify":
req = Notification(method, *positional, **named)
... | def main(
context: click.core.Context, method: str, request_type: str, id: Any, send: str
) -> None | Create a JSON-RPC request. | 2.854961 | 2.602654 | 1.096942 |
if extra is None:
extra = {}
# Clean up the message for logging
if message:
message = message.replace("\n", "").replace(" ", " ").replace("{ ", "{")
if trim:
message = _trim_message(message)
# Log.
getattr(logger, level)(message, extra=extra) | def log_(
message: str,
logger: logging.Logger,
level: str = "info",
extra: Optional[Dict] = None,
trim: bool = False,
) -> None | Log a request or response
Args:
message: JSON-RPC request or response string.
level: Log level.
extra: More details to include in the log entry.
trim: Abbreviate log messages. | 3.982939 | 3.862546 | 1.031169 |
sort_order = ["jsonrpc", "method", "params", "id"]
return OrderedDict(sorted(request.items(), key=lambda k: sort_order.index(k[0]))) | def sort_request(request: Dict[str, Any]) -> OrderedDict | Sort a JSON-RPC request dict.
This has no effect other than making the request nicer to read.
>>> json.dumps(sort_request(
... {'id': 2, 'params': [2, 3], 'method': 'add', 'jsonrpc': '2.0'}))
'{"jsonrpc": "2.0", "method": "add", "params": [2, 3], "id": 2}'
Args:
request: J... | 3.135538 | 4.726992 | 0.663326 |
# Request handler
if len(request_log.handlers) == 0:
request_handler = logging.StreamHandler()
request_handler.setFormatter(
logging.Formatter(fmt=self.DEFAULT_REQUEST_LOG_FORMAT)
)
request_log.addHandler(request_handler)
... | def basic_logging(self) -> None | Call this on the client object to create log handlers to output request and
response messages. | 1.772969 | 1.632757 | 1.085874 |
return log_(request, request_log, "info", trim=trim_log_values, **kwargs) | def log_request(
self, request: str, trim_log_values: bool = False, **kwargs: Any
) -> None | Log a request.
Args:
request: The JSON-RPC request string.
trim_log_values: Log an abbreviated version of the request. | 13.860272 | 14.333539 | 0.966982 |
return log_(response.text, response_log, "info", trim=trim_log_values, **kwargs) | def log_response(
self, response: Response, trim_log_values: bool = False, **kwargs: Any
) -> None | Log a response.
Note this is different to log_request, in that it takes a Response object, not a
string.
Args:
response: The Response object to log. Note this is different to log_request
which takes a string.
trim_log_values: Log an abbreviated version o... | 15.983236 | 17.937197 | 0.891067 |
return self.send(
Notification(method_name, *args, **kwargs),
trim_log_values=trim_log_values,
validate_against_schema=validate_against_schema,
) | def notify(
self,
method_name: str,
*args: Any,
trim_log_values: Optional[bool] = None,
validate_against_schema: Optional[bool] = None,
**kwargs: Any
) -> Response | Send a JSON-RPC request, without expecting a response.
Args:
method_name: The remote procedure's method name.
args: Positional arguments passed to the remote procedure.
kwargs: Keyword arguments passed to the remote procedure.
trim_log_values: Abbreviate the log ... | 2.121562 | 2.316833 | 0.915717 |
return self.send(
Request(method_name, id_generator=id_generator, *args, **kwargs),
trim_log_values=trim_log_values,
validate_against_schema=validate_against_schema,
) | def request(
self,
method_name: str,
*args: Any,
trim_log_values: bool = False,
validate_against_schema: bool = True,
id_generator: Optional[Iterator] = None,
**kwargs: Any
) -> Response | Send a request by passing the method and arguments.
>>> client.request("cat", name="Yoko")
<Response[1]
Args:
method_name: The remote procedure's method name.
args: Positional arguments passed to the remote procedure.
kwargs: Keyword arguments passed to the ... | 1.984559 | 2.234626 | 0.888095 |
payload = str(request) + self.delimiter
self.socket.send(payload.encode(self.encoding))
response = bytes()
decoded = None
# Receive the response until we find the delimiter.
# TODO Do not wait for a response if the message sent is a notification.
while ... | def send_message(
self, request: str, response_expected: bool, **kwargs: Any
) -> Response | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | 4.534997 | 4.379014 | 1.035621 |
response = self.session.post(self.endpoint, data=request.encode(), **kwargs)
return Response(response.text, raw=response) | def send_message(
self, request: str, response_expected: bool, **kwargs: Any
) -> Response | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | 4.596635 | 5.342785 | 0.860344 |
self.socket.send_string(request)
return Response(self.socket.recv().decode()) | def send_message(
self, request: str, response_expected: bool, **kwargs: Any
) -> Response | Transport the message to the server and return the response.
Args:
request: The JSON-RPC request string.
response_expected: Whether the request expects a response.
Returns:
A Response object. | 6.00173 | 6.35208 | 0.944845 |
func = InvokeFunction('init')
tx_hash = self.__sdk.get_network().send_neo_vm_transaction(self.__hex_contract_address, acct, payer_acct,
gas_limit, gas_price, func)
return tx_hash | def init(self, acct: Account, payer_acct: Account, gas_limit: int, gas_price: int) -> str | This interface is used to call the TotalSupply method in ope4
that initialize smart contract parameter.
:param acct: an Account class that used to sign the transaction.
:param payer_acct: an Account class that used to pay for the transaction.
:param gas_limit: an int value that indicate... | 7.040846 | 7.312531 | 0.962847 |
func = InvokeFunction('totalSupply')
response = self.__sdk.get_network().send_neo_vm_transaction_pre_exec(self.__hex_contract_address, None, func)
try:
total_supply = ContractDataParser.to_int(response['Result'])
except SDKException:
total_supply = 0
... | def get_total_supply(self) -> int | This interface is used to call the TotalSupply method in ope4
that return the total supply of the oep4 token.
:return: the total supply of the oep4 token. | 9.213976 | 8.927822 | 1.032052 |
func = InvokeFunction('balanceOf')
Oep4.__b58_address_check(b58_address)
address = Address.b58decode(b58_address).to_bytes()
func.set_params_value(address)
result = self.__sdk.get_network().send_neo_vm_transaction_pre_exec(self.__hex_contract_address, None, func)
... | def balance_of(self, b58_address: str) -> int | This interface is used to call the BalanceOf method in ope4
that query the ope4 token balance of the given base58 encode address.
:param b58_address: the base58 encode address.
:return: the oep4 token balance of the base58 encode address. | 8.249653 | 7.644918 | 1.079103 |
func = InvokeFunction('transfer')
if not isinstance(value, int):
raise SDKException(ErrorCode.param_err('the data type of value should be int.'))
if value < 0:
raise SDKException(ErrorCode.param_err('the value should be equal or great than 0.'))
if not is... | def transfer(self, from_acct: Account, b58_to_address: str, value: int, payer_acct: Account, gas_limit: int,
gas_price: int) -> str | This interface is used to call the Transfer method in ope4
that transfer an amount of tokens from one account to another account.
:param from_acct: an Account class that send the oep4 token.
:param b58_to_address: a base58 encode address that receive the oep4 token.
:param value: an int... | 3.31105 | 3.338616 | 0.991743 |
func = InvokeFunction('transferMulti')
for index, item in enumerate(transfer_list):
Oep4.__b58_address_check(item[0])
Oep4.__b58_address_check(item[1])
if not isinstance(item[2], int):
raise SDKException(ErrorCode.param_err('the data type of v... | def transfer_multi(self, transfer_list: list, payer_acct: Account, signers: list, gas_limit: int, gas_price: int) | This interface is used to call the TransferMulti method in ope4
that allow transfer amount of token from multiple from-account to multiple to-account multiple times.
:param transfer_list: a parameter list with each item contains three sub-items:
base58 encode transaction sender address,... | 3.404233 | 3.374979 | 1.008668 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.