repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
tkf/python-epc | epc/client.py | EPCClient.connect | def connect(self, socket_or_address):
"""
Connect to server and start serving registered functions.
:type socket_or_address: tuple or socket object
:arg socket_or_address: A ``(host, port)`` pair to be passed
to `socket.create_connection`, or
... | python | def connect(self, socket_or_address):
"""
Connect to server and start serving registered functions.
:type socket_or_address: tuple or socket object
:arg socket_or_address: A ``(host, port)`` pair to be passed
to `socket.create_connection`, or
... | [
"def",
"connect",
"(",
"self",
",",
"socket_or_address",
")",
":",
"if",
"isinstance",
"(",
"socket_or_address",
",",
"tuple",
")",
":",
"import",
"socket",
"self",
".",
"socket",
"=",
"socket",
".",
"create_connection",
"(",
"socket_or_address",
")",
"else",
... | Connect to server and start serving registered functions.
:type socket_or_address: tuple or socket object
:arg socket_or_address: A ``(host, port)`` pair to be passed
to `socket.create_connection`, or
a socket object. | [
"Connect",
"to",
"server",
"and",
"start",
"serving",
"registered",
"functions",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/client.py#L98-L126 | train |
tkf/python-epc | epc/server.py | main | def main(args=None):
"""
Quick CLI to serve Python functions in a module.
Example usage::
python -m epc.server --allow-dotted-names os
Note that only the functions which gets and returns simple
built-in types (str, int, float, list, tuple, dict) works.
"""
import argparse
fro... | python | def main(args=None):
"""
Quick CLI to serve Python functions in a module.
Example usage::
python -m epc.server --allow-dotted-names os
Note that only the functions which gets and returns simple
built-in types (str, int, float, list, tuple, dict) works.
"""
import argparse
fro... | [
"def",
"main",
"(",
"args",
"=",
"None",
")",
":",
"import",
"argparse",
"from",
"textwrap",
"import",
"dedent",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"formatter_class",
"=",
"type",
"(",
"'EPCHelpFormatter'",
",",
"(",
"argparse",
".",
"Arg... | Quick CLI to serve Python functions in a module.
Example usage::
python -m epc.server --allow-dotted-names os
Note that only the functions which gets and returns simple
built-in types (str, int, float, list, tuple, dict) works. | [
"Quick",
"CLI",
"to",
"serve",
"Python",
"functions",
"in",
"a",
"module",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/server.py#L174-L221 | train |
tkf/python-epc | epc/server.py | EPCServer.print_port | def print_port(self, stream=sys.stdout):
"""
Print port this EPC server runs on.
As Emacs client reads port number from STDOUT, you need to
call this just before calling :meth:`serve_forever`.
:type stream: text stream
:arg stream: A stream object to write port on.
... | python | def print_port(self, stream=sys.stdout):
"""
Print port this EPC server runs on.
As Emacs client reads port number from STDOUT, you need to
call this just before calling :meth:`serve_forever`.
:type stream: text stream
:arg stream: A stream object to write port on.
... | [
"def",
"print_port",
"(",
"self",
",",
"stream",
"=",
"sys",
".",
"stdout",
")",
":",
"stream",
".",
"write",
"(",
"str",
"(",
"self",
".",
"server_address",
"[",
"1",
"]",
")",
")",
"stream",
".",
"write",
"(",
"\"\\n\"",
")",
"stream",
".",
"flus... | Print port this EPC server runs on.
As Emacs client reads port number from STDOUT, you need to
call this just before calling :meth:`serve_forever`.
:type stream: text stream
:arg stream: A stream object to write port on.
Default is :data:`sys.stdout`. | [
"Print",
"port",
"this",
"EPC",
"server",
"runs",
"on",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/server.py#L138-L152 | train |
tkf/python-epc | epc/handler.py | EPCHandler.call | def call(self, name, *args, **kwds):
"""
Call method connected to this handler.
:type name: str
:arg name: Method name to call.
:type args: list
:arg args: Arguments for remote method to call.
:type callback: callable
:arg callback: A f... | python | def call(self, name, *args, **kwds):
"""
Call method connected to this handler.
:type name: str
:arg name: Method name to call.
:type args: list
:arg args: Arguments for remote method to call.
:type callback: callable
:arg callback: A f... | [
"def",
"call",
"(",
"self",
",",
"name",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"self",
".",
"callmanager",
".",
"call",
"(",
"self",
",",
"name",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")"
] | Call method connected to this handler.
:type name: str
:arg name: Method name to call.
:type args: list
:arg args: Arguments for remote method to call.
:type callback: callable
:arg callback: A function to be called with returned value of
... | [
"Call",
"method",
"connected",
"to",
"this",
"handler",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/handler.py#L362-L379 | train |
tkf/python-epc | epc/handler.py | EPCHandler.methods | def methods(self, *args, **kwds):
"""
Request info of callable remote methods.
Arguments for :meth:`call` except for `name` can be applied to
this function too.
"""
self.callmanager.methods(self, *args, **kwds) | python | def methods(self, *args, **kwds):
"""
Request info of callable remote methods.
Arguments for :meth:`call` except for `name` can be applied to
this function too.
"""
self.callmanager.methods(self, *args, **kwds) | [
"def",
"methods",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"self",
".",
"callmanager",
".",
"methods",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")"
] | Request info of callable remote methods.
Arguments for :meth:`call` except for `name` can be applied to
this function too. | [
"Request",
"info",
"of",
"callable",
"remote",
"methods",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/handler.py#L381-L389 | train |
tkf/python-epc | epc/handler.py | EPCHandler.call_sync | def call_sync(self, name, args, timeout=None):
"""
Blocking version of :meth:`call`.
:type name: str
:arg name: Remote function name to call.
:type args: list
:arg args: Arguments passed to the remote function.
:type timeout: int or None
:ar... | python | def call_sync(self, name, args, timeout=None):
"""
Blocking version of :meth:`call`.
:type name: str
:arg name: Remote function name to call.
:type args: list
:arg args: Arguments passed to the remote function.
:type timeout: int or None
:ar... | [
"def",
"call_sync",
"(",
"self",
",",
"name",
",",
"args",
",",
"timeout",
"=",
"None",
")",
":",
"return",
"self",
".",
"_blocking_request",
"(",
"self",
".",
"call",
",",
"timeout",
",",
"name",
",",
"args",
")"
] | Blocking version of :meth:`call`.
:type name: str
:arg name: Remote function name to call.
:type args: list
:arg args: Arguments passed to the remote function.
:type timeout: int or None
:arg timeout: Timeout in second. None means no timeout.
If ... | [
"Blocking",
"version",
"of",
":",
"meth",
":",
"call",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/handler.py#L397-L413 | train |
tkf/python-epc | epc/utils.py | func_call_as_str | def func_call_as_str(name, *args, **kwds):
"""
Return arguments and keyword arguments as formatted string
>>> func_call_as_str('f', 1, 2, a=1)
'f(1, 2, a=1)'
"""
return '{0}({1})'.format(
name,
', '.join(itertools.chain(
map('{0!r}'.format, args),
map('{... | python | def func_call_as_str(name, *args, **kwds):
"""
Return arguments and keyword arguments as formatted string
>>> func_call_as_str('f', 1, 2, a=1)
'f(1, 2, a=1)'
"""
return '{0}({1})'.format(
name,
', '.join(itertools.chain(
map('{0!r}'.format, args),
map('{... | [
"def",
"func_call_as_str",
"(",
"name",
",",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"return",
"'{0}({1})'",
".",
"format",
"(",
"name",
",",
"', '",
".",
"join",
"(",
"itertools",
".",
"chain",
"(",
"map",
"(",
"'{0!r}'",
".",
"format",
",",
... | Return arguments and keyword arguments as formatted string
>>> func_call_as_str('f', 1, 2, a=1)
'f(1, 2, a=1)' | [
"Return",
"arguments",
"and",
"keyword",
"arguments",
"as",
"formatted",
"string"
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/utils.py#L26-L38 | train |
tkf/python-epc | epc/utils.py | newthread | def newthread(template="EPCThread-{0}", **kwds):
"""
Instantiate :class:`threading.Thread` with an appropriate name.
"""
if not isinstance(template, str):
template = '{0}.{1}-{{0}}'.format(template.__module__,
template.__class__.__name__)
return thre... | python | def newthread(template="EPCThread-{0}", **kwds):
"""
Instantiate :class:`threading.Thread` with an appropriate name.
"""
if not isinstance(template, str):
template = '{0}.{1}-{{0}}'.format(template.__module__,
template.__class__.__name__)
return thre... | [
"def",
"newthread",
"(",
"template",
"=",
"\"EPCThread-{0}\"",
",",
"*",
"*",
"kwds",
")",
":",
"if",
"not",
"isinstance",
"(",
"template",
",",
"str",
")",
":",
"template",
"=",
"'{0}.{1}-{{0}}'",
".",
"format",
"(",
"template",
".",
"__module__",
",",
... | Instantiate :class:`threading.Thread` with an appropriate name. | [
"Instantiate",
":",
"class",
":",
"threading",
".",
"Thread",
"with",
"an",
"appropriate",
"name",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/utils.py#L81-L89 | train |
tkf/python-epc | epc/utils.py | callwith | def callwith(context_manager):
"""
A decorator to wrap execution of function with a context manager.
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
with context_manager:
return func(*args, **kwds)
return wrapper
return ... | python | def callwith(context_manager):
"""
A decorator to wrap execution of function with a context manager.
"""
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
with context_manager:
return func(*args, **kwds)
return wrapper
return ... | [
"def",
"callwith",
"(",
"context_manager",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"functools",
".",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwds",
")",
":",
"with",
"context_manager",
":",
"re... | A decorator to wrap execution of function with a context manager. | [
"A",
"decorator",
"to",
"wrap",
"execution",
"of",
"function",
"with",
"a",
"context",
"manager",
"."
] | f3673ae5c35f20a0f71546ab34c28e3dde3595c1 | https://github.com/tkf/python-epc/blob/f3673ae5c35f20a0f71546ab34c28e3dde3595c1/epc/utils.py#L121-L131 | train |
dgketchum/satellite_image | sat_image/image.py | LandsatImage._scene_centroid | def _scene_centroid(self):
""" Compute image center coordinates
:return: Tuple of image center in lat, lon
"""
ul_lat = self.corner_ul_lat_product
ll_lat = self.corner_ll_lat_product
ul_lon = self.corner_ul_lon_product
ur_lon = self.corner_ur_lon_product
l... | python | def _scene_centroid(self):
""" Compute image center coordinates
:return: Tuple of image center in lat, lon
"""
ul_lat = self.corner_ul_lat_product
ll_lat = self.corner_ll_lat_product
ul_lon = self.corner_ul_lon_product
ur_lon = self.corner_ur_lon_product
l... | [
"def",
"_scene_centroid",
"(",
"self",
")",
":",
"ul_lat",
"=",
"self",
".",
"corner_ul_lat_product",
"ll_lat",
"=",
"self",
".",
"corner_ll_lat_product",
"ul_lon",
"=",
"self",
".",
"corner_ul_lon_product",
"ur_lon",
"=",
"self",
".",
"corner_ur_lon_product",
"la... | Compute image center coordinates
:return: Tuple of image center in lat, lon | [
"Compute",
"image",
"center",
"coordinates",
":",
"return",
":",
"Tuple",
"of",
"image",
"center",
"in",
"lat",
"lon"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L126-L137 | train |
dgketchum/satellite_image | sat_image/image.py | LandsatImage.earth_sun_d | def earth_sun_d(dtime):
""" Earth-sun distance in AU
:param dtime time, e.g. datetime.datetime(2007, 5, 1)
:type datetime object
:return float(distance from sun to earth in astronomical units)
"""
doy = int(dtime.strftime('%j'))
rad_term = 0.9856 * (doy -... | python | def earth_sun_d(dtime):
""" Earth-sun distance in AU
:param dtime time, e.g. datetime.datetime(2007, 5, 1)
:type datetime object
:return float(distance from sun to earth in astronomical units)
"""
doy = int(dtime.strftime('%j'))
rad_term = 0.9856 * (doy -... | [
"def",
"earth_sun_d",
"(",
"dtime",
")",
":",
"doy",
"=",
"int",
"(",
"dtime",
".",
"strftime",
"(",
"'%j'",
")",
")",
"rad_term",
"=",
"0.9856",
"*",
"(",
"doy",
"-",
"4",
")",
"*",
"pi",
"/",
"180",
"distance_au",
"=",
"1",
"-",
"0.01672",
"*",... | Earth-sun distance in AU
:param dtime time, e.g. datetime.datetime(2007, 5, 1)
:type datetime object
:return float(distance from sun to earth in astronomical units) | [
"Earth",
"-",
"sun",
"distance",
"in",
"AU",
":",
"param",
"dtime",
"time",
"e",
".",
"g",
".",
"datetime",
".",
"datetime",
"(",
"2007",
"5",
"1",
")",
":",
"type",
"datetime",
"object",
":",
"return",
"float",
"(",
"distance",
"from",
"sun",
"to",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L140-L150 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat5.reflectance | def reflectance(self, band):
"""
:param band: An optical band, i.e. 1-5, 7
:return: At satellite reflectance, [-]
"""
if band == 6:
raise ValueError('LT5 reflectance must be other than band 6')
rad = self.radiance(band)
esun = self.ex_atm_irrad[band... | python | def reflectance(self, band):
"""
:param band: An optical band, i.e. 1-5, 7
:return: At satellite reflectance, [-]
"""
if band == 6:
raise ValueError('LT5 reflectance must be other than band 6')
rad = self.radiance(band)
esun = self.ex_atm_irrad[band... | [
"def",
"reflectance",
"(",
"self",
",",
"band",
")",
":",
"if",
"band",
"==",
"6",
":",
"raise",
"ValueError",
"(",
"'LT5 reflectance must be other than band 6'",
")",
"rad",
"=",
"self",
".",
"radiance",
"(",
"band",
")",
"esun",
"=",
"self",
".",
"ex_at... | :param band: An optical band, i.e. 1-5, 7
:return: At satellite reflectance, [-] | [
":",
"param",
"band",
":",
"An",
"optical",
"band",
"i",
".",
"e",
".",
"1",
"-",
"5",
"7",
":",
"return",
":",
"At",
"satellite",
"reflectance",
"[",
"-",
"]"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L279-L291 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat5.albedo | def albedo(self, model='smith'):
"""Finds broad-band surface reflectance (albedo)
Smith (2010), “The heat budget of the earth’s surface deduced from space”
LT5 toa reflectance bands 1, 3, 4, 5, 7
# normalized i.e. 0.356 + 0.130 + 0.373 + 0.085 + 0.07 = 1.014
Sh... | python | def albedo(self, model='smith'):
"""Finds broad-band surface reflectance (albedo)
Smith (2010), “The heat budget of the earth’s surface deduced from space”
LT5 toa reflectance bands 1, 3, 4, 5, 7
# normalized i.e. 0.356 + 0.130 + 0.373 + 0.085 + 0.07 = 1.014
Sh... | [
"def",
"albedo",
"(",
"self",
",",
"model",
"=",
"'smith'",
")",
":",
"if",
"model",
"==",
"'smith'",
":",
"blue",
",",
"red",
",",
"nir",
",",
"swir1",
",",
"swir2",
"=",
"(",
"self",
".",
"reflectance",
"(",
"1",
")",
",",
"self",
".",
"reflect... | Finds broad-band surface reflectance (albedo)
Smith (2010), “The heat budget of the earth’s surface deduced from space”
LT5 toa reflectance bands 1, 3, 4, 5, 7
# normalized i.e. 0.356 + 0.130 + 0.373 + 0.085 + 0.07 = 1.014
Should have option for Liang, 2000;
... | [
"Finds",
"broad",
"-",
"band",
"surface",
"reflectance",
"(",
"albedo",
")",
"Smith",
"(",
"2010",
")",
"“The",
"heat",
"budget",
"of",
"the",
"earth’s",
"surface",
"deduced",
"from",
"space”",
"LT5",
"toa",
"reflectance",
"bands",
"1",
"3",
"4",
"5",
"7... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L293-L315 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat5.saturation_mask | def saturation_mask(self, band, value=255):
""" Mask saturated pixels, 1 (True) is saturated.
:param band: Image band with dn values, type: array
:param value: Maximum (saturated) value, i.e. 255 for 8-bit data, type: int
:return: boolean array
"""
dn = self._get_band('b{... | python | def saturation_mask(self, band, value=255):
""" Mask saturated pixels, 1 (True) is saturated.
:param band: Image band with dn values, type: array
:param value: Maximum (saturated) value, i.e. 255 for 8-bit data, type: int
:return: boolean array
"""
dn = self._get_band('b{... | [
"def",
"saturation_mask",
"(",
"self",
",",
"band",
",",
"value",
"=",
"255",
")",
":",
"dn",
"=",
"self",
".",
"_get_band",
"(",
"'b{}'",
".",
"format",
"(",
"band",
")",
")",
"mask",
"=",
"self",
".",
"mask",
"(",
")",
"mask",
"=",
"where",
"("... | Mask saturated pixels, 1 (True) is saturated.
:param band: Image band with dn values, type: array
:param value: Maximum (saturated) value, i.e. 255 for 8-bit data, type: int
:return: boolean array | [
"Mask",
"saturated",
"pixels",
"1",
"(",
"True",
")",
"is",
"saturated",
".",
":",
"param",
"band",
":",
"Image",
"band",
"with",
"dn",
"values",
"type",
":",
"array",
":",
"param",
"value",
":",
"Maximum",
"(",
"saturated",
")",
"value",
"i",
".",
"... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L317-L327 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat5.ndvi | def ndvi(self):
""" Normalized difference vegetation index.
:return: NDVI
"""
red, nir = self.reflectance(3), self.reflectance(4)
ndvi = self._divide_zero((nir - red), (nir + red), nan)
return ndvi | python | def ndvi(self):
""" Normalized difference vegetation index.
:return: NDVI
"""
red, nir = self.reflectance(3), self.reflectance(4)
ndvi = self._divide_zero((nir - red), (nir + red), nan)
return ndvi | [
"def",
"ndvi",
"(",
"self",
")",
":",
"red",
",",
"nir",
"=",
"self",
".",
"reflectance",
"(",
"3",
")",
",",
"self",
".",
"reflectance",
"(",
"4",
")",
"ndvi",
"=",
"self",
".",
"_divide_zero",
"(",
"(",
"nir",
"-",
"red",
")",
",",
"(",
"nir"... | Normalized difference vegetation index.
:return: NDVI | [
"Normalized",
"difference",
"vegetation",
"index",
".",
":",
"return",
":",
"NDVI"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L329-L336 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat5.lai | def lai(self):
"""
Leaf area index (LAI), or the surface area of leaves to surface area ground.
Trezza and Allen, 2014
:param ndvi: normalized difference vegetation index [-]
:return: LAI [-]
"""
ndvi = self.ndvi()
lai = 7.0 * (ndvi ** 3)
lai = whe... | python | def lai(self):
"""
Leaf area index (LAI), or the surface area of leaves to surface area ground.
Trezza and Allen, 2014
:param ndvi: normalized difference vegetation index [-]
:return: LAI [-]
"""
ndvi = self.ndvi()
lai = 7.0 * (ndvi ** 3)
lai = whe... | [
"def",
"lai",
"(",
"self",
")",
":",
"ndvi",
"=",
"self",
".",
"ndvi",
"(",
")",
"lai",
"=",
"7.0",
"*",
"(",
"ndvi",
"**",
"3",
")",
"lai",
"=",
"where",
"(",
"lai",
">",
"6.",
",",
"6.",
",",
"lai",
")",
"return",
"lai"
] | Leaf area index (LAI), or the surface area of leaves to surface area ground.
Trezza and Allen, 2014
:param ndvi: normalized difference vegetation index [-]
:return: LAI [-] | [
"Leaf",
"area",
"index",
"(",
"LAI",
")",
"or",
"the",
"surface",
"area",
"of",
"leaves",
"to",
"surface",
"area",
"ground",
".",
"Trezza",
"and",
"Allen",
"2014",
":",
"param",
"ndvi",
":",
"normalized",
"difference",
"vegetation",
"index",
"[",
"-",
"]... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L338-L348 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat5.land_surface_temp | def land_surface_temp(self):
"""
Mean values from Allen (2007)
:return:
"""
rp = 0.91
tau = 0.866
rsky = 1.32
epsilon = self.emissivity(approach='tasumi')
radiance = self.radiance(6)
rc = ((radiance - rp) / tau) - ((1 - epsilon) * rsky)
... | python | def land_surface_temp(self):
"""
Mean values from Allen (2007)
:return:
"""
rp = 0.91
tau = 0.866
rsky = 1.32
epsilon = self.emissivity(approach='tasumi')
radiance = self.radiance(6)
rc = ((radiance - rp) / tau) - ((1 - epsilon) * rsky)
... | [
"def",
"land_surface_temp",
"(",
"self",
")",
":",
"rp",
"=",
"0.91",
"tau",
"=",
"0.866",
"rsky",
"=",
"1.32",
"epsilon",
"=",
"self",
".",
"emissivity",
"(",
"approach",
"=",
"'tasumi'",
")",
"radiance",
"=",
"self",
".",
"radiance",
"(",
"6",
")",
... | Mean values from Allen (2007)
:return: | [
"Mean",
"values",
"from",
"Allen",
"(",
"2007",
")",
":",
"return",
":"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L375-L387 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat8.brightness_temp | def brightness_temp(self, band, temp_scale='K'):
"""Calculate brightness temperature of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
T = K2 / log((K1 / L) + 1)
and
L = ML * Q + AL
where:
T = At-satellite brightness temperature (degrees kelvin)
... | python | def brightness_temp(self, band, temp_scale='K'):
"""Calculate brightness temperature of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
T = K2 / log((K1 / L) + 1)
and
L = ML * Q + AL
where:
T = At-satellite brightness temperature (degrees kelvin)
... | [
"def",
"brightness_temp",
"(",
"self",
",",
"band",
",",
"temp_scale",
"=",
"'K'",
")",
":",
"if",
"band",
"in",
"self",
".",
"oli_bands",
":",
"raise",
"ValueError",
"(",
"'Landsat 8 brightness should be TIRS band (i.e. 10 or 11)'",
")",
"k1",
"=",
"getattr",
"... | Calculate brightness temperature of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
T = K2 / log((K1 / L) + 1)
and
L = ML * Q + AL
where:
T = At-satellite brightness temperature (degrees kelvin)
L = TOA spectral radiance (Watts / (m2 * srad * mm)... | [
"Calculate",
"brightness",
"temperature",
"of",
"Landsat",
"8",
"as",
"outlined",
"here",
":",
"http",
":",
"//",
"landsat",
".",
"usgs",
".",
"gov",
"/",
"Landsat8_Using_Product",
".",
"php"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L560-L608 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat8.reflectance | def reflectance(self, band):
"""Calculate top of atmosphere reflectance of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
R_raw = MR * Q + AR
R = R_raw / cos(Z) = R_raw / sin(E)
Z = 90 - E (in degrees)
where:
... | python | def reflectance(self, band):
"""Calculate top of atmosphere reflectance of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
R_raw = MR * Q + AR
R = R_raw / cos(Z) = R_raw / sin(E)
Z = 90 - E (in degrees)
where:
... | [
"def",
"reflectance",
"(",
"self",
",",
"band",
")",
":",
"if",
"band",
"not",
"in",
"self",
".",
"oli_bands",
":",
"raise",
"ValueError",
"(",
"'Landsat 8 reflectance should OLI band (i.e. bands 1-8)'",
")",
"elev",
"=",
"getattr",
"(",
"self",
",",
"'sun_eleva... | Calculate top of atmosphere reflectance of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
R_raw = MR * Q + AR
R = R_raw / cos(Z) = R_raw / sin(E)
Z = 90 - E (in degrees)
where:
R_raw = TOA planetary reflectance,... | [
"Calculate",
"top",
"of",
"atmosphere",
"reflectance",
"of",
"Landsat",
"8",
"as",
"outlined",
"here",
":",
"http",
":",
"//",
"landsat",
".",
"usgs",
".",
"gov",
"/",
"Landsat8_Using_Product",
".",
"php",
"R_raw",
"=",
"MR",
"*",
"Q",
"+",
"AR",
"R",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L610-L655 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat8.radiance | def radiance(self, band):
"""Calculate top of atmosphere radiance of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
L = ML * Q + AL
where:
L = TOA spectral radiance (Watts / (m2 * srad * mm))
ML = Band-specific multiplica... | python | def radiance(self, band):
"""Calculate top of atmosphere radiance of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
L = ML * Q + AL
where:
L = TOA spectral radiance (Watts / (m2 * srad * mm))
ML = Band-specific multiplica... | [
"def",
"radiance",
"(",
"self",
",",
"band",
")",
":",
"ml",
"=",
"getattr",
"(",
"self",
",",
"'radiance_mult_band_{}'",
".",
"format",
"(",
"band",
")",
")",
"al",
"=",
"getattr",
"(",
"self",
",",
"'radiance_add_band_{}'",
".",
"format",
"(",
"band",
... | Calculate top of atmosphere radiance of Landsat 8
as outlined here: http://landsat.usgs.gov/Landsat8_Using_Product.php
L = ML * Q + AL
where:
L = TOA spectral radiance (Watts / (m2 * srad * mm))
ML = Band-specific multiplicative rescaling factor from the metada... | [
"Calculate",
"top",
"of",
"atmosphere",
"radiance",
"of",
"Landsat",
"8",
"as",
"outlined",
"here",
":",
"http",
":",
"//",
"landsat",
".",
"usgs",
".",
"gov",
"/",
"Landsat8_Using_Product",
".",
"php",
"L",
"=",
"ML",
"*",
"Q",
"+",
"AL",
"where",
":"... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L657-L682 | train |
dgketchum/satellite_image | sat_image/image.py | Landsat8.ndsi | def ndsi(self):
""" Normalized difference snow index.
:return: NDSI
"""
green, swir1 = self.reflectance(3), self.reflectance(6)
ndsi = self._divide_zero((green - swir1), (green + swir1), nan)
return ndsi | python | def ndsi(self):
""" Normalized difference snow index.
:return: NDSI
"""
green, swir1 = self.reflectance(3), self.reflectance(6)
ndsi = self._divide_zero((green - swir1), (green + swir1), nan)
return ndsi | [
"def",
"ndsi",
"(",
"self",
")",
":",
"green",
",",
"swir1",
"=",
"self",
".",
"reflectance",
"(",
"3",
")",
",",
"self",
".",
"reflectance",
"(",
"6",
")",
"ndsi",
"=",
"self",
".",
"_divide_zero",
"(",
"(",
"green",
"-",
"swir1",
")",
",",
"(",... | Normalized difference snow index.
:return: NDSI | [
"Normalized",
"difference",
"snow",
"index",
".",
":",
"return",
":",
"NDSI"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/image.py#L761-L768 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.whiteness_index | def whiteness_index(self):
"""Index of "Whiteness" based on visible bands.
Parameters
----------
Output
------
ndarray:
whiteness index
"""
mean_vis = (self.blue + self.green + self.red) / 3
blue_absdiff = np.absolute(self._divide_zer... | python | def whiteness_index(self):
"""Index of "Whiteness" based on visible bands.
Parameters
----------
Output
------
ndarray:
whiteness index
"""
mean_vis = (self.blue + self.green + self.red) / 3
blue_absdiff = np.absolute(self._divide_zer... | [
"def",
"whiteness_index",
"(",
"self",
")",
":",
"mean_vis",
"=",
"(",
"self",
".",
"blue",
"+",
"self",
".",
"green",
"+",
"self",
".",
"red",
")",
"/",
"3",
"blue_absdiff",
"=",
"np",
".",
"absolute",
"(",
"self",
".",
"_divide_zero",
"(",
"self",
... | Index of "Whiteness" based on visible bands.
Parameters
----------
Output
------
ndarray:
whiteness index | [
"Index",
"of",
"Whiteness",
"based",
"on",
"visible",
"bands",
".",
"Parameters",
"----------"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L119-L135 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.potential_cloud_pixels | def potential_cloud_pixels(self):
"""Determine potential cloud pixels (PCPs)
Combine basic spectral testsr to get a premliminary cloud mask
First pass, section 3.1.1 in Zhu and Woodcock 2012
Equation 6 (Zhu and Woodcock, 2012)
Parameters
----------
ndvi: ndarray
... | python | def potential_cloud_pixels(self):
"""Determine potential cloud pixels (PCPs)
Combine basic spectral testsr to get a premliminary cloud mask
First pass, section 3.1.1 in Zhu and Woodcock 2012
Equation 6 (Zhu and Woodcock, 2012)
Parameters
----------
ndvi: ndarray
... | [
"def",
"potential_cloud_pixels",
"(",
"self",
")",
":",
"eq1",
"=",
"self",
".",
"basic_test",
"(",
")",
"eq2",
"=",
"self",
".",
"whiteness_test",
"(",
")",
"eq3",
"=",
"self",
".",
"hot_test",
"(",
")",
"eq4",
"=",
"self",
".",
"nirswir_test",
"(",
... | Determine potential cloud pixels (PCPs)
Combine basic spectral testsr to get a premliminary cloud mask
First pass, section 3.1.1 in Zhu and Woodcock 2012
Equation 6 (Zhu and Woodcock, 2012)
Parameters
----------
ndvi: ndarray
ndsi: ndarray
blue: ndarray
... | [
"Determine",
"potential",
"cloud",
"pixels",
"(",
"PCPs",
")",
"Combine",
"basic",
"spectral",
"testsr",
"to",
"get",
"a",
"premliminary",
"cloud",
"mask",
"First",
"pass",
"section",
"3",
".",
"1",
".",
"1",
"in",
"Zhu",
"and",
"Woodcock",
"2012",
"Equati... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L224-L254 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.temp_water | def temp_water(self):
"""Use water to mask tirs and find 82.5 pctile
Equation 7 and 8 (Zhu and Woodcock, 2012)
Parameters
----------
is_water: ndarray, boolean
water mask, water is True, land is False
swir2: ndarray
tirs1: ndarray
Output
... | python | def temp_water(self):
"""Use water to mask tirs and find 82.5 pctile
Equation 7 and 8 (Zhu and Woodcock, 2012)
Parameters
----------
is_water: ndarray, boolean
water mask, water is True, land is False
swir2: ndarray
tirs1: ndarray
Output
... | [
"def",
"temp_water",
"(",
"self",
")",
":",
"# eq7",
"th_swir2",
"=",
"0.03",
"water",
"=",
"self",
".",
"water_test",
"(",
")",
"clear_sky_water",
"=",
"water",
"&",
"(",
"self",
".",
"swir2",
"<",
"th_swir2",
")",
"# eq8",
"clear_water_temp",
"=",
"sel... | Use water to mask tirs and find 82.5 pctile
Equation 7 and 8 (Zhu and Woodcock, 2012)
Parameters
----------
is_water: ndarray, boolean
water mask, water is True, land is False
swir2: ndarray
tirs1: ndarray
Output
------
float:
... | [
"Use",
"water",
"to",
"mask",
"tirs",
"and",
"find",
"82",
".",
"5",
"pctile",
"Equation",
"7",
"and",
"8",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"is_water",
":",
"ndarray",
"boolean",
"water",
"mask",
"water",
"is",
"Tr... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L256-L280 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.water_temp_prob | def water_temp_prob(self):
"""Temperature probability for water
Equation 9 (Zhu and Woodcock, 2012)
Parameters
----------
water_temp: float
82.5th percentile temperature over water
swir2: ndarray
tirs1: ndarray
Output
------
nda... | python | def water_temp_prob(self):
"""Temperature probability for water
Equation 9 (Zhu and Woodcock, 2012)
Parameters
----------
water_temp: float
82.5th percentile temperature over water
swir2: ndarray
tirs1: ndarray
Output
------
nda... | [
"def",
"water_temp_prob",
"(",
"self",
")",
":",
"temp_const",
"=",
"4.0",
"# degrees C",
"water_temp",
"=",
"self",
".",
"temp_water",
"(",
")",
"return",
"(",
"water_temp",
"-",
"self",
".",
"tirs1",
")",
"/",
"temp_const"
] | Temperature probability for water
Equation 9 (Zhu and Woodcock, 2012)
Parameters
----------
water_temp: float
82.5th percentile temperature over water
swir2: ndarray
tirs1: ndarray
Output
------
ndarray:
probability of cloud... | [
"Temperature",
"probability",
"for",
"water",
"Equation",
"9",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"water_temp",
":",
"float",
"82",
".",
"5th",
"percentile",
"temperature",
"over",
"water",
"swir2",
":",
"ndarray",
"tirs1",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L282-L298 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.brightness_prob | def brightness_prob(self, clip=True):
"""The brightest water may have Band 5 reflectance
as high as LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.TIF.11
Equation 10 (Zhu and Woodcock, 2012)
Parameters
----------
nir: ndarray
clip: boolean
Output
... | python | def brightness_prob(self, clip=True):
"""The brightest water may have Band 5 reflectance
as high as LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.TIF.11
Equation 10 (Zhu and Woodcock, 2012)
Parameters
----------
nir: ndarray
clip: boolean
Output
... | [
"def",
"brightness_prob",
"(",
"self",
",",
"clip",
"=",
"True",
")",
":",
"thresh",
"=",
"0.11",
"bp",
"=",
"np",
".",
"minimum",
"(",
"thresh",
",",
"self",
".",
"nir",
")",
"/",
"thresh",
"if",
"clip",
":",
"bp",
"[",
"bp",
">",
"1",
"]",
"=... | The brightest water may have Band 5 reflectance
as high as LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.TIF.11
Equation 10 (Zhu and Woodcock, 2012)
Parameters
----------
nir: ndarray
clip: boolean
Output
------
ndarray:
brightness p... | [
"The",
"brightest",
"water",
"may",
"have",
"Band",
"5",
"reflectance",
"as",
"high",
"as",
"LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1",
".",
"TIF",
".",
"11",
"Equation",
"10",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"nir",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L300-L318 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.temp_land | def temp_land(self, pcps, water):
"""Derive high/low percentiles of land temperature
Equations 12 an 13 (Zhu and Woodcock, 2012)
Parameters
----------
pcps: ndarray
potential cloud pixels, boolean
water: ndarray
water mask, boolean
tirs1: n... | python | def temp_land(self, pcps, water):
"""Derive high/low percentiles of land temperature
Equations 12 an 13 (Zhu and Woodcock, 2012)
Parameters
----------
pcps: ndarray
potential cloud pixels, boolean
water: ndarray
water mask, boolean
tirs1: n... | [
"def",
"temp_land",
"(",
"self",
",",
"pcps",
",",
"water",
")",
":",
"# eq 12",
"clearsky_land",
"=",
"~",
"(",
"pcps",
"|",
"water",
")",
"# use clearsky_land to mask tirs1",
"clear_land_temp",
"=",
"self",
".",
"tirs1",
".",
"copy",
"(",
")",
"clear_land_... | Derive high/low percentiles of land temperature
Equations 12 an 13 (Zhu and Woodcock, 2012)
Parameters
----------
pcps: ndarray
potential cloud pixels, boolean
water: ndarray
water mask, boolean
tirs1: ndarray
Output
------
... | [
"Derive",
"high",
"/",
"low",
"percentiles",
"of",
"land",
"temperature",
"Equations",
"12",
"an",
"13",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"pcps",
":",
"ndarray",
"potential",
"cloud",
"pixels",
"boolean",
"water",
":",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L320-L345 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.land_temp_prob | def land_temp_prob(self, tlow, thigh):
"""Temperature-based probability of cloud over land
Equation 14 (Zhu and Woodcock, 2012)
Parameters
----------
tirs1: ndarray
tlow: float
Low (17.5 percentile) temperature of land
thigh: float
High (82... | python | def land_temp_prob(self, tlow, thigh):
"""Temperature-based probability of cloud over land
Equation 14 (Zhu and Woodcock, 2012)
Parameters
----------
tirs1: ndarray
tlow: float
Low (17.5 percentile) temperature of land
thigh: float
High (82... | [
"def",
"land_temp_prob",
"(",
"self",
",",
"tlow",
",",
"thigh",
")",
":",
"temp_diff",
"=",
"4",
"# degrees",
"return",
"(",
"thigh",
"+",
"temp_diff",
"-",
"self",
".",
"tirs1",
")",
"/",
"(",
"thigh",
"+",
"4",
"-",
"(",
"tlow",
"-",
"4",
")",
... | Temperature-based probability of cloud over land
Equation 14 (Zhu and Woodcock, 2012)
Parameters
----------
tirs1: ndarray
tlow: float
Low (17.5 percentile) temperature of land
thigh: float
High (82.5 percentile) temperature of land
Output
... | [
"Temperature",
"-",
"based",
"probability",
"of",
"cloud",
"over",
"land",
"Equation",
"14",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"tirs1",
":",
"ndarray",
"tlow",
":",
"float",
"Low",
"(",
"17",
".",
"5",
"percentile",
")... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L347-L363 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.variability_prob | def variability_prob(self, whiteness):
"""Use the probability of the spectral variability
to identify clouds over land.
Equation 15 (Zhu and Woodcock, 2012)
Parameters
----------
ndvi: ndarray
ndsi: ndarray
whiteness: ndarray
Output
------
... | python | def variability_prob(self, whiteness):
"""Use the probability of the spectral variability
to identify clouds over land.
Equation 15 (Zhu and Woodcock, 2012)
Parameters
----------
ndvi: ndarray
ndsi: ndarray
whiteness: ndarray
Output
------
... | [
"def",
"variability_prob",
"(",
"self",
",",
"whiteness",
")",
":",
"if",
"self",
".",
"sat",
"in",
"[",
"'LT5'",
",",
"'LE7'",
"]",
":",
"# check for green and red saturation",
"# if red is saturated and less than nir, ndvi = LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.... | Use the probability of the spectral variability
to identify clouds over land.
Equation 15 (Zhu and Woodcock, 2012)
Parameters
----------
ndvi: ndarray
ndsi: ndarray
whiteness: ndarray
Output
------
ndarray :
probability of cloud... | [
"Use",
"the",
"probability",
"of",
"the",
"spectral",
"variability",
"to",
"identify",
"clouds",
"over",
"land",
".",
"Equation",
"15",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"ndvi",
":",
"ndarray",
"ndsi",
":",
"ndarray",
"w... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L365-L395 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.land_threshold | def land_threshold(self, land_cloud_prob, pcps, water):
"""Dynamic threshold for determining cloud cutoff
Equation 17 (Zhu and Woodcock, 2012)
Parameters
----------
land_cloud_prob: ndarray
probability of cloud over land
pcps: ndarray
potential clo... | python | def land_threshold(self, land_cloud_prob, pcps, water):
"""Dynamic threshold for determining cloud cutoff
Equation 17 (Zhu and Woodcock, 2012)
Parameters
----------
land_cloud_prob: ndarray
probability of cloud over land
pcps: ndarray
potential clo... | [
"def",
"land_threshold",
"(",
"self",
",",
"land_cloud_prob",
",",
"pcps",
",",
"water",
")",
":",
"# eq 12",
"clearsky_land",
"=",
"~",
"(",
"pcps",
"|",
"water",
")",
"# 82.5th percentile of lCloud_Prob(masked by clearsky_land) + LE07_clip_L1TP_039027_20150529_20160902_01... | Dynamic threshold for determining cloud cutoff
Equation 17 (Zhu and Woodcock, 2012)
Parameters
----------
land_cloud_prob: ndarray
probability of cloud over land
pcps: ndarray
potential cloud pixels
water: ndarray
water mask
Out... | [
"Dynamic",
"threshold",
"for",
"determining",
"cloud",
"cutoff",
"Equation",
"17",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Parameters",
"----------",
"land_cloud_prob",
":",
"ndarray",
"probability",
"of",
"cloud",
"over",
"land",
"pcps",
":",
"ndarray",
"p... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L397-L423 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.potential_cloud_layer | def potential_cloud_layer(self, pcp, water, tlow, land_cloud_prob, land_threshold,
water_cloud_prob, water_threshold=0.5):
"""Final step of determining potential cloud layer
Equation 18 (Zhu and Woodcock, 2012)
Saturation (green or red) test is not in the algorithm
... | python | def potential_cloud_layer(self, pcp, water, tlow, land_cloud_prob, land_threshold,
water_cloud_prob, water_threshold=0.5):
"""Final step of determining potential cloud layer
Equation 18 (Zhu and Woodcock, 2012)
Saturation (green or red) test is not in the algorithm
... | [
"def",
"potential_cloud_layer",
"(",
"self",
",",
"pcp",
",",
"water",
",",
"tlow",
",",
"land_cloud_prob",
",",
"land_threshold",
",",
"water_cloud_prob",
",",
"water_threshold",
"=",
"0.5",
")",
":",
"# Using pcp and water as mask todo",
"# change water threshold to d... | Final step of determining potential cloud layer
Equation 18 (Zhu and Woodcock, 2012)
Saturation (green or red) test is not in the algorithm
Parameters
----------
pcps: ndarray
potential cloud pixels
water: ndarray
water mask
... | [
"Final",
"step",
"of",
"determining",
"potential",
"cloud",
"layer",
"Equation",
"18",
"(",
"Zhu",
"and",
"Woodcock",
"2012",
")",
"Saturation",
"(",
"green",
"or",
"red",
")",
"test",
"is",
"not",
"in",
"the",
"algorithm",
"Parameters",
"----------",
"pcps"... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L425-L466 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.potential_snow_layer | def potential_snow_layer(self):
"""Spectral test to determine potential snow
Uses the 9.85C (283K) threshold defined in Zhu, Woodcock 2015
Parameters
----------
ndsi: ndarray
green: ndarray
nir: ndarray
tirs1: ndarray
Output
------
... | python | def potential_snow_layer(self):
"""Spectral test to determine potential snow
Uses the 9.85C (283K) threshold defined in Zhu, Woodcock 2015
Parameters
----------
ndsi: ndarray
green: ndarray
nir: ndarray
tirs1: ndarray
Output
------
... | [
"def",
"potential_snow_layer",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"ndsi",
">",
"0.15",
")",
"&",
"(",
"self",
".",
"tirs1",
"<",
"9.85",
")",
"&",
"(",
"self",
".",
"nir",
">",
"0.11",
")",
"&",
"(",
"self",
".",
"green",
">",
"... | Spectral test to determine potential snow
Uses the 9.85C (283K) threshold defined in Zhu, Woodcock 2015
Parameters
----------
ndsi: ndarray
green: ndarray
nir: ndarray
tirs1: ndarray
Output
------
ndarray:
boolean, True is poten... | [
"Spectral",
"test",
"to",
"determine",
"potential",
"snow",
"Uses",
"the",
"9",
".",
"85C",
"(",
"283K",
")",
"threshold",
"defined",
"in",
"Zhu",
"Woodcock",
"2015",
"Parameters",
"----------",
"ndsi",
":",
"ndarray",
"green",
":",
"ndarray",
"nir",
":",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L484-L498 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.cloud_mask | def cloud_mask(self, min_filter=(3, 3), max_filter=(10, 10), combined=False, cloud_and_shadow=False):
"""Calculate the potential cloud layer from source data
*This is the high level function which ties together all
the equations for generating potential clouds*
Parameters
-------... | python | def cloud_mask(self, min_filter=(3, 3), max_filter=(10, 10), combined=False, cloud_and_shadow=False):
"""Calculate the potential cloud layer from source data
*This is the high level function which ties together all
the equations for generating potential clouds*
Parameters
-------... | [
"def",
"cloud_mask",
"(",
"self",
",",
"min_filter",
"=",
"(",
"3",
",",
"3",
")",
",",
"max_filter",
"=",
"(",
"10",
",",
"10",
")",
",",
"combined",
"=",
"False",
",",
"cloud_and_shadow",
"=",
"False",
")",
":",
"# logger.info(\"Running initial testsr\")... | Calculate the potential cloud layer from source data
*This is the high level function which ties together all
the equations for generating potential clouds*
Parameters
----------
blue: ndarray
green: ndarray
red: ndarray
nir: ndarray
swir1: ndarray... | [
"Calculate",
"the",
"potential",
"cloud",
"layer",
"from",
"source",
"data",
"*",
"This",
"is",
"the",
"high",
"level",
"function",
"which",
"ties",
"together",
"all",
"the",
"equations",
"for",
"generating",
"potential",
"clouds",
"*",
"Parameters",
"----------... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L500-L612 | train |
dgketchum/satellite_image | sat_image/fmask.py | Fmask.gdal_nodata_mask | def gdal_nodata_mask(pcl, pcsl, tirs_arr):
"""
Given a boolean potential cloud layer,
a potential cloud shadow layer and a thermal band
Calculate the GDAL-style uint8 mask
"""
tirs_mask = np.isnan(tirs_arr) | (tirs_arr == 0)
return ((~(pcl | pcsl | tirs_mask)) * 2... | python | def gdal_nodata_mask(pcl, pcsl, tirs_arr):
"""
Given a boolean potential cloud layer,
a potential cloud shadow layer and a thermal band
Calculate the GDAL-style uint8 mask
"""
tirs_mask = np.isnan(tirs_arr) | (tirs_arr == 0)
return ((~(pcl | pcsl | tirs_mask)) * 2... | [
"def",
"gdal_nodata_mask",
"(",
"pcl",
",",
"pcsl",
",",
"tirs_arr",
")",
":",
"tirs_mask",
"=",
"np",
".",
"isnan",
"(",
"tirs_arr",
")",
"|",
"(",
"tirs_arr",
"==",
"0",
")",
"return",
"(",
"(",
"~",
"(",
"pcl",
"|",
"pcsl",
"|",
"tirs_mask",
")"... | Given a boolean potential cloud layer,
a potential cloud shadow layer and a thermal band
Calculate the GDAL-style uint8 mask | [
"Given",
"a",
"boolean",
"potential",
"cloud",
"layer",
"a",
"potential",
"cloud",
"shadow",
"layer",
"and",
"a",
"thermal",
"band",
"Calculate",
"the",
"GDAL",
"-",
"style",
"uint8",
"mask"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/fmask.py#L634-L641 | train |
dgketchum/satellite_image | sat_image/mtl.py | parsemeta | def parsemeta(metadataloc):
"""Parses the metadata from a Landsat image bundle.
Arguments:
metadataloc: a filename or a directory.
Returns metadata dictionary
"""
# filename or directory? if several fit, use first one and warn
if os.path.isdir(metadataloc):
me... | python | def parsemeta(metadataloc):
"""Parses the metadata from a Landsat image bundle.
Arguments:
metadataloc: a filename or a directory.
Returns metadata dictionary
"""
# filename or directory? if several fit, use first one and warn
if os.path.isdir(metadataloc):
me... | [
"def",
"parsemeta",
"(",
"metadataloc",
")",
":",
"# filename or directory? if several fit, use first one and warn",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"metadataloc",
")",
":",
"metalist",
"=",
"glob",
".",
"glob",
"(",
"os",
".",
"path",
".",
"join",
... | Parses the metadata from a Landsat image bundle.
Arguments:
metadataloc: a filename or a directory.
Returns metadata dictionary | [
"Parses",
"the",
"metadata",
"from",
"a",
"Landsat",
"image",
"bundle",
".",
"Arguments",
":",
"metadataloc",
":",
"a",
"filename",
"or",
"a",
"directory",
".",
"Returns",
"metadata",
"dictionary"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/mtl.py#L60-L112 | train |
dgketchum/satellite_image | sat_image/mtl.py | _checkstatus | def _checkstatus(status, line):
"""Returns state/status after reading the next line.
The status codes are::
LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.TIF - BEGIN parsing; 1 - ENTER METADATA GROUP, 2 - READ METADATA LINE,
3 - END METDADATA GROUP, 4 - END PARSING
Permitted Transitions::... | python | def _checkstatus(status, line):
"""Returns state/status after reading the next line.
The status codes are::
LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.TIF - BEGIN parsing; 1 - ENTER METADATA GROUP, 2 - READ METADATA LINE,
3 - END METDADATA GROUP, 4 - END PARSING
Permitted Transitions::... | [
"def",
"_checkstatus",
"(",
"status",
",",
"line",
")",
":",
"newstatus",
"=",
"0",
"if",
"status",
"==",
"0",
":",
"# begin --> enter metadata group OR end",
"if",
"_islinetype",
"(",
"line",
",",
"GRPSTART",
")",
":",
"newstatus",
"=",
"1",
"elif",
"_isfin... | Returns state/status after reading the next line.
The status codes are::
LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1.TIF - BEGIN parsing; 1 - ENTER METADATA GROUP, 2 - READ METADATA LINE,
3 - END METDADATA GROUP, 4 - END PARSING
Permitted Transitions::
LE07_clip_L1TP_039027_20150529... | [
"Returns",
"state",
"/",
"status",
"after",
"reading",
"the",
"next",
"line",
".",
"The",
"status",
"codes",
"are",
"::",
"LE07_clip_L1TP_039027_20150529_20160902_01_T1_B1",
".",
"TIF",
"-",
"BEGIN",
"parsing",
";",
"1",
"-",
"ENTER",
"METADATA",
"GROUP",
"2",
... | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/mtl.py#L148-L194 | train |
dgketchum/satellite_image | sat_image/mtl.py | _transstat | def _transstat(status, grouppath, dictpath, line):
"""Executes processing steps when reading a line"""
if status == 0:
raise MTLParseError(
"Status should not be '%s' after reading line:\n%s"
% (STATUSCODE[status], line))
elif status == 1:
currentdict = dictpath[-1]
... | python | def _transstat(status, grouppath, dictpath, line):
"""Executes processing steps when reading a line"""
if status == 0:
raise MTLParseError(
"Status should not be '%s' after reading line:\n%s"
% (STATUSCODE[status], line))
elif status == 1:
currentdict = dictpath[-1]
... | [
"def",
"_transstat",
"(",
"status",
",",
"grouppath",
",",
"dictpath",
",",
"line",
")",
":",
"if",
"status",
"==",
"0",
":",
"raise",
"MTLParseError",
"(",
"\"Status should not be '%s' after reading line:\\n%s\"",
"%",
"(",
"STATUSCODE",
"[",
"status",
"]",
","... | Executes processing steps when reading a line | [
"Executes",
"processing",
"steps",
"when",
"reading",
"a",
"line"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/mtl.py#L198-L238 | train |
dgketchum/satellite_image | sat_image/mtl.py | _postprocess | def _postprocess(valuestr):
"""
Takes value as str, returns str, int, float, date, datetime, or time
"""
# USGS has started quoting time sometimes. Grr, strip quotes in this case
intpattern = re.compile(r'^\-?\d+$')
floatpattern = re.compile(r'^\-?\d+\.\d+(E[+-]?\d\d+)?$')
datedtpattern = '... | python | def _postprocess(valuestr):
"""
Takes value as str, returns str, int, float, date, datetime, or time
"""
# USGS has started quoting time sometimes. Grr, strip quotes in this case
intpattern = re.compile(r'^\-?\d+$')
floatpattern = re.compile(r'^\-?\d+\.\d+(E[+-]?\d\d+)?$')
datedtpattern = '... | [
"def",
"_postprocess",
"(",
"valuestr",
")",
":",
"# USGS has started quoting time sometimes. Grr, strip quotes in this case",
"intpattern",
"=",
"re",
".",
"compile",
"(",
"r'^\\-?\\d+$'",
")",
"floatpattern",
"=",
"re",
".",
"compile",
"(",
"r'^\\-?\\d+\\.\\d+(E[+-]?\\d\... | Takes value as str, returns str, int, float, date, datetime, or time | [
"Takes",
"value",
"as",
"str",
"returns",
"str",
"int",
"float",
"date",
"datetime",
"or",
"time"
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/mtl.py#L242-L285 | train |
dgketchum/satellite_image | sat_image/warped_vrt.py | warp_vrt | def warp_vrt(directory, delete_extra=False, use_band_map=False,
overwrite=False, remove_bqa=True, return_profile=False):
""" Read in image geometry, resample subsequent images to same grid.
The purpose of this function is to snap many Landsat images to one geometry. Use Landsat578
to download ... | python | def warp_vrt(directory, delete_extra=False, use_band_map=False,
overwrite=False, remove_bqa=True, return_profile=False):
""" Read in image geometry, resample subsequent images to same grid.
The purpose of this function is to snap many Landsat images to one geometry. Use Landsat578
to download ... | [
"def",
"warp_vrt",
"(",
"directory",
",",
"delete_extra",
"=",
"False",
",",
"use_band_map",
"=",
"False",
",",
"overwrite",
"=",
"False",
",",
"remove_bqa",
"=",
"True",
",",
"return_profile",
"=",
"False",
")",
":",
"if",
"'resample_meta.txt'",
"in",
"os",... | Read in image geometry, resample subsequent images to same grid.
The purpose of this function is to snap many Landsat images to one geometry. Use Landsat578
to download and unzip them, then run them through this to get identical geometries for analysis.
Files
:param use_band_map:
:param delete_extr... | [
"Read",
"in",
"image",
"geometry",
"resample",
"subsequent",
"images",
"to",
"same",
"grid",
"."
] | 0207fbb7b2bbf14f4307db65489bb4d4c5b92f52 | https://github.com/dgketchum/satellite_image/blob/0207fbb7b2bbf14f4307db65489bb4d4c5b92f52/sat_image/warped_vrt.py#L30-L121 | train |
samstav/tox-pyenv | tox_pyenv.py | tox_get_python_executable | def tox_get_python_executable(envconfig):
"""Return a python executable for the given python base name.
The first plugin/hook which returns an executable path will determine it.
``envconfig`` is the testenv configuration which contains
per-testenv configuration, notably the ``.envname`` and ``.basepyt... | python | def tox_get_python_executable(envconfig):
"""Return a python executable for the given python base name.
The first plugin/hook which returns an executable path will determine it.
``envconfig`` is the testenv configuration which contains
per-testenv configuration, notably the ``.envname`` and ``.basepyt... | [
"def",
"tox_get_python_executable",
"(",
"envconfig",
")",
":",
"try",
":",
"# pylint: disable=no-member",
"pyenv",
"=",
"(",
"getattr",
"(",
"py",
".",
"path",
".",
"local",
".",
"sysfind",
"(",
"'pyenv'",
")",
",",
"'strpath'",
",",
"'pyenv'",
")",
"or",
... | Return a python executable for the given python base name.
The first plugin/hook which returns an executable path will determine it.
``envconfig`` is the testenv configuration which contains
per-testenv configuration, notably the ``.envname`` and ``.basepython``
setting. | [
"Return",
"a",
"python",
"executable",
"for",
"the",
"given",
"python",
"base",
"name",
"."
] | 7391610c2c4f1c95abde2e8638763b1b24e604cd | https://github.com/samstav/tox-pyenv/blob/7391610c2c4f1c95abde2e8638763b1b24e604cd/tox_pyenv.py#L69-L106 | train |
samstav/tox-pyenv | tox_pyenv.py | _setup_no_fallback | def _setup_no_fallback(parser):
"""Add the option, --tox-pyenv-no-fallback.
If this option is set, do not allow fallback to tox's built-in
strategy for looking up python executables if the call to `pyenv which`
by this plugin fails. This will allow the error to raise instead
of falling back to tox'... | python | def _setup_no_fallback(parser):
"""Add the option, --tox-pyenv-no-fallback.
If this option is set, do not allow fallback to tox's built-in
strategy for looking up python executables if the call to `pyenv which`
by this plugin fails. This will allow the error to raise instead
of falling back to tox'... | [
"def",
"_setup_no_fallback",
"(",
"parser",
")",
":",
"cli_dest",
"=",
"'tox_pyenv_fallback'",
"halp",
"=",
"(",
"'If `pyenv which {basepython}` exits non-zero when looking '",
"'up the python executable, do not allow fallback to tox\\'s '",
"'built-in default logic.'",
")",
"# Add a... | Add the option, --tox-pyenv-no-fallback.
If this option is set, do not allow fallback to tox's built-in
strategy for looking up python executables if the call to `pyenv which`
by this plugin fails. This will allow the error to raise instead
of falling back to tox's default behavior. | [
"Add",
"the",
"option",
"--",
"tox",
"-",
"pyenv",
"-",
"no",
"-",
"fallback",
"."
] | 7391610c2c4f1c95abde2e8638763b1b24e604cd | https://github.com/samstav/tox-pyenv/blob/7391610c2c4f1c95abde2e8638763b1b24e604cd/tox_pyenv.py#L109-L147 | train |
alanjcastonguay/pyforce | src/pyforce/xmlclient.py | Client.sendEmail | def sendEmail(self, emails, massType='SingleEmailMessage'):
"""
Send one or more emails from Salesforce.
Parameters:
emails - a dictionary or list of dictionaries, each representing a
single email as described by https://www.salesforce.com/us
... | python | def sendEmail(self, emails, massType='SingleEmailMessage'):
"""
Send one or more emails from Salesforce.
Parameters:
emails - a dictionary or list of dictionaries, each representing a
single email as described by https://www.salesforce.com/us
... | [
"def",
"sendEmail",
"(",
"self",
",",
"emails",
",",
"massType",
"=",
"'SingleEmailMessage'",
")",
":",
"return",
"SendEmailRequest",
"(",
"self",
".",
"__serverUrl",
",",
"self",
".",
"sessionId",
",",
"emails",
",",
"massType",
")",
".",
"post",
"(",
"se... | Send one or more emails from Salesforce.
Parameters:
emails - a dictionary or list of dictionaries, each representing a
single email as described by https://www.salesforce.com/us
/developer/docs/api/Content/sforce_api_calls_sendemail.htm
massTyp... | [
"Send",
"one",
"or",
"more",
"emails",
"from",
"Salesforce",
"."
] | d69a73c62725f411aa7c7588f3b231249935c068 | https://github.com/alanjcastonguay/pyforce/blob/d69a73c62725f411aa7c7588f3b231249935c068/src/pyforce/xmlclient.py#L233-L254 | train |
alanjcastonguay/pyforce | src/pyforce/xmltramp.py | quote | def quote(myitem, elt=True):
'''URL encode string'''
if elt and '<' in myitem and len(myitem) > 24 and myitem.find(']]>') == -1:
return '<![CDATA[%s]]>' % (myitem)
else:
myitem = myitem.replace('&', '&').\
replace('<', '<').replace(']]>', ']]>')
if not elt:
... | python | def quote(myitem, elt=True):
'''URL encode string'''
if elt and '<' in myitem and len(myitem) > 24 and myitem.find(']]>') == -1:
return '<![CDATA[%s]]>' % (myitem)
else:
myitem = myitem.replace('&', '&').\
replace('<', '<').replace(']]>', ']]>')
if not elt:
... | [
"def",
"quote",
"(",
"myitem",
",",
"elt",
"=",
"True",
")",
":",
"if",
"elt",
"and",
"'<'",
"in",
"myitem",
"and",
"len",
"(",
"myitem",
")",
">",
"24",
"and",
"myitem",
".",
"find",
"(",
"']]>'",
")",
"==",
"-",
"1",
":",
"return",
"'<![CDATA[%... | URL encode string | [
"URL",
"encode",
"string"
] | d69a73c62725f411aa7c7588f3b231249935c068 | https://github.com/alanjcastonguay/pyforce/blob/d69a73c62725f411aa7c7588f3b231249935c068/src/pyforce/xmltramp.py#L37-L46 | train |
alanjcastonguay/pyforce | src/pyforce/pyforce.py | _doPrep | def _doPrep(field_dict):
"""
_doPrep is makes changes in-place.
Do some prep work converting python types into formats that
Salesforce will accept.
This includes converting lists of strings to "apple;orange;pear".
Dicts will be converted to embedded objects
None or empty list values will be ... | python | def _doPrep(field_dict):
"""
_doPrep is makes changes in-place.
Do some prep work converting python types into formats that
Salesforce will accept.
This includes converting lists of strings to "apple;orange;pear".
Dicts will be converted to embedded objects
None or empty list values will be ... | [
"def",
"_doPrep",
"(",
"field_dict",
")",
":",
"fieldsToNull",
"=",
"[",
"]",
"for",
"key",
",",
"value",
"in",
"field_dict",
".",
"items",
"(",
")",
":",
"if",
"value",
"is",
"None",
":",
"fieldsToNull",
".",
"append",
"(",
"key",
")",
"field_dict",
... | _doPrep is makes changes in-place.
Do some prep work converting python types into formats that
Salesforce will accept.
This includes converting lists of strings to "apple;orange;pear".
Dicts will be converted to embedded objects
None or empty list values will be Null-ed | [
"_doPrep",
"is",
"makes",
"changes",
"in",
"-",
"place",
".",
"Do",
"some",
"prep",
"work",
"converting",
"python",
"types",
"into",
"formats",
"that",
"Salesforce",
"will",
"accept",
".",
"This",
"includes",
"converting",
"lists",
"of",
"strings",
"to",
"ap... | d69a73c62725f411aa7c7588f3b231249935c068 | https://github.com/alanjcastonguay/pyforce/blob/d69a73c62725f411aa7c7588f3b231249935c068/src/pyforce/pyforce.py#L528-L555 | train |
alanjcastonguay/pyforce | src/pyforce/pyforce.py | _prepareSObjects | def _prepareSObjects(sObjects):
'''Prepare a SObject'''
sObjectsCopy = copy.deepcopy(sObjects)
if isinstance(sObjectsCopy, dict):
# If root element is a dict, then this is a single object not an array
_doPrep(sObjectsCopy)
else:
# else this is an array, and each elelment should b... | python | def _prepareSObjects(sObjects):
'''Prepare a SObject'''
sObjectsCopy = copy.deepcopy(sObjects)
if isinstance(sObjectsCopy, dict):
# If root element is a dict, then this is a single object not an array
_doPrep(sObjectsCopy)
else:
# else this is an array, and each elelment should b... | [
"def",
"_prepareSObjects",
"(",
"sObjects",
")",
":",
"sObjectsCopy",
"=",
"copy",
".",
"deepcopy",
"(",
"sObjects",
")",
"if",
"isinstance",
"(",
"sObjectsCopy",
",",
"dict",
")",
":",
"# If root element is a dict, then this is a single object not an array",
"_doPrep",... | Prepare a SObject | [
"Prepare",
"a",
"SObject"
] | d69a73c62725f411aa7c7588f3b231249935c068 | https://github.com/alanjcastonguay/pyforce/blob/d69a73c62725f411aa7c7588f3b231249935c068/src/pyforce/pyforce.py#L562-L572 | train |
alanjcastonguay/pyforce | src/pyforce/pyforce.py | Client.sendEmail | def sendEmail(self, emails, mass_type='SingleEmailMessage'):
"""
Send one or more emails from Salesforce.
Parameters:
emails - a dictionary or list of dictionaries, each representing
a single email as described by https://www.salesforce.com
... | python | def sendEmail(self, emails, mass_type='SingleEmailMessage'):
"""
Send one or more emails from Salesforce.
Parameters:
emails - a dictionary or list of dictionaries, each representing
a single email as described by https://www.salesforce.com
... | [
"def",
"sendEmail",
"(",
"self",
",",
"emails",
",",
"mass_type",
"=",
"'SingleEmailMessage'",
")",
":",
"preparedEmails",
"=",
"_prepareSObjects",
"(",
"emails",
")",
"if",
"isinstance",
"(",
"preparedEmails",
",",
"dict",
")",
":",
"# If root element is a dict, ... | Send one or more emails from Salesforce.
Parameters:
emails - a dictionary or list of dictionaries, each representing
a single email as described by https://www.salesforce.com
/us/developer/docs/api/Content/sforce_api_calls_sendemail
.h... | [
"Send",
"one",
"or",
"more",
"emails",
"from",
"Salesforce",
"."
] | d69a73c62725f411aa7c7588f3b231249935c068 | https://github.com/alanjcastonguay/pyforce/blob/d69a73c62725f411aa7c7588f3b231249935c068/src/pyforce/pyforce.py#L238-L278 | train |
alanjcastonguay/pyforce | src/pyforce/pyforce.py | Client.queryTypesDescriptions | def queryTypesDescriptions(self, types):
"""
Given a list of types, construct a dictionary such that
each key is a type, and each value is the corresponding sObject
for that type.
"""
types = list(types)
if types:
types_descs = self.describeSObjects(ty... | python | def queryTypesDescriptions(self, types):
"""
Given a list of types, construct a dictionary such that
each key is a type, and each value is the corresponding sObject
for that type.
"""
types = list(types)
if types:
types_descs = self.describeSObjects(ty... | [
"def",
"queryTypesDescriptions",
"(",
"self",
",",
"types",
")",
":",
"types",
"=",
"list",
"(",
"types",
")",
"if",
"types",
":",
"types_descs",
"=",
"self",
".",
"describeSObjects",
"(",
"types",
")",
"else",
":",
"types_descs",
"=",
"[",
"]",
"return"... | Given a list of types, construct a dictionary such that
each key is a type, and each value is the corresponding sObject
for that type. | [
"Given",
"a",
"list",
"of",
"types",
"construct",
"a",
"dictionary",
"such",
"that",
"each",
"key",
"is",
"a",
"type",
"and",
"each",
"value",
"is",
"the",
"corresponding",
"sObject",
"for",
"that",
"type",
"."
] | d69a73c62725f411aa7c7588f3b231249935c068 | https://github.com/alanjcastonguay/pyforce/blob/d69a73c62725f411aa7c7588f3b231249935c068/src/pyforce/pyforce.py#L316-L327 | train |
miguelgrinberg/flask-paranoid | flask_paranoid/paranoid.py | Paranoid.create_token | def create_token(self):
"""Create a session protection token for this client.
This method generates a session protection token for the cilent, which
consists in a hash of the user agent and the IP address. This method
can be overriden by subclasses to implement different token generatio... | python | def create_token(self):
"""Create a session protection token for this client.
This method generates a session protection token for the cilent, which
consists in a hash of the user agent and the IP address. This method
can be overriden by subclasses to implement different token generatio... | [
"def",
"create_token",
"(",
"self",
")",
":",
"user_agent",
"=",
"request",
".",
"headers",
".",
"get",
"(",
"'User-Agent'",
")",
"if",
"user_agent",
"is",
"None",
":",
"# pragma: no cover",
"user_agent",
"=",
"'no user agent'",
"user_agent",
"=",
"user_agent",
... | Create a session protection token for this client.
This method generates a session protection token for the cilent, which
consists in a hash of the user agent and the IP address. This method
can be overriden by subclasses to implement different token generation
algorithms. | [
"Create",
"a",
"session",
"protection",
"token",
"for",
"this",
"client",
"."
] | ec6205756d55edd1b135249b9bb345871fef0977 | https://github.com/miguelgrinberg/flask-paranoid/blob/ec6205756d55edd1b135249b9bb345871fef0977/flask_paranoid/paranoid.py#L63-L78 | train |
miguelgrinberg/flask-paranoid | flask_paranoid/paranoid.py | Paranoid.clear_session | def clear_session(self, response):
"""Clear the session.
This method is invoked when the session is found to be invalid.
Subclasses can override this method to implement a custom session
reset.
"""
session.clear()
# if flask-login is installed, we try to clear t... | python | def clear_session(self, response):
"""Clear the session.
This method is invoked when the session is found to be invalid.
Subclasses can override this method to implement a custom session
reset.
"""
session.clear()
# if flask-login is installed, we try to clear t... | [
"def",
"clear_session",
"(",
"self",
",",
"response",
")",
":",
"session",
".",
"clear",
"(",
")",
"# if flask-login is installed, we try to clear the",
"# \"remember me\" cookie, just in case it is set",
"if",
"'flask_login'",
"in",
"sys",
".",
"modules",
":",
"remember_... | Clear the session.
This method is invoked when the session is found to be invalid.
Subclasses can override this method to implement a custom session
reset. | [
"Clear",
"the",
"session",
"."
] | ec6205756d55edd1b135249b9bb345871fef0977 | https://github.com/miguelgrinberg/flask-paranoid/blob/ec6205756d55edd1b135249b9bb345871fef0977/flask_paranoid/paranoid.py#L99-L113 | train |
Atrox/haikunatorpy | haikunator/haikunator.py | Haikunator.haikunate | def haikunate(self, delimiter='-', token_length=4, token_hex=False, token_chars='0123456789'):
"""
Generate heroku-like random names to use in your python applications
:param delimiter: Delimiter
:param token_length: TokenLength
:param token_hex: TokenHex
:param token_ch... | python | def haikunate(self, delimiter='-', token_length=4, token_hex=False, token_chars='0123456789'):
"""
Generate heroku-like random names to use in your python applications
:param delimiter: Delimiter
:param token_length: TokenLength
:param token_hex: TokenHex
:param token_ch... | [
"def",
"haikunate",
"(",
"self",
",",
"delimiter",
"=",
"'-'",
",",
"token_length",
"=",
"4",
",",
"token_hex",
"=",
"False",
",",
"token_chars",
"=",
"'0123456789'",
")",
":",
"if",
"token_hex",
":",
"token_chars",
"=",
"'0123456789abcdef'",
"adjective",
"=... | Generate heroku-like random names to use in your python applications
:param delimiter: Delimiter
:param token_length: TokenLength
:param token_hex: TokenHex
:param token_chars: TokenChars
:type delimiter: str
:type token_length: int
:type token_hex: bool
... | [
"Generate",
"heroku",
"-",
"like",
"random",
"names",
"to",
"use",
"in",
"your",
"python",
"applications"
] | 47551e8564dc903341706c35852f7b66e7e49a24 | https://github.com/Atrox/haikunatorpy/blob/47551e8564dc903341706c35852f7b66e7e49a24/haikunator/haikunator.py#L53-L76 | train |
ftao/python-ifcfg | src/ifcfg/__init__.py | get_parser_class | def get_parser_class():
"""
Returns the parser according to the system platform
"""
global distro
if distro == 'Linux':
Parser = parser.LinuxParser
if not os.path.exists(Parser.get_command()[0]):
Parser = parser.UnixIPParser
elif distro in ['Darwin', 'MacOSX']:
... | python | def get_parser_class():
"""
Returns the parser according to the system platform
"""
global distro
if distro == 'Linux':
Parser = parser.LinuxParser
if not os.path.exists(Parser.get_command()[0]):
Parser = parser.UnixIPParser
elif distro in ['Darwin', 'MacOSX']:
... | [
"def",
"get_parser_class",
"(",
")",
":",
"global",
"distro",
"if",
"distro",
"==",
"'Linux'",
":",
"Parser",
"=",
"parser",
".",
"LinuxParser",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"Parser",
".",
"get_command",
"(",
")",
"[",
"0",
"]",
... | Returns the parser according to the system platform | [
"Returns",
"the",
"parser",
"according",
"to",
"the",
"system",
"platform"
] | 724a4a103088fee7dc2bc2f63b0b9006a614e1d0 | https://github.com/ftao/python-ifcfg/blob/724a4a103088fee7dc2bc2f63b0b9006a614e1d0/src/ifcfg/__init__.py#L18-L39 | train |
ftao/python-ifcfg | src/ifcfg/__init__.py | default_interface | def default_interface(ifconfig=None, route_output=None):
"""
Return just the default interface device dictionary.
:param ifconfig: For mocking actual command output
:param route_output: For mocking actual command output
"""
global Parser
return Parser(ifconfig=ifconfig)._default_interface(r... | python | def default_interface(ifconfig=None, route_output=None):
"""
Return just the default interface device dictionary.
:param ifconfig: For mocking actual command output
:param route_output: For mocking actual command output
"""
global Parser
return Parser(ifconfig=ifconfig)._default_interface(r... | [
"def",
"default_interface",
"(",
"ifconfig",
"=",
"None",
",",
"route_output",
"=",
"None",
")",
":",
"global",
"Parser",
"return",
"Parser",
"(",
"ifconfig",
"=",
"ifconfig",
")",
".",
"_default_interface",
"(",
"route_output",
"=",
"route_output",
")"
] | Return just the default interface device dictionary.
:param ifconfig: For mocking actual command output
:param route_output: For mocking actual command output | [
"Return",
"just",
"the",
"default",
"interface",
"device",
"dictionary",
"."
] | 724a4a103088fee7dc2bc2f63b0b9006a614e1d0 | https://github.com/ftao/python-ifcfg/blob/724a4a103088fee7dc2bc2f63b0b9006a614e1d0/src/ifcfg/__init__.py#L69-L77 | train |
ftao/python-ifcfg | src/ifcfg/parser.py | Parser.parse | def parse(self, ifconfig=None): # noqa: max-complexity=12
"""
Parse ifconfig output into self._interfaces.
Optional Arguments:
ifconfig
The data (stdout) from the ifconfig command. Default is to
call exec_cmd(self.get_command()).
"""
... | python | def parse(self, ifconfig=None): # noqa: max-complexity=12
"""
Parse ifconfig output into self._interfaces.
Optional Arguments:
ifconfig
The data (stdout) from the ifconfig command. Default is to
call exec_cmd(self.get_command()).
"""
... | [
"def",
"parse",
"(",
"self",
",",
"ifconfig",
"=",
"None",
")",
":",
"# noqa: max-complexity=12",
"if",
"not",
"ifconfig",
":",
"ifconfig",
",",
"__",
",",
"__",
"=",
"exec_cmd",
"(",
"self",
".",
"get_command",
"(",
")",
")",
"self",
".",
"ifconfig_data... | Parse ifconfig output into self._interfaces.
Optional Arguments:
ifconfig
The data (stdout) from the ifconfig command. Default is to
call exec_cmd(self.get_command()). | [
"Parse",
"ifconfig",
"output",
"into",
"self",
".",
"_interfaces",
"."
] | 724a4a103088fee7dc2bc2f63b0b9006a614e1d0 | https://github.com/ftao/python-ifcfg/blob/724a4a103088fee7dc2bc2f63b0b9006a614e1d0/src/ifcfg/parser.py#L42-L104 | train |
ftao/python-ifcfg | src/ifcfg/parser.py | Parser.alter | def alter(self, interfaces):
"""
Used to provide the ability to alter the interfaces dictionary before
it is returned from self.parse().
Required Arguments:
interfaces
The interfaces dictionary.
Returns: interfaces dict
"""
# fixup ... | python | def alter(self, interfaces):
"""
Used to provide the ability to alter the interfaces dictionary before
it is returned from self.parse().
Required Arguments:
interfaces
The interfaces dictionary.
Returns: interfaces dict
"""
# fixup ... | [
"def",
"alter",
"(",
"self",
",",
"interfaces",
")",
":",
"# fixup some things",
"for",
"device",
",",
"device_dict",
"in",
"interfaces",
".",
"items",
"(",
")",
":",
"if",
"len",
"(",
"device_dict",
"[",
"'inet4'",
"]",
")",
">",
"0",
":",
"device_dict"... | Used to provide the ability to alter the interfaces dictionary before
it is returned from self.parse().
Required Arguments:
interfaces
The interfaces dictionary.
Returns: interfaces dict | [
"Used",
"to",
"provide",
"the",
"ability",
"to",
"alter",
"the",
"interfaces",
"dictionary",
"before",
"it",
"is",
"returned",
"from",
"self",
".",
"parse",
"()",
"."
] | 724a4a103088fee7dc2bc2f63b0b9006a614e1d0 | https://github.com/ftao/python-ifcfg/blob/724a4a103088fee7dc2bc2f63b0b9006a614e1d0/src/ifcfg/parser.py#L106-L137 | train |
ftao/python-ifcfg | src/ifcfg/parser.py | UnixIPParser._default_interface | def _default_interface(self, route_output=None):
"""
:param route_output: For mocking actual output
"""
if not route_output:
out, __, __ = exec_cmd('/sbin/ip route')
lines = out.splitlines()
else:
lines = route_output.split("\n")
for l... | python | def _default_interface(self, route_output=None):
"""
:param route_output: For mocking actual output
"""
if not route_output:
out, __, __ = exec_cmd('/sbin/ip route')
lines = out.splitlines()
else:
lines = route_output.split("\n")
for l... | [
"def",
"_default_interface",
"(",
"self",
",",
"route_output",
"=",
"None",
")",
":",
"if",
"not",
"route_output",
":",
"out",
",",
"__",
",",
"__",
"=",
"exec_cmd",
"(",
"'/sbin/ip route'",
")",
"lines",
"=",
"out",
".",
"splitlines",
"(",
")",
"else",
... | :param route_output: For mocking actual output | [
":",
"param",
"route_output",
":",
"For",
"mocking",
"actual",
"output"
] | 724a4a103088fee7dc2bc2f63b0b9006a614e1d0 | https://github.com/ftao/python-ifcfg/blob/724a4a103088fee7dc2bc2f63b0b9006a614e1d0/src/ifcfg/parser.py#L312-L326 | train |
fossasia/AYABInterface | AYABInterface/communication/cache.py | NeedlePositionCache.get | def get(self, line_number):
"""Return the needle positions or None.
:param int line_number: the number of the line
:rtype: list
:return: the needle positions for a specific line specified by
:paramref:`line_number` or :obj:`None` if no were given
"""
if line_nu... | python | def get(self, line_number):
"""Return the needle positions or None.
:param int line_number: the number of the line
:rtype: list
:return: the needle positions for a specific line specified by
:paramref:`line_number` or :obj:`None` if no were given
"""
if line_nu... | [
"def",
"get",
"(",
"self",
",",
"line_number",
")",
":",
"if",
"line_number",
"not",
"in",
"self",
".",
"_get_cache",
":",
"self",
".",
"_get_cache",
"[",
"line_number",
"]",
"=",
"self",
".",
"_get",
"(",
"line_number",
")",
"return",
"self",
".",
"_g... | Return the needle positions or None.
:param int line_number: the number of the line
:rtype: list
:return: the needle positions for a specific line specified by
:paramref:`line_number` or :obj:`None` if no were given | [
"Return",
"the",
"needle",
"positions",
"or",
"None",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/cache.py#L17-L27 | train |
fossasia/AYABInterface | AYABInterface/communication/cache.py | NeedlePositionCache.get_bytes | def get_bytes(self, line_number):
"""Get the bytes representing needle positions or None.
:param int line_number: the line number to take the bytes from
:rtype: bytes
:return: the bytes that represent the message or :obj:`None` if no
data is there for the line.
Depend... | python | def get_bytes(self, line_number):
"""Get the bytes representing needle positions or None.
:param int line_number: the line number to take the bytes from
:rtype: bytes
:return: the bytes that represent the message or :obj:`None` if no
data is there for the line.
Depend... | [
"def",
"get_bytes",
"(",
"self",
",",
"line_number",
")",
":",
"if",
"line_number",
"not",
"in",
"self",
".",
"_needle_position_bytes_cache",
":",
"line",
"=",
"self",
".",
"_get",
"(",
"line_number",
")",
"if",
"line",
"is",
"None",
":",
"line_bytes",
"="... | Get the bytes representing needle positions or None.
:param int line_number: the line number to take the bytes from
:rtype: bytes
:return: the bytes that represent the message or :obj:`None` if no
data is there for the line.
Depending on the :attr:`machine`, the length and re... | [
"Get",
"the",
"bytes",
"representing",
"needle",
"positions",
"or",
"None",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/cache.py#L37-L54 | train |
fossasia/AYABInterface | AYABInterface/communication/cache.py | NeedlePositionCache.get_line_configuration_message | def get_line_configuration_message(self, line_number):
"""Return the cnfLine content without id for the line.
:param int line_number: the number of the line
:rtype: bytes
:return: a cnfLine message without id as defined in :ref:`cnfLine`
"""
if line_number not in self._l... | python | def get_line_configuration_message(self, line_number):
"""Return the cnfLine content without id for the line.
:param int line_number: the number of the line
:rtype: bytes
:return: a cnfLine message without id as defined in :ref:`cnfLine`
"""
if line_number not in self._l... | [
"def",
"get_line_configuration_message",
"(",
"self",
",",
"line_number",
")",
":",
"if",
"line_number",
"not",
"in",
"self",
".",
"_line_configuration_message_cache",
":",
"line_bytes",
"=",
"self",
".",
"get_bytes",
"(",
"line_number",
")",
"if",
"line_bytes",
"... | Return the cnfLine content without id for the line.
:param int line_number: the number of the line
:rtype: bytes
:return: a cnfLine message without id as defined in :ref:`cnfLine` | [
"Return",
"the",
"cnfLine",
"content",
"without",
"id",
"for",
"the",
"line",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/cache.py#L56-L78 | train |
fossasia/AYABInterface | AYABInterface/communication/hardware_messages.py | read_message_type | def read_message_type(file):
"""Read the message type from a file."""
message_byte = file.read(1)
if message_byte == b'':
return ConnectionClosed
message_number = message_byte[0]
return _message_types.get(message_number, UnknownMessage) | python | def read_message_type(file):
"""Read the message type from a file."""
message_byte = file.read(1)
if message_byte == b'':
return ConnectionClosed
message_number = message_byte[0]
return _message_types.get(message_number, UnknownMessage) | [
"def",
"read_message_type",
"(",
"file",
")",
":",
"message_byte",
"=",
"file",
".",
"read",
"(",
"1",
")",
"if",
"message_byte",
"==",
"b''",
":",
"return",
"ConnectionClosed",
"message_number",
"=",
"message_byte",
"[",
"0",
"]",
"return",
"_message_types",
... | Read the message type from a file. | [
"Read",
"the",
"message",
"type",
"from",
"a",
"file",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/hardware_messages.py#L485-L491 | train |
fossasia/AYABInterface | AYABInterface/communication/hardware_messages.py | FixedSizeMessage.read_end_of_message | def read_end_of_message(self):
"""Read the b"\\r\\n" at the end of the message."""
read = self._file.read
last = read(1)
current = read(1)
while last != b'' and current != b'' and not \
(last == b'\r' and current == b'\n'):
last = current
c... | python | def read_end_of_message(self):
"""Read the b"\\r\\n" at the end of the message."""
read = self._file.read
last = read(1)
current = read(1)
while last != b'' and current != b'' and not \
(last == b'\r' and current == b'\n'):
last = current
c... | [
"def",
"read_end_of_message",
"(",
"self",
")",
":",
"read",
"=",
"self",
".",
"_file",
".",
"read",
"last",
"=",
"read",
"(",
"1",
")",
"current",
"=",
"read",
"(",
"1",
")",
"while",
"last",
"!=",
"b''",
"and",
"current",
"!=",
"b''",
"and",
"not... | Read the b"\\r\\n" at the end of the message. | [
"Read",
"the",
"b",
"\\\\",
"r",
"\\\\",
"n",
"at",
"the",
"end",
"of",
"the",
"message",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/hardware_messages.py#L139-L147 | train |
fossasia/AYABInterface | AYABInterface/communication/hardware_messages.py | InformationConfirmation._init | def _init(self):
"""Read the success byte."""
self._api_version = self._file.read(1)[0]
self._firmware_version = FirmwareVersion(*self._file.read(2)) | python | def _init(self):
"""Read the success byte."""
self._api_version = self._file.read(1)[0]
self._firmware_version = FirmwareVersion(*self._file.read(2)) | [
"def",
"_init",
"(",
"self",
")",
":",
"self",
".",
"_api_version",
"=",
"self",
".",
"_file",
".",
"read",
"(",
"1",
")",
"[",
"0",
"]",
"self",
".",
"_firmware_version",
"=",
"FirmwareVersion",
"(",
"*",
"self",
".",
"_file",
".",
"read",
"(",
"2... | Read the success byte. | [
"Read",
"the",
"success",
"byte",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/hardware_messages.py#L258-L261 | train |
fossasia/AYABInterface | AYABInterface/communication/hardware_messages.py | LineRequest._init | def _init(self):
"""Read the line number."""
self._line_number = next_line(
self._communication.last_requested_line_number,
self._file.read(1)[0]) | python | def _init(self):
"""Read the line number."""
self._line_number = next_line(
self._communication.last_requested_line_number,
self._file.read(1)[0]) | [
"def",
"_init",
"(",
"self",
")",
":",
"self",
".",
"_line_number",
"=",
"next_line",
"(",
"self",
".",
"_communication",
".",
"last_requested_line_number",
",",
"self",
".",
"_file",
".",
"read",
"(",
"1",
")",
"[",
"0",
"]",
")"
] | Read the line number. | [
"Read",
"the",
"line",
"number",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/hardware_messages.py#L342-L346 | train |
fossasia/AYABInterface | AYABInterface/communication/hardware_messages.py | StateIndication._init | def _init(self):
"""Read the success byte."""
self._ready = self._file.read(1)
self._hall_left = self._file.read(2)
self._hall_right = self._file.read(2)
self._carriage_type = self._file.read(1)[0]
self._carriage_position = self._file.read(1)[0] | python | def _init(self):
"""Read the success byte."""
self._ready = self._file.read(1)
self._hall_left = self._file.read(2)
self._hall_right = self._file.read(2)
self._carriage_type = self._file.read(1)[0]
self._carriage_position = self._file.read(1)[0] | [
"def",
"_init",
"(",
"self",
")",
":",
"self",
".",
"_ready",
"=",
"self",
".",
"_file",
".",
"read",
"(",
"1",
")",
"self",
".",
"_hall_left",
"=",
"self",
".",
"_file",
".",
"read",
"(",
"2",
")",
"self",
".",
"_hall_right",
"=",
"self",
".",
... | Read the success byte. | [
"Read",
"the",
"success",
"byte",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/hardware_messages.py#L375-L381 | train |
fossasia/AYABInterface | AYABInterface/communication/hardware_messages.py | Debug._init | def _init(self):
"""Read the b"\\r\\n" at the end of the message."""
read_values = []
read = self._file.read
last = read(1)
current = read(1)
while last != b'' and current != b'' and not \
(last == b'\r' and current == b'\n'):
read_values.appen... | python | def _init(self):
"""Read the b"\\r\\n" at the end of the message."""
read_values = []
read = self._file.read
last = read(1)
current = read(1)
while last != b'' and current != b'' and not \
(last == b'\r' and current == b'\n'):
read_values.appen... | [
"def",
"_init",
"(",
"self",
")",
":",
"read_values",
"=",
"[",
"]",
"read",
"=",
"self",
".",
"_file",
".",
"read",
"last",
"=",
"read",
"(",
"1",
")",
"current",
"=",
"read",
"(",
"1",
")",
"while",
"last",
"!=",
"b''",
"and",
"current",
"!=",
... | Read the b"\\r\\n" at the end of the message. | [
"Read",
"the",
"b",
"\\\\",
"r",
"\\\\",
"n",
"at",
"the",
"end",
"of",
"the",
"message",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/hardware_messages.py#L447-L460 | train |
fossasia/AYABInterface | AYABInterface/communication/host_messages.py | Message.send | def send(self):
"""Send this message to the controller."""
self._file.write(self.as_bytes())
self._file.write(b'\r\n') | python | def send(self):
"""Send this message to the controller."""
self._file.write(self.as_bytes())
self._file.write(b'\r\n') | [
"def",
"send",
"(",
"self",
")",
":",
"self",
".",
"_file",
".",
"write",
"(",
"self",
".",
"as_bytes",
"(",
")",
")",
"self",
".",
"_file",
".",
"write",
"(",
"b'\\r\\n'",
")"
] | Send this message to the controller. | [
"Send",
"this",
"message",
"to",
"the",
"controller",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/host_messages.py#L50-L53 | train |
fossasia/AYABInterface | AYABInterface/communication/host_messages.py | StartRequest.init | def init(self, left_end_needle, right_end_needle):
"""Initialize the StartRequest with start and stop needle.
:raises TypeError: if the arguments are not integers
:raises ValueError: if the values do not match the
:ref:`specification <m4-01>`
"""
if not isinstance(left... | python | def init(self, left_end_needle, right_end_needle):
"""Initialize the StartRequest with start and stop needle.
:raises TypeError: if the arguments are not integers
:raises ValueError: if the values do not match the
:ref:`specification <m4-01>`
"""
if not isinstance(left... | [
"def",
"init",
"(",
"self",
",",
"left_end_needle",
",",
"right_end_needle",
")",
":",
"if",
"not",
"isinstance",
"(",
"left_end_needle",
",",
"int",
")",
":",
"raise",
"TypeError",
"(",
"_left_end_needle_error_message",
"(",
"left_end_needle",
")",
")",
"if",
... | Initialize the StartRequest with start and stop needle.
:raises TypeError: if the arguments are not integers
:raises ValueError: if the values do not match the
:ref:`specification <m4-01>` | [
"Initialize",
"the",
"StartRequest",
"with",
"start",
"and",
"stop",
"needle",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/host_messages.py#L83-L100 | train |
fossasia/AYABInterface | AYABInterface/communication/host_messages.py | LineConfirmation.content_bytes | def content_bytes(self):
"""Return the start and stop needle."""
get_message = \
self._communication.needle_positions.get_line_configuration_message
return get_message(self._line_number) | python | def content_bytes(self):
"""Return the start and stop needle."""
get_message = \
self._communication.needle_positions.get_line_configuration_message
return get_message(self._line_number) | [
"def",
"content_bytes",
"(",
"self",
")",
":",
"get_message",
"=",
"self",
".",
"_communication",
".",
"needle_positions",
".",
"get_line_configuration_message",
"return",
"get_message",
"(",
"self",
".",
"_line_number",
")"
] | Return the start and stop needle. | [
"Return",
"the",
"start",
"and",
"stop",
"needle",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/host_messages.py#L141-L145 | train |
fossasia/AYABInterface | AYABInterface/utils.py | sum_all | def sum_all(iterable, start):
"""Sum up an iterable starting with a start value.
In contrast to :func:`sum`, this also works on other types like
:class:`lists <list>` and :class:`sets <set>`.
"""
if hasattr(start, "__add__"):
for value in iterable:
start += value
else:
... | python | def sum_all(iterable, start):
"""Sum up an iterable starting with a start value.
In contrast to :func:`sum`, this also works on other types like
:class:`lists <list>` and :class:`sets <set>`.
"""
if hasattr(start, "__add__"):
for value in iterable:
start += value
else:
... | [
"def",
"sum_all",
"(",
"iterable",
",",
"start",
")",
":",
"if",
"hasattr",
"(",
"start",
",",
"\"__add__\"",
")",
":",
"for",
"value",
"in",
"iterable",
":",
"start",
"+=",
"value",
"else",
":",
"for",
"value",
"in",
"iterable",
":",
"start",
"|=",
... | Sum up an iterable starting with a start value.
In contrast to :func:`sum`, this also works on other types like
:class:`lists <list>` and :class:`sets <set>`. | [
"Sum",
"up",
"an",
"iterable",
"starting",
"with",
"a",
"start",
"value",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/utils.py#L4-L16 | train |
fossasia/AYABInterface | AYABInterface/utils.py | next_line | def next_line(last_line, next_line_8bit):
"""Compute the next line based on the last line and a 8bit next line.
The behaviour of the function is specified in :ref:`reqline`.
:param int last_line: the last line that was processed
:param int next_line_8bit: the lower 8 bits of the next line
:return:... | python | def next_line(last_line, next_line_8bit):
"""Compute the next line based on the last line and a 8bit next line.
The behaviour of the function is specified in :ref:`reqline`.
:param int last_line: the last line that was processed
:param int next_line_8bit: the lower 8 bits of the next line
:return:... | [
"def",
"next_line",
"(",
"last_line",
",",
"next_line_8bit",
")",
":",
"# compute the line without the lowest byte",
"base_line",
"=",
"last_line",
"-",
"(",
"last_line",
"&",
"255",
")",
"# compute the three different lines",
"line",
"=",
"base_line",
"+",
"next_line_8... | Compute the next line based on the last line and a 8bit next line.
The behaviour of the function is specified in :ref:`reqline`.
:param int last_line: the last line that was processed
:param int next_line_8bit: the lower 8 bits of the next line
:return: the next line closest to :paramref:`last_line`
... | [
"Compute",
"the",
"next",
"line",
"based",
"on",
"the",
"last",
"line",
"and",
"a",
"8bit",
"next",
"line",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/utils.py#L27-L49 | train |
fossasia/AYABInterface | AYABInterface/utils.py | camel_case_to_under_score | def camel_case_to_under_score(camel_case_name):
"""Return the underscore name of a camel case name.
:param str camel_case_name: a name in camel case such as
``"ACamelCaseName"``
:return: the name using underscores, e.g. ``"a_camel_case_name"``
:rtype: str
"""
result = []
for letter in... | python | def camel_case_to_under_score(camel_case_name):
"""Return the underscore name of a camel case name.
:param str camel_case_name: a name in camel case such as
``"ACamelCaseName"``
:return: the name using underscores, e.g. ``"a_camel_case_name"``
:rtype: str
"""
result = []
for letter in... | [
"def",
"camel_case_to_under_score",
"(",
"camel_case_name",
")",
":",
"result",
"=",
"[",
"]",
"for",
"letter",
"in",
"camel_case_name",
":",
"if",
"letter",
".",
"lower",
"(",
")",
"!=",
"letter",
":",
"result",
".",
"append",
"(",
"\"_\"",
"+",
"letter",... | Return the underscore name of a camel case name.
:param str camel_case_name: a name in camel case such as
``"ACamelCaseName"``
:return: the name using underscores, e.g. ``"a_camel_case_name"``
:rtype: str | [
"Return",
"the",
"underscore",
"name",
"of",
"a",
"camel",
"case",
"name",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/utils.py#L52-L68 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication._message_received | def _message_received(self, message):
"""Notify the observers about the received message."""
with self.lock:
self._state.receive_message(message)
for callable in chain(self._on_message_received, self._on_message):
callable(message) | python | def _message_received(self, message):
"""Notify the observers about the received message."""
with self.lock:
self._state.receive_message(message)
for callable in chain(self._on_message_received, self._on_message):
callable(message) | [
"def",
"_message_received",
"(",
"self",
",",
"message",
")",
":",
"with",
"self",
".",
"lock",
":",
"self",
".",
"_state",
".",
"receive_message",
"(",
"message",
")",
"for",
"callable",
"in",
"chain",
"(",
"self",
".",
"_on_message_received",
",",
"self"... | Notify the observers about the received message. | [
"Notify",
"the",
"observers",
"about",
"the",
"received",
"message",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L79-L84 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication.receive_message | def receive_message(self):
"""Receive a message from the file."""
with self.lock:
assert self.can_receive_messages()
message_type = self._read_message_type(self._file)
message = message_type(self._file, self)
self._message_received(message) | python | def receive_message(self):
"""Receive a message from the file."""
with self.lock:
assert self.can_receive_messages()
message_type = self._read_message_type(self._file)
message = message_type(self._file, self)
self._message_received(message) | [
"def",
"receive_message",
"(",
"self",
")",
":",
"with",
"self",
".",
"lock",
":",
"assert",
"self",
".",
"can_receive_messages",
"(",
")",
"message_type",
"=",
"self",
".",
"_read_message_type",
"(",
"self",
".",
"_file",
")",
"message",
"=",
"message_type"... | Receive a message from the file. | [
"Receive",
"a",
"message",
"from",
"the",
"file",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L96-L102 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication.can_receive_messages | def can_receive_messages(self):
"""Whether tihs communication is ready to receive messages.]
:rtype: bool
.. code:: python
assert not communication.can_receive_messages()
communication.start()
assert communication.can_receive_messages()
communic... | python | def can_receive_messages(self):
"""Whether tihs communication is ready to receive messages.]
:rtype: bool
.. code:: python
assert not communication.can_receive_messages()
communication.start()
assert communication.can_receive_messages()
communic... | [
"def",
"can_receive_messages",
"(",
"self",
")",
":",
"with",
"self",
".",
"lock",
":",
"return",
"not",
"self",
".",
"_state",
".",
"is_waiting_for_start",
"(",
")",
"and",
"not",
"self",
".",
"_state",
".",
"is_connection_closed",
"(",
")"
] | Whether tihs communication is ready to receive messages.]
:rtype: bool
.. code:: python
assert not communication.can_receive_messages()
communication.start()
assert communication.can_receive_messages()
communication.stop()
assert not communi... | [
"Whether",
"tihs",
"communication",
"is",
"ready",
"to",
"receive",
"messages",
".",
"]"
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L104-L120 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication.stop | def stop(self):
"""Stop the communication with the shield."""
with self.lock:
self._message_received(ConnectionClosed(self._file, self)) | python | def stop(self):
"""Stop the communication with the shield."""
with self.lock:
self._message_received(ConnectionClosed(self._file, self)) | [
"def",
"stop",
"(",
"self",
")",
":",
"with",
"self",
".",
"lock",
":",
"self",
".",
"_message_received",
"(",
"ConnectionClosed",
"(",
"self",
".",
"_file",
",",
"self",
")",
")"
] | Stop the communication with the shield. | [
"Stop",
"the",
"communication",
"with",
"the",
"shield",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L122-L125 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication.send | def send(self, host_message_class, *args):
"""Send a host message.
:param type host_message_class: a subclass of
:class:`AYABImterface.communication.host_messages.Message`
:param args: additional arguments that shall be passed to the
:paramref:`host_message_class` as argumen... | python | def send(self, host_message_class, *args):
"""Send a host message.
:param type host_message_class: a subclass of
:class:`AYABImterface.communication.host_messages.Message`
:param args: additional arguments that shall be passed to the
:paramref:`host_message_class` as argumen... | [
"def",
"send",
"(",
"self",
",",
"host_message_class",
",",
"*",
"args",
")",
":",
"message",
"=",
"host_message_class",
"(",
"self",
".",
"_file",
",",
"self",
",",
"*",
"args",
")",
"with",
"self",
".",
"lock",
":",
"message",
".",
"send",
"(",
")"... | Send a host message.
:param type host_message_class: a subclass of
:class:`AYABImterface.communication.host_messages.Message`
:param args: additional arguments that shall be passed to the
:paramref:`host_message_class` as arguments | [
"Send",
"a",
"host",
"message",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L138-L150 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication.state | def state(self, new_state):
"""Set the state."""
with self.lock:
self._state.exit()
self._state = new_state
self._state.enter() | python | def state(self, new_state):
"""Set the state."""
with self.lock:
self._state.exit()
self._state = new_state
self._state.enter() | [
"def",
"state",
"(",
"self",
",",
"new_state",
")",
":",
"with",
"self",
".",
"lock",
":",
"self",
".",
"_state",
".",
"exit",
"(",
")",
"self",
".",
"_state",
"=",
"new_state",
"self",
".",
"_state",
".",
"enter",
"(",
")"
] | Set the state. | [
"Set",
"the",
"state",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L175-L180 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication.parallelize | def parallelize(self, seconds_to_wait=2):
"""Start a parallel thread for receiving messages.
If :meth:`start` was no called before, start will be called in the
thread.
The thread calls :meth:`receive_message` until the :attr:`state`
:meth:`~AYABInterface.communication.states.Sta... | python | def parallelize(self, seconds_to_wait=2):
"""Start a parallel thread for receiving messages.
If :meth:`start` was no called before, start will be called in the
thread.
The thread calls :meth:`receive_message` until the :attr:`state`
:meth:`~AYABInterface.communication.states.Sta... | [
"def",
"parallelize",
"(",
"self",
",",
"seconds_to_wait",
"=",
"2",
")",
":",
"with",
"self",
".",
"lock",
":",
"thread",
"=",
"Thread",
"(",
"target",
"=",
"self",
".",
"_parallel_receive_loop",
",",
"args",
"=",
"(",
"seconds_to_wait",
",",
")",
")",
... | Start a parallel thread for receiving messages.
If :meth:`start` was no called before, start will be called in the
thread.
The thread calls :meth:`receive_message` until the :attr:`state`
:meth:`~AYABInterface.communication.states.State.is_connection_closed`.
:param float secon... | [
"Start",
"a",
"parallel",
"thread",
"for",
"receiving",
"messages",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L244-L263 | train |
fossasia/AYABInterface | AYABInterface/communication/__init__.py | Communication._parallel_receive_loop | def _parallel_receive_loop(self, seconds_to_wait):
"""Run the receiving in parallel."""
sleep(seconds_to_wait)
with self._lock:
self._number_of_threads_receiving_messages += 1
try:
with self._lock:
if self.state.is_waiting_for_start():
... | python | def _parallel_receive_loop(self, seconds_to_wait):
"""Run the receiving in parallel."""
sleep(seconds_to_wait)
with self._lock:
self._number_of_threads_receiving_messages += 1
try:
with self._lock:
if self.state.is_waiting_for_start():
... | [
"def",
"_parallel_receive_loop",
"(",
"self",
",",
"seconds_to_wait",
")",
":",
"sleep",
"(",
"seconds_to_wait",
")",
"with",
"self",
".",
"_lock",
":",
"self",
".",
"_number_of_threads_receiving_messages",
"+=",
"1",
"try",
":",
"with",
"self",
".",
"_lock",
... | Run the receiving in parallel. | [
"Run",
"the",
"receiving",
"in",
"parallel",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/__init__.py#L265-L281 | train |
fossasia/AYABInterface | AYABInterface/communication/states.py | State._next | def _next(self, state_class, *args):
"""Transition into the next state.
:param type state_class: a subclass of :class:`State`. It is intialized
with the communication object and :paramref:`args`
:param args: additional arguments
"""
self._communication.state = state_cl... | python | def _next(self, state_class, *args):
"""Transition into the next state.
:param type state_class: a subclass of :class:`State`. It is intialized
with the communication object and :paramref:`args`
:param args: additional arguments
"""
self._communication.state = state_cl... | [
"def",
"_next",
"(",
"self",
",",
"state_class",
",",
"*",
"args",
")",
":",
"self",
".",
"_communication",
".",
"state",
"=",
"state_class",
"(",
"self",
".",
"_communication",
",",
"*",
"args",
")"
] | Transition into the next state.
:param type state_class: a subclass of :class:`State`. It is intialized
with the communication object and :paramref:`args`
:param args: additional arguments | [
"Transition",
"into",
"the",
"next",
"state",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/states.py#L186-L193 | train |
fossasia/AYABInterface | AYABInterface/communication/states.py | InitialHandshake.receive_information_confirmation | def receive_information_confirmation(self, message):
"""A InformationConfirmation is received.
If :meth:`the api version is supported
<AYABInterface.communication.Communication.api_version_is_supported>`,
the communication object transitions into a
:class:`InitializingMachine`, ... | python | def receive_information_confirmation(self, message):
"""A InformationConfirmation is received.
If :meth:`the api version is supported
<AYABInterface.communication.Communication.api_version_is_supported>`,
the communication object transitions into a
:class:`InitializingMachine`, ... | [
"def",
"receive_information_confirmation",
"(",
"self",
",",
"message",
")",
":",
"if",
"message",
".",
"api_version_is_supported",
"(",
")",
":",
"self",
".",
"_next",
"(",
"InitializingMachine",
")",
"else",
":",
"self",
".",
"_next",
"(",
"UnsupportedApiVersi... | A InformationConfirmation is received.
If :meth:`the api version is supported
<AYABInterface.communication.Communication.api_version_is_supported>`,
the communication object transitions into a
:class:`InitializingMachine`, if unsupported, into a
:class:`UnsupportedApiVersion` | [
"A",
"InformationConfirmation",
"is",
"received",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/states.py#L316-L330 | train |
fossasia/AYABInterface | AYABInterface/communication/states.py | StartingToKnit.receive_start_confirmation | def receive_start_confirmation(self, message):
"""Receive a StartConfirmation message.
:param message: a :class:`StartConfirmation
<AYABInterface.communication.hardware_messages.StartConfirmation>`
message
If the message indicates success, the communication object transitio... | python | def receive_start_confirmation(self, message):
"""Receive a StartConfirmation message.
:param message: a :class:`StartConfirmation
<AYABInterface.communication.hardware_messages.StartConfirmation>`
message
If the message indicates success, the communication object transitio... | [
"def",
"receive_start_confirmation",
"(",
"self",
",",
"message",
")",
":",
"if",
"message",
".",
"is_success",
"(",
")",
":",
"self",
".",
"_next",
"(",
"KnittingStarted",
")",
"else",
":",
"self",
".",
"_next",
"(",
"StartingFailed",
")"
] | Receive a StartConfirmation message.
:param message: a :class:`StartConfirmation
<AYABInterface.communication.hardware_messages.StartConfirmation>`
message
If the message indicates success, the communication object transitions
into :class:`KnittingStarted` or else, into :cl... | [
"Receive",
"a",
"StartConfirmation",
"message",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/states.py#L418-L431 | train |
fossasia/AYABInterface | AYABInterface/communication/states.py | StartingToKnit.enter | def enter(self):
"""Send a StartRequest."""
self._communication.send(StartRequest,
self._communication.left_end_needle,
self._communication.right_end_needle) | python | def enter(self):
"""Send a StartRequest."""
self._communication.send(StartRequest,
self._communication.left_end_needle,
self._communication.right_end_needle) | [
"def",
"enter",
"(",
"self",
")",
":",
"self",
".",
"_communication",
".",
"send",
"(",
"StartRequest",
",",
"self",
".",
"_communication",
".",
"left_end_needle",
",",
"self",
".",
"_communication",
".",
"right_end_needle",
")"
] | Send a StartRequest. | [
"Send",
"a",
"StartRequest",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/states.py#L441-L445 | train |
fossasia/AYABInterface | AYABInterface/communication/states.py | KnittingLine.enter | def enter(self):
"""Send a LineConfirmation to the controller.
When this state is entered, a
:class:`AYABInterface.communication.host_messages.LineConfirmation`
is sent to the controller.
Also, the :attr:`last line requested
<AYABInterface.communication.Communication.las... | python | def enter(self):
"""Send a LineConfirmation to the controller.
When this state is entered, a
:class:`AYABInterface.communication.host_messages.LineConfirmation`
is sent to the controller.
Also, the :attr:`last line requested
<AYABInterface.communication.Communication.las... | [
"def",
"enter",
"(",
"self",
")",
":",
"self",
".",
"_communication",
".",
"last_requested_line_number",
"=",
"self",
".",
"_line_number",
"self",
".",
"_communication",
".",
"send",
"(",
"LineConfirmation",
",",
"self",
".",
"_line_number",
")"
] | Send a LineConfirmation to the controller.
When this state is entered, a
:class:`AYABInterface.communication.host_messages.LineConfirmation`
is sent to the controller.
Also, the :attr:`last line requested
<AYABInterface.communication.Communication.last_requested_line_number>`
... | [
"Send",
"a",
"LineConfirmation",
"to",
"the",
"controller",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/communication/states.py#L502-L513 | train |
fossasia/AYABInterface | AYABInterface/convert/__init__.py | colors_to_needle_positions | def colors_to_needle_positions(rows):
"""Convert rows to needle positions.
:return:
:rtype: list
"""
needles = []
for row in rows:
colors = set(row)
if len(colors) == 1:
needles.append([NeedlePositions(row, tuple(colors), False)])
elif len(colors) == 2:
... | python | def colors_to_needle_positions(rows):
"""Convert rows to needle positions.
:return:
:rtype: list
"""
needles = []
for row in rows:
colors = set(row)
if len(colors) == 1:
needles.append([NeedlePositions(row, tuple(colors), False)])
elif len(colors) == 2:
... | [
"def",
"colors_to_needle_positions",
"(",
"rows",
")",
":",
"needles",
"=",
"[",
"]",
"for",
"row",
"in",
"rows",
":",
"colors",
"=",
"set",
"(",
"row",
")",
"if",
"len",
"(",
"colors",
")",
"==",
"1",
":",
"needles",
".",
"append",
"(",
"[",
"Need... | Convert rows to needle positions.
:return:
:rtype: list | [
"Convert",
"rows",
"to",
"needle",
"positions",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/convert/__init__.py#L12-L39 | train |
fossasia/AYABInterface | AYABInterface/needle_positions.py | NeedlePositions.check | def check(self):
"""Check for validity.
:raises ValueError:
- if not all lines are as long as the :attr:`number of needles
<AYABInterface.machines.Machine.number_of_needles>`
- if the contents of the rows are not :attr:`needle positions
<AYABInterface.machin... | python | def check(self):
"""Check for validity.
:raises ValueError:
- if not all lines are as long as the :attr:`number of needles
<AYABInterface.machines.Machine.number_of_needles>`
- if the contents of the rows are not :attr:`needle positions
<AYABInterface.machin... | [
"def",
"check",
"(",
"self",
")",
":",
"# TODO: This violates the law of demeter.",
"# The architecture should be changed that this check is either",
"# performed by the machine or by the unity of machine and",
"# carriage.",
"expected_positions",
"=",
"self",
".",
"_ma... | Check for validity.
:raises ValueError:
- if not all lines are as long as the :attr:`number of needles
<AYABInterface.machines.Machine.number_of_needles>`
- if the contents of the rows are not :attr:`needle positions
<AYABInterface.machines.Machine.needle_positions>... | [
"Check",
"for",
"validity",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/needle_positions.py#L26-L52 | train |
fossasia/AYABInterface | AYABInterface/needle_positions.py | NeedlePositions.get_row | def get_row(self, index, default=None):
"""Return the row at the given index or the default value."""
if not isinstance(index, int) or index < 0 or index >= len(self._rows):
return default
return self._rows[index] | python | def get_row(self, index, default=None):
"""Return the row at the given index or the default value."""
if not isinstance(index, int) or index < 0 or index >= len(self._rows):
return default
return self._rows[index] | [
"def",
"get_row",
"(",
"self",
",",
"index",
",",
"default",
"=",
"None",
")",
":",
"if",
"not",
"isinstance",
"(",
"index",
",",
"int",
")",
"or",
"index",
"<",
"0",
"or",
"index",
">=",
"len",
"(",
"self",
".",
"_rows",
")",
":",
"return",
"def... | Return the row at the given index or the default value. | [
"Return",
"the",
"row",
"at",
"the",
"given",
"index",
"or",
"the",
"default",
"value",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/needle_positions.py#L61-L65 | train |
fossasia/AYABInterface | AYABInterface/needle_positions.py | NeedlePositions.row_completed | def row_completed(self, index):
"""Mark the row at index as completed.
.. seealso:: :meth:`completed_row_indices`
This method notifies the obsevrers from :meth:`on_row_completed`.
"""
self._completed_rows.append(index)
for row_completed in self._on_row_completed:
... | python | def row_completed(self, index):
"""Mark the row at index as completed.
.. seealso:: :meth:`completed_row_indices`
This method notifies the obsevrers from :meth:`on_row_completed`.
"""
self._completed_rows.append(index)
for row_completed in self._on_row_completed:
... | [
"def",
"row_completed",
"(",
"self",
",",
"index",
")",
":",
"self",
".",
"_completed_rows",
".",
"append",
"(",
"index",
")",
"for",
"row_completed",
"in",
"self",
".",
"_on_row_completed",
":",
"row_completed",
"(",
"index",
")"
] | Mark the row at index as completed.
.. seealso:: :meth:`completed_row_indices`
This method notifies the obsevrers from :meth:`on_row_completed`. | [
"Mark",
"the",
"row",
"at",
"index",
"as",
"completed",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/needle_positions.py#L67-L76 | train |
fossasia/AYABInterface | AYABInterface/interaction.py | Interaction.communicate_through | def communicate_through(self, file):
"""Setup communication through a file.
:rtype: AYABInterface.communication.Communication
"""
if self._communication is not None:
raise ValueError("Already communicating.")
self._communication = communication = Communication(
... | python | def communicate_through(self, file):
"""Setup communication through a file.
:rtype: AYABInterface.communication.Communication
"""
if self._communication is not None:
raise ValueError("Already communicating.")
self._communication = communication = Communication(
... | [
"def",
"communicate_through",
"(",
"self",
",",
"file",
")",
":",
"if",
"self",
".",
"_communication",
"is",
"not",
"None",
":",
"raise",
"ValueError",
"(",
"\"Already communicating.\"",
")",
"self",
".",
"_communication",
"=",
"communication",
"=",
"Communicati... | Setup communication through a file.
:rtype: AYABInterface.communication.Communication | [
"Setup",
"communication",
"through",
"a",
"file",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/interaction.py#L47-L59 | train |
fossasia/AYABInterface | AYABInterface/interaction.py | Interaction.actions | def actions(self):
"""A list of actions to perform.
:return: a list of :class:`AYABInterface.actions.Action`
"""
actions = []
do = actions.append
# determine the number of colors
colors = self.colors
# rows and colors
movements = (
M... | python | def actions(self):
"""A list of actions to perform.
:return: a list of :class:`AYABInterface.actions.Action`
"""
actions = []
do = actions.append
# determine the number of colors
colors = self.colors
# rows and colors
movements = (
M... | [
"def",
"actions",
"(",
"self",
")",
":",
"actions",
"=",
"[",
"]",
"do",
"=",
"actions",
".",
"append",
"# determine the number of colors",
"colors",
"=",
"self",
".",
"colors",
"# rows and colors",
"movements",
"=",
"(",
"MoveCarriageToTheRight",
"(",
"KnitCarr... | A list of actions to perform.
:return: a list of :class:`AYABInterface.actions.Action` | [
"A",
"list",
"of",
"actions",
"to",
"perform",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/interaction.py#L93-L135 | train |
fossasia/AYABInterface | AYABInterface/machines.py | Machine.needle_positions_to_bytes | def needle_positions_to_bytes(self, needle_positions):
"""Convert the needle positions to the wire format.
This conversion is used for :ref:`cnfline`.
:param needle_positions: an iterable over :attr:`needle_positions` of
length :attr:`number_of_needles`
:rtype: bytes
... | python | def needle_positions_to_bytes(self, needle_positions):
"""Convert the needle positions to the wire format.
This conversion is used for :ref:`cnfline`.
:param needle_positions: an iterable over :attr:`needle_positions` of
length :attr:`number_of_needles`
:rtype: bytes
... | [
"def",
"needle_positions_to_bytes",
"(",
"self",
",",
"needle_positions",
")",
":",
"bit",
"=",
"self",
".",
"needle_positions",
"assert",
"len",
"(",
"bit",
")",
"==",
"2",
"max_length",
"=",
"len",
"(",
"needle_positions",
")",
"assert",
"max_length",
"==",
... | Convert the needle positions to the wire format.
This conversion is used for :ref:`cnfline`.
:param needle_positions: an iterable over :attr:`needle_positions` of
length :attr:`number_of_needles`
:rtype: bytes | [
"Convert",
"the",
"needle",
"positions",
"to",
"the",
"wire",
"format",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/machines.py#L105-L132 | train |
fossasia/AYABInterface | AYABInterface/machines.py | Machine.name | def name(self):
"""The identifier of the machine."""
name = self.__class__.__name__
for i, character in enumerate(name):
if character.isdigit():
return name[:i] + "-" + name[i:]
return name | python | def name(self):
"""The identifier of the machine."""
name = self.__class__.__name__
for i, character in enumerate(name):
if character.isdigit():
return name[:i] + "-" + name[i:]
return name | [
"def",
"name",
"(",
"self",
")",
":",
"name",
"=",
"self",
".",
"__class__",
".",
"__name__",
"for",
"i",
",",
"character",
"in",
"enumerate",
"(",
"name",
")",
":",
"if",
"character",
".",
"isdigit",
"(",
")",
":",
"return",
"name",
"[",
":",
"i",... | The identifier of the machine. | [
"The",
"identifier",
"of",
"the",
"machine",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/machines.py#L135-L141 | train |
fossasia/AYABInterface | AYABInterface/machines.py | Machine._id | def _id(self):
"""What this object is equal to."""
return (self.__class__, self.number_of_needles, self.needle_positions,
self.left_end_needle) | python | def _id(self):
"""What this object is equal to."""
return (self.__class__, self.number_of_needles, self.needle_positions,
self.left_end_needle) | [
"def",
"_id",
"(",
"self",
")",
":",
"return",
"(",
"self",
".",
"__class__",
",",
"self",
".",
"number_of_needles",
",",
"self",
".",
"needle_positions",
",",
"self",
".",
"left_end_needle",
")"
] | What this object is equal to. | [
"What",
"this",
"object",
"is",
"equal",
"to",
"."
] | e2065eed8daf17b2936f6ca5e488c9bfb850914e | https://github.com/fossasia/AYABInterface/blob/e2065eed8daf17b2936f6ca5e488c9bfb850914e/AYABInterface/machines.py#L144-L147 | train |
wcember/pypub | pypub/epub.py | Epub.add_chapter | def add_chapter(self, c):
"""
Add a Chapter to your epub.
Args:
c (Chapter): A Chapter object representing your chapter.
Raises:
TypeError: Raised if a Chapter object isn't supplied to this
method.
"""
try:
assert type... | python | def add_chapter(self, c):
"""
Add a Chapter to your epub.
Args:
c (Chapter): A Chapter object representing your chapter.
Raises:
TypeError: Raised if a Chapter object isn't supplied to this
method.
"""
try:
assert type... | [
"def",
"add_chapter",
"(",
"self",
",",
"c",
")",
":",
"try",
":",
"assert",
"type",
"(",
"c",
")",
"==",
"chapter",
".",
"Chapter",
"except",
"AssertionError",
":",
"raise",
"TypeError",
"(",
"'chapter must be of type Chapter'",
")",
"chapter_file_output",
"=... | Add a Chapter to your epub.
Args:
c (Chapter): A Chapter object representing your chapter.
Raises:
TypeError: Raised if a Chapter object isn't supplied to this
method. | [
"Add",
"a",
"Chapter",
"to",
"your",
"epub",
"."
] | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/epub.py#L219-L238 | train |
wcember/pypub | pypub/epub.py | Epub.create_epub | def create_epub(self, output_directory, epub_name=None):
"""
Create an epub file from this object.
Args:
output_directory (str): Directory to output the epub file to
epub_name (Option[str]): The file name of your epub. This should not contain
.epub at the... | python | def create_epub(self, output_directory, epub_name=None):
"""
Create an epub file from this object.
Args:
output_directory (str): Directory to output the epub file to
epub_name (Option[str]): The file name of your epub. This should not contain
.epub at the... | [
"def",
"create_epub",
"(",
"self",
",",
"output_directory",
",",
"epub_name",
"=",
"None",
")",
":",
"def",
"createTOCs_and_ContentOPF",
"(",
")",
":",
"for",
"epub_file",
",",
"name",
"in",
"(",
"(",
"self",
".",
"toc_html",
",",
"'toc.html'",
")",
",",
... | Create an epub file from this object.
Args:
output_directory (str): Directory to output the epub file to
epub_name (Option[str]): The file name of your epub. This should not contain
.epub at the end. If this argument is not provided, defaults to the title of the epub. | [
"Create",
"an",
"epub",
"file",
"from",
"this",
"object",
"."
] | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/epub.py#L240-L280 | train |
wcember/pypub | pypub/chapter.py | save_image | def save_image(image_url, image_directory, image_name):
"""
Saves an online image from image_url to image_directory with the name image_name.
Returns the extension of the image saved, which is determined dynamically.
Args:
image_url (str): The url of the image.
image_directory (str): Th... | python | def save_image(image_url, image_directory, image_name):
"""
Saves an online image from image_url to image_directory with the name image_name.
Returns the extension of the image saved, which is determined dynamically.
Args:
image_url (str): The url of the image.
image_directory (str): Th... | [
"def",
"save_image",
"(",
"image_url",
",",
"image_directory",
",",
"image_name",
")",
":",
"image_type",
"=",
"get_image_type",
"(",
"image_url",
")",
"if",
"image_type",
"is",
"None",
":",
"raise",
"ImageErrorException",
"(",
"image_url",
")",
"full_image_file_n... | Saves an online image from image_url to image_directory with the name image_name.
Returns the extension of the image saved, which is determined dynamically.
Args:
image_url (str): The url of the image.
image_directory (str): The directory to save the image in.
image_name (str): The file... | [
"Saves",
"an",
"online",
"image",
"from",
"image_url",
"to",
"image_directory",
"with",
"the",
"name",
"image_name",
".",
"Returns",
"the",
"extension",
"of",
"the",
"image",
"saved",
"which",
"is",
"determined",
"dynamically",
"."
] | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/chapter.py#L46-L83 | train |
wcember/pypub | pypub/chapter.py | _replace_image | def _replace_image(image_url, image_tag, ebook_folder,
image_name=None):
"""
Replaces the src of an image to link to the local copy in the images folder of the ebook. Tightly coupled with bs4
package.
Args:
image_url (str): The url of the image.
image_tag (bs4.ele... | python | def _replace_image(image_url, image_tag, ebook_folder,
image_name=None):
"""
Replaces the src of an image to link to the local copy in the images folder of the ebook. Tightly coupled with bs4
package.
Args:
image_url (str): The url of the image.
image_tag (bs4.ele... | [
"def",
"_replace_image",
"(",
"image_url",
",",
"image_tag",
",",
"ebook_folder",
",",
"image_name",
"=",
"None",
")",
":",
"try",
":",
"assert",
"isinstance",
"(",
"image_tag",
",",
"bs4",
".",
"element",
".",
"Tag",
")",
"except",
"AssertionError",
":",
... | Replaces the src of an image to link to the local copy in the images folder of the ebook. Tightly coupled with bs4
package.
Args:
image_url (str): The url of the image.
image_tag (bs4.element.Tag): The bs4 tag containing the image.
ebook_folder (str): The directory where the ebook f... | [
"Replaces",
"the",
"src",
"of",
"an",
"image",
"to",
"link",
"to",
"the",
"local",
"copy",
"in",
"the",
"images",
"folder",
"of",
"the",
"ebook",
".",
"Tightly",
"coupled",
"with",
"bs4",
"package",
"."
] | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/chapter.py#L86-L116 | train |
wcember/pypub | pypub/chapter.py | Chapter.write | def write(self, file_name):
"""
Writes the chapter object to an xhtml file.
Args:
file_name (str): The full name of the xhtml file to save to.
"""
try:
assert file_name[-6:] == '.xhtml'
except (AssertionError, IndexError):
raise ValueE... | python | def write(self, file_name):
"""
Writes the chapter object to an xhtml file.
Args:
file_name (str): The full name of the xhtml file to save to.
"""
try:
assert file_name[-6:] == '.xhtml'
except (AssertionError, IndexError):
raise ValueE... | [
"def",
"write",
"(",
"self",
",",
"file_name",
")",
":",
"try",
":",
"assert",
"file_name",
"[",
"-",
"6",
":",
"]",
"==",
"'.xhtml'",
"except",
"(",
"AssertionError",
",",
"IndexError",
")",
":",
"raise",
"ValueError",
"(",
"'filename must end with .xhtml'"... | Writes the chapter object to an xhtml file.
Args:
file_name (str): The full name of the xhtml file to save to. | [
"Writes",
"the",
"chapter",
"object",
"to",
"an",
"xhtml",
"file",
"."
] | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/chapter.py#L148-L160 | train |
wcember/pypub | pypub/chapter.py | ChapterFactory.create_chapter_from_url | def create_chapter_from_url(self, url, title=None):
"""
Creates a Chapter object from a url. Pulls the webpage from the
given url, sanitizes it using the clean_function method, and saves
it as the content of the created chapter. Basic webpage loaded
before any javascript executed... | python | def create_chapter_from_url(self, url, title=None):
"""
Creates a Chapter object from a url. Pulls the webpage from the
given url, sanitizes it using the clean_function method, and saves
it as the content of the created chapter. Basic webpage loaded
before any javascript executed... | [
"def",
"create_chapter_from_url",
"(",
"self",
",",
"url",
",",
"title",
"=",
"None",
")",
":",
"try",
":",
"request_object",
"=",
"requests",
".",
"get",
"(",
"url",
",",
"headers",
"=",
"self",
".",
"request_headers",
",",
"allow_redirects",
"=",
"False"... | Creates a Chapter object from a url. Pulls the webpage from the
given url, sanitizes it using the clean_function method, and saves
it as the content of the created chapter. Basic webpage loaded
before any javascript executed.
Args:
url (string): The url to pull the content o... | [
"Creates",
"a",
"Chapter",
"object",
"from",
"a",
"url",
".",
"Pulls",
"the",
"webpage",
"from",
"the",
"given",
"url",
"sanitizes",
"it",
"using",
"the",
"clean_function",
"method",
"and",
"saves",
"it",
"as",
"the",
"content",
"of",
"the",
"created",
"ch... | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/chapter.py#L220-L249 | train |
wcember/pypub | pypub/chapter.py | ChapterFactory.create_chapter_from_file | def create_chapter_from_file(self, file_name, url=None, title=None):
"""
Creates a Chapter object from an html or xhtml file. Sanitizes the
file's content using the clean_function method, and saves
it as the content of the created chapter.
Args:
file_name (string): T... | python | def create_chapter_from_file(self, file_name, url=None, title=None):
"""
Creates a Chapter object from an html or xhtml file. Sanitizes the
file's content using the clean_function method, and saves
it as the content of the created chapter.
Args:
file_name (string): T... | [
"def",
"create_chapter_from_file",
"(",
"self",
",",
"file_name",
",",
"url",
"=",
"None",
",",
"title",
"=",
"None",
")",
":",
"with",
"codecs",
".",
"open",
"(",
"file_name",
",",
"'r'",
",",
"encoding",
"=",
"'utf-8'",
")",
"as",
"f",
":",
"content_... | Creates a Chapter object from an html or xhtml file. Sanitizes the
file's content using the clean_function method, and saves
it as the content of the created chapter.
Args:
file_name (string): The file_name containing the html or xhtml
content of the created Chapter
... | [
"Creates",
"a",
"Chapter",
"object",
"from",
"an",
"html",
"or",
"xhtml",
"file",
".",
"Sanitizes",
"the",
"file",
"s",
"content",
"using",
"the",
"clean_function",
"method",
"and",
"saves",
"it",
"as",
"the",
"content",
"of",
"the",
"created",
"chapter",
... | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/chapter.py#L251-L271 | train |
wcember/pypub | pypub/chapter.py | ChapterFactory.create_chapter_from_string | def create_chapter_from_string(self, html_string, url=None, title=None):
"""
Creates a Chapter object from a string. Sanitizes the
string using the clean_function method, and saves
it as the content of the created chapter.
Args:
html_string (string): The html or xhtm... | python | def create_chapter_from_string(self, html_string, url=None, title=None):
"""
Creates a Chapter object from a string. Sanitizes the
string using the clean_function method, and saves
it as the content of the created chapter.
Args:
html_string (string): The html or xhtm... | [
"def",
"create_chapter_from_string",
"(",
"self",
",",
"html_string",
",",
"url",
"=",
"None",
",",
"title",
"=",
"None",
")",
":",
"clean_html_string",
"=",
"self",
".",
"clean_function",
"(",
"html_string",
")",
"clean_xhtml_string",
"=",
"clean",
".",
"html... | Creates a Chapter object from a string. Sanitizes the
string using the clean_function method, and saves
it as the content of the created chapter.
Args:
html_string (string): The html or xhtml content of the created
Chapter
url (Option[string]): A url to i... | [
"Creates",
"a",
"Chapter",
"object",
"from",
"a",
"string",
".",
"Sanitizes",
"the",
"string",
"using",
"the",
"clean_function",
"method",
"and",
"saves",
"it",
"as",
"the",
"content",
"of",
"the",
"created",
"chapter",
"."
] | 88a1adc2ccf6f02c33adea1d2d52c729128216fb | https://github.com/wcember/pypub/blob/88a1adc2ccf6f02c33adea1d2d52c729128216fb/pypub/chapter.py#L273-L305 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.