repository_name stringlengths 7 55 | func_path_in_repository stringlengths 4 223 | func_name stringlengths 1 134 | whole_func_string stringlengths 75 104k | language stringclasses 1
value | func_code_string stringlengths 75 104k | func_code_tokens listlengths 19 28.4k | func_documentation_string stringlengths 1 46.9k | func_documentation_tokens listlengths 1 1.97k | split_name stringclasses 1
value | func_code_url stringlengths 87 315 |
|---|---|---|---|---|---|---|---|---|---|---|
realestate-com-au/dashmat | dashmat/option_spec/import_line.py | import_line_spec.create_result | def create_result(self, imports, module_name, import_from, meta, val, dividers):
"""Default permissions to rw"""
options = {"imports": imports, "module_name": module_name, "import_from": import_from}
return ImportLine.FieldSpec(formatter=MergedOptionStringFormatter).normalise(meta, options) | python | def create_result(self, imports, module_name, import_from, meta, val, dividers):
"""Default permissions to rw"""
options = {"imports": imports, "module_name": module_name, "import_from": import_from}
return ImportLine.FieldSpec(formatter=MergedOptionStringFormatter).normalise(meta, options) | [
"def",
"create_result",
"(",
"self",
",",
"imports",
",",
"module_name",
",",
"import_from",
",",
"meta",
",",
"val",
",",
"dividers",
")",
":",
"options",
"=",
"{",
"\"imports\"",
":",
"imports",
",",
"\"module_name\"",
":",
"module_name",
",",
"\"import_fr... | Default permissions to rw | [
"Default",
"permissions",
"to",
"rw"
] | train | https://github.com/realestate-com-au/dashmat/blob/433886e52698f0ddb9956f087b76041966c3bcd1/dashmat/option_spec/import_line.py#L17-L20 |
praekelt/jmbo-music | music/management/commands/base_track_feed.py | _do_create | def _do_create(di):
"""Function that interprets a dictionary and creates objects"""
track = di['track'].strip()
artists = di['artist']
if isinstance(artists, StringType):
artists = [artists]
# todo: handle case where different artists have a song with the same title
tracks = Track.objec... | python | def _do_create(di):
"""Function that interprets a dictionary and creates objects"""
track = di['track'].strip()
artists = di['artist']
if isinstance(artists, StringType):
artists = [artists]
# todo: handle case where different artists have a song with the same title
tracks = Track.objec... | [
"def",
"_do_create",
"(",
"di",
")",
":",
"track",
"=",
"di",
"[",
"'track'",
"]",
".",
"strip",
"(",
")",
"artists",
"=",
"di",
"[",
"'artist'",
"]",
"if",
"isinstance",
"(",
"artists",
",",
"StringType",
")",
":",
"artists",
"=",
"[",
"artists",
... | Function that interprets a dictionary and creates objects | [
"Function",
"that",
"interprets",
"a",
"dictionary",
"and",
"creates",
"objects"
] | train | https://github.com/praekelt/jmbo-music/blob/baeacaa1971b9110ff952fc4eca938c6b426f33e/music/management/commands/base_track_feed.py#L13-L41 |
toumorokoshi/jenks | jenks/data.py | JenksData.get_jobs_from_argument | def get_jobs_from_argument(self, raw_job_string):
""" return a list of jobs corresponding to the raw_job_string """
jobs = []
if raw_job_string.startswith(":"):
job_keys = raw_job_string.strip(" :")
jobs.extend([job for job in self.jobs(job_keys)])
# we assume a j... | python | def get_jobs_from_argument(self, raw_job_string):
""" return a list of jobs corresponding to the raw_job_string """
jobs = []
if raw_job_string.startswith(":"):
job_keys = raw_job_string.strip(" :")
jobs.extend([job for job in self.jobs(job_keys)])
# we assume a j... | [
"def",
"get_jobs_from_argument",
"(",
"self",
",",
"raw_job_string",
")",
":",
"jobs",
"=",
"[",
"]",
"if",
"raw_job_string",
".",
"startswith",
"(",
"\":\"",
")",
":",
"job_keys",
"=",
"raw_job_string",
".",
"strip",
"(",
"\" :\"",
")",
"jobs",
".",
"exte... | return a list of jobs corresponding to the raw_job_string | [
"return",
"a",
"list",
"of",
"jobs",
"corresponding",
"to",
"the",
"raw_job_string"
] | train | https://github.com/toumorokoshi/jenks/blob/d3333a7b86ba290b7185aa5b8da75e76a28124f5/jenks/data.py#L81-L99 |
toumorokoshi/jenks | jenks/data.py | JenksData.add_job | def add_job(self, raw_host, job_name):
""" add a job to the config with <host> and <job_name> """
url_host_map = dict(((host_dict.get('url', host_name).rstrip('/'), host_name)
for host_name, host_dict in self._config_dict.items()))
if raw_host in self._config_dict:
... | python | def add_job(self, raw_host, job_name):
""" add a job to the config with <host> and <job_name> """
url_host_map = dict(((host_dict.get('url', host_name).rstrip('/'), host_name)
for host_name, host_dict in self._config_dict.items()))
if raw_host in self._config_dict:
... | [
"def",
"add_job",
"(",
"self",
",",
"raw_host",
",",
"job_name",
")",
":",
"url_host_map",
"=",
"dict",
"(",
"(",
"(",
"host_dict",
".",
"get",
"(",
"'url'",
",",
"host_name",
")",
".",
"rstrip",
"(",
"'/'",
")",
",",
"host_name",
")",
"for",
"host_n... | add a job to the config with <host> and <job_name> | [
"add",
"a",
"job",
"to",
"the",
"config",
"with",
"<host",
">",
"and",
"<job_name",
">"
] | train | https://github.com/toumorokoshi/jenks/blob/d3333a7b86ba290b7185aa5b8da75e76a28124f5/jenks/data.py#L105-L127 |
FujiMakoto/AgentML | agentml/parser/init/__init__.py | Init._parse_substitutions | def _parse_substitutions(self, element):
"""
Parse word substitutions
:param element: The XML Element object
:type element: etree._Element
"""
subs = element.findall('sub')
for sub in subs:
self.agentml.set_substitution(attribute(sub, 'word'), sub.te... | python | def _parse_substitutions(self, element):
"""
Parse word substitutions
:param element: The XML Element object
:type element: etree._Element
"""
subs = element.findall('sub')
for sub in subs:
self.agentml.set_substitution(attribute(sub, 'word'), sub.te... | [
"def",
"_parse_substitutions",
"(",
"self",
",",
"element",
")",
":",
"subs",
"=",
"element",
".",
"findall",
"(",
"'sub'",
")",
"for",
"sub",
"in",
"subs",
":",
"self",
".",
"agentml",
".",
"set_substitution",
"(",
"attribute",
"(",
"sub",
",",
"'word'"... | Parse word substitutions
:param element: The XML Element object
:type element: etree._Element | [
"Parse",
"word",
"substitutions",
":",
"param",
"element",
":",
"The",
"XML",
"Element",
"object",
":",
"type",
"element",
":",
"etree",
".",
"_Element"
] | train | https://github.com/FujiMakoto/AgentML/blob/c8cb64b460d876666bf29ea2c682189874c7c403/agentml/parser/init/__init__.py#L16-L25 |
roboogle/gtkmvc3 | gtkmvco/examples/treeview/predicates.py | eqdate | def eqdate(y):
"""
Like eq but compares datetime with y,m,d tuple.
Also accepts magic string 'TODAY'.
"""
y = datetime.date.today() if y == 'TODAY' else datetime.date(*y)
return lambda x: x == y | python | def eqdate(y):
"""
Like eq but compares datetime with y,m,d tuple.
Also accepts magic string 'TODAY'.
"""
y = datetime.date.today() if y == 'TODAY' else datetime.date(*y)
return lambda x: x == y | [
"def",
"eqdate",
"(",
"y",
")",
":",
"y",
"=",
"datetime",
".",
"date",
".",
"today",
"(",
")",
"if",
"y",
"==",
"'TODAY'",
"else",
"datetime",
".",
"date",
"(",
"*",
"y",
")",
"return",
"lambda",
"x",
":",
"x",
"==",
"y"
] | Like eq but compares datetime with y,m,d tuple.
Also accepts magic string 'TODAY'. | [
"Like",
"eq",
"but",
"compares",
"datetime",
"with",
"y",
"m",
"d",
"tuple",
".",
"Also",
"accepts",
"magic",
"string",
"TODAY",
"."
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/examples/treeview/predicates.py#L46-L52 |
pbrisk/mathtoolspy | mathtoolspy/utils/math_fcts.py | interpolation_linear | def interpolation_linear(x, x1, x2, y1, y2):
"""
Linear interpolation
returns (y2 - y1) / (x2 - x1) * (x - x1) + y1
"""
m = (y2 - y1) / (x2 - x1)
t = (x - x1)
return m * t + y1 | python | def interpolation_linear(x, x1, x2, y1, y2):
"""
Linear interpolation
returns (y2 - y1) / (x2 - x1) * (x - x1) + y1
"""
m = (y2 - y1) / (x2 - x1)
t = (x - x1)
return m * t + y1 | [
"def",
"interpolation_linear",
"(",
"x",
",",
"x1",
",",
"x2",
",",
"y1",
",",
"y2",
")",
":",
"m",
"=",
"(",
"y2",
"-",
"y1",
")",
"/",
"(",
"x2",
"-",
"x1",
")",
"t",
"=",
"(",
"x",
"-",
"x1",
")",
"return",
"m",
"*",
"t",
"+",
"y1"
] | Linear interpolation
returns (y2 - y1) / (x2 - x1) * (x - x1) + y1 | [
"Linear",
"interpolation",
"returns",
"(",
"y2",
"-",
"y1",
")",
"/",
"(",
"x2",
"-",
"x1",
")",
"*",
"(",
"x",
"-",
"x1",
")",
"+",
"y1"
] | train | https://github.com/pbrisk/mathtoolspy/blob/d0d35b45d20f346ba8a755e53ed0aa182fab43dd/mathtoolspy/utils/math_fcts.py#L51-L58 |
pbrisk/mathtoolspy | mathtoolspy/utils/math_fcts.py | interpolation_bilinear | def interpolation_bilinear(x, y, x1, x2, y1, y2, z11, z21, z22, z12):
'''
The points (x_i, y_i) and values z_ij are connected as follows:
Starting from lower left going in mathematically positive direction, i.e. counter clockwise.
Therefore: (x1,y1,z11), (x2,y1,z21), (x2,y2,z22), (x1,y2,z12).
'''
... | python | def interpolation_bilinear(x, y, x1, x2, y1, y2, z11, z21, z22, z12):
'''
The points (x_i, y_i) and values z_ij are connected as follows:
Starting from lower left going in mathematically positive direction, i.e. counter clockwise.
Therefore: (x1,y1,z11), (x2,y1,z21), (x2,y2,z22), (x1,y2,z12).
'''
... | [
"def",
"interpolation_bilinear",
"(",
"x",
",",
"y",
",",
"x1",
",",
"x2",
",",
"y1",
",",
"y2",
",",
"z11",
",",
"z21",
",",
"z22",
",",
"z12",
")",
":",
"t",
"=",
"(",
"x",
"-",
"x1",
")",
"/",
"(",
"x2",
"-",
"x1",
")",
"s",
"=",
"(",
... | The points (x_i, y_i) and values z_ij are connected as follows:
Starting from lower left going in mathematically positive direction, i.e. counter clockwise.
Therefore: (x1,y1,z11), (x2,y1,z21), (x2,y2,z22), (x1,y2,z12). | [
"The",
"points",
"(",
"x_i",
"y_i",
")",
"and",
"values",
"z_ij",
"are",
"connected",
"as",
"follows",
":",
"Starting",
"from",
"lower",
"left",
"going",
"in",
"mathematically",
"positive",
"direction",
"i",
".",
"e",
".",
"counter",
"clockwise",
".",
"The... | train | https://github.com/pbrisk/mathtoolspy/blob/d0d35b45d20f346ba8a755e53ed0aa182fab43dd/mathtoolspy/utils/math_fcts.py#L61-L74 |
pbrisk/mathtoolspy | mathtoolspy/utils/math_fcts.py | get_grid | def get_grid(start, end, nsteps=100):
"""
Generates a equal distanced list of float values with nsteps+1 values, begining start and ending with end.
:param start: the start value of the generated list.
:type float
:param end: the end value of the generated list.
:type float
:param nstep... | python | def get_grid(start, end, nsteps=100):
"""
Generates a equal distanced list of float values with nsteps+1 values, begining start and ending with end.
:param start: the start value of the generated list.
:type float
:param end: the end value of the generated list.
:type float
:param nstep... | [
"def",
"get_grid",
"(",
"start",
",",
"end",
",",
"nsteps",
"=",
"100",
")",
":",
"step",
"=",
"(",
"end",
"-",
"start",
")",
"/",
"float",
"(",
"nsteps",
")",
"return",
"[",
"start",
"+",
"i",
"*",
"step",
"for",
"i",
"in",
"xrange",
"(",
"nst... | Generates a equal distanced list of float values with nsteps+1 values, begining start and ending with end.
:param start: the start value of the generated list.
:type float
:param end: the end value of the generated list.
:type float
:param nsteps: optional the number of steps (default=100), i.e... | [
"Generates",
"a",
"equal",
"distanced",
"list",
"of",
"float",
"values",
"with",
"nsteps",
"+",
"1",
"values",
"begining",
"start",
"and",
"ending",
"with",
"end",
"."
] | train | https://github.com/pbrisk/mathtoolspy/blob/d0d35b45d20f346ba8a755e53ed0aa182fab43dd/mathtoolspy/utils/math_fcts.py#L77-L96 |
JukeboxPipeline/jukebox-core | src/jukeboxcore/gui/filesysitemdata.py | taskfileinfo_element_data | def taskfileinfo_element_data(tfi, role):
"""Return the data for the element (e.g. the Asset or Shot)
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:ret... | python | def taskfileinfo_element_data(tfi, role):
"""Return the data for the element (e.g. the Asset or Shot)
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:ret... | [
"def",
"taskfileinfo_element_data",
"(",
"tfi",
",",
"role",
")",
":",
"task",
"=",
"tfi",
".",
"task",
"element",
"=",
"task",
".",
"element",
"if",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"DisplayRole",
"or",
"role",
"==",
"QtCore",
".",
"Qt",
".",
... | Return the data for the element (e.g. the Asset or Shot)
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the element
:rtype: depending ... | [
"Return",
"the",
"data",
"for",
"the",
"element",
"(",
"e",
".",
"g",
".",
"the",
"Asset",
"or",
"Shot",
")"
] | train | https://github.com/JukeboxPipeline/jukebox-core/blob/bac2280ca49940355270e4b69400ce9976ab2e6f/src/jukeboxcore/gui/filesysitemdata.py#L10-L24 |
JukeboxPipeline/jukebox-core | src/jukeboxcore/gui/filesysitemdata.py | taskfileinfo_task_data | def taskfileinfo_task_data(tfi, role):
"""Return the data for task
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the task
:rtype:... | python | def taskfileinfo_task_data(tfi, role):
"""Return the data for task
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the task
:rtype:... | [
"def",
"taskfileinfo_task_data",
"(",
"tfi",
",",
"role",
")",
":",
"task",
"=",
"tfi",
".",
"task",
"if",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"DisplayRole",
"or",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"EditRole",
":",
"return",
"task",
".",
"n... | Return the data for task
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the task
:rtype: depending on role
:raises: None | [
"Return",
"the",
"data",
"for",
"task"
] | train | https://github.com/JukeboxPipeline/jukebox-core/blob/bac2280ca49940355270e4b69400ce9976ab2e6f/src/jukeboxcore/gui/filesysitemdata.py#L27-L40 |
JukeboxPipeline/jukebox-core | src/jukeboxcore/gui/filesysitemdata.py | taskfileinfo_descriptor_data | def taskfileinfo_descriptor_data(tfi, role):
"""Return the data for descriptor
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the desc... | python | def taskfileinfo_descriptor_data(tfi, role):
"""Return the data for descriptor
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the desc... | [
"def",
"taskfileinfo_descriptor_data",
"(",
"tfi",
",",
"role",
")",
":",
"if",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"DisplayRole",
"or",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"EditRole",
":",
"return",
"tfi",
".",
"descriptor"
] | Return the data for descriptor
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the descriptor
:rtype: depending on role
:raises: No... | [
"Return",
"the",
"data",
"for",
"descriptor"
] | train | https://github.com/JukeboxPipeline/jukebox-core/blob/bac2280ca49940355270e4b69400ce9976ab2e6f/src/jukeboxcore/gui/filesysitemdata.py#L43-L55 |
JukeboxPipeline/jukebox-core | src/jukeboxcore/gui/filesysitemdata.py | taskfileinfo_path_data | def taskfileinfo_path_data(tfi, role):
"""Return the data for path
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the path
:rtype:... | python | def taskfileinfo_path_data(tfi, role):
"""Return the data for path
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the path
:rtype:... | [
"def",
"taskfileinfo_path_data",
"(",
"tfi",
",",
"role",
")",
":",
"if",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"DisplayRole",
"or",
"role",
"==",
"QtCore",
".",
"Qt",
".",
"EditRole",
":",
"return",
"JB_File",
"(",
"tfi",
")",
".",
"get_fullpath",
"... | Return the data for path
:param tfi: the :class:`jukeboxcore.filesys.TaskFileInfo` holds the data
:type tfi: :class:`jukeboxcore.filesys.TaskFileInfo`
:param role: item data role
:type role: QtCore.Qt.ItemDataRole
:returns: data for the path
:rtype: depending on role
:raises: None | [
"Return",
"the",
"data",
"for",
"path"
] | train | https://github.com/JukeboxPipeline/jukebox-core/blob/bac2280ca49940355270e4b69400ce9976ab2e6f/src/jukeboxcore/gui/filesysitemdata.py#L58-L70 |
JukeboxPipeline/jukebox-core | src/jukeboxcore/gui/filesysitemdata.py | TaskFileInfoItemData.data | def data(self, column, role):
"""Return the data for the specified column and role
The column addresses one attribute of the data.
:param column: the data column
:type column: int
:param role: the data role
:type role: QtCore.Qt.ItemDataRole
:returns: data depen... | python | def data(self, column, role):
"""Return the data for the specified column and role
The column addresses one attribute of the data.
:param column: the data column
:type column: int
:param role: the data role
:type role: QtCore.Qt.ItemDataRole
:returns: data depen... | [
"def",
"data",
"(",
"self",
",",
"column",
",",
"role",
")",
":",
"return",
"self",
".",
"columns",
"[",
"column",
"]",
"(",
"self",
".",
"_taskfileinfo",
",",
"role",
")"
] | Return the data for the specified column and role
The column addresses one attribute of the data.
:param column: the data column
:type column: int
:param role: the data role
:type role: QtCore.Qt.ItemDataRole
:returns: data depending on the role
:rtype:
... | [
"Return",
"the",
"data",
"for",
"the",
"specified",
"column",
"and",
"role"
] | train | https://github.com/JukeboxPipeline/jukebox-core/blob/bac2280ca49940355270e4b69400ce9976ab2e6f/src/jukeboxcore/gui/filesysitemdata.py#L133-L146 |
pip-services3-python/pip-services3-commons-python | pip_services3_commons/validate/PropertySchema.py | PropertySchema._perform_validation | def _perform_validation(self, path, value, results):
"""
Validates a given value against the schema and configured validation rules.
:param path: a dot notation path to the value.
:param value: a value to be validated.
:param results: a list with validation results to add new ... | python | def _perform_validation(self, path, value, results):
"""
Validates a given value against the schema and configured validation rules.
:param path: a dot notation path to the value.
:param value: a value to be validated.
:param results: a list with validation results to add new ... | [
"def",
"_perform_validation",
"(",
"self",
",",
"path",
",",
"value",
",",
"results",
")",
":",
"path",
"=",
"self",
".",
"name",
"if",
"path",
"==",
"None",
"or",
"len",
"(",
"path",
")",
"==",
"0",
"else",
"path",
"+",
"\".\"",
"+",
"self",
".",
... | Validates a given value against the schema and configured validation rules.
:param path: a dot notation path to the value.
:param value: a value to be validated.
:param results: a list with validation results to add new results. | [
"Validates",
"a",
"given",
"value",
"against",
"the",
"schema",
"and",
"configured",
"validation",
"rules",
"."
] | train | https://github.com/pip-services3-python/pip-services3-commons-python/blob/22cbbb3e91e49717f65c083d36147fdb07ba9e3b/pip_services3_commons/validate/PropertySchema.py#L40-L53 |
bwesterb/sarah | src/drv.py | DiscreteRandomVariable.pick | def pick(self):
""" picks a value accoriding to the given density """
v = random.uniform(0, self.ub)
d = self.dist
c = self.vc - 1
s = self.vc
while True:
s = s / 2
if s == 0:
break
if v <= d[c][1]:
c -= ... | python | def pick(self):
""" picks a value accoriding to the given density """
v = random.uniform(0, self.ub)
d = self.dist
c = self.vc - 1
s = self.vc
while True:
s = s / 2
if s == 0:
break
if v <= d[c][1]:
c -= ... | [
"def",
"pick",
"(",
"self",
")",
":",
"v",
"=",
"random",
".",
"uniform",
"(",
"0",
",",
"self",
".",
"ub",
")",
"d",
"=",
"self",
".",
"dist",
"c",
"=",
"self",
".",
"vc",
"-",
"1",
"s",
"=",
"self",
".",
"vc",
"while",
"True",
":",
"s",
... | picks a value accoriding to the given density | [
"picks",
"a",
"value",
"accoriding",
"to",
"the",
"given",
"density"
] | train | https://github.com/bwesterb/sarah/blob/a9e46e875dfff1dc11255d714bb736e5eb697809/src/drv.py#L24-L47 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.set_output_fields | def set_output_fields(self, output_fields):
"""Defines where to put the dictionary output of the extractor in the doc, but renames
the fields of the extracted output for the document or just filters the keys"""
if isinstance(output_fields, dict) or isinstance(output_fields, list):
se... | python | def set_output_fields(self, output_fields):
"""Defines where to put the dictionary output of the extractor in the doc, but renames
the fields of the extracted output for the document or just filters the keys"""
if isinstance(output_fields, dict) or isinstance(output_fields, list):
se... | [
"def",
"set_output_fields",
"(",
"self",
",",
"output_fields",
")",
":",
"if",
"isinstance",
"(",
"output_fields",
",",
"dict",
")",
"or",
"isinstance",
"(",
"output_fields",
",",
"list",
")",
":",
"self",
".",
"output_fields",
"=",
"output_fields",
"elif",
... | Defines where to put the dictionary output of the extractor in the doc, but renames
the fields of the extracted output for the document or just filters the keys | [
"Defines",
"where",
"to",
"put",
"the",
"dictionary",
"output",
"of",
"the",
"extractor",
"in",
"the",
"doc",
"but",
"renames",
"the",
"fields",
"of",
"the",
"extracted",
"output",
"for",
"the",
"document",
"or",
"just",
"filters",
"the",
"keys"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L45-L55 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.__get_jp | def __get_jp(self, extractor_processor, sub_output=None):
"""Tries to get name from ExtractorProcessor to filter on first.
Otherwise falls back to filtering based on its metadata"""
if sub_output is None and extractor_processor.output_field is None:
raise ValueError(
... | python | def __get_jp(self, extractor_processor, sub_output=None):
"""Tries to get name from ExtractorProcessor to filter on first.
Otherwise falls back to filtering based on its metadata"""
if sub_output is None and extractor_processor.output_field is None:
raise ValueError(
... | [
"def",
"__get_jp",
"(",
"self",
",",
"extractor_processor",
",",
"sub_output",
"=",
"None",
")",
":",
"if",
"sub_output",
"is",
"None",
"and",
"extractor_processor",
".",
"output_field",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"ExtractorProcessors input p... | Tries to get name from ExtractorProcessor to filter on first.
Otherwise falls back to filtering based on its metadata | [
"Tries",
"to",
"get",
"name",
"from",
"ExtractorProcessor",
"to",
"filter",
"on",
"first",
".",
"Otherwise",
"falls",
"back",
"to",
"filtering",
"based",
"on",
"its",
"metadata"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L57-L66 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.set_extractor_processor_inputs | def set_extractor_processor_inputs(self, extractor_processors,
sub_output=None):
"""Instead of specifying fields in the source document to rename
for the extractor, allows the user to specify ExtractorProcessors that
are executed earlier in the chain and ge... | python | def set_extractor_processor_inputs(self, extractor_processors,
sub_output=None):
"""Instead of specifying fields in the source document to rename
for the extractor, allows the user to specify ExtractorProcessors that
are executed earlier in the chain and ge... | [
"def",
"set_extractor_processor_inputs",
"(",
"self",
",",
"extractor_processors",
",",
"sub_output",
"=",
"None",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"extractor_processors",
",",
"ExtractorProcessor",
")",
"or",
"isinstance",
"(",
"extractor_processors",
... | Instead of specifying fields in the source document to rename
for the extractor, allows the user to specify ExtractorProcessors that
are executed earlier in the chain and generate json paths from
their output fields | [
"Instead",
"of",
"specifying",
"fields",
"in",
"the",
"source",
"document",
"to",
"rename",
"for",
"the",
"extractor",
"allows",
"the",
"user",
"to",
"specify",
"ExtractorProcessors",
"that",
"are",
"executed",
"earlier",
"in",
"the",
"chain",
"and",
"generate",... | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L68-L95 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.get_output_jsonpath_field | def get_output_jsonpath_field(self, sub_output=None):
"""attempts to create an output jsonpath from a particular ouput field"""
if sub_output is not None:
if self.output_fields is None or\
(isinstance(self.output_fields, dict) and not sub_output in self.output_fields.itervalu... | python | def get_output_jsonpath_field(self, sub_output=None):
"""attempts to create an output jsonpath from a particular ouput field"""
if sub_output is not None:
if self.output_fields is None or\
(isinstance(self.output_fields, dict) and not sub_output in self.output_fields.itervalu... | [
"def",
"get_output_jsonpath_field",
"(",
"self",
",",
"sub_output",
"=",
"None",
")",
":",
"if",
"sub_output",
"is",
"not",
"None",
":",
"if",
"self",
".",
"output_fields",
"is",
"None",
"or",
"(",
"isinstance",
"(",
"self",
".",
"output_fields",
",",
"dic... | attempts to create an output jsonpath from a particular ouput field | [
"attempts",
"to",
"create",
"an",
"output",
"jsonpath",
"from",
"a",
"particular",
"ouput",
"field"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L97-L108 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.get_output_jsonpath_with_name | def get_output_jsonpath_with_name(self, sub_output=None):
"""If ExtractorProcessor has a name defined, return
a JSONPath that has a filter on that name"""
if self.name is None:
return None
output_jsonpath_field = self.get_output_jsonpath_field(sub_output)
extractor_f... | python | def get_output_jsonpath_with_name(self, sub_output=None):
"""If ExtractorProcessor has a name defined, return
a JSONPath that has a filter on that name"""
if self.name is None:
return None
output_jsonpath_field = self.get_output_jsonpath_field(sub_output)
extractor_f... | [
"def",
"get_output_jsonpath_with_name",
"(",
"self",
",",
"sub_output",
"=",
"None",
")",
":",
"if",
"self",
".",
"name",
"is",
"None",
":",
"return",
"None",
"output_jsonpath_field",
"=",
"self",
".",
"get_output_jsonpath_field",
"(",
"sub_output",
")",
"extrac... | If ExtractorProcessor has a name defined, return
a JSONPath that has a filter on that name | [
"If",
"ExtractorProcessor",
"has",
"a",
"name",
"defined",
"return",
"a",
"JSONPath",
"that",
"has",
"a",
"filter",
"on",
"that",
"name"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L110-L121 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.get_output_jsonpath | def get_output_jsonpath(self, sub_output=None):
"""Attempt to build a JSONPath filter for this ExtractorProcessor
that captures how to get at the outputs of the wrapped Extractor"""
output_jsonpath_field = self.get_output_jsonpath_field(sub_output)
metadata = self.extractor.get_metadata... | python | def get_output_jsonpath(self, sub_output=None):
"""Attempt to build a JSONPath filter for this ExtractorProcessor
that captures how to get at the outputs of the wrapped Extractor"""
output_jsonpath_field = self.get_output_jsonpath_field(sub_output)
metadata = self.extractor.get_metadata... | [
"def",
"get_output_jsonpath",
"(",
"self",
",",
"sub_output",
"=",
"None",
")",
":",
"output_jsonpath_field",
"=",
"self",
".",
"get_output_jsonpath_field",
"(",
"sub_output",
")",
"metadata",
"=",
"self",
".",
"extractor",
".",
"get_metadata",
"(",
")",
"metada... | Attempt to build a JSONPath filter for this ExtractorProcessor
that captures how to get at the outputs of the wrapped Extractor | [
"Attempt",
"to",
"build",
"a",
"JSONPath",
"filter",
"for",
"this",
"ExtractorProcessor",
"that",
"captures",
"how",
"to",
"get",
"at",
"the",
"outputs",
"of",
"the",
"wrapped",
"Extractor"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L123-L148 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.set_input_fields | def set_input_fields(self, input_fields):
"""Given a scalar or ordered list of strings generate JSONPaths
that describe how to access the values necessary for the Extractor """
if not (isinstance(input_fields, basestring) or
isinstance(input_fields, types.ListType)):
... | python | def set_input_fields(self, input_fields):
"""Given a scalar or ordered list of strings generate JSONPaths
that describe how to access the values necessary for the Extractor """
if not (isinstance(input_fields, basestring) or
isinstance(input_fields, types.ListType)):
... | [
"def",
"set_input_fields",
"(",
"self",
",",
"input_fields",
")",
":",
"if",
"not",
"(",
"isinstance",
"(",
"input_fields",
",",
"basestring",
")",
"or",
"isinstance",
"(",
"input_fields",
",",
"types",
".",
"ListType",
")",
")",
":",
"raise",
"ValueError",
... | Given a scalar or ordered list of strings generate JSONPaths
that describe how to access the values necessary for the Extractor | [
"Given",
"a",
"scalar",
"or",
"ordered",
"list",
"of",
"strings",
"generate",
"JSONPaths",
"that",
"describe",
"how",
"to",
"access",
"the",
"values",
"necessary",
"for",
"the",
"Extractor"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L150-L158 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.generate_json_paths | def generate_json_paths(self):
"""Given a scalar or ordered list of strings parse them to
generate JSONPaths"""
if isinstance(self.input_fields, basestring):
try:
self.jsonpaths = parse(self.input_fields)
except Exception as exception:
prin... | python | def generate_json_paths(self):
"""Given a scalar or ordered list of strings parse them to
generate JSONPaths"""
if isinstance(self.input_fields, basestring):
try:
self.jsonpaths = parse(self.input_fields)
except Exception as exception:
prin... | [
"def",
"generate_json_paths",
"(",
"self",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"input_fields",
",",
"basestring",
")",
":",
"try",
":",
"self",
".",
"jsonpaths",
"=",
"parse",
"(",
"self",
".",
"input_fields",
")",
"except",
"Exception",
"as",
... | Given a scalar or ordered list of strings parse them to
generate JSONPaths | [
"Given",
"a",
"scalar",
"or",
"ordered",
"list",
"of",
"strings",
"parse",
"them",
"to",
"generate",
"JSONPaths"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L160-L175 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.insert_extracted_value | def insert_extracted_value(self, doc, extracted_value,
output_field, original_output_field=None):
"""inserts the extracted value into doc at the field specified
by output_field"""
if not extracted_value:
return doc
metadata = self.extractor.get... | python | def insert_extracted_value(self, doc, extracted_value,
output_field, original_output_field=None):
"""inserts the extracted value into doc at the field specified
by output_field"""
if not extracted_value:
return doc
metadata = self.extractor.get... | [
"def",
"insert_extracted_value",
"(",
"self",
",",
"doc",
",",
"extracted_value",
",",
"output_field",
",",
"original_output_field",
"=",
"None",
")",
":",
"if",
"not",
"extracted_value",
":",
"return",
"doc",
"metadata",
"=",
"self",
".",
"extractor",
".",
"g... | inserts the extracted value into doc at the field specified
by output_field | [
"inserts",
"the",
"extracted",
"value",
"into",
"doc",
"at",
"the",
"field",
"specified",
"by",
"output_field"
] | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L186-L244 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.extract_from_renamed_inputs | def extract_from_renamed_inputs(self, doc, renamed_inputs):
"""Apply the extractor to a document containing the renamed_inputs
and insert the resulting value if defined in the value field
of a copy of the extractor's metadata and insert that into the doc"""
extracted_value = self.extract... | python | def extract_from_renamed_inputs(self, doc, renamed_inputs):
"""Apply the extractor to a document containing the renamed_inputs
and insert the resulting value if defined in the value field
of a copy of the extractor's metadata and insert that into the doc"""
extracted_value = self.extract... | [
"def",
"extract_from_renamed_inputs",
"(",
"self",
",",
"doc",
",",
"renamed_inputs",
")",
":",
"extracted_value",
"=",
"self",
".",
"extractor",
".",
"extract",
"(",
"renamed_inputs",
")",
"if",
"not",
"extracted_value",
":",
"return",
"doc",
"if",
"self",
".... | Apply the extractor to a document containing the renamed_inputs
and insert the resulting value if defined in the value field
of a copy of the extractor's metadata and insert that into the doc | [
"Apply",
"the",
"extractor",
"to",
"a",
"document",
"containing",
"the",
"renamed_inputs",
"and",
"insert",
"the",
"resulting",
"value",
"if",
"defined",
"in",
"the",
"value",
"field",
"of",
"a",
"copy",
"of",
"the",
"extractor",
"s",
"metadata",
"and",
"ins... | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L246-L267 |
usc-isi-i2/dig-extractor | digExtractor/extractor_processor.py | ExtractorProcessor.extract | def extract(self, doc):
"""From the defined JSONPath(s), pull out the values and
insert them into a document with renamed field(s) then
apply the Extractor and return the doc with the extracted values """
if isinstance(self.jsonpaths, JSONPath):
input_field = self.extractor.... | python | def extract(self, doc):
"""From the defined JSONPath(s), pull out the values and
insert them into a document with renamed field(s) then
apply the Extractor and return the doc with the extracted values """
if isinstance(self.jsonpaths, JSONPath):
input_field = self.extractor.... | [
"def",
"extract",
"(",
"self",
",",
"doc",
")",
":",
"if",
"isinstance",
"(",
"self",
".",
"jsonpaths",
",",
"JSONPath",
")",
":",
"input_field",
"=",
"self",
".",
"extractor",
".",
"get_renamed_input_fields",
"(",
")",
"if",
"isinstance",
"(",
"self",
"... | From the defined JSONPath(s), pull out the values and
insert them into a document with renamed field(s) then
apply the Extractor and return the doc with the extracted values | [
"From",
"the",
"defined",
"JSONPath",
"(",
"s",
")",
"pull",
"out",
"the",
"values",
"and",
"insert",
"them",
"into",
"a",
"document",
"with",
"renamed",
"field",
"(",
"s",
")",
"then",
"apply",
"the",
"Extractor",
"and",
"return",
"the",
"doc",
"with",
... | train | https://github.com/usc-isi-i2/dig-extractor/blob/87c138e0300d77e35ebeb5f5e9488c3d71e60eb3/digExtractor/extractor_processor.py#L276-L337 |
tarvitz/django-unity-asset-server-http-client | duashttp/router.py | UnityAssetServerRouter.db_for_write | def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to duashttp.
"""
if model._meta.app_label == 'duashttp':
if not DUAS_ENABLE_DB_WRITE:
raise ImproperlyConfigured(
"Set `DUAS_ENABLE_DB_WRITE` to True in your setti... | python | def db_for_write(self, model, **hints):
"""
Attempts to write auth models go to duashttp.
"""
if model._meta.app_label == 'duashttp':
if not DUAS_ENABLE_DB_WRITE:
raise ImproperlyConfigured(
"Set `DUAS_ENABLE_DB_WRITE` to True in your setti... | [
"def",
"db_for_write",
"(",
"self",
",",
"model",
",",
"*",
"*",
"hints",
")",
":",
"if",
"model",
".",
"_meta",
".",
"app_label",
"==",
"'duashttp'",
":",
"if",
"not",
"DUAS_ENABLE_DB_WRITE",
":",
"raise",
"ImproperlyConfigured",
"(",
"\"Set `DUAS_ENABLE_DB_W... | Attempts to write auth models go to duashttp. | [
"Attempts",
"to",
"write",
"auth",
"models",
"go",
"to",
"duashttp",
"."
] | train | https://github.com/tarvitz/django-unity-asset-server-http-client/blob/2b7e3b1116b5e98b31c2e267bdd66a77e0579ad1/duashttp/router.py#L23-L34 |
tarvitz/django-unity-asset-server-http-client | duashttp/router.py | UnityAssetServerRouter.allow_migrate | def allow_migrate(self, db, model):
"""
Make sure the auth app only appears in the 'duashttp'
database.
"""
if db == DUAS_DB_ROUTE_PREFIX:
return model._meta.app_label == 'duashttp'
elif model._meta.app_label == 'duashttp':
return False
ret... | python | def allow_migrate(self, db, model):
"""
Make sure the auth app only appears in the 'duashttp'
database.
"""
if db == DUAS_DB_ROUTE_PREFIX:
return model._meta.app_label == 'duashttp'
elif model._meta.app_label == 'duashttp':
return False
ret... | [
"def",
"allow_migrate",
"(",
"self",
",",
"db",
",",
"model",
")",
":",
"if",
"db",
"==",
"DUAS_DB_ROUTE_PREFIX",
":",
"return",
"model",
".",
"_meta",
".",
"app_label",
"==",
"'duashttp'",
"elif",
"model",
".",
"_meta",
".",
"app_label",
"==",
"'duashttp'... | Make sure the auth app only appears in the 'duashttp'
database. | [
"Make",
"sure",
"the",
"auth",
"app",
"only",
"appears",
"in",
"the",
"duashttp",
"database",
"."
] | train | https://github.com/tarvitz/django-unity-asset-server-http-client/blob/2b7e3b1116b5e98b31c2e267bdd66a77e0579ad1/duashttp/router.py#L45-L54 |
aaronbassett/sometimes | sometimes/decorators.py | sometimes | def sometimes(fn):
"""
They've done studies, you know. 50% of the time,
it works every time.
"""
def wrapped(*args, **kwargs):
wrapped.x += 1
if wrapped.x % 2 == 1:
return fn(*args, **kwargs)
wrapped.x = 0
return wrapped | python | def sometimes(fn):
"""
They've done studies, you know. 50% of the time,
it works every time.
"""
def wrapped(*args, **kwargs):
wrapped.x += 1
if wrapped.x % 2 == 1:
return fn(*args, **kwargs)
wrapped.x = 0
return wrapped | [
"def",
"sometimes",
"(",
"fn",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"wrapped",
".",
"x",
"+=",
"1",
"if",
"wrapped",
".",
"x",
"%",
"2",
"==",
"1",
":",
"return",
"fn",
"(",
"*",
"args",
",",
"*",
... | They've done studies, you know. 50% of the time,
it works every time. | [
"They",
"ve",
"done",
"studies",
"you",
"know",
".",
"50%",
"of",
"the",
"time",
"it",
"works",
"every",
"time",
"."
] | train | https://github.com/aaronbassett/sometimes/blob/d71959c4bdf5643a1d1e4e60f719da94406df6e6/sometimes/decorators.py#L7-L19 |
aaronbassett/sometimes | sometimes/decorators.py | sometimesish | def sometimesish(fn):
"""
Has a 50/50 chance of calling a function
"""
def wrapped(*args, **kwargs):
if random.randint(1, 2) == 1:
return fn(*args, **kwargs)
return wrapped | python | def sometimesish(fn):
"""
Has a 50/50 chance of calling a function
"""
def wrapped(*args, **kwargs):
if random.randint(1, 2) == 1:
return fn(*args, **kwargs)
return wrapped | [
"def",
"sometimesish",
"(",
"fn",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"random",
".",
"randint",
"(",
"1",
",",
"2",
")",
"==",
"1",
":",
"return",
"fn",
"(",
"*",
"args",
",",
"*",
"*",
"kwar... | Has a 50/50 chance of calling a function | [
"Has",
"a",
"50",
"/",
"50",
"chance",
"of",
"calling",
"a",
"function"
] | train | https://github.com/aaronbassett/sometimes/blob/d71959c4bdf5643a1d1e4e60f719da94406df6e6/sometimes/decorators.py#L24-L32 |
aaronbassett/sometimes | sometimes/decorators.py | percent_of_the_time | def percent_of_the_time(p):
"""
Function has a X percentage chance of running
"""
def decorator(fn):
def wrapped(*args, **kwargs):
if in_percentage(p):
fn(*args, **kwargs)
return wrapped
return decorator | python | def percent_of_the_time(p):
"""
Function has a X percentage chance of running
"""
def decorator(fn):
def wrapped(*args, **kwargs):
if in_percentage(p):
fn(*args, **kwargs)
return wrapped
return decorator | [
"def",
"percent_of_the_time",
"(",
"p",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"in_percentage",
"(",
"p",
")",
":",
"fn",
"(",
"*",
"args",
",",
"*",
"*",
... | Function has a X percentage chance of running | [
"Function",
"has",
"a",
"X",
"percentage",
"chance",
"of",
"running"
] | train | https://github.com/aaronbassett/sometimes/blob/d71959c4bdf5643a1d1e4e60f719da94406df6e6/sometimes/decorators.py#L35-L47 |
aaronbassett/sometimes | sometimes/decorators.py | rarely | def rarely(fn):
"""
Only 5% chance of happening
"""
def wrapped(*args, **kwargs):
if in_percentage(5):
fn(*args, **kwargs)
return wrapped | python | def rarely(fn):
"""
Only 5% chance of happening
"""
def wrapped(*args, **kwargs):
if in_percentage(5):
fn(*args, **kwargs)
return wrapped | [
"def",
"rarely",
"(",
"fn",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"in_percentage",
"(",
"5",
")",
":",
"fn",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"return",
"wrapped"
] | Only 5% chance of happening | [
"Only",
"5%",
"chance",
"of",
"happening"
] | train | https://github.com/aaronbassett/sometimes/blob/d71959c4bdf5643a1d1e4e60f719da94406df6e6/sometimes/decorators.py#L50-L57 |
aaronbassett/sometimes | sometimes/decorators.py | mostly | def mostly(fn):
"""
95% chance of happening
"""
def wrapped(*args, **kwargs):
if in_percentage(95):
fn(*args, **kwargs)
return wrapped | python | def mostly(fn):
"""
95% chance of happening
"""
def wrapped(*args, **kwargs):
if in_percentage(95):
fn(*args, **kwargs)
return wrapped | [
"def",
"mostly",
"(",
"fn",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"in_percentage",
"(",
"95",
")",
":",
"fn",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"return",
"wrapped"
] | 95% chance of happening | [
"95%",
"chance",
"of",
"happening"
] | train | https://github.com/aaronbassett/sometimes/blob/d71959c4bdf5643a1d1e4e60f719da94406df6e6/sometimes/decorators.py#L60-L67 |
aaronbassett/sometimes | sometimes/decorators.py | times | def times(x, y):
"""
Do something a random amount of times
between x & y
"""
def decorator(fn):
def wrapped(*args, **kwargs):
n = random.randint(x, y)
for z in range(1, n):
fn(*args, **kwargs)
return wrapped
return decorator | python | def times(x, y):
"""
Do something a random amount of times
between x & y
"""
def decorator(fn):
def wrapped(*args, **kwargs):
n = random.randint(x, y)
for z in range(1, n):
fn(*args, **kwargs)
return wrapped
return decorator | [
"def",
"times",
"(",
"x",
",",
"y",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"def",
"wrapped",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"n",
"=",
"random",
".",
"randint",
"(",
"x",
",",
"y",
")",
"for",
"z",
"in",
"ra... | Do something a random amount of times
between x & y | [
"Do",
"something",
"a",
"random",
"amount",
"of",
"times",
"between",
"x",
"&",
"y"
] | train | https://github.com/aaronbassett/sometimes/blob/d71959c4bdf5643a1d1e4e60f719da94406df6e6/sometimes/decorators.py#L70-L84 |
6809/dragonlib | dragonlib/core/basic.py | BasicTokenUtil.ascii2token | def ascii2token(self, ascii_code, debug=False):
"""
TODO: replace no tokens in comments and strings
"""
log.info(repr(ascii_code))
parts = self.regex.split(ascii_code)
log.info(repr(parts))
tokens = []
for part in parts:
if not part:
... | python | def ascii2token(self, ascii_code, debug=False):
"""
TODO: replace no tokens in comments and strings
"""
log.info(repr(ascii_code))
parts = self.regex.split(ascii_code)
log.info(repr(parts))
tokens = []
for part in parts:
if not part:
... | [
"def",
"ascii2token",
"(",
"self",
",",
"ascii_code",
",",
"debug",
"=",
"False",
")",
":",
"log",
".",
"info",
"(",
"repr",
"(",
"ascii_code",
")",
")",
"parts",
"=",
"self",
".",
"regex",
".",
"split",
"(",
"ascii_code",
")",
"log",
".",
"info",
... | TODO: replace no tokens in comments and strings | [
"TODO",
":",
"replace",
"no",
"tokens",
"in",
"comments",
"and",
"strings"
] | train | https://github.com/6809/dragonlib/blob/faa4011e76c5857db96efdb4199e2fd49711e999/dragonlib/core/basic.py#L75-L97 |
6809/dragonlib | dragonlib/core/basic.py | BasicTokenUtil.pformat_tokens | def pformat_tokens(self, tokens):
"""
format a tokenized BASIC program line. Useful for debugging.
returns a list of formated string lines.
"""
result = []
for token_value in self.iter_token_values(tokens):
char = self.token2ascii(token_value)
if t... | python | def pformat_tokens(self, tokens):
"""
format a tokenized BASIC program line. Useful for debugging.
returns a list of formated string lines.
"""
result = []
for token_value in self.iter_token_values(tokens):
char = self.token2ascii(token_value)
if t... | [
"def",
"pformat_tokens",
"(",
"self",
",",
"tokens",
")",
":",
"result",
"=",
"[",
"]",
"for",
"token_value",
"in",
"self",
".",
"iter_token_values",
"(",
"tokens",
")",
":",
"char",
"=",
"self",
".",
"token2ascii",
"(",
"token_value",
")",
"if",
"token_... | format a tokenized BASIC program line. Useful for debugging.
returns a list of formated string lines. | [
"format",
"a",
"tokenized",
"BASIC",
"program",
"line",
".",
"Useful",
"for",
"debugging",
".",
"returns",
"a",
"list",
"of",
"formated",
"string",
"lines",
"."
] | train | https://github.com/6809/dragonlib/blob/faa4011e76c5857db96efdb4199e2fd49711e999/dragonlib/core/basic.py#L136-L149 |
6809/dragonlib | dragonlib/core/basic.py | BasicLine.token_load | def token_load(self, line_number, tokens):
self.line_number = line_number
assert tokens[-1] == 0x00, "line code %s doesn't ends with \\x00: %s" % (
repr(tokens), repr(tokens[-1])
)
"""
NOTE: The BASIC interpreter changed REM shortcut and ELSE
internaly:
... | python | def token_load(self, line_number, tokens):
self.line_number = line_number
assert tokens[-1] == 0x00, "line code %s doesn't ends with \\x00: %s" % (
repr(tokens), repr(tokens[-1])
)
"""
NOTE: The BASIC interpreter changed REM shortcut and ELSE
internaly:
... | [
"def",
"token_load",
"(",
"self",
",",
"line_number",
",",
"tokens",
")",
":",
"self",
".",
"line_number",
"=",
"line_number",
"assert",
"tokens",
"[",
"-",
"1",
"]",
"==",
"0x00",
",",
"\"line code %s doesn't ends with \\\\x00: %s\"",
"%",
"(",
"repr",
"(",
... | NOTE: The BASIC interpreter changed REM shortcut and ELSE
internaly:
"'" <-> ":'"
"ELSE" <-> ":ELSE"
See also:
http://archive.worldofdragon.org/phpBB3/viewtopic.php?f=8&t=4310&p=11632#p11630 | [
"NOTE",
":",
"The",
"BASIC",
"interpreter",
"changed",
"REM",
"shortcut",
"and",
"ELSE",
"internaly",
":",
"<",
"-",
">",
":",
"ELSE",
"<",
"-",
">",
":",
"ELSE"
] | train | https://github.com/6809/dragonlib/blob/faa4011e76c5857db96efdb4199e2fd49711e999/dragonlib/core/basic.py#L169-L192 |
6809/dragonlib | dragonlib/core/basic.py | BasicListing.pformat_program_dump | def pformat_program_dump(self, program_dump, program_start, formated_dump=None):
"""
format a BASIC program dump. Useful for debugging.
returns a list of formated string lines.
"""
if formated_dump is None:
formated_dump = []
formated_dump.append(
... | python | def pformat_program_dump(self, program_dump, program_start, formated_dump=None):
"""
format a BASIC program dump. Useful for debugging.
returns a list of formated string lines.
"""
if formated_dump is None:
formated_dump = []
formated_dump.append(
... | [
"def",
"pformat_program_dump",
"(",
"self",
",",
"program_dump",
",",
"program_start",
",",
"formated_dump",
"=",
"None",
")",
":",
"if",
"formated_dump",
"is",
"None",
":",
"formated_dump",
"=",
"[",
"]",
"formated_dump",
".",
"append",
"(",
"\"program start ad... | format a BASIC program dump. Useful for debugging.
returns a list of formated string lines. | [
"format",
"a",
"BASIC",
"program",
"dump",
".",
"Useful",
"for",
"debugging",
".",
"returns",
"a",
"list",
"of",
"formated",
"string",
"lines",
"."
] | train | https://github.com/6809/dragonlib/blob/faa4011e76c5857db96efdb4199e2fd49711e999/dragonlib/core/basic.py#L353-L396 |
6809/dragonlib | dragonlib/core/basic.py | RenumTool.get_destinations | def get_destinations(self, ascii_listing):
"""
returns all line numbers that are used in a jump.
"""
self.destinations = set()
def collect_destinations(matchobj):
numbers = matchobj.group("no")
if numbers:
self.destinations.update(set(
... | python | def get_destinations(self, ascii_listing):
"""
returns all line numbers that are used in a jump.
"""
self.destinations = set()
def collect_destinations(matchobj):
numbers = matchobj.group("no")
if numbers:
self.destinations.update(set(
... | [
"def",
"get_destinations",
"(",
"self",
",",
"ascii_listing",
")",
":",
"self",
".",
"destinations",
"=",
"set",
"(",
")",
"def",
"collect_destinations",
"(",
"matchobj",
")",
":",
"numbers",
"=",
"matchobj",
".",
"group",
"(",
"\"no\"",
")",
"if",
"number... | returns all line numbers that are used in a jump. | [
"returns",
"all",
"line",
"numbers",
"that",
"are",
"used",
"in",
"a",
"jump",
"."
] | train | https://github.com/6809/dragonlib/blob/faa4011e76c5857db96efdb4199e2fd49711e999/dragonlib/core/basic.py#L451-L466 |
majerteam/sqla_inspect | sqla_inspect/excel.py | get_cell_format | def get_cell_format(column_dict, key=None):
"""
Return the cell format for the given column
:param column_dict: The column datas collected during inspection
:param key: The exportation key
"""
format = column_dict.get('format')
prop = column_dict.get('__col__')
if format is None and pr... | python | def get_cell_format(column_dict, key=None):
"""
Return the cell format for the given column
:param column_dict: The column datas collected during inspection
:param key: The exportation key
"""
format = column_dict.get('format')
prop = column_dict.get('__col__')
if format is None and pr... | [
"def",
"get_cell_format",
"(",
"column_dict",
",",
"key",
"=",
"None",
")",
":",
"format",
"=",
"column_dict",
".",
"get",
"(",
"'format'",
")",
"prop",
"=",
"column_dict",
".",
"get",
"(",
"'__col__'",
")",
"if",
"format",
"is",
"None",
"and",
"prop",
... | Return the cell format for the given column
:param column_dict: The column datas collected during inspection
:param key: The exportation key | [
"Return",
"the",
"cell",
"format",
"for",
"the",
"given",
"column"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L189-L204 |
majerteam/sqla_inspect | sqla_inspect/excel.py | XlsWriter.save_book | def save_book(self, f_buf=None):
"""
Return a file buffer containing the resulting xls
:param obj f_buf: A file buffer supporting the write and seek
methods
"""
if f_buf is None:
f_buf = StringIO.StringIO()
f_buf.write(openpyxl.writer.excel.save_virtu... | python | def save_book(self, f_buf=None):
"""
Return a file buffer containing the resulting xls
:param obj f_buf: A file buffer supporting the write and seek
methods
"""
if f_buf is None:
f_buf = StringIO.StringIO()
f_buf.write(openpyxl.writer.excel.save_virtu... | [
"def",
"save_book",
"(",
"self",
",",
"f_buf",
"=",
"None",
")",
":",
"if",
"f_buf",
"is",
"None",
":",
"f_buf",
"=",
"StringIO",
".",
"StringIO",
"(",
")",
"f_buf",
".",
"write",
"(",
"openpyxl",
".",
"writer",
".",
"excel",
".",
"save_virtual_workboo... | Return a file buffer containing the resulting xls
:param obj f_buf: A file buffer supporting the write and seek
methods | [
"Return",
"a",
"file",
"buffer",
"containing",
"the",
"resulting",
"xls"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L70-L81 |
majerteam/sqla_inspect | sqla_inspect/excel.py | XlsWriter.set_color | def set_color(self, cell, color):
"""
Set the given color to the provided cell
cell
A xls cell object
color
A openpyxl color var
"""
cell.style = cell.style.copy(font=Font(color=Color(rgb=color))) | python | def set_color(self, cell, color):
"""
Set the given color to the provided cell
cell
A xls cell object
color
A openpyxl color var
"""
cell.style = cell.style.copy(font=Font(color=Color(rgb=color))) | [
"def",
"set_color",
"(",
"self",
",",
"cell",
",",
"color",
")",
":",
"cell",
".",
"style",
"=",
"cell",
".",
"style",
".",
"copy",
"(",
"font",
"=",
"Font",
"(",
"color",
"=",
"Color",
"(",
"rgb",
"=",
"color",
")",
")",
")"
] | Set the given color to the provided cell
cell
A xls cell object
color
A openpyxl color var | [
"Set",
"the",
"given",
"color",
"to",
"the",
"provided",
"cell"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L83-L95 |
majerteam/sqla_inspect | sqla_inspect/excel.py | XlsWriter.format_row | def format_row(self, row):
"""
The render method expects rows as lists, here we switch our row format
from dict to list respecting the order of the headers
"""
res = []
headers = getattr(self, 'headers', [])
for column in headers:
column_name = column[... | python | def format_row(self, row):
"""
The render method expects rows as lists, here we switch our row format
from dict to list respecting the order of the headers
"""
res = []
headers = getattr(self, 'headers', [])
for column in headers:
column_name = column[... | [
"def",
"format_row",
"(",
"self",
",",
"row",
")",
":",
"res",
"=",
"[",
"]",
"headers",
"=",
"getattr",
"(",
"self",
",",
"'headers'",
",",
"[",
"]",
")",
"for",
"column",
"in",
"headers",
":",
"column_name",
"=",
"column",
"[",
"'name'",
"]",
"va... | The render method expects rows as lists, here we switch our row format
from dict to list respecting the order of the headers | [
"The",
"render",
"method",
"expects",
"rows",
"as",
"lists",
"here",
"we",
"switch",
"our",
"row",
"format",
"from",
"dict",
"to",
"list",
"respecting",
"the",
"order",
"of",
"the",
"headers"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L97-L110 |
majerteam/sqla_inspect | sqla_inspect/excel.py | XlsWriter._render_rows | def _render_rows(self):
"""
Render the rows in the current stylesheet
"""
_datas = getattr(self, '_datas', ())
headers = getattr(self, 'headers', ())
for index, row in enumerate(_datas):
row_number = index + 2
for col_num, value in enumerate(row):
... | python | def _render_rows(self):
"""
Render the rows in the current stylesheet
"""
_datas = getattr(self, '_datas', ())
headers = getattr(self, 'headers', ())
for index, row in enumerate(_datas):
row_number = index + 2
for col_num, value in enumerate(row):
... | [
"def",
"_render_rows",
"(",
"self",
")",
":",
"_datas",
"=",
"getattr",
"(",
"self",
",",
"'_datas'",
",",
"(",
")",
")",
"headers",
"=",
"getattr",
"(",
"self",
",",
"'headers'",
",",
"(",
")",
")",
"for",
"index",
",",
"row",
"in",
"enumerate",
"... | Render the rows in the current stylesheet | [
"Render",
"the",
"rows",
"in",
"the",
"current",
"stylesheet"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L130-L148 |
majerteam/sqla_inspect | sqla_inspect/excel.py | XlsWriter._render_headers | def _render_headers(self):
"""
Write the headers row
"""
headers = getattr(self, 'headers', ())
for index, col in enumerate(headers):
# We write the headers
cell = self.worksheet.cell(row=1, column=index + 1)
cell.value = col['label']
... | python | def _render_headers(self):
"""
Write the headers row
"""
headers = getattr(self, 'headers', ())
for index, col in enumerate(headers):
# We write the headers
cell = self.worksheet.cell(row=1, column=index + 1)
cell.value = col['label']
... | [
"def",
"_render_headers",
"(",
"self",
")",
":",
"headers",
"=",
"getattr",
"(",
"self",
",",
"'headers'",
",",
"(",
")",
")",
"for",
"index",
",",
"col",
"in",
"enumerate",
"(",
"headers",
")",
":",
"# We write the headers",
"cell",
"=",
"self",
".",
... | Write the headers row | [
"Write",
"the",
"headers",
"row"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L150-L165 |
majerteam/sqla_inspect | sqla_inspect/excel.py | SqlaXlsExporter._get_related_exporter | def _get_related_exporter(self, related_obj, column):
"""
returns an SqlaXlsExporter for the given related object and stores it in
the column object as a cache
"""
result = column.get('sqla_xls_exporter')
if result is None:
worksheet = self.book.create_sheet(
... | python | def _get_related_exporter(self, related_obj, column):
"""
returns an SqlaXlsExporter for the given related object and stores it in
the column object as a cache
"""
result = column.get('sqla_xls_exporter')
if result is None:
worksheet = self.book.create_sheet(
... | [
"def",
"_get_related_exporter",
"(",
"self",
",",
"related_obj",
",",
"column",
")",
":",
"result",
"=",
"column",
".",
"get",
"(",
"'sqla_xls_exporter'",
")",
"if",
"result",
"is",
"None",
":",
"worksheet",
"=",
"self",
".",
"book",
".",
"create_sheet",
"... | returns an SqlaXlsExporter for the given related object and stores it in
the column object as a cache | [
"returns",
"an",
"SqlaXlsExporter",
"for",
"the",
"given",
"related",
"object",
"and",
"stores",
"it",
"in",
"the",
"column",
"object",
"as",
"a",
"cache"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L258-L272 |
majerteam/sqla_inspect | sqla_inspect/excel.py | SqlaXlsExporter._populate | def _populate(self):
"""
Enhance the default populate script by handling related elements
"""
XlsWriter._populate(self)
for header in self.headers:
if "sqla_xls_exporter" in header:
header['sqla_xls_exporter']._populate() | python | def _populate(self):
"""
Enhance the default populate script by handling related elements
"""
XlsWriter._populate(self)
for header in self.headers:
if "sqla_xls_exporter" in header:
header['sqla_xls_exporter']._populate() | [
"def",
"_populate",
"(",
"self",
")",
":",
"XlsWriter",
".",
"_populate",
"(",
"self",
")",
"for",
"header",
"in",
"self",
".",
"headers",
":",
"if",
"\"sqla_xls_exporter\"",
"in",
"header",
":",
"header",
"[",
"'sqla_xls_exporter'",
"]",
".",
"_populate",
... | Enhance the default populate script by handling related elements | [
"Enhance",
"the",
"default",
"populate",
"script",
"by",
"handling",
"related",
"elements"
] | train | https://github.com/majerteam/sqla_inspect/blob/67edb5541e6a56b0a657d3774d1e19c1110cd402/sqla_inspect/excel.py#L301-L308 |
Brazelton-Lab/bio_utils | bio_utils/blast_tools/retrieve_subject_sequences.py | subject_sequence_retriever | def subject_sequence_retriever(fasta_handle, b6_handle, e_value,
*args, **kwargs):
"""Returns FASTA entries for subject sequences from BLAST hits
Stores B6/M8 entries with E-Values below the e_value cutoff. Then iterates
through the FASTA file and if an entry matches the subj... | python | def subject_sequence_retriever(fasta_handle, b6_handle, e_value,
*args, **kwargs):
"""Returns FASTA entries for subject sequences from BLAST hits
Stores B6/M8 entries with E-Values below the e_value cutoff. Then iterates
through the FASTA file and if an entry matches the subj... | [
"def",
"subject_sequence_retriever",
"(",
"fasta_handle",
",",
"b6_handle",
",",
"e_value",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"filtered_b6",
"=",
"defaultdict",
"(",
"list",
")",
"for",
"entry",
"in",
"b6_evalue_filter",
"(",
"b6_handle",
... | Returns FASTA entries for subject sequences from BLAST hits
Stores B6/M8 entries with E-Values below the e_value cutoff. Then iterates
through the FASTA file and if an entry matches the subject of an B6/M8
entry, it's sequence is extracted and returned as a FASTA entry
plus the E-Value.
Args:
... | [
"Returns",
"FASTA",
"entries",
"for",
"subject",
"sequences",
"from",
"BLAST",
"hits"
] | train | https://github.com/Brazelton-Lab/bio_utils/blob/5a7ddf13ee0bf4baaaeb6b2b99e01bf74aa132b7/bio_utils/blast_tools/retrieve_subject_sequences.py#L44-L106 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.get_table_schema | def get_table_schema(self, tname):
''' Returns a list of column names of the provided table name '''
tname = self._check_tname(tname, noload=True)
if tname not in self._schemas:
raise ValueError('Table "%s" not found in schema store' % tname)
return list(self._schemas[tname]) | python | def get_table_schema(self, tname):
''' Returns a list of column names of the provided table name '''
tname = self._check_tname(tname, noload=True)
if tname not in self._schemas:
raise ValueError('Table "%s" not found in schema store' % tname)
return list(self._schemas[tname]) | [
"def",
"get_table_schema",
"(",
"self",
",",
"tname",
")",
":",
"tname",
"=",
"self",
".",
"_check_tname",
"(",
"tname",
",",
"noload",
"=",
"True",
")",
"if",
"tname",
"not",
"in",
"self",
".",
"_schemas",
":",
"raise",
"ValueError",
"(",
"'Table \"%s\"... | Returns a list of column names of the provided table name | [
"Returns",
"a",
"list",
"of",
"column",
"names",
"of",
"the",
"provided",
"table",
"name"
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L142-L147 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.load | def load(self, table_names=None, table_schemas=None, table_rowgens=None):
'''
Initiates the tables, schemas and record generators for this database.
Parameters
----------
table_names : list of str, str or None
List of tables to load into this database. If `auto_load`... | python | def load(self, table_names=None, table_schemas=None, table_rowgens=None):
'''
Initiates the tables, schemas and record generators for this database.
Parameters
----------
table_names : list of str, str or None
List of tables to load into this database. If `auto_load`... | [
"def",
"load",
"(",
"self",
",",
"table_names",
"=",
"None",
",",
"table_schemas",
"=",
"None",
",",
"table_rowgens",
"=",
"None",
")",
":",
"# Check for table schemas",
"if",
"table_schemas",
"is",
"not",
"None",
":",
"table_schemas",
"=",
"self",
".",
"_ch... | Initiates the tables, schemas and record generators for this database.
Parameters
----------
table_names : list of str, str or None
List of tables to load into this database. If `auto_load` is true, inserting a record
into a new table not provided here will automatically... | [
"Initiates",
"the",
"tables",
"schemas",
"and",
"record",
"generators",
"for",
"this",
"database",
"."
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L160-L253 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.drop | def drop(self, table_names):
'''
Drops the provided table(s) from this database.
Parameters
----------
table_names : list of str, str or None
Table(s) to be dropped
'''
table_names = self._check_table_names(table_names)
for tname in table_nam... | python | def drop(self, table_names):
'''
Drops the provided table(s) from this database.
Parameters
----------
table_names : list of str, str or None
Table(s) to be dropped
'''
table_names = self._check_table_names(table_names)
for tname in table_nam... | [
"def",
"drop",
"(",
"self",
",",
"table_names",
")",
":",
"table_names",
"=",
"self",
".",
"_check_table_names",
"(",
"table_names",
")",
"for",
"tname",
"in",
"table_names",
":",
"tname",
"=",
"self",
".",
"_check_tname",
"(",
"tname",
",",
"noload",
"=",... | Drops the provided table(s) from this database.
Parameters
----------
table_names : list of str, str or None
Table(s) to be dropped | [
"Drops",
"the",
"provided",
"table",
"(",
"s",
")",
"from",
"this",
"database",
"."
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L255-L279 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.drop_all | def drop_all(self):
''' Drops all tables from this database '''
self.drop(self.get_table_names())
if self.persistent:
with self._lock:
try:
dbfolder = os.path.join(self.root_dir, self.name)
if os.path.exists(dbfolder) and not os... | python | def drop_all(self):
''' Drops all tables from this database '''
self.drop(self.get_table_names())
if self.persistent:
with self._lock:
try:
dbfolder = os.path.join(self.root_dir, self.name)
if os.path.exists(dbfolder) and not os... | [
"def",
"drop_all",
"(",
"self",
")",
":",
"self",
".",
"drop",
"(",
"self",
".",
"get_table_names",
"(",
")",
")",
"if",
"self",
".",
"persistent",
":",
"with",
"self",
".",
"_lock",
":",
"try",
":",
"dbfolder",
"=",
"os",
".",
"path",
".",
"join",... | Drops all tables from this database | [
"Drops",
"all",
"tables",
"from",
"this",
"database"
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L281-L293 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.find | def find(self, tname, where=None, where_not=None, columns=None, astype=None):
'''
Find records in the provided table from the database. If no records are found, return empty
list, str or dataframe depending on the value of `astype`.
Parameters
----------
tname : str
... | python | def find(self, tname, where=None, where_not=None, columns=None, astype=None):
'''
Find records in the provided table from the database. If no records are found, return empty
list, str or dataframe depending on the value of `astype`.
Parameters
----------
tname : str
... | [
"def",
"find",
"(",
"self",
",",
"tname",
",",
"where",
"=",
"None",
",",
"where_not",
"=",
"None",
",",
"columns",
"=",
"None",
",",
"astype",
"=",
"None",
")",
":",
"try",
":",
"# Find is inherently read-only so don't try to autoload table",
"tname",
"=",
... | Find records in the provided table from the database. If no records are found, return empty
list, str or dataframe depending on the value of `astype`.
Parameters
----------
tname : str
Table to search records from.
where : dict or None (default `None`)
Di... | [
"Find",
"records",
"in",
"the",
"provided",
"table",
"from",
"the",
"database",
".",
"If",
"no",
"records",
"are",
"found",
"return",
"empty",
"list",
"str",
"or",
"dataframe",
"depending",
"on",
"the",
"value",
"of",
"astype",
"."
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L401-L471 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.find_one | def find_one(self, tname, where=None, where_not=None, columns=None, astype=None):
'''
Find a single record in the provided table from the database. If multiple match, return
the first one based on the internal order of the records. If no records are found, return
empty dictionary, string... | python | def find_one(self, tname, where=None, where_not=None, columns=None, astype=None):
'''
Find a single record in the provided table from the database. If multiple match, return
the first one based on the internal order of the records. If no records are found, return
empty dictionary, string... | [
"def",
"find_one",
"(",
"self",
",",
"tname",
",",
"where",
"=",
"None",
",",
"where_not",
"=",
"None",
",",
"columns",
"=",
"None",
",",
"astype",
"=",
"None",
")",
":",
"records",
"=",
"self",
".",
"find",
"(",
"tname",
",",
"where",
"=",
"where"... | Find a single record in the provided table from the database. If multiple match, return
the first one based on the internal order of the records. If no records are found, return
empty dictionary, string or series depending on the value of `astype`.
Parameters
----------
tname : ... | [
"Find",
"a",
"single",
"record",
"in",
"the",
"provided",
"table",
"from",
"the",
"database",
".",
"If",
"multiple",
"match",
"return",
"the",
"first",
"one",
"based",
"on",
"the",
"internal",
"order",
"of",
"the",
"records",
".",
"If",
"no",
"records",
... | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L473-L525 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.delete | def delete(self, tname, where=None, where_not=None, columns=None, astype=None):
'''
Delete records from the provided table. Parameters, matching and output are identical to
`find()`.
Parameters
----------
tname : str
Table to delete records from.
wher... | python | def delete(self, tname, where=None, where_not=None, columns=None, astype=None):
'''
Delete records from the provided table. Parameters, matching and output are identical to
`find()`.
Parameters
----------
tname : str
Table to delete records from.
wher... | [
"def",
"delete",
"(",
"self",
",",
"tname",
",",
"where",
"=",
"None",
",",
"where_not",
"=",
"None",
",",
"columns",
"=",
"None",
",",
"astype",
"=",
"None",
")",
":",
"tname",
"=",
"self",
".",
"_check_tname",
"(",
"tname",
")",
"where",
"=",
"Pa... | Delete records from the provided table. Parameters, matching and output are identical to
`find()`.
Parameters
----------
tname : str
Table to delete records from.
where : dict or None (default `None`)
Dictionary of <column, value> where value can be of st... | [
"Delete",
"records",
"from",
"the",
"provided",
"table",
".",
"Parameters",
"matching",
"and",
"output",
"are",
"identical",
"to",
"find",
"()",
"."
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L527-L578 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.insert | def insert(self, tname, record=None, columns=None, astype=None):
'''
Inserts record into the provided table from the database. Returns inserted record as
list, str or series depending on the value of `astype`.
Parameters
----------
tname : str
Table to insert... | python | def insert(self, tname, record=None, columns=None, astype=None):
'''
Inserts record into the provided table from the database. Returns inserted record as
list, str or series depending on the value of `astype`.
Parameters
----------
tname : str
Table to insert... | [
"def",
"insert",
"(",
"self",
",",
"tname",
",",
"record",
"=",
"None",
",",
"columns",
"=",
"None",
",",
"astype",
"=",
"None",
")",
":",
"tname",
"=",
"self",
".",
"_check_tname",
"(",
"tname",
")",
"record",
"=",
"PandasDatabase",
".",
"_check_dict_... | Inserts record into the provided table from the database. Returns inserted record as
list, str or series depending on the value of `astype`.
Parameters
----------
tname : str
Table to insert records into.
where : dict or None (default `None`)
Dictionary o... | [
"Inserts",
"record",
"into",
"the",
"provided",
"table",
"from",
"the",
"database",
".",
"Returns",
"inserted",
"record",
"as",
"list",
"str",
"or",
"series",
"depending",
"on",
"the",
"value",
"of",
"astype",
"."
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L599-L664 |
omtinez/pddb | pddb/pddb.py | PandasDatabase.upsert | def upsert(self, tname, record=None, where=None, where_not=None, columns=None, astype=None):
'''
Attempts to update records in the provided table from the database. If none are found,
inserts new record that would match all the conditions. Returns updated or inserted record
as list, dict... | python | def upsert(self, tname, record=None, where=None, where_not=None, columns=None, astype=None):
'''
Attempts to update records in the provided table from the database. If none are found,
inserts new record that would match all the conditions. Returns updated or inserted record
as list, dict... | [
"def",
"upsert",
"(",
"self",
",",
"tname",
",",
"record",
"=",
"None",
",",
"where",
"=",
"None",
",",
"where_not",
"=",
"None",
",",
"columns",
"=",
"None",
",",
"astype",
"=",
"None",
")",
":",
"tname",
"=",
"self",
".",
"_check_tname",
"(",
"tn... | Attempts to update records in the provided table from the database. If none are found,
inserts new record that would match all the conditions. Returns updated or inserted record
as list, dict, str, dataframe or series depending on the value of `astype`.
Parameters
----------
tna... | [
"Attempts",
"to",
"update",
"records",
"in",
"the",
"provided",
"table",
"from",
"the",
"database",
".",
"If",
"none",
"are",
"found",
"inserts",
"new",
"record",
"that",
"would",
"match",
"all",
"the",
"conditions",
".",
"Returns",
"updated",
"or",
"inserte... | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L666-L770 |
omtinez/pddb | pddb/pddb.py | PandasDatabase._request | def _request(request, request_fallback=None):
''' Extract request fields wherever they may come from: GET, POST, forms, fallback '''
# Use lambdas to avoid evaluating bottle.request.* which may throw an Error
all_dicts = [
lambda: request.json,
lambda: request.forms,
... | python | def _request(request, request_fallback=None):
''' Extract request fields wherever they may come from: GET, POST, forms, fallback '''
# Use lambdas to avoid evaluating bottle.request.* which may throw an Error
all_dicts = [
lambda: request.json,
lambda: request.forms,
... | [
"def",
"_request",
"(",
"request",
",",
"request_fallback",
"=",
"None",
")",
":",
"# Use lambdas to avoid evaluating bottle.request.* which may throw an Error",
"all_dicts",
"=",
"[",
"lambda",
":",
"request",
".",
"json",
",",
"lambda",
":",
"request",
".",
"forms",... | Extract request fields wherever they may come from: GET, POST, forms, fallback | [
"Extract",
"request",
"fields",
"wherever",
"they",
"may",
"come",
"from",
":",
"GET",
"POST",
"forms",
"fallback"
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L947-L967 |
omtinez/pddb | pddb/pddb.py | PandasDatabase._extract_params | def _extract_params(request_dict, param_list, param_fallback=False):
''' Extract pddb parameters from request '''
if not param_list or not request_dict:
return dict()
query = dict()
for param in param_list:
# Retrieve all items in the form of {param: value} and
... | python | def _extract_params(request_dict, param_list, param_fallback=False):
''' Extract pddb parameters from request '''
if not param_list or not request_dict:
return dict()
query = dict()
for param in param_list:
# Retrieve all items in the form of {param: value} and
... | [
"def",
"_extract_params",
"(",
"request_dict",
",",
"param_list",
",",
"param_fallback",
"=",
"False",
")",
":",
"if",
"not",
"param_list",
"or",
"not",
"request_dict",
":",
"return",
"dict",
"(",
")",
"query",
"=",
"dict",
"(",
")",
"for",
"param",
"in",
... | Extract pddb parameters from request | [
"Extract",
"pddb",
"parameters",
"from",
"request"
] | train | https://github.com/omtinez/pddb/blob/a24cee0702c8286c5c466c51ca65cf8dbc2c183c/pddb/pddb.py#L970-L997 |
flipagram/smarterling | smarterling/__init__.py | sha1 | def sha1(s):
""" Returns a sha1 of the given string
"""
h = hashlib.new('sha1')
h.update(s)
return h.hexdigest() | python | def sha1(s):
""" Returns a sha1 of the given string
"""
h = hashlib.new('sha1')
h.update(s)
return h.hexdigest() | [
"def",
"sha1",
"(",
"s",
")",
":",
"h",
"=",
"hashlib",
".",
"new",
"(",
"'sha1'",
")",
"h",
".",
"update",
"(",
"s",
")",
"return",
"h",
".",
"hexdigest",
"(",
")"
] | Returns a sha1 of the given string | [
"Returns",
"a",
"sha1",
"of",
"the",
"given",
"string"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L35-L40 |
flipagram/smarterling | smarterling/__init__.py | get_translated_items | def get_translated_items(fapi, file_uri, use_cache, cache_dir=None):
""" Returns the last modified from smarterling
"""
items = None
cache_file = os.path.join(cache_dir, sha1(file_uri)) if use_cache else None
if use_cache and os.path.exists(cache_file):
print("Using cache file %s for transla... | python | def get_translated_items(fapi, file_uri, use_cache, cache_dir=None):
""" Returns the last modified from smarterling
"""
items = None
cache_file = os.path.join(cache_dir, sha1(file_uri)) if use_cache else None
if use_cache and os.path.exists(cache_file):
print("Using cache file %s for transla... | [
"def",
"get_translated_items",
"(",
"fapi",
",",
"file_uri",
",",
"use_cache",
",",
"cache_dir",
"=",
"None",
")",
":",
"items",
"=",
"None",
"cache_file",
"=",
"os",
".",
"path",
".",
"join",
"(",
"cache_dir",
",",
"sha1",
"(",
"file_uri",
")",
")",
"... | Returns the last modified from smarterling | [
"Returns",
"the",
"last",
"modified",
"from",
"smarterling"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L59-L74 |
flipagram/smarterling | smarterling/__init__.py | get_translated_file | def get_translated_file(fapi, file_uri, locale, retrieval_type, include_original_strings, use_cache, cache_dir=None):
""" Returns a translated file from smartling
"""
file_data = None
cache_name = str(file_uri)+"."+str(locale)+"."+str(retrieval_type)+"."+str(include_original_strings)
cache_file = os... | python | def get_translated_file(fapi, file_uri, locale, retrieval_type, include_original_strings, use_cache, cache_dir=None):
""" Returns a translated file from smartling
"""
file_data = None
cache_name = str(file_uri)+"."+str(locale)+"."+str(retrieval_type)+"."+str(include_original_strings)
cache_file = os... | [
"def",
"get_translated_file",
"(",
"fapi",
",",
"file_uri",
",",
"locale",
",",
"retrieval_type",
",",
"include_original_strings",
",",
"use_cache",
",",
"cache_dir",
"=",
"None",
")",
":",
"file_data",
"=",
"None",
"cache_name",
"=",
"str",
"(",
"file_uri",
"... | Returns a translated file from smartling | [
"Returns",
"a",
"translated",
"file",
"from",
"smartling"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L76-L97 |
flipagram/smarterling | smarterling/__init__.py | download_files | def download_files(fapi, file_name, conf, use_cache, cache_dir=None):
""" Downloads translated versions of the files
"""
retrieval_type = conf.get('retrieval-type', 'published')
include_original_strings = 'true' if conf.get('include-original-strings', False) else 'false'
save_pattern... | python | def download_files(fapi, file_name, conf, use_cache, cache_dir=None):
""" Downloads translated versions of the files
"""
retrieval_type = conf.get('retrieval-type', 'published')
include_original_strings = 'true' if conf.get('include-original-strings', False) else 'false'
save_pattern... | [
"def",
"download_files",
"(",
"fapi",
",",
"file_name",
",",
"conf",
",",
"use_cache",
",",
"cache_dir",
"=",
"None",
")",
":",
"retrieval_type",
"=",
"conf",
".",
"get",
"(",
"'retrieval-type'",
",",
"'published'",
")",
"include_original_strings",
"=",
"'true... | Downloads translated versions of the files | [
"Downloads",
"translated",
"versions",
"of",
"the",
"files"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L99-L186 |
flipagram/smarterling | smarterling/__init__.py | upload_file | def upload_file(fapi, file_name, conf):
""" Uploads a file to smartling
"""
if not conf.has_key('file-type'):
raise SmarterlingError("%s doesn't have a file-type" % file_name)
print("Uploading %s to smartling" % file_name)
data = UploadData(
os.path.dirname(file_name)+os.sep,
... | python | def upload_file(fapi, file_name, conf):
""" Uploads a file to smartling
"""
if not conf.has_key('file-type'):
raise SmarterlingError("%s doesn't have a file-type" % file_name)
print("Uploading %s to smartling" % file_name)
data = UploadData(
os.path.dirname(file_name)+os.sep,
... | [
"def",
"upload_file",
"(",
"fapi",
",",
"file_name",
",",
"conf",
")",
":",
"if",
"not",
"conf",
".",
"has_key",
"(",
"'file-type'",
")",
":",
"raise",
"SmarterlingError",
"(",
"\"%s doesn't have a file-type\"",
"%",
"file_name",
")",
"print",
"(",
"\"Uploadin... | Uploads a file to smartling | [
"Uploads",
"a",
"file",
"to",
"smartling"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L189-L211 |
flipagram/smarterling | smarterling/__init__.py | create_file_api | def create_file_api(conf):
""" Creates a SmartlingFileApi from the given config
"""
api_key = conf.config.get('api-key', os.environ.get('SMARTLING_API_KEY'))
project_id = conf.config.get('project-id', os.environ.get('SMARTLING_PROJECT_ID'))
if not project_id or not api_key:
raise Smarterlin... | python | def create_file_api(conf):
""" Creates a SmartlingFileApi from the given config
"""
api_key = conf.config.get('api-key', os.environ.get('SMARTLING_API_KEY'))
project_id = conf.config.get('project-id', os.environ.get('SMARTLING_PROJECT_ID'))
if not project_id or not api_key:
raise Smarterlin... | [
"def",
"create_file_api",
"(",
"conf",
")",
":",
"api_key",
"=",
"conf",
".",
"config",
".",
"get",
"(",
"'api-key'",
",",
"os",
".",
"environ",
".",
"get",
"(",
"'SMARTLING_API_KEY'",
")",
")",
"project_id",
"=",
"conf",
".",
"config",
".",
"get",
"("... | Creates a SmartlingFileApi from the given config | [
"Creates",
"a",
"SmartlingFileApi",
"from",
"the",
"given",
"config"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L213-L232 |
flipagram/smarterling | smarterling/__init__.py | parse_config | def parse_config(file_name='smarterling.config'):
""" Parses a smarterling configuration file
"""
if not os.path.exists(file_name) or not os.path.isfile(file_name):
raise SmarterlingError('Config file not found: %s' % file_name)
try:
contents = read_from_file(file_name)
contents_... | python | def parse_config(file_name='smarterling.config'):
""" Parses a smarterling configuration file
"""
if not os.path.exists(file_name) or not os.path.isfile(file_name):
raise SmarterlingError('Config file not found: %s' % file_name)
try:
contents = read_from_file(file_name)
contents_... | [
"def",
"parse_config",
"(",
"file_name",
"=",
"'smarterling.config'",
")",
":",
"if",
"not",
"os",
".",
"path",
".",
"exists",
"(",
"file_name",
")",
"or",
"not",
"os",
".",
"path",
".",
"isfile",
"(",
"file_name",
")",
":",
"raise",
"SmarterlingError",
... | Parses a smarterling configuration file | [
"Parses",
"a",
"smarterling",
"configuration",
"file"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L234-L244 |
flipagram/smarterling | smarterling/__init__.py | AttributeDict.get | def get(self, key, default_val=None, require_value=False):
""" Returns a dictionary value
"""
val = dict.get(self, key, default_val)
if val is None and require_value:
raise KeyError('key "%s" not found' % key)
if isinstance(val, dict):
return AttributeDict... | python | def get(self, key, default_val=None, require_value=False):
""" Returns a dictionary value
"""
val = dict.get(self, key, default_val)
if val is None and require_value:
raise KeyError('key "%s" not found' % key)
if isinstance(val, dict):
return AttributeDict... | [
"def",
"get",
"(",
"self",
",",
"key",
",",
"default_val",
"=",
"None",
",",
"require_value",
"=",
"False",
")",
":",
"val",
"=",
"dict",
".",
"get",
"(",
"self",
",",
"key",
",",
"default_val",
")",
"if",
"val",
"is",
"None",
"and",
"require_value",... | Returns a dictionary value | [
"Returns",
"a",
"dictionary",
"value"
] | train | https://github.com/flipagram/smarterling/blob/2ea0957edad0657ba4c54280796869ffc1031b11/smarterling/__init__.py#L25-L33 |
kervi/kervi-devices | kervi/devices/displays/SSD1306.py | _SSD1306I2CBase.reset | def reset(self):
"""Reset the display."""
if self._rst is None:
return
# Set reset high for a millisecond.
self._rst.value = True
time.sleep(0.001)
# Set reset low for 10 milliseconds.
self._rst.value = False
time.sleep(0.010)
# Set res... | python | def reset(self):
"""Reset the display."""
if self._rst is None:
return
# Set reset high for a millisecond.
self._rst.value = True
time.sleep(0.001)
# Set reset low for 10 milliseconds.
self._rst.value = False
time.sleep(0.010)
# Set res... | [
"def",
"reset",
"(",
"self",
")",
":",
"if",
"self",
".",
"_rst",
"is",
"None",
":",
"return",
"# Set reset high for a millisecond.",
"self",
".",
"_rst",
".",
"value",
"=",
"True",
"time",
".",
"sleep",
"(",
"0.001",
")",
"# Set reset low for 10 milliseconds.... | Reset the display. | [
"Reset",
"the",
"display",
"."
] | train | https://github.com/kervi/kervi-devices/blob/c6aaddc6da1d0bce0ea2b0c6eb8393ba10aefa56/kervi/devices/displays/SSD1306.py#L111-L122 |
kervi/kervi-devices | kervi/devices/displays/SSD1306.py | _SSD1306I2CBase.display | def display(self):
"""Write display buffer to physical display."""
self.command(SSD1306_COLUMNADDR)
self.command(0) # Column start address. (0 = reset)
self.command(self.width-1) # Column end address.
self.command(SSD1306_PAGEADDR)
self.command(0) ... | python | def display(self):
"""Write display buffer to physical display."""
self.command(SSD1306_COLUMNADDR)
self.command(0) # Column start address. (0 = reset)
self.command(self.width-1) # Column end address.
self.command(SSD1306_PAGEADDR)
self.command(0) ... | [
"def",
"display",
"(",
"self",
")",
":",
"self",
".",
"command",
"(",
"SSD1306_COLUMNADDR",
")",
"self",
".",
"command",
"(",
"0",
")",
"# Column start address. (0 = reset)",
"self",
".",
"command",
"(",
"self",
".",
"width",
"-",
"1",
")",
"# Column end add... | Write display buffer to physical display. | [
"Write",
"display",
"buffer",
"to",
"physical",
"display",
"."
] | train | https://github.com/kervi/kervi-devices/blob/c6aaddc6da1d0bce0ea2b0c6eb8393ba10aefa56/kervi/devices/displays/SSD1306.py#L124-L134 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter.connect_widget | def connect_widget(self, wid,
getter=None, setter=None,
signal=None, arg=None, update=True,
flavour=None):
"""
Finish set-up by connecting the widget. The model was already
specified in the constructor.
*wid* is a wid... | python | def connect_widget(self, wid,
getter=None, setter=None,
signal=None, arg=None, update=True,
flavour=None):
"""
Finish set-up by connecting the widget. The model was already
specified in the constructor.
*wid* is a wid... | [
"def",
"connect_widget",
"(",
"self",
",",
"wid",
",",
"getter",
"=",
"None",
",",
"setter",
"=",
"None",
",",
"signal",
"=",
"None",
",",
"arg",
"=",
"None",
",",
"update",
"=",
"True",
",",
"flavour",
"=",
"None",
")",
":",
"if",
"wid",
"in",
"... | Finish set-up by connecting the widget. The model was already
specified in the constructor.
*wid* is a widget instance.
*getter* is a callable. It is passed *wid* and must return its
current value.
*setter* is a callable. It is passed *wid* and the current value of
the... | [
"Finish",
"set",
"-",
"up",
"by",
"connecting",
"the",
"widget",
".",
"The",
"model",
"was",
"already",
"specified",
"in",
"the",
"constructor",
"."
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L160-L229 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter._connect_model | def _connect_model(self, model):
"""
Used internally to connect the property into the model, and
register self as a value observer for that property"""
parts = self._prop_name.split(".")
if len(parts) > 1:
# identifies the model
models = parts[:-1]
... | python | def _connect_model(self, model):
"""
Used internally to connect the property into the model, and
register self as a value observer for that property"""
parts = self._prop_name.split(".")
if len(parts) > 1:
# identifies the model
models = parts[:-1]
... | [
"def",
"_connect_model",
"(",
"self",
",",
"model",
")",
":",
"parts",
"=",
"self",
".",
"_prop_name",
".",
"split",
"(",
"\".\"",
")",
"if",
"len",
"(",
"parts",
")",
">",
"1",
":",
"# identifies the model",
"models",
"=",
"parts",
"[",
":",
"-",
"1... | Used internally to connect the property into the model, and
register self as a value observer for that property | [
"Used",
"internally",
"to",
"connect",
"the",
"property",
"into",
"the",
"model",
"and",
"register",
"self",
"as",
"a",
"value",
"observer",
"for",
"that",
"property"
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L257-L292 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter._get_observer_fun | def _get_observer_fun(self, prop_name):
"""This is the code for an value change observer"""
def _observer_fun(self, model, old, new):
if self._itsme:
return
self._on_prop_changed()
# doesn't affect stack traces
_observer_fun.__name__ = "property_%... | python | def _get_observer_fun(self, prop_name):
"""This is the code for an value change observer"""
def _observer_fun(self, model, old, new):
if self._itsme:
return
self._on_prop_changed()
# doesn't affect stack traces
_observer_fun.__name__ = "property_%... | [
"def",
"_get_observer_fun",
"(",
"self",
",",
"prop_name",
")",
":",
"def",
"_observer_fun",
"(",
"self",
",",
"model",
",",
"old",
",",
"new",
")",
":",
"if",
"self",
".",
"_itsme",
":",
"return",
"self",
".",
"_on_prop_changed",
"(",
")",
"# doesn't af... | This is the code for an value change observer | [
"This",
"is",
"the",
"code",
"for",
"an",
"value",
"change",
"observer"
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L294-L303 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter._read_property | def _read_property(self, *args):
"""
Return the model's current value, using *prop_read* if used in the
constructor.
*args* is just passed on to :meth:`_get_property`. This does nothing,
but may be used in subclasses.
"""
if self._prop_read:
return se... | python | def _read_property(self, *args):
"""
Return the model's current value, using *prop_read* if used in the
constructor.
*args* is just passed on to :meth:`_get_property`. This does nothing,
but may be used in subclasses.
"""
if self._prop_read:
return se... | [
"def",
"_read_property",
"(",
"self",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"_prop_read",
":",
"return",
"self",
".",
"_prop_read",
"(",
"self",
".",
"_get_property",
"(",
"*",
"args",
")",
")",
"return",
"self",
".",
"_get_property",
"(",
"*"... | Return the model's current value, using *prop_read* if used in the
constructor.
*args* is just passed on to :meth:`_get_property`. This does nothing,
but may be used in subclasses. | [
"Return",
"the",
"model",
"s",
"current",
"value",
"using",
"*",
"prop_read",
"*",
"if",
"used",
"in",
"the",
"constructor",
"."
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L314-L324 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter._write_property | def _write_property(self, val, *args):
"""Sets the value of property. Given val is transformed
accodingly to prop_write function when specified at
construction-time. A try to cast the value to the property
type is given."""
val_wid = val
# 'finally' would be better here, ... | python | def _write_property(self, val, *args):
"""Sets the value of property. Given val is transformed
accodingly to prop_write function when specified at
construction-time. A try to cast the value to the property
type is given."""
val_wid = val
# 'finally' would be better here, ... | [
"def",
"_write_property",
"(",
"self",
",",
"val",
",",
"*",
"args",
")",
":",
"val_wid",
"=",
"val",
"# 'finally' would be better here, but not supported in 2.4 :(",
"try",
":",
"totype",
"=",
"type",
"(",
"self",
".",
"_get_property",
"(",
"*",
"args",
")",
... | Sets the value of property. Given val is transformed
accodingly to prop_write function when specified at
construction-time. A try to cast the value to the property
type is given. | [
"Sets",
"the",
"value",
"of",
"property",
".",
"Given",
"val",
"is",
"transformed",
"accodingly",
"to",
"prop_write",
"function",
"when",
"specified",
"at",
"construction",
"-",
"time",
".",
"A",
"try",
"to",
"cast",
"the",
"value",
"to",
"the",
"property",
... | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L326-L356 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter._read_widget | def _read_widget(self):
"""Returns the value currently stored into the widget, after
transforming it accordingly to possibly specified function.
This is implemented by calling the getter provided by the
user. This method can raise InvalidValue (raised by the
getter) when the val... | python | def _read_widget(self):
"""Returns the value currently stored into the widget, after
transforming it accordingly to possibly specified function.
This is implemented by calling the getter provided by the
user. This method can raise InvalidValue (raised by the
getter) when the val... | [
"def",
"_read_widget",
"(",
"self",
")",
":",
"getter",
"=",
"self",
".",
"_wid_info",
"[",
"self",
".",
"_wid",
"]",
"[",
"0",
"]",
"return",
"getter",
"(",
"self",
".",
"_wid",
")"
] | Returns the value currently stored into the widget, after
transforming it accordingly to possibly specified function.
This is implemented by calling the getter provided by the
user. This method can raise InvalidValue (raised by the
getter) when the value in the widget must not be consid... | [
"Returns",
"the",
"value",
"currently",
"stored",
"into",
"the",
"widget",
"after",
"transforming",
"it",
"accordingly",
"to",
"possibly",
"specified",
"function",
"."
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L358-L367 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | Adapter._write_widget | def _write_widget(self, val):
"""Writes value into the widget. If specified, user setter
is invoked."""
self._itsme = True
try:
setter = self._wid_info[self._wid][1]
wtype = self._wid_info[self._wid][2]
if setter:
if wtype is not None:
... | python | def _write_widget(self, val):
"""Writes value into the widget. If specified, user setter
is invoked."""
self._itsme = True
try:
setter = self._wid_info[self._wid][1]
wtype = self._wid_info[self._wid][2]
if setter:
if wtype is not None:
... | [
"def",
"_write_widget",
"(",
"self",
",",
"val",
")",
":",
"self",
".",
"_itsme",
"=",
"True",
"try",
":",
"setter",
"=",
"self",
".",
"_wid_info",
"[",
"self",
".",
"_wid",
"]",
"[",
"1",
"]",
"wtype",
"=",
"self",
".",
"_wid_info",
"[",
"self",
... | Writes value into the widget. If specified, user setter
is invoked. | [
"Writes",
"value",
"into",
"the",
"widget",
".",
"If",
"specified",
"user",
"setter",
"is",
"invoked",
"."
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L369-L382 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | UserClassAdapter._resolve_to_func | def _resolve_to_func(self, what):
"""This method resolves whatever is passed: a string, a
bound or unbound method, a function, to make it a
function. This makes internal handling of setter and getter
uniform and easier."""
if isinstance(what, str):
what = getattr(Adap... | python | def _resolve_to_func(self, what):
"""This method resolves whatever is passed: a string, a
bound or unbound method, a function, to make it a
function. This makes internal handling of setter and getter
uniform and easier."""
if isinstance(what, str):
what = getattr(Adap... | [
"def",
"_resolve_to_func",
"(",
"self",
",",
"what",
")",
":",
"if",
"isinstance",
"(",
"what",
",",
"str",
")",
":",
"what",
"=",
"getattr",
"(",
"Adapter",
".",
"_get_property",
"(",
"self",
")",
",",
"what",
")",
"# makes it an unbounded function if neede... | This method resolves whatever is passed: a string, a
bound or unbound method, a function, to make it a
function. This makes internal handling of setter and getter
uniform and easier. | [
"This",
"method",
"resolves",
"whatever",
"is",
"passed",
":",
"a",
"string",
"a",
"bound",
"or",
"unbound",
"method",
"a",
"function",
"to",
"make",
"it",
"a",
"function",
".",
"This",
"makes",
"internal",
"handling",
"of",
"setter",
"and",
"getter",
"uni... | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L433-L447 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | UserClassAdapter._on_prop_changed | def _on_prop_changed(self, instance, meth_name, res, args, kwargs):
"""Called by the observation code, when a modifying method
is called"""
Adapter._on_prop_changed(self) | python | def _on_prop_changed(self, instance, meth_name, res, args, kwargs):
"""Called by the observation code, when a modifying method
is called"""
Adapter._on_prop_changed(self) | [
"def",
"_on_prop_changed",
"(",
"self",
",",
"instance",
",",
"meth_name",
",",
"res",
",",
"args",
",",
"kwargs",
")",
":",
"Adapter",
".",
"_on_prop_changed",
"(",
"self",
")"
] | Called by the observation code, when a modifying method
is called | [
"Called",
"by",
"the",
"observation",
"code",
"when",
"a",
"modifying",
"method",
"is",
"called"
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L459-L462 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | UserClassAdapter._get_property | def _get_property(self, *args):
"""Private method that returns the value currently stored
into the property"""
val = self._getter(Adapter._get_property(self), *args)
if self._prop_read:
return self._prop_read(val, *args)
return val | python | def _get_property(self, *args):
"""Private method that returns the value currently stored
into the property"""
val = self._getter(Adapter._get_property(self), *args)
if self._prop_read:
return self._prop_read(val, *args)
return val | [
"def",
"_get_property",
"(",
"self",
",",
"*",
"args",
")",
":",
"val",
"=",
"self",
".",
"_getter",
"(",
"Adapter",
".",
"_get_property",
"(",
"self",
")",
",",
"*",
"args",
")",
"if",
"self",
".",
"_prop_read",
":",
"return",
"self",
".",
"_prop_re... | Private method that returns the value currently stored
into the property | [
"Private",
"method",
"that",
"returns",
"the",
"value",
"currently",
"stored",
"into",
"the",
"property"
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L464-L470 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | UserClassAdapter._set_property | def _set_property(self, val, *args):
"""Private method that sets the value currently of the property"""
if self._prop_write:
val = self._prop_write(val)
return self._setter(Adapter._get_property(self), val, *args) | python | def _set_property(self, val, *args):
"""Private method that sets the value currently of the property"""
if self._prop_write:
val = self._prop_write(val)
return self._setter(Adapter._get_property(self), val, *args) | [
"def",
"_set_property",
"(",
"self",
",",
"val",
",",
"*",
"args",
")",
":",
"if",
"self",
".",
"_prop_write",
":",
"val",
"=",
"self",
".",
"_prop_write",
"(",
"val",
")",
"return",
"self",
".",
"_setter",
"(",
"Adapter",
".",
"_get_property",
"(",
... | Private method that sets the value currently of the property | [
"Private",
"method",
"that",
"sets",
"the",
"value",
"currently",
"of",
"the",
"property"
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L472-L476 |
roboogle/gtkmvc3 | gtkmvco/gtkmvc3/adapters/basic.py | RoUserClassAdapter._set_property | def _set_property(self, val, *args):
"""Private method that sets the value currently of the property"""
val = UserClassAdapter._set_property(self, val, *args)
if val:
Adapter._set_property(self, val, *args)
return val | python | def _set_property(self, val, *args):
"""Private method that sets the value currently of the property"""
val = UserClassAdapter._set_property(self, val, *args)
if val:
Adapter._set_property(self, val, *args)
return val | [
"def",
"_set_property",
"(",
"self",
",",
"val",
",",
"*",
"args",
")",
":",
"val",
"=",
"UserClassAdapter",
".",
"_set_property",
"(",
"self",
",",
"val",
",",
"*",
"args",
")",
"if",
"val",
":",
"Adapter",
".",
"_set_property",
"(",
"self",
",",
"v... | Private method that sets the value currently of the property | [
"Private",
"method",
"that",
"sets",
"the",
"value",
"currently",
"of",
"the",
"property"
] | train | https://github.com/roboogle/gtkmvc3/blob/63405fd8d2056be26af49103b13a8d5e57fe4dff/gtkmvco/gtkmvc3/adapters/basic.py#L514-L519 |
pip-services3-python/pip-services3-commons-python | pip_services3_commons/random/RandomString.py | RandomString.distort | def distort(value):
"""
Distorts a string by randomly replacing characters in it.
:param value: a string to distort.
:return: a distored string.
"""
value = value.lower()
if (RandomBoolean.chance(1, 5)):
value = value[0:1].upper() + value[1:]
... | python | def distort(value):
"""
Distorts a string by randomly replacing characters in it.
:param value: a string to distort.
:return: a distored string.
"""
value = value.lower()
if (RandomBoolean.chance(1, 5)):
value = value[0:1].upper() + value[1:]
... | [
"def",
"distort",
"(",
"value",
")",
":",
"value",
"=",
"value",
".",
"lower",
"(",
")",
"if",
"(",
"RandomBoolean",
".",
"chance",
"(",
"1",
",",
"5",
")",
")",
":",
"value",
"=",
"value",
"[",
"0",
":",
"1",
"]",
".",
"upper",
"(",
")",
"+"... | Distorts a string by randomly replacing characters in it.
:param value: a string to distort.
:return: a distored string. | [
"Distorts",
"a",
"string",
"by",
"randomly",
"replacing",
"characters",
"in",
"it",
"."
] | train | https://github.com/pip-services3-python/pip-services3-commons-python/blob/22cbbb3e91e49717f65c083d36147fdb07ba9e3b/pip_services3_commons/random/RandomString.py#L47-L63 |
pip-services3-python/pip-services3-commons-python | pip_services3_commons/random/RandomString.py | RandomString.next_string | def next_string(min_size, max_size):
"""
Generates a random string, consisting of upper and lower case letters (of the English alphabet),
digits (0-9), and symbols ("_,.:-/.[].{},#-!,$=%.+^.&*-() ").
:param min_size: (optional) minimum string length.
:param max_size: maximum st... | python | def next_string(min_size, max_size):
"""
Generates a random string, consisting of upper and lower case letters (of the English alphabet),
digits (0-9), and symbols ("_,.:-/.[].{},#-!,$=%.+^.&*-() ").
:param min_size: (optional) minimum string length.
:param max_size: maximum st... | [
"def",
"next_string",
"(",
"min_size",
",",
"max_size",
")",
":",
"result",
"=",
"''",
"max_size",
"=",
"max_size",
"if",
"max_size",
"!=",
"None",
"else",
"min_size",
"length",
"=",
"RandomInteger",
".",
"next_integer",
"(",
"min_size",
",",
"max_size",
")"... | Generates a random string, consisting of upper and lower case letters (of the English alphabet),
digits (0-9), and symbols ("_,.:-/.[].{},#-!,$=%.+^.&*-() ").
:param min_size: (optional) minimum string length.
:param max_size: maximum string length.
:return: a random string. | [
"Generates",
"a",
"random",
"string",
"consisting",
"of",
"upper",
"and",
"lower",
"case",
"letters",
"(",
"of",
"the",
"English",
"alphabet",
")",
"digits",
"(",
"0",
"-",
"9",
")",
"and",
"symbols",
"(",
"_",
".",
":",
"-",
"/",
".",
"[]",
".",
"... | train | https://github.com/pip-services3-python/pip-services3-commons-python/blob/22cbbb3e91e49717f65c083d36147fdb07ba9e3b/pip_services3_commons/random/RandomString.py#L74-L92 |
kervi/kervi-devices | kervi/devices/pwm/PCA9685.py | PCA9685DeviceDriver.pwm_start | def pwm_start(self, channel, duty_cycle=None, frequency=None):
"""
Starts the pwm signal on a channel. The channel should be defined as pwm prior to this call.
If no duty_cycle or frequency is passed in this call previous values from call to
define_as_pwm or pwm_start is used.
:... | python | def pwm_start(self, channel, duty_cycle=None, frequency=None):
"""
Starts the pwm signal on a channel. The channel should be defined as pwm prior to this call.
If no duty_cycle or frequency is passed in this call previous values from call to
define_as_pwm or pwm_start is used.
:... | [
"def",
"pwm_start",
"(",
"self",
",",
"channel",
",",
"duty_cycle",
"=",
"None",
",",
"frequency",
"=",
"None",
")",
":",
"if",
"frequency",
":",
"self",
".",
"set_pwm_freq",
"(",
"frequency",
")",
"self",
".",
"set_pwm",
"(",
"channel",
",",
"0",
",",... | Starts the pwm signal on a channel. The channel should be defined as pwm prior to this call.
If no duty_cycle or frequency is passed in this call previous values from call to
define_as_pwm or pwm_start is used.
:param channel:
The channel to start the pwm signal on.
:type c... | [
"Starts",
"the",
"pwm",
"signal",
"on",
"a",
"channel",
".",
"The",
"channel",
"should",
"be",
"defined",
"as",
"pwm",
"prior",
"to",
"this",
"call",
".",
"If",
"no",
"duty_cycle",
"or",
"frequency",
"is",
"passed",
"in",
"this",
"call",
"previous",
"val... | train | https://github.com/kervi/kervi-devices/blob/c6aaddc6da1d0bce0ea2b0c6eb8393ba10aefa56/kervi/devices/pwm/PCA9685.py#L119-L143 |
kervi/kervi-devices | kervi/devices/pwm/PCA9685.py | PCA9685DeviceDriver.set_pwm_freq | def set_pwm_freq(self, freq_hz):
"""Set the PWM frequency to the provided value in hertz."""
prescaleval = 25000000.0 # 25MHz
prescaleval /= 4096.0 # 12-bit
prescaleval /= float(freq_hz)
prescaleval -= 1.0
logger.debug('Setting PWM frequency to {0} Hz'.format(fre... | python | def set_pwm_freq(self, freq_hz):
"""Set the PWM frequency to the provided value in hertz."""
prescaleval = 25000000.0 # 25MHz
prescaleval /= 4096.0 # 12-bit
prescaleval /= float(freq_hz)
prescaleval -= 1.0
logger.debug('Setting PWM frequency to {0} Hz'.format(fre... | [
"def",
"set_pwm_freq",
"(",
"self",
",",
"freq_hz",
")",
":",
"prescaleval",
"=",
"25000000.0",
"# 25MHz",
"prescaleval",
"/=",
"4096.0",
"# 12-bit",
"prescaleval",
"/=",
"float",
"(",
"freq_hz",
")",
"prescaleval",
"-=",
"1.0",
"logger",
".",
"debug",
"(",
... | Set the PWM frequency to the provided value in hertz. | [
"Set",
"the",
"PWM",
"frequency",
"to",
"the",
"provided",
"value",
"in",
"hertz",
"."
] | train | https://github.com/kervi/kervi-devices/blob/c6aaddc6da1d0bce0ea2b0c6eb8393ba10aefa56/kervi/devices/pwm/PCA9685.py#L151-L167 |
kervi/kervi-devices | kervi/devices/pwm/PCA9685.py | PCA9685DeviceDriver.set_pwm | def set_pwm(self, channel, on, off):
"""Sets a single PWM channel."""
self.i2c.write8(LED0_ON_L+4*channel, on & 0xFF)
self.i2c.write8(LED0_ON_H+4*channel, on >> 8)
self.i2c.write8(LED0_OFF_L+4*channel, off & 0xFF)
self.i2c.write8(LED0_OFF_H+4*channel, off >> 8) | python | def set_pwm(self, channel, on, off):
"""Sets a single PWM channel."""
self.i2c.write8(LED0_ON_L+4*channel, on & 0xFF)
self.i2c.write8(LED0_ON_H+4*channel, on >> 8)
self.i2c.write8(LED0_OFF_L+4*channel, off & 0xFF)
self.i2c.write8(LED0_OFF_H+4*channel, off >> 8) | [
"def",
"set_pwm",
"(",
"self",
",",
"channel",
",",
"on",
",",
"off",
")",
":",
"self",
".",
"i2c",
".",
"write8",
"(",
"LED0_ON_L",
"+",
"4",
"*",
"channel",
",",
"on",
"&",
"0xFF",
")",
"self",
".",
"i2c",
".",
"write8",
"(",
"LED0_ON_H",
"+",
... | Sets a single PWM channel. | [
"Sets",
"a",
"single",
"PWM",
"channel",
"."
] | train | https://github.com/kervi/kervi-devices/blob/c6aaddc6da1d0bce0ea2b0c6eb8393ba10aefa56/kervi/devices/pwm/PCA9685.py#L169-L174 |
kervi/kervi-devices | kervi/devices/pwm/PCA9685.py | PCA9685DeviceDriver.set_all_pwm | def set_all_pwm(self, on, off):
"""Sets all PWM channels."""
self.i2c.write8(ALL_LED_ON_L, on & 0xFF)
self.i2c.write8(ALL_LED_ON_H, on >> 8)
self.i2c.write8(ALL_LED_OFF_L, off & 0xFF)
self.i2c.write8(ALL_LED_OFF_H, off >> 8) | python | def set_all_pwm(self, on, off):
"""Sets all PWM channels."""
self.i2c.write8(ALL_LED_ON_L, on & 0xFF)
self.i2c.write8(ALL_LED_ON_H, on >> 8)
self.i2c.write8(ALL_LED_OFF_L, off & 0xFF)
self.i2c.write8(ALL_LED_OFF_H, off >> 8) | [
"def",
"set_all_pwm",
"(",
"self",
",",
"on",
",",
"off",
")",
":",
"self",
".",
"i2c",
".",
"write8",
"(",
"ALL_LED_ON_L",
",",
"on",
"&",
"0xFF",
")",
"self",
".",
"i2c",
".",
"write8",
"(",
"ALL_LED_ON_H",
",",
"on",
">>",
"8",
")",
"self",
".... | Sets all PWM channels. | [
"Sets",
"all",
"PWM",
"channels",
"."
] | train | https://github.com/kervi/kervi-devices/blob/c6aaddc6da1d0bce0ea2b0c6eb8393ba10aefa56/kervi/devices/pwm/PCA9685.py#L176-L181 |
host-anshu/simpleInterceptor | example/call_graph/generate.py | collect_ansible_classes | def collect_ansible_classes():
"""Run playbook and collect classes of ansible that are run."""
def trace_calls(frame, event, arg): # pylint: disable=W0613
"""Trace function calls to collect ansible classes.
Trace functions and check if they have self as an arg. If so, get their class if the
... | python | def collect_ansible_classes():
"""Run playbook and collect classes of ansible that are run."""
def trace_calls(frame, event, arg): # pylint: disable=W0613
"""Trace function calls to collect ansible classes.
Trace functions and check if they have self as an arg. If so, get their class if the
... | [
"def",
"collect_ansible_classes",
"(",
")",
":",
"def",
"trace_calls",
"(",
"frame",
",",
"event",
",",
"arg",
")",
":",
"# pylint: disable=W0613",
"\"\"\"Trace function calls to collect ansible classes.\n\n Trace functions and check if they have self as an arg. If so, get the... | Run playbook and collect classes of ansible that are run. | [
"Run",
"playbook",
"and",
"collect",
"classes",
"of",
"ansible",
"that",
"are",
"run",
"."
] | train | https://github.com/host-anshu/simpleInterceptor/blob/71238fed57c62b5f77ce32d0c9b98acad73ab6a8/example/call_graph/generate.py#L30-L54 |
host-anshu/simpleInterceptor | example/call_graph/generate.py | _parse_args | def _parse_args():
"""Parse args and separate generator and playbook args."""
class HelpOnErrorArgParser(argparse.ArgumentParser):
"""Print help message as well when an error is raised."""
def error(self, message):
sys.stderr.write("Error: %s\n" % message)
self.print_help... | python | def _parse_args():
"""Parse args and separate generator and playbook args."""
class HelpOnErrorArgParser(argparse.ArgumentParser):
"""Print help message as well when an error is raised."""
def error(self, message):
sys.stderr.write("Error: %s\n" % message)
self.print_help... | [
"def",
"_parse_args",
"(",
")",
":",
"class",
"HelpOnErrorArgParser",
"(",
"argparse",
".",
"ArgumentParser",
")",
":",
"\"\"\"Print help message as well when an error is raised.\"\"\"",
"def",
"error",
"(",
"self",
",",
"message",
")",
":",
"sys",
".",
"stderr",
".... | Parse args and separate generator and playbook args. | [
"Parse",
"args",
"and",
"separate",
"generator",
"and",
"playbook",
"args",
"."
] | train | https://github.com/host-anshu/simpleInterceptor/blob/71238fed57c62b5f77ce32d0c9b98acad73ab6a8/example/call_graph/generate.py#L68-L144 |
wickman/compactor | compactor/httpd.py | WireProtocolMessageHandler.detect_process | def detect_process(cls, headers):
"""Returns tuple of process, legacy or None, None if not process originating."""
try:
if 'Libprocess-From' in headers:
return PID.from_string(headers['Libprocess-From']), False
elif 'User-Agent' in headers and headers['User-Agent'].startswith('libprocess/')... | python | def detect_process(cls, headers):
"""Returns tuple of process, legacy or None, None if not process originating."""
try:
if 'Libprocess-From' in headers:
return PID.from_string(headers['Libprocess-From']), False
elif 'User-Agent' in headers and headers['User-Agent'].startswith('libprocess/')... | [
"def",
"detect_process",
"(",
"cls",
",",
"headers",
")",
":",
"try",
":",
"if",
"'Libprocess-From'",
"in",
"headers",
":",
"return",
"PID",
".",
"from_string",
"(",
"headers",
"[",
"'Libprocess-From'",
"]",
")",
",",
"False",
"elif",
"'User-Agent'",
"in",
... | Returns tuple of process, legacy or None, None if not process originating. | [
"Returns",
"tuple",
"of",
"process",
"legacy",
"or",
"None",
"None",
"if",
"not",
"process",
"originating",
"."
] | train | https://github.com/wickman/compactor/blob/52714be3d84aa595a212feccb4d92ec250cede2a/compactor/httpd.py#L27-L39 |
wickman/compactor | compactor/httpd.py | HTTPD.mount_process | def mount_process(self, process):
"""
Mount a Process onto the http server to receive message callbacks.
"""
for route_path in process.route_paths:
route = '/%s%s' % (process.pid.id, route_path)
log.info('Mounting route %s' % route)
self.app.add_handlers('.*$', [(
re.escape(... | python | def mount_process(self, process):
"""
Mount a Process onto the http server to receive message callbacks.
"""
for route_path in process.route_paths:
route = '/%s%s' % (process.pid.id, route_path)
log.info('Mounting route %s' % route)
self.app.add_handlers('.*$', [(
re.escape(... | [
"def",
"mount_process",
"(",
"self",
",",
"process",
")",
":",
"for",
"route_path",
"in",
"process",
".",
"route_paths",
":",
"route",
"=",
"'/%s%s'",
"%",
"(",
"process",
".",
"pid",
".",
"id",
",",
"route_path",
")",
"log",
".",
"info",
"(",
"'Mounti... | Mount a Process onto the http server to receive message callbacks. | [
"Mount",
"a",
"Process",
"onto",
"the",
"http",
"server",
"to",
"receive",
"message",
"callbacks",
"."
] | train | https://github.com/wickman/compactor/blob/52714be3d84aa595a212feccb4d92ec250cede2a/compactor/httpd.py#L118-L139 |
wickman/compactor | compactor/httpd.py | HTTPD.unmount_process | def unmount_process(self, process):
"""
Unmount a process from the http server to stop receiving message
callbacks.
"""
# There is no remove_handlers, but .handlers is public so why not. server.handlers is a list of
# 2-tuples of the form (host_pattern, [list of RequestHandler]) objects. We f... | python | def unmount_process(self, process):
"""
Unmount a process from the http server to stop receiving message
callbacks.
"""
# There is no remove_handlers, but .handlers is public so why not. server.handlers is a list of
# 2-tuples of the form (host_pattern, [list of RequestHandler]) objects. We f... | [
"def",
"unmount_process",
"(",
"self",
",",
"process",
")",
":",
"# There is no remove_handlers, but .handlers is public so why not. server.handlers is a list of",
"# 2-tuples of the form (host_pattern, [list of RequestHandler]) objects. We filter out all",
"# handlers matching our process fro... | Unmount a process from the http server to stop receiving message
callbacks. | [
"Unmount",
"a",
"process",
"from",
"the",
"http",
"server",
"to",
"stop",
"receiving",
"message",
"callbacks",
"."
] | train | https://github.com/wickman/compactor/blob/52714be3d84aa595a212feccb4d92ec250cede2a/compactor/httpd.py#L141-L157 |
staffanm/layeredconfig | layeredconfig/configsource.py | ConfigSource.typevalue | def typevalue(self, key, value):
"""Given a parameter identified by ``key`` and an untyped string,
convert that string to the type that our version of key has.
"""
def listconvert(value):
# this function might be called with both string
# represenations of entir... | python | def typevalue(self, key, value):
"""Given a parameter identified by ``key`` and an untyped string,
convert that string to the type that our version of key has.
"""
def listconvert(value):
# this function might be called with both string
# represenations of entir... | [
"def",
"typevalue",
"(",
"self",
",",
"key",
",",
"value",
")",
":",
"def",
"listconvert",
"(",
"value",
")",
":",
"# this function might be called with both string",
"# represenations of entire lists and simple (unquoted)",
"# strings. String representations come in two flavours... | Given a parameter identified by ``key`` and an untyped string,
convert that string to the type that our version of key has. | [
"Given",
"a",
"parameter",
"identified",
"by",
"key",
"and",
"an",
"untyped",
"string",
"convert",
"that",
"string",
"to",
"the",
"type",
"that",
"our",
"version",
"of",
"key",
"has",
"."
] | train | https://github.com/staffanm/layeredconfig/blob/f3dad66729854f5c34910c7533f88d39b223a977/layeredconfig/configsource.py#L175-L218 |
dyachan/django-usuario | usuario/models.py | _get_instance | def _get_instance(user):
""" función que busca la instancia de la clase hija más baja de Usuario y que
esté enlazada con el usuario dado por parámetro.
"""
inst = None
f = Usuario.objects.filter(user=user)
if f.exists():
inst = f[0]
for sub_u in Usuario.__subclasses__():
if hasattr(inst, sub_... | python | def _get_instance(user):
""" función que busca la instancia de la clase hija más baja de Usuario y que
esté enlazada con el usuario dado por parámetro.
"""
inst = None
f = Usuario.objects.filter(user=user)
if f.exists():
inst = f[0]
for sub_u in Usuario.__subclasses__():
if hasattr(inst, sub_... | [
"def",
"_get_instance",
"(",
"user",
")",
":",
"inst",
"=",
"None",
"f",
"=",
"Usuario",
".",
"objects",
".",
"filter",
"(",
"user",
"=",
"user",
")",
"if",
"f",
".",
"exists",
"(",
")",
":",
"inst",
"=",
"f",
"[",
"0",
"]",
"for",
"sub_u",
"in... | función que busca la instancia de la clase hija más baja de Usuario y que
esté enlazada con el usuario dado por parámetro. | [
"función",
"que",
"busca",
"la",
"instancia",
"de",
"la",
"clase",
"hija",
"más",
"baja",
"de",
"Usuario",
"y",
"que",
"esté",
"enlazada",
"con",
"el",
"usuario",
"dado",
"por",
"parámetro",
"."
] | train | https://github.com/dyachan/django-usuario/blob/10712cf78d202721b965c6b89b11d4b3bd6bb67b/usuario/models.py#L98-L111 |
dyachan/django-usuario | usuario/models.py | Usuario.save | def save(self, UserSave=True, *args, **kwargs):
""" Se sobreescribe el método salvar para poder gestionar la creación de un
User en caso que no se haya creado y enlazado uno antes.
Se puede elegir si se desea guardar los cambios efectuados en user.
"""
if hasattr(self, 'user') and self.user is not ... | python | def save(self, UserSave=True, *args, **kwargs):
""" Se sobreescribe el método salvar para poder gestionar la creación de un
User en caso que no se haya creado y enlazado uno antes.
Se puede elegir si se desea guardar los cambios efectuados en user.
"""
if hasattr(self, 'user') and self.user is not ... | [
"def",
"save",
"(",
"self",
",",
"UserSave",
"=",
"True",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"hasattr",
"(",
"self",
",",
"'user'",
")",
"and",
"self",
".",
"user",
"is",
"not",
"None",
":",
"# caso que se le asigna un usuario d... | Se sobreescribe el método salvar para poder gestionar la creación de un
User en caso que no se haya creado y enlazado uno antes.
Se puede elegir si se desea guardar los cambios efectuados en user. | [
"Se",
"sobreescribe",
"el",
"método",
"salvar",
"para",
"poder",
"gestionar",
"la",
"creación",
"de",
"un",
"User",
"en",
"caso",
"que",
"no",
"se",
"haya",
"creado",
"y",
"enlazado",
"uno",
"antes",
".",
"Se",
"puede",
"elegir",
"si",
"se",
"desea",
"gu... | train | https://github.com/dyachan/django-usuario/blob/10712cf78d202721b965c6b89b11d4b3bd6bb67b/usuario/models.py#L49-L96 |
toumorokoshi/jenks | jenks/utils.py | generate_valid_keys | def generate_valid_keys():
""" create a list of valid keys """
valid_keys = []
for minimum, maximum in RANGES:
for i in range(ord(minimum), ord(maximum) + 1):
valid_keys.append(chr(i))
return valid_keys | python | def generate_valid_keys():
""" create a list of valid keys """
valid_keys = []
for minimum, maximum in RANGES:
for i in range(ord(minimum), ord(maximum) + 1):
valid_keys.append(chr(i))
return valid_keys | [
"def",
"generate_valid_keys",
"(",
")",
":",
"valid_keys",
"=",
"[",
"]",
"for",
"minimum",
",",
"maximum",
"in",
"RANGES",
":",
"for",
"i",
"in",
"range",
"(",
"ord",
"(",
"minimum",
")",
",",
"ord",
"(",
"maximum",
")",
"+",
"1",
")",
":",
"valid... | create a list of valid keys | [
"create",
"a",
"list",
"of",
"valid",
"keys"
] | train | https://github.com/toumorokoshi/jenks/blob/d3333a7b86ba290b7185aa5b8da75e76a28124f5/jenks/utils.py#L27-L33 |
toumorokoshi/jenks | jenks/utils.py | get_configuration_file | def get_configuration_file():
""" return jenks configuration file """
path = os.path.abspath(os.curdir)
while path != os.sep:
config_path = os.path.join(path, CONFIG_FILE_NAME)
if os.path.exists(config_path):
return config_path
path = os.path.dirname(path)
return None | python | def get_configuration_file():
""" return jenks configuration file """
path = os.path.abspath(os.curdir)
while path != os.sep:
config_path = os.path.join(path, CONFIG_FILE_NAME)
if os.path.exists(config_path):
return config_path
path = os.path.dirname(path)
return None | [
"def",
"get_configuration_file",
"(",
")",
":",
"path",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"os",
".",
"curdir",
")",
"while",
"path",
"!=",
"os",
".",
"sep",
":",
"config_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"path",
",",
"CONF... | return jenks configuration file | [
"return",
"jenks",
"configuration",
"file"
] | train | https://github.com/toumorokoshi/jenks/blob/d3333a7b86ba290b7185aa5b8da75e76a28124f5/jenks/utils.py#L36-L44 |
toumorokoshi/jenks | jenks/utils.py | generate_write_yaml_to_file | def generate_write_yaml_to_file(file_name):
""" generate a method to write the configuration in yaml to the method desired """
def write_yaml(config):
with open(file_name, 'w+') as fh:
fh.write(yaml.dump(config))
return write_yaml | python | def generate_write_yaml_to_file(file_name):
""" generate a method to write the configuration in yaml to the method desired """
def write_yaml(config):
with open(file_name, 'w+') as fh:
fh.write(yaml.dump(config))
return write_yaml | [
"def",
"generate_write_yaml_to_file",
"(",
"file_name",
")",
":",
"def",
"write_yaml",
"(",
"config",
")",
":",
"with",
"open",
"(",
"file_name",
",",
"'w+'",
")",
"as",
"fh",
":",
"fh",
".",
"write",
"(",
"yaml",
".",
"dump",
"(",
"config",
")",
")",
... | generate a method to write the configuration in yaml to the method desired | [
"generate",
"a",
"method",
"to",
"write",
"the",
"configuration",
"in",
"yaml",
"to",
"the",
"method",
"desired"
] | train | https://github.com/toumorokoshi/jenks/blob/d3333a7b86ba290b7185aa5b8da75e76a28124f5/jenks/utils.py#L47-L52 |
emilydolson/avida-spatial-tools | avidaspatial/parse_files.py | load_grid_data | def load_grid_data(file_list, data_type="binary", sort=True, delim=" "):
"""
Loads data from one or multiple grid_task files.
Arguments:
file_list - either a string or a list of strings indicating files to
load data from. Files are assumed to be in grid_task.dat
... | python | def load_grid_data(file_list, data_type="binary", sort=True, delim=" "):
"""
Loads data from one or multiple grid_task files.
Arguments:
file_list - either a string or a list of strings indicating files to
load data from. Files are assumed to be in grid_task.dat
... | [
"def",
"load_grid_data",
"(",
"file_list",
",",
"data_type",
"=",
"\"binary\"",
",",
"sort",
"=",
"True",
",",
"delim",
"=",
"\" \"",
")",
":",
"# If there's only one file, we pretend it's a list",
"if",
"not",
"type",
"(",
"file_list",
")",
"is",
"list",
":",
... | Loads data from one or multiple grid_task files.
Arguments:
file_list - either a string or a list of strings indicating files to
load data from. Files are assumed to be in grid_task.dat
format (space delimited values, one per cell).
data_type - a string repr... | [
"Loads",
"data",
"from",
"one",
"or",
"multiple",
"grid_task",
"files",
"."
] | train | https://github.com/emilydolson/avida-spatial-tools/blob/7beb0166ccefad5fa722215b030ac2a53d62b59e/avidaspatial/parse_files.py#L11-L70 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.