partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | extension_counts | extension counts will return a dictionary with counts of file extensions for
an image.
:param container: if provided, will use container as image. Can also provide
:param image_package: if provided, can be used instead of container
:param file_list: the complete list of files
:param return_counts: r... | singularity/analysis/classify.py | def extension_counts(container=None, file_list=None, return_counts=True):
'''extension counts will return a dictionary with counts of file extensions for
an image.
:param container: if provided, will use container as image. Can also provide
:param image_package: if provided, can be used instead of conta... | def extension_counts(container=None, file_list=None, return_counts=True):
'''extension counts will return a dictionary with counts of file extensions for
an image.
:param container: if provided, will use container as image. Can also provide
:param image_package: if provided, can be used instead of conta... | [
"extension",
"counts",
"will",
"return",
"a",
"dictionary",
"with",
"counts",
"of",
"file",
"extensions",
"for",
"an",
"image",
".",
":",
"param",
"container",
":",
"if",
"provided",
"will",
"use",
"container",
"as",
"image",
".",
"Can",
"also",
"provide",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/classify.py#L133-L158 | [
"def",
"extension_counts",
"(",
"container",
"=",
"None",
",",
"file_list",
"=",
"None",
",",
"return_counts",
"=",
"True",
")",
":",
"if",
"file_list",
"is",
"None",
":",
"file_list",
"=",
"get_container_contents",
"(",
"container",
",",
"split_delim",
"=",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | assess_differences | assess_differences will compare two images on each level of
reproducibility, returning for each level a dictionary with files
that are the same, different, and an overall score.
:param size_heuristic: if True, assess root owned files based on size
:param guts1,guts2: the result (dict with sizes,roots,e... | singularity/analysis/reproduce/metrics.py | def assess_differences(image_file1,
image_file2,
levels=None,
version=None,
size_heuristic=False,
guts1=None,
guts2=None):
'''assess_differences will compare two images on each ... | def assess_differences(image_file1,
image_file2,
levels=None,
version=None,
size_heuristic=False,
guts1=None,
guts2=None):
'''assess_differences will compare two images on each ... | [
"assess_differences",
"will",
"compare",
"two",
"images",
"on",
"each",
"level",
"of",
"reproducibility",
"returning",
"for",
"each",
"level",
"a",
"dictionary",
"with",
"files",
"that",
"are",
"the",
"same",
"different",
"and",
"an",
"overall",
"score",
".",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/metrics.py#L30-L134 | [
"def",
"assess_differences",
"(",
"image_file1",
",",
"image_file2",
",",
"levels",
"=",
"None",
",",
"version",
"=",
"None",
",",
"size_heuristic",
"=",
"False",
",",
"guts1",
"=",
"None",
",",
"guts2",
"=",
"None",
")",
":",
"if",
"levels",
"is",
"None... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | include_file | include_file will look at a path and determine
if it matches a regular expression from a level | singularity/analysis/reproduce/criteria.py | def include_file(member,file_filter):
'''include_file will look at a path and determine
if it matches a regular expression from a level
'''
member_path = member.name.replace('.','',1)
if len(member_path) == 0:
return False
# Does the filter skip it explicitly?
if "skip_files" in fi... | def include_file(member,file_filter):
'''include_file will look at a path and determine
if it matches a regular expression from a level
'''
member_path = member.name.replace('.','',1)
if len(member_path) == 0:
return False
# Does the filter skip it explicitly?
if "skip_files" in fi... | [
"include_file",
"will",
"look",
"at",
"a",
"path",
"and",
"determine",
"if",
"it",
"matches",
"a",
"regular",
"expression",
"from",
"a",
"level"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/criteria.py#L27-L50 | [
"def",
"include_file",
"(",
"member",
",",
"file_filter",
")",
":",
"member_path",
"=",
"member",
".",
"name",
".",
"replace",
"(",
"'.'",
",",
"''",
",",
"1",
")",
"if",
"len",
"(",
"member_path",
")",
"==",
"0",
":",
"return",
"False",
"# Does the fi... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | is_root_owned | assess if a file is root owned, meaning "root" or user/group
id of 0 | singularity/analysis/reproduce/criteria.py | def is_root_owned(member):
'''assess if a file is root owned, meaning "root" or user/group
id of 0'''
if member.uid == 0 or member.gid == 0:
return True
elif member.uname == 'root' or member.gname == 'root':
return True
return False | def is_root_owned(member):
'''assess if a file is root owned, meaning "root" or user/group
id of 0'''
if member.uid == 0 or member.gid == 0:
return True
elif member.uname == 'root' or member.gname == 'root':
return True
return False | [
"assess",
"if",
"a",
"file",
"is",
"root",
"owned",
"meaning",
"root",
"or",
"user",
"/",
"group",
"id",
"of",
"0"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/criteria.py#L53-L60 | [
"def",
"is_root_owned",
"(",
"member",
")",
":",
"if",
"member",
".",
"uid",
"==",
"0",
"or",
"member",
".",
"gid",
"==",
"0",
":",
"return",
"True",
"elif",
"member",
".",
"uname",
"==",
"'root'",
"or",
"member",
".",
"gname",
"==",
"'root'",
":",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | assess_content | Determine if the filter wants the file to be read for content.
In the case of yes, we would then want to add the content to the
hash and not the file object. | singularity/analysis/reproduce/criteria.py | def assess_content(member,file_filter):
'''Determine if the filter wants the file to be read for content.
In the case of yes, we would then want to add the content to the
hash and not the file object.
'''
member_path = member.name.replace('.','',1)
if len(member_path) == 0:
return False... | def assess_content(member,file_filter):
'''Determine if the filter wants the file to be read for content.
In the case of yes, we would then want to add the content to the
hash and not the file object.
'''
member_path = member.name.replace('.','',1)
if len(member_path) == 0:
return False... | [
"Determine",
"if",
"the",
"filter",
"wants",
"the",
"file",
"to",
"be",
"read",
"for",
"content",
".",
"In",
"the",
"case",
"of",
"yes",
"we",
"would",
"then",
"want",
"to",
"add",
"the",
"content",
"to",
"the",
"hash",
"and",
"not",
"the",
"file",
"... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/criteria.py#L63-L81 | [
"def",
"assess_content",
"(",
"member",
",",
"file_filter",
")",
":",
"member_path",
"=",
"member",
".",
"name",
".",
"replace",
"(",
"'.'",
",",
"''",
",",
"1",
")",
"if",
"len",
"(",
"member_path",
")",
"==",
"0",
":",
"return",
"False",
"# Does the ... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_custom_level | get_custom_level will generate a custom level for the user,
based on a regular expression. If used outside the context of tarsum, the user
can generate their own named and described filters.
:param regexp: must be defined, the file filter regular expression
:param description: optional description | singularity/analysis/reproduce/levels.py | def get_custom_level(regexp=None,description=None,skip_files=None,include_files=None):
'''get_custom_level will generate a custom level for the user,
based on a regular expression. If used outside the context of tarsum, the user
can generate their own named and described filters.
:param regexp: must be... | def get_custom_level(regexp=None,description=None,skip_files=None,include_files=None):
'''get_custom_level will generate a custom level for the user,
based on a regular expression. If used outside the context of tarsum, the user
can generate their own named and described filters.
:param regexp: must be... | [
"get_custom_level",
"will",
"generate",
"a",
"custom",
"level",
"for",
"the",
"user",
"based",
"on",
"a",
"regular",
"expression",
".",
"If",
"used",
"outside",
"the",
"context",
"of",
"tarsum",
"the",
"user",
"can",
"generate",
"their",
"own",
"named",
"and... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L34-L61 | [
"def",
"get_custom_level",
"(",
"regexp",
"=",
"None",
",",
"description",
"=",
"None",
",",
"skip_files",
"=",
"None",
",",
"include_files",
"=",
"None",
")",
":",
"if",
"regexp",
"==",
"None",
":",
"regexp",
"=",
"\".\"",
"if",
"description",
"is",
"No... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_level | get_level returns a single level, with option to customize files
added and skipped. | singularity/analysis/reproduce/levels.py | def get_level(level,version=None,include_files=None,skip_files=None):
'''get_level returns a single level, with option to customize files
added and skipped.
'''
levels = get_levels(version=version)
level_names = list(levels.keys())
if level.upper() in level_names:
level = levels[level]... | def get_level(level,version=None,include_files=None,skip_files=None):
'''get_level returns a single level, with option to customize files
added and skipped.
'''
levels = get_levels(version=version)
level_names = list(levels.keys())
if level.upper() in level_names:
level = levels[level]... | [
"get_level",
"returns",
"a",
"single",
"level",
"with",
"option",
"to",
"customize",
"files",
"added",
"and",
"skipped",
"."
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L64-L86 | [
"def",
"get_level",
"(",
"level",
",",
"version",
"=",
"None",
",",
"include_files",
"=",
"None",
",",
"skip_files",
"=",
"None",
")",
":",
"levels",
"=",
"get_levels",
"(",
"version",
"=",
"version",
")",
"level_names",
"=",
"list",
"(",
"levels",
".",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | modify_level | modify level is intended to add / modify a content type.
Default content type is list, meaning the entry is appended.
If you set append to False, the content will be overwritten
For any other content type, the entry is overwritten. | singularity/analysis/reproduce/levels.py | def modify_level(level,field,values,append=True):
'''modify level is intended to add / modify a content type.
Default content type is list, meaning the entry is appended.
If you set append to False, the content will be overwritten
For any other content type, the entry is overwritten.
'''
field =... | def modify_level(level,field,values,append=True):
'''modify level is intended to add / modify a content type.
Default content type is list, meaning the entry is appended.
If you set append to False, the content will be overwritten
For any other content type, the entry is overwritten.
'''
field =... | [
"modify",
"level",
"is",
"intended",
"to",
"add",
"/",
"modify",
"a",
"content",
"type",
".",
"Default",
"content",
"type",
"is",
"list",
"meaning",
"the",
"entry",
"is",
"appended",
".",
"If",
"you",
"set",
"append",
"to",
"False",
"the",
"content",
"wi... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L89-L112 | [
"def",
"modify_level",
"(",
"level",
",",
"field",
",",
"values",
",",
"append",
"=",
"True",
")",
":",
"field",
"=",
"field",
".",
"lower",
"(",
")",
"valid_fields",
"=",
"[",
"'regexp'",
",",
"'skip_files'",
",",
"'include_files'",
"]",
"if",
"field",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_levels | get_levels returns a dictionary of levels (key) and values (dictionaries with
descriptions and regular expressions for files) for the user.
:param version: the version of singularity to use (default is 2.2)
:param include_files: files to add to the level, only relvant if | singularity/analysis/reproduce/levels.py | def get_levels(version=None):
'''get_levels returns a dictionary of levels (key) and values (dictionaries with
descriptions and regular expressions for files) for the user.
:param version: the version of singularity to use (default is 2.2)
:param include_files: files to add to the level, only relvant i... | def get_levels(version=None):
'''get_levels returns a dictionary of levels (key) and values (dictionaries with
descriptions and regular expressions for files) for the user.
:param version: the version of singularity to use (default is 2.2)
:param include_files: files to add to the level, only relvant i... | [
"get_levels",
"returns",
"a",
"dictionary",
"of",
"levels",
"(",
"key",
")",
"and",
"values",
"(",
"dictionaries",
"with",
"descriptions",
"and",
"regular",
"expressions",
"for",
"files",
")",
"for",
"the",
"user",
".",
":",
"param",
"version",
":",
"the",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L115-L143 | [
"def",
"get_levels",
"(",
"version",
"=",
"None",
")",
":",
"valid_versions",
"=",
"[",
"'2.3'",
",",
"'2.2'",
"]",
"if",
"version",
"is",
"None",
":",
"version",
"=",
"\"2.3\"",
"version",
"=",
"str",
"(",
"version",
")",
"if",
"version",
"not",
"in",... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | make_levels_set | make set efficient will convert all lists of items
in levels to a set to speed up operations | singularity/analysis/reproduce/levels.py | def make_levels_set(levels):
'''make set efficient will convert all lists of items
in levels to a set to speed up operations'''
for level_key,level_filters in levels.items():
levels[level_key] = make_level_set(level_filters)
return levels | def make_levels_set(levels):
'''make set efficient will convert all lists of items
in levels to a set to speed up operations'''
for level_key,level_filters in levels.items():
levels[level_key] = make_level_set(level_filters)
return levels | [
"make",
"set",
"efficient",
"will",
"convert",
"all",
"lists",
"of",
"items",
"in",
"levels",
"to",
"a",
"set",
"to",
"speed",
"up",
"operations"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L146-L151 | [
"def",
"make_levels_set",
"(",
"levels",
")",
":",
"for",
"level_key",
",",
"level_filters",
"in",
"levels",
".",
"items",
"(",
")",
":",
"levels",
"[",
"level_key",
"]",
"=",
"make_level_set",
"(",
"level_filters",
")",
"return",
"levels"
] | 498c3433724b332f7493fec632d8daf479f47b82 |
train | make_level_set | make level set will convert one level into
a set | singularity/analysis/reproduce/levels.py | def make_level_set(level):
'''make level set will convert one level into
a set'''
new_level = dict()
for key,value in level.items():
if isinstance(value,list):
new_level[key] = set(value)
else:
new_level[key] = value
return new_level | def make_level_set(level):
'''make level set will convert one level into
a set'''
new_level = dict()
for key,value in level.items():
if isinstance(value,list):
new_level[key] = set(value)
else:
new_level[key] = value
return new_level | [
"make",
"level",
"set",
"will",
"convert",
"one",
"level",
"into",
"a",
"set"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/levels.py#L155-L164 | [
"def",
"make_level_set",
"(",
"level",
")",
":",
"new_level",
"=",
"dict",
"(",
")",
"for",
"key",
",",
"value",
"in",
"level",
".",
"items",
"(",
")",
":",
"if",
"isinstance",
"(",
"value",
",",
"list",
")",
":",
"new_level",
"[",
"key",
"]",
"=",... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | extract_guts | extract the file guts from an in memory tarfile. The file is not closed.
This should not be done for large images. | singularity/analysis/reproduce/utils.py | def extract_guts(image_path,
tar,
file_filter=None,
tag_root=True,
include_sizes=True):
'''extract the file guts from an in memory tarfile. The file is not closed.
This should not be done for large images.
'''
if file_filter is None... | def extract_guts(image_path,
tar,
file_filter=None,
tag_root=True,
include_sizes=True):
'''extract the file guts from an in memory tarfile. The file is not closed.
This should not be done for large images.
'''
if file_filter is None... | [
"extract",
"the",
"file",
"guts",
"from",
"an",
"in",
"memory",
"tarfile",
".",
"The",
"file",
"is",
"not",
"closed",
".",
"This",
"should",
"not",
"be",
"done",
"for",
"large",
"images",
"."
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/utils.py#L39-L88 | [
"def",
"extract_guts",
"(",
"image_path",
",",
"tar",
",",
"file_filter",
"=",
"None",
",",
"tag_root",
"=",
"True",
",",
"include_sizes",
"=",
"True",
")",
":",
"if",
"file_filter",
"is",
"None",
":",
"file_filter",
"=",
"get_level",
"(",
"'IDENTICAL'",
"... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_memory_tar | get an in memory tar of an image. Use carefully, not as reliable
as get_image_tar | singularity/analysis/reproduce/utils.py | def get_memory_tar(image_path):
'''get an in memory tar of an image. Use carefully, not as reliable
as get_image_tar
'''
byte_array = Client.image.export(image_path)
file_object = io.BytesIO(byte_array)
tar = tarfile.open(mode="r|*", fileobj=file_object)
return (file_object,tar) | def get_memory_tar(image_path):
'''get an in memory tar of an image. Use carefully, not as reliable
as get_image_tar
'''
byte_array = Client.image.export(image_path)
file_object = io.BytesIO(byte_array)
tar = tarfile.open(mode="r|*", fileobj=file_object)
return (file_object,tar) | [
"get",
"an",
"in",
"memory",
"tar",
"of",
"an",
"image",
".",
"Use",
"carefully",
"not",
"as",
"reliable",
"as",
"get_image_tar"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/utils.py#L92-L99 | [
"def",
"get_memory_tar",
"(",
"image_path",
")",
":",
"byte_array",
"=",
"Client",
".",
"image",
".",
"export",
"(",
"image_path",
")",
"file_object",
"=",
"io",
".",
"BytesIO",
"(",
"byte_array",
")",
"tar",
"=",
"tarfile",
".",
"open",
"(",
"mode",
"="... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_image_tar | get an image tar, either written in memory or to
the file system. file_obj will either be the file object,
or the file itself. | singularity/analysis/reproduce/utils.py | def get_image_tar(image_path):
'''get an image tar, either written in memory or to
the file system. file_obj will either be the file object,
or the file itself.
'''
bot.debug('Generate file system tar...')
file_obj = Client.image.export(image_path=image_path)
if file_obj is None:
... | def get_image_tar(image_path):
'''get an image tar, either written in memory or to
the file system. file_obj will either be the file object,
or the file itself.
'''
bot.debug('Generate file system tar...')
file_obj = Client.image.export(image_path=image_path)
if file_obj is None:
... | [
"get",
"an",
"image",
"tar",
"either",
"written",
"in",
"memory",
"or",
"to",
"the",
"file",
"system",
".",
"file_obj",
"will",
"either",
"be",
"the",
"file",
"object",
"or",
"the",
"file",
"itself",
"."
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/utils.py#L102-L113 | [
"def",
"get_image_tar",
"(",
"image_path",
")",
":",
"bot",
".",
"debug",
"(",
"'Generate file system tar...'",
")",
"file_obj",
"=",
"Client",
".",
"image",
".",
"export",
"(",
"image_path",
"=",
"image_path",
")",
"if",
"file_obj",
"is",
"None",
":",
"bot"... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | delete_image_tar | delete image tar will close a file object (if extracted into
memory) or delete from the file system (if saved to disk) | singularity/analysis/reproduce/utils.py | def delete_image_tar(file_obj, tar):
'''delete image tar will close a file object (if extracted into
memory) or delete from the file system (if saved to disk)'''
try:
file_obj.close()
except:
tar.close()
if os.path.exists(file_obj):
os.remove(file_obj)
deleted = True
... | def delete_image_tar(file_obj, tar):
'''delete image tar will close a file object (if extracted into
memory) or delete from the file system (if saved to disk)'''
try:
file_obj.close()
except:
tar.close()
if os.path.exists(file_obj):
os.remove(file_obj)
deleted = True
... | [
"delete",
"image",
"tar",
"will",
"close",
"a",
"file",
"object",
"(",
"if",
"extracted",
"into",
"memory",
")",
"or",
"delete",
"from",
"the",
"file",
"system",
"(",
"if",
"saved",
"to",
"disk",
")"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/utils.py#L116-L127 | [
"def",
"delete_image_tar",
"(",
"file_obj",
",",
"tar",
")",
":",
"try",
":",
"file_obj",
".",
"close",
"(",
")",
"except",
":",
"tar",
".",
"close",
"(",
")",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"file_obj",
")",
":",
"os",
".",
"remove",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | extract_content | extract_content will extract content from an image using cat.
If hash=True, a hash sum is returned instead | singularity/analysis/reproduce/utils.py | def extract_content(image_path, member_name, return_hash=False):
'''extract_content will extract content from an image using cat.
If hash=True, a hash sum is returned instead
'''
if member_name.startswith('./'):
member_name = member_name.replace('.','',1)
if return_hash:
hashy = hash... | def extract_content(image_path, member_name, return_hash=False):
'''extract_content will extract content from an image using cat.
If hash=True, a hash sum is returned instead
'''
if member_name.startswith('./'):
member_name = member_name.replace('.','',1)
if return_hash:
hashy = hash... | [
"extract_content",
"will",
"extract",
"content",
"from",
"an",
"image",
"using",
"cat",
".",
"If",
"hash",
"=",
"True",
"a",
"hash",
"sum",
"is",
"returned",
"instead"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/reproduce/utils.py#L130-L154 | [
"def",
"extract_content",
"(",
"image_path",
",",
"member_name",
",",
"return_hash",
"=",
"False",
")",
":",
"if",
"member_name",
".",
"startswith",
"(",
"'./'",
")",
":",
"member_name",
"=",
"member_name",
".",
"replace",
"(",
"'.'",
",",
"''",
",",
"1",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | run_build | run_build takes a build directory and params dictionary, and does the following:
- downloads repo to a temporary directory
- changes branch or commit, if needed
- creates and bootstraps singularity image from Singularity file
- returns a dictionary with:
image (path), metadata (dict)
... | singularity/build/main.py | def run_build(build_dir, params, verbose=True):
'''run_build takes a build directory and params dictionary, and does the following:
- downloads repo to a temporary directory
- changes branch or commit, if needed
- creates and bootstraps singularity image from Singularity file
- returns a dic... | def run_build(build_dir, params, verbose=True):
'''run_build takes a build directory and params dictionary, and does the following:
- downloads repo to a temporary directory
- changes branch or commit, if needed
- creates and bootstraps singularity image from Singularity file
- returns a dic... | [
"run_build",
"takes",
"a",
"build",
"directory",
"and",
"params",
"dictionary",
"and",
"does",
"the",
"following",
":",
"-",
"downloads",
"repo",
"to",
"a",
"temporary",
"directory",
"-",
"changes",
"branch",
"or",
"commit",
"if",
"needed",
"-",
"creates",
"... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/main.py#L53-L166 | [
"def",
"run_build",
"(",
"build_dir",
",",
"params",
",",
"verbose",
"=",
"True",
")",
":",
"# Download the repository",
"download_repo",
"(",
"repo_url",
"=",
"params",
"[",
"'repo_url'",
"]",
",",
"destination",
"=",
"build_dir",
")",
"os",
".",
"chdir",
"... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | send_build_data | finish build sends the build and data (response) to a response url
:param build_dir: the directory of the build
:response_url: where to send the response. If None, won't send
:param data: the data object to send as a post
:param clean_up: If true (default) removes build directory | singularity/build/main.py | def send_build_data(build_dir, data, secret,
response_url=None,clean_up=True):
'''finish build sends the build and data (response) to a response url
:param build_dir: the directory of the build
:response_url: where to send the response. If None, won't send
:param data: the data obje... | def send_build_data(build_dir, data, secret,
response_url=None,clean_up=True):
'''finish build sends the build and data (response) to a response url
:param build_dir: the directory of the build
:response_url: where to send the response. If None, won't send
:param data: the data obje... | [
"finish",
"build",
"sends",
"the",
"build",
"and",
"data",
"(",
"response",
")",
"to",
"a",
"response",
"url",
":",
"param",
"build_dir",
":",
"the",
"directory",
"of",
"the",
"build",
":",
"response_url",
":",
"where",
"to",
"send",
"the",
"response",
"... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/main.py#L170-L203 | [
"def",
"send_build_data",
"(",
"build_dir",
",",
"data",
",",
"secret",
",",
"response_url",
"=",
"None",
",",
"clean_up",
"=",
"True",
")",
":",
"# Send with Authentication header",
"body",
"=",
"'%s|%s|%s|%s|%s'",
"%",
"(",
"data",
"[",
"'container_id'",
"]",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | send_build_close | send build close sends a final response (post) to the server to bring down
the instance. The following must be included in params:
repo_url, logfile, repo_id, secret, log_file, token | singularity/build/main.py | def send_build_close(params,response_url):
'''send build close sends a final response (post) to the server to bring down
the instance. The following must be included in params:
repo_url, logfile, repo_id, secret, log_file, token
'''
# Finally, package everything to send back to shub
response = ... | def send_build_close(params,response_url):
'''send build close sends a final response (post) to the server to bring down
the instance. The following must be included in params:
repo_url, logfile, repo_id, secret, log_file, token
'''
# Finally, package everything to send back to shub
response = ... | [
"send",
"build",
"close",
"sends",
"a",
"final",
"response",
"(",
"post",
")",
"to",
"the",
"server",
"to",
"bring",
"down",
"the",
"instance",
".",
"The",
"following",
"must",
"be",
"included",
"in",
"params",
":"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/main.py#L208-L237 | [
"def",
"send_build_close",
"(",
"params",
",",
"response_url",
")",
":",
"# Finally, package everything to send back to shub",
"response",
"=",
"{",
"\"log\"",
":",
"json",
".",
"dumps",
"(",
"params",
"[",
"'log_file'",
"]",
")",
",",
"\"repo_url\"",
":",
"params... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | remove_unicode_dict | remove unicode keys and values from dict, encoding in utf8 | singularity/analysis/utils.py | def remove_unicode_dict(input_dict):
'''remove unicode keys and values from dict, encoding in utf8
'''
if isinstance(input_dict, collections.Mapping):
return dict(map(remove_unicode_dict, input_dict.iteritems()))
elif isinstance(input_dict, collections.Iterable):
return type(input_dict)(... | def remove_unicode_dict(input_dict):
'''remove unicode keys and values from dict, encoding in utf8
'''
if isinstance(input_dict, collections.Mapping):
return dict(map(remove_unicode_dict, input_dict.iteritems()))
elif isinstance(input_dict, collections.Iterable):
return type(input_dict)(... | [
"remove",
"unicode",
"keys",
"and",
"values",
"from",
"dict",
"encoding",
"in",
"utf8"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/utils.py#L39-L47 | [
"def",
"remove_unicode_dict",
"(",
"input_dict",
")",
":",
"if",
"isinstance",
"(",
"input_dict",
",",
"collections",
".",
"Mapping",
")",
":",
"return",
"dict",
"(",
"map",
"(",
"remove_unicode_dict",
",",
"input_dict",
".",
"iteritems",
"(",
")",
")",
")",... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | update_dict | update_dict will update lists in a dictionary. If the key is not included,
if will add as new list. If it is, it will append.
:param input_dict: the dict to update
:param value: the value to update with | singularity/analysis/utils.py | def update_dict(input_dict,key,value):
'''update_dict will update lists in a dictionary. If the key is not included,
if will add as new list. If it is, it will append.
:param input_dict: the dict to update
:param value: the value to update with
'''
if key in input_dict:
input_dict[key].a... | def update_dict(input_dict,key,value):
'''update_dict will update lists in a dictionary. If the key is not included,
if will add as new list. If it is, it will append.
:param input_dict: the dict to update
:param value: the value to update with
'''
if key in input_dict:
input_dict[key].a... | [
"update_dict",
"will",
"update",
"lists",
"in",
"a",
"dictionary",
".",
"If",
"the",
"key",
"is",
"not",
"included",
"if",
"will",
"add",
"as",
"new",
"list",
".",
"If",
"it",
"is",
"it",
"will",
"append",
".",
":",
"param",
"input_dict",
":",
"the",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/utils.py#L50-L60 | [
"def",
"update_dict",
"(",
"input_dict",
",",
"key",
",",
"value",
")",
":",
"if",
"key",
"in",
"input_dict",
":",
"input_dict",
"[",
"key",
"]",
".",
"append",
"(",
"value",
")",
"else",
":",
"input_dict",
"[",
"key",
"]",
"=",
"[",
"value",
"]",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | update_dict_sum | update_dict sum will increment a dictionary key
by an increment, and add a value of 0 if it doesn't exist
:param input_dict: the dict to update
:param increment: the value to increment by. Default is 1
:param initial_value: value to start with. Default is 0 | singularity/analysis/utils.py | def update_dict_sum(input_dict,key,increment=None,initial_value=None):
'''update_dict sum will increment a dictionary key
by an increment, and add a value of 0 if it doesn't exist
:param input_dict: the dict to update
:param increment: the value to increment by. Default is 1
:param initial_value: v... | def update_dict_sum(input_dict,key,increment=None,initial_value=None):
'''update_dict sum will increment a dictionary key
by an increment, and add a value of 0 if it doesn't exist
:param input_dict: the dict to update
:param increment: the value to increment by. Default is 1
:param initial_value: v... | [
"update_dict",
"sum",
"will",
"increment",
"a",
"dictionary",
"key",
"by",
"an",
"increment",
"and",
"add",
"a",
"value",
"of",
"0",
"if",
"it",
"doesn",
"t",
"exist",
":",
"param",
"input_dict",
":",
"the",
"dict",
"to",
"update",
":",
"param",
"increme... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/utils.py#L63-L80 | [
"def",
"update_dict_sum",
"(",
"input_dict",
",",
"key",
",",
"increment",
"=",
"None",
",",
"initial_value",
"=",
"None",
")",
":",
"if",
"increment",
"==",
"None",
":",
"increment",
"=",
"1",
"if",
"initial_value",
"==",
"None",
":",
"initial_value",
"="... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | information_coefficient | a simple jacaard (information coefficient) to compare two lists of overlaps/diffs | singularity/analysis/metrics.py | def information_coefficient(total1,total2,intersect):
'''a simple jacaard (information coefficient) to compare two lists of overlaps/diffs
'''
total = total1 + total2
return 2.0*len(intersect) / total | def information_coefficient(total1,total2,intersect):
'''a simple jacaard (information coefficient) to compare two lists of overlaps/diffs
'''
total = total1 + total2
return 2.0*len(intersect) / total | [
"a",
"simple",
"jacaard",
"(",
"information",
"coefficient",
")",
"to",
"compare",
"two",
"lists",
"of",
"overlaps",
"/",
"diffs"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/metrics.py#L34-L38 | [
"def",
"information_coefficient",
"(",
"total1",
",",
"total2",
",",
"intersect",
")",
":",
"total",
"=",
"total1",
"+",
"total2",
"return",
"2.0",
"*",
"len",
"(",
"intersect",
")",
"/",
"total"
] | 498c3433724b332f7493fec632d8daf479f47b82 |
train | RSA | RSA analysis will compare the similarity of two matrices | singularity/analysis/metrics.py | def RSA(m1,m2):
'''RSA analysis will compare the similarity of two matrices
'''
from scipy.stats import pearsonr
import scipy.linalg
import numpy
# This will take the diagonal of each matrix (and the other half is changed to nan) and flatten to vector
vectorm1 = m1.mask(numpy.triu(numpy.one... | def RSA(m1,m2):
'''RSA analysis will compare the similarity of two matrices
'''
from scipy.stats import pearsonr
import scipy.linalg
import numpy
# This will take the diagonal of each matrix (and the other half is changed to nan) and flatten to vector
vectorm1 = m1.mask(numpy.triu(numpy.one... | [
"RSA",
"analysis",
"will",
"compare",
"the",
"similarity",
"of",
"two",
"matrices"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/analysis/metrics.py#L42-L56 | [
"def",
"RSA",
"(",
"m1",
",",
"m2",
")",
":",
"from",
"scipy",
".",
"stats",
"import",
"pearsonr",
"import",
"scipy",
".",
"linalg",
"import",
"numpy",
"# This will take the diagonal of each matrix (and the other half is changed to nan) and flatten to vector",
"vectorm1",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_google_service | get_url will use the requests library to get a url
:param service_type: the service to get (default is storage)
:param version: version to use (default is v1) | singularity/build/google.py | def get_google_service(service_type=None,version=None):
'''
get_url will use the requests library to get a url
:param service_type: the service to get (default is storage)
:param version: version to use (default is v1)
'''
if service_type == None:
service_type = "storage"
if version ... | def get_google_service(service_type=None,version=None):
'''
get_url will use the requests library to get a url
:param service_type: the service to get (default is storage)
:param version: version to use (default is v1)
'''
if service_type == None:
service_type = "storage"
if version ... | [
"get_url",
"will",
"use",
"the",
"requests",
"library",
"to",
"get",
"a",
"url",
":",
"param",
"service_type",
":",
"the",
"service",
"to",
"get",
"(",
"default",
"is",
"storage",
")",
":",
"param",
"version",
":",
"version",
"to",
"use",
"(",
"default",... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L63-L75 | [
"def",
"get_google_service",
"(",
"service_type",
"=",
"None",
",",
"version",
"=",
"None",
")",
":",
"if",
"service_type",
"==",
"None",
":",
"service_type",
"=",
"\"storage\"",
"if",
"version",
"==",
"None",
":",
"version",
"=",
"\"v1\"",
"credentials",
"=... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | upload_file | get_folder will return the folder with folder_name, and if create=True,
will create it if not found. If folder is found or created, the metadata is
returned, otherwise None is returned
:param storage_service: the drive_service created from get_storage_service
:param bucket: the bucket object from get_bu... | singularity/build/google.py | def upload_file(storage_service,bucket,bucket_path,file_name,verbose=True):
'''get_folder will return the folder with folder_name, and if create=True,
will create it if not found. If folder is found or created, the metadata is
returned, otherwise None is returned
:param storage_service: the drive_servic... | def upload_file(storage_service,bucket,bucket_path,file_name,verbose=True):
'''get_folder will return the folder with folder_name, and if create=True,
will create it if not found. If folder is found or created, the metadata is
returned, otherwise None is returned
:param storage_service: the drive_servic... | [
"get_folder",
"will",
"return",
"the",
"folder",
"with",
"folder_name",
"and",
"if",
"create",
"=",
"True",
"will",
"create",
"it",
"if",
"not",
"found",
".",
"If",
"folder",
"is",
"found",
"or",
"created",
"the",
"metadata",
"is",
"returned",
"otherwise",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L105-L132 | [
"def",
"upload_file",
"(",
"storage_service",
",",
"bucket",
",",
"bucket_path",
",",
"file_name",
",",
"verbose",
"=",
"True",
")",
":",
"# Set up path on bucket",
"upload_path",
"=",
"\"%s/%s\"",
"%",
"(",
"bucket",
"[",
"'id'",
"]",
",",
"bucket_path",
")",... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_image_path | get_image_path will determine an image path based on a repo url, removing
any token, and taking into account urls that end with .git.
:param repo_url: the repo url to parse:
:param trailing_path: the trailing path (commit then hash is common) | singularity/build/google.py | def get_image_path(repo_url, trailing_path):
'''get_image_path will determine an image path based on a repo url, removing
any token, and taking into account urls that end with .git.
:param repo_url: the repo url to parse:
:param trailing_path: the trailing path (commit then hash is common)
'''
r... | def get_image_path(repo_url, trailing_path):
'''get_image_path will determine an image path based on a repo url, removing
any token, and taking into account urls that end with .git.
:param repo_url: the repo url to parse:
:param trailing_path: the trailing path (commit then hash is common)
'''
r... | [
"get_image_path",
"will",
"determine",
"an",
"image",
"path",
"based",
"on",
"a",
"repo",
"url",
"removing",
"any",
"token",
"and",
"taking",
"into",
"account",
"urls",
"that",
"end",
"with",
".",
"git",
".",
":",
"param",
"repo_url",
":",
"the",
"repo",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L147-L156 | [
"def",
"get_image_path",
"(",
"repo_url",
",",
"trailing_path",
")",
":",
"repo_url",
"=",
"repo_url",
".",
"split",
"(",
"'@'",
")",
"[",
"-",
"1",
"]",
".",
"strip",
"(",
")",
"if",
"repo_url",
".",
"endswith",
"(",
"'.git'",
")",
":",
"repo_url",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | run_build | run_build will generate the Singularity build from a spec_file from a repo_url.
If no arguments are required, the metadata api is queried for the values.
:param build_dir: directory to do the build in. If not specified, will use temporary.
:param spec_file: the spec_file name to use, assumed to be in g... | singularity/build/google.py | def run_build(logfile='/tmp/.shub-log'):
'''run_build will generate the Singularity build from a spec_file from a repo_url.
If no arguments are required, the metadata api is queried for the values.
:param build_dir: directory to do the build in. If not specified, will use temporary.
:param spec_fi... | def run_build(logfile='/tmp/.shub-log'):
'''run_build will generate the Singularity build from a spec_file from a repo_url.
If no arguments are required, the metadata api is queried for the values.
:param build_dir: directory to do the build in. If not specified, will use temporary.
:param spec_fi... | [
"run_build",
"will",
"generate",
"the",
"Singularity",
"build",
"from",
"a",
"spec_file",
"from",
"a",
"repo_url",
"."
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L160-L291 | [
"def",
"run_build",
"(",
"logfile",
"=",
"'/tmp/.shub-log'",
")",
":",
"# If we are building the image, this will not be set",
"go",
"=",
"get_build_metadata",
"(",
"key",
"=",
"'dobuild'",
")",
"if",
"go",
"==",
"None",
":",
"sys",
".",
"exit",
"(",
"0",
")",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | finish_build | finish_build will finish the build by way of sending the log to the same bucket.
the params are loaded from the previous function that built the image, expected in
$HOME/params.pkl
:: note: this function is currently configured to work with Google Compute
Engine metadata api, and should (will) be custom... | singularity/build/google.py | def finish_build(verbose=True):
'''finish_build will finish the build by way of sending the log to the same bucket.
the params are loaded from the previous function that built the image, expected in
$HOME/params.pkl
:: note: this function is currently configured to work with Google Compute
Engine me... | def finish_build(verbose=True):
'''finish_build will finish the build by way of sending the log to the same bucket.
the params are loaded from the previous function that built the image, expected in
$HOME/params.pkl
:: note: this function is currently configured to work with Google Compute
Engine me... | [
"finish_build",
"will",
"finish",
"the",
"build",
"by",
"way",
"of",
"sending",
"the",
"log",
"to",
"the",
"same",
"bucket",
".",
"the",
"params",
"are",
"loaded",
"from",
"the",
"previous",
"function",
"that",
"built",
"the",
"image",
"expected",
"in",
"$... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L295-L330 | [
"def",
"finish_build",
"(",
"verbose",
"=",
"True",
")",
":",
"# If we are building the image, this will not be set",
"go",
"=",
"get_build_metadata",
"(",
"key",
"=",
"'dobuild'",
")",
"if",
"go",
"==",
"None",
":",
"sys",
".",
"exit",
"(",
"0",
")",
"# Load ... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_build_metadata | get_build_metadata will return metadata about an instance from within it.
:param key: the key to look up | singularity/build/google.py | def get_build_metadata(key):
'''get_build_metadata will return metadata about an instance from within it.
:param key: the key to look up
'''
headers = {"Metadata-Flavor":"Google"}
url = "http://metadata.google.internal/computeMetadata/v1/instance/attributes/%s" %(key)
response = requests... | def get_build_metadata(key):
'''get_build_metadata will return metadata about an instance from within it.
:param key: the key to look up
'''
headers = {"Metadata-Flavor":"Google"}
url = "http://metadata.google.internal/computeMetadata/v1/instance/attributes/%s" %(key)
response = requests... | [
"get_build_metadata",
"will",
"return",
"metadata",
"about",
"an",
"instance",
"from",
"within",
"it",
".",
":",
"param",
"key",
":",
"the",
"key",
"to",
"look",
"up"
] | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L338-L347 | [
"def",
"get_build_metadata",
"(",
"key",
")",
":",
"headers",
"=",
"{",
"\"Metadata-Flavor\"",
":",
"\"Google\"",
"}",
"url",
"=",
"\"http://metadata.google.internal/computeMetadata/v1/instance/attributes/%s\"",
"%",
"(",
"key",
")",
"response",
"=",
"requests",
".",
... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | get_build_params | get_build_params uses get_build_metadata to retrieve corresponding meta data values for a build
:param metadata: a list, each item a dictionary of metadata, in format:
metadata = [{'key': 'repo_url', 'value': repo_url },
{'key': 'repo_id', 'value': repo_id },
{'key': 'credential'... | singularity/build/google.py | def get_build_params(metadata):
'''get_build_params uses get_build_metadata to retrieve corresponding meta data values for a build
:param metadata: a list, each item a dictionary of metadata, in format:
metadata = [{'key': 'repo_url', 'value': repo_url },
{'key': 'repo_id', 'value': repo_id ... | def get_build_params(metadata):
'''get_build_params uses get_build_metadata to retrieve corresponding meta data values for a build
:param metadata: a list, each item a dictionary of metadata, in format:
metadata = [{'key': 'repo_url', 'value': repo_url },
{'key': 'repo_id', 'value': repo_id ... | [
"get_build_params",
"uses",
"get_build_metadata",
"to",
"retrieve",
"corresponding",
"meta",
"data",
"values",
"for",
"a",
"build",
":",
"param",
"metadata",
":",
"a",
"list",
"each",
"item",
"a",
"dictionary",
"of",
"metadata",
"in",
"format",
":",
"metadata",
... | singularityhub/singularity-python | python | https://github.com/singularityhub/singularity-python/blob/498c3433724b332f7493fec632d8daf479f47b82/singularity/build/google.py#L350-L369 | [
"def",
"get_build_params",
"(",
"metadata",
")",
":",
"params",
"=",
"dict",
"(",
")",
"for",
"item",
"in",
"metadata",
":",
"if",
"item",
"[",
"'value'",
"]",
"==",
"None",
":",
"response",
"=",
"get_build_metadata",
"(",
"key",
"=",
"item",
"[",
"'ke... | 498c3433724b332f7493fec632d8daf479f47b82 |
train | rsync | wrapper around the rsync command.
the ssh connection arguments are set automatically.
any args are just passed directly to rsync.
you can use {host_string} in place of the server.
the kwargs are passed on the 'local' fabric command.
if not set, 'capture' is set to False.
... | bsdploy/fabutils.py | def rsync(*args, **kwargs):
""" wrapper around the rsync command.
the ssh connection arguments are set automatically.
any args are just passed directly to rsync.
you can use {host_string} in place of the server.
the kwargs are passed on the 'local' fabric command.
if not s... | def rsync(*args, **kwargs):
""" wrapper around the rsync command.
the ssh connection arguments are set automatically.
any args are just passed directly to rsync.
you can use {host_string} in place of the server.
the kwargs are passed on the 'local' fabric command.
if not s... | [
"wrapper",
"around",
"the",
"rsync",
"command",
"."
] | ployground/bsdploy | python | https://github.com/ployground/bsdploy/blob/096d63b316264931627bed1f8ca8abf7eb517352/bsdploy/fabutils.py#L23-L53 | [
"def",
"rsync",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
".",
"setdefault",
"(",
"'capture'",
",",
"False",
")",
"replacements",
"=",
"dict",
"(",
"host_string",
"=",
"\"{user}@{host}\"",
".",
"format",
"(",
"user",
"=",
"env",
".... | 096d63b316264931627bed1f8ca8abf7eb517352 |
train | bootstrap | Bootstrap an EC2 instance that has been booted into an AMI from http://www.daemonology.net/freebsd-on-ec2/
Note: deprecated, current AMI images are basically pre-bootstrapped, they just need to be configured. | bsdploy/fabfile_daemonology.py | def bootstrap(**kwargs):
""" Bootstrap an EC2 instance that has been booted into an AMI from http://www.daemonology.net/freebsd-on-ec2/
Note: deprecated, current AMI images are basically pre-bootstrapped, they just need to be configured.
"""
# the user for the image is `ec2-user`, there is no sudo, but ... | def bootstrap(**kwargs):
""" Bootstrap an EC2 instance that has been booted into an AMI from http://www.daemonology.net/freebsd-on-ec2/
Note: deprecated, current AMI images are basically pre-bootstrapped, they just need to be configured.
"""
# the user for the image is `ec2-user`, there is no sudo, but ... | [
"Bootstrap",
"an",
"EC2",
"instance",
"that",
"has",
"been",
"booted",
"into",
"an",
"AMI",
"from",
"http",
":",
"//",
"www",
".",
"daemonology",
".",
"net",
"/",
"freebsd",
"-",
"on",
"-",
"ec2",
"/",
"Note",
":",
"deprecated",
"current",
"AMI",
"imag... | ployground/bsdploy | python | https://github.com/ployground/bsdploy/blob/096d63b316264931627bed1f8ca8abf7eb517352/bsdploy/fabfile_daemonology.py#L14-L44 | [
"def",
"bootstrap",
"(",
"*",
"*",
"kwargs",
")",
":",
"# the user for the image is `ec2-user`, there is no sudo, but we can su to root w/o password",
"original_host",
"=",
"env",
".",
"host_string",
"env",
".",
"host_string",
"=",
"'ec2-user@%s'",
"%",
"env",
".",
"insta... | 096d63b316264931627bed1f8ca8abf7eb517352 |
train | bootstrap | Digital Oceans FreeBSD droplets are pretty much already pre-bootstrapped,
including having python2.7 and sudo etc. pre-installed.
the only thing we need to change is to allow root to login (without a password)
enable pf and ensure it is running | bsdploy/fabfile_digitalocean.py | def bootstrap(**kwargs):
"""Digital Oceans FreeBSD droplets are pretty much already pre-bootstrapped,
including having python2.7 and sudo etc. pre-installed.
the only thing we need to change is to allow root to login (without a password)
enable pf and ensure it is running
"""
bu = BootstrapUtil... | def bootstrap(**kwargs):
"""Digital Oceans FreeBSD droplets are pretty much already pre-bootstrapped,
including having python2.7 and sudo etc. pre-installed.
the only thing we need to change is to allow root to login (without a password)
enable pf and ensure it is running
"""
bu = BootstrapUtil... | [
"Digital",
"Oceans",
"FreeBSD",
"droplets",
"are",
"pretty",
"much",
"already",
"pre",
"-",
"bootstrapped",
"including",
"having",
"python2",
".",
"7",
"and",
"sudo",
"etc",
".",
"pre",
"-",
"installed",
".",
"the",
"only",
"thing",
"we",
"need",
"to",
"ch... | ployground/bsdploy | python | https://github.com/ployground/bsdploy/blob/096d63b316264931627bed1f8ca8abf7eb517352/bsdploy/fabfile_digitalocean.py#L14-L65 | [
"def",
"bootstrap",
"(",
"*",
"*",
"kwargs",
")",
":",
"bu",
"=",
"BootstrapUtils",
"(",
")",
"# (temporarily) set the user to `freebsd`",
"original_host",
"=",
"env",
".",
"host_string",
"env",
".",
"host_string",
"=",
"'freebsd@%s'",
"%",
"env",
".",
"instance... | 096d63b316264931627bed1f8ca8abf7eb517352 |
train | BootstrapUtils.bootstrap_files | we need some files to bootstrap the FreeBSD installation.
Some...
- need to be provided by the user (i.e. authorized_keys)
- others have some (sensible) defaults (i.e. rc.conf)
- some can be downloaded via URL (i.e.) http://pkg.freebsd.org/freebsd:10:x86:64/latest/Latest/pkg.... | bsdploy/bootstrap_utils.py | def bootstrap_files(self):
""" we need some files to bootstrap the FreeBSD installation.
Some...
- need to be provided by the user (i.e. authorized_keys)
- others have some (sensible) defaults (i.e. rc.conf)
- some can be downloaded via URL (i.e.) http://pkg.freebsd.o... | def bootstrap_files(self):
""" we need some files to bootstrap the FreeBSD installation.
Some...
- need to be provided by the user (i.e. authorized_keys)
- others have some (sensible) defaults (i.e. rc.conf)
- some can be downloaded via URL (i.e.) http://pkg.freebsd.o... | [
"we",
"need",
"some",
"files",
"to",
"bootstrap",
"the",
"FreeBSD",
"installation",
".",
"Some",
"...",
"-",
"need",
"to",
"be",
"provided",
"by",
"the",
"user",
"(",
"i",
".",
"e",
".",
"authorized_keys",
")",
"-",
"others",
"have",
"some",
"(",
"sens... | ployground/bsdploy | python | https://github.com/ployground/bsdploy/blob/096d63b316264931627bed1f8ca8abf7eb517352/bsdploy/bootstrap_utils.py#L158-L266 | [
"def",
"bootstrap_files",
"(",
"self",
")",
":",
"bootstrap_file_yamls",
"=",
"[",
"abspath",
"(",
"join",
"(",
"self",
".",
"default_template_path",
",",
"self",
".",
"bootstrap_files_yaml",
")",
")",
",",
"abspath",
"(",
"join",
"(",
"self",
".",
"custom_t... | 096d63b316264931627bed1f8ca8abf7eb517352 |
train | BootstrapUtils.devices | computes the name of the disk devices that are suitable
installation targets by subtracting CDROM- and USB devices
from the list of total mounts. | bsdploy/bootstrap_utils.py | def devices(self):
""" computes the name of the disk devices that are suitable
installation targets by subtracting CDROM- and USB devices
from the list of total mounts.
"""
install_devices = self.install_devices
if 'bootstrap-system-devices' in env.instance.config:
... | def devices(self):
""" computes the name of the disk devices that are suitable
installation targets by subtracting CDROM- and USB devices
from the list of total mounts.
"""
install_devices = self.install_devices
if 'bootstrap-system-devices' in env.instance.config:
... | [
"computes",
"the",
"name",
"of",
"the",
"disk",
"devices",
"that",
"are",
"suitable",
"installation",
"targets",
"by",
"subtracting",
"CDROM",
"-",
"and",
"USB",
"devices",
"from",
"the",
"list",
"of",
"total",
"mounts",
"."
] | ployground/bsdploy | python | https://github.com/ployground/bsdploy/blob/096d63b316264931627bed1f8ca8abf7eb517352/bsdploy/bootstrap_utils.py#L372-L386 | [
"def",
"devices",
"(",
"self",
")",
":",
"install_devices",
"=",
"self",
".",
"install_devices",
"if",
"'bootstrap-system-devices'",
"in",
"env",
".",
"instance",
".",
"config",
":",
"devices",
"=",
"set",
"(",
"env",
".",
"instance",
".",
"config",
"[",
"... | 096d63b316264931627bed1f8ca8abf7eb517352 |
train | BootstrapUtils.fetch_assets | download bootstrap assets to control host.
If present on the control host they will be uploaded to the target host during bootstrapping. | bsdploy/bootstrap_utils.py | def fetch_assets(self):
""" download bootstrap assets to control host.
If present on the control host they will be uploaded to the target host during bootstrapping.
"""
# allow overwrites from the commandline
packages = set(
env.instance.config.get('bootstrap-packages... | def fetch_assets(self):
""" download bootstrap assets to control host.
If present on the control host they will be uploaded to the target host during bootstrapping.
"""
# allow overwrites from the commandline
packages = set(
env.instance.config.get('bootstrap-packages... | [
"download",
"bootstrap",
"assets",
"to",
"control",
"host",
".",
"If",
"present",
"on",
"the",
"control",
"host",
"they",
"will",
"be",
"uploaded",
"to",
"the",
"target",
"host",
"during",
"bootstrapping",
"."
] | ployground/bsdploy | python | https://github.com/ployground/bsdploy/blob/096d63b316264931627bed1f8ca8abf7eb517352/bsdploy/bootstrap_utils.py#L457-L474 | [
"def",
"fetch_assets",
"(",
"self",
")",
":",
"# allow overwrites from the commandline",
"packages",
"=",
"set",
"(",
"env",
".",
"instance",
".",
"config",
".",
"get",
"(",
"'bootstrap-packages'",
",",
"''",
")",
".",
"split",
"(",
")",
")",
"packages",
"."... | 096d63b316264931627bed1f8ca8abf7eb517352 |
train | res_to_str | :param res: :class:`requests.Response` object
Parse the given request and generate an informative string from it | foreman/client.py | def res_to_str(res):
"""
:param res: :class:`requests.Response` object
Parse the given request and generate an informative string from it
"""
if 'Authorization' in res.request.headers:
res.request.headers['Authorization'] = "*****"
return """
####################################
url = %... | def res_to_str(res):
"""
:param res: :class:`requests.Response` object
Parse the given request and generate an informative string from it
"""
if 'Authorization' in res.request.headers:
res.request.headers['Authorization'] = "*****"
return """
####################################
url = %... | [
":",
"param",
"res",
":",
":",
"class",
":",
"requests",
".",
"Response",
"object"
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L63-L92 | [
"def",
"res_to_str",
"(",
"res",
")",
":",
"if",
"'Authorization'",
"in",
"res",
".",
"request",
".",
"headers",
":",
"res",
".",
"request",
".",
"headers",
"[",
"'Authorization'",
"]",
"=",
"\"*****\"",
"return",
"\"\"\"\n####################################\nurl... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | parse_resource_definition | Returns all the info extracted from a resource section of the apipie json
:param resource_name: Name of the resource that is defined by the section
:param resrouce_dict: Dictionary as generated by apipie of the resource
definition | foreman/client.py | def parse_resource_definition(resource_name, resource_dct):
"""
Returns all the info extracted from a resource section of the apipie json
:param resource_name: Name of the resource that is defined by the section
:param resrouce_dict: Dictionary as generated by apipie of the resource
definition
... | def parse_resource_definition(resource_name, resource_dct):
"""
Returns all the info extracted from a resource section of the apipie json
:param resource_name: Name of the resource that is defined by the section
:param resrouce_dict: Dictionary as generated by apipie of the resource
definition
... | [
"Returns",
"all",
"the",
"info",
"extracted",
"from",
"a",
"resource",
"section",
"of",
"the",
"apipie",
"json"
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L312-L406 | [
"def",
"parse_resource_definition",
"(",
"resource_name",
",",
"resource_dct",
")",
":",
"new_dict",
"=",
"{",
"'__module__'",
":",
"resource_dct",
".",
"get",
"(",
"'__module__'",
",",
"__name__",
")",
",",
"'__doc__'",
":",
"resource_dct",
"[",
"'full_descriptio... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | MethodAPIDescription.parse_resource_from_url | Returns the appropriate resource name for the given URL.
:param url: API URL stub, like: '/api/hosts'
:return: Resource name, like 'hosts', or None if not found | foreman/client.py | def parse_resource_from_url(self, url):
"""
Returns the appropriate resource name for the given URL.
:param url: API URL stub, like: '/api/hosts'
:return: Resource name, like 'hosts', or None if not found
"""
# special case for the api root
if url == '/api':
... | def parse_resource_from_url(self, url):
"""
Returns the appropriate resource name for the given URL.
:param url: API URL stub, like: '/api/hosts'
:return: Resource name, like 'hosts', or None if not found
"""
# special case for the api root
if url == '/api':
... | [
"Returns",
"the",
"appropriate",
"resource",
"name",
"for",
"the",
"given",
"URL",
"."
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L137-L152 | [
"def",
"parse_resource_from_url",
"(",
"self",
",",
"url",
")",
":",
"# special case for the api root",
"if",
"url",
"==",
"'/api'",
":",
"return",
"'api'",
"elif",
"url",
"==",
"'/katello'",
":",
"return",
"'katello'",
"match",
"=",
"self",
".",
"resource_patte... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | MethodAPIDescription._get_name | There are three cases, because apipie definitions can have multiple
signatures but python does not
For example, the api endpoint:
/api/myres/:myres_id/subres/:subres_id/subres2
for method *index* will be translated to the api method name:
subres_index_subres2
So ... | foreman/client.py | def _get_name(self):
"""
There are three cases, because apipie definitions can have multiple
signatures but python does not
For example, the api endpoint:
/api/myres/:myres_id/subres/:subres_id/subres2
for method *index* will be translated to the api method name:
... | def _get_name(self):
"""
There are three cases, because apipie definitions can have multiple
signatures but python does not
For example, the api endpoint:
/api/myres/:myres_id/subres/:subres_id/subres2
for method *index* will be translated to the api method name:
... | [
"There",
"are",
"three",
"cases",
"because",
"apipie",
"definitions",
"can",
"have",
"multiple",
"signatures",
"but",
"python",
"does",
"not",
"For",
"example",
"the",
"api",
"endpoint",
":",
"/",
"api",
"/",
"myres",
"/",
":",
"myres_id",
"/",
"subres",
"... | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L154-L191 | [
"def",
"_get_name",
"(",
"self",
")",
":",
"if",
"self",
".",
"url",
".",
"count",
"(",
"':'",
")",
">",
"1",
":",
"# /api/one/two/:three/four -> two_:three_four",
"base_name",
"=",
"self",
".",
"url",
".",
"split",
"(",
"'/'",
",",
"3",
")",
"[",
"-",... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | MethodAPIDescription.generate_func | Generate function for specific method and using specific api
:param as_global: if set, will use the global function name, instead of
the class method (usually {resource}_{class_method}) when defining
the function | foreman/client.py | def generate_func(self, as_global=False):
"""
Generate function for specific method and using specific api
:param as_global: if set, will use the global function name, instead of
the class method (usually {resource}_{class_method}) when defining
the function
"""
... | def generate_func(self, as_global=False):
"""
Generate function for specific method and using specific api
:param as_global: if set, will use the global function name, instead of
the class method (usually {resource}_{class_method}) when defining
the function
"""
... | [
"Generate",
"function",
"for",
"specific",
"method",
"and",
"using",
"specific",
"api"
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L196-L287 | [
"def",
"generate_func",
"(",
"self",
",",
"as_global",
"=",
"False",
")",
":",
"keywords",
"=",
"[",
"]",
"params_def",
"=",
"[",
"]",
"params_doc",
"=",
"\"\"",
"original_names",
"=",
"{",
"}",
"params",
"=",
"dict",
"(",
"(",
"param",
"[",
"'name'",
... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | MethodAPIDescription.create_param_doc | Generate documentation for single parameter of function
:param param: dict contains info about parameter
:param sub: prefix string for recursive purposes | foreman/client.py | def create_param_doc(cls, param, prefix=None):
"""
Generate documentation for single parameter of function
:param param: dict contains info about parameter
:param sub: prefix string for recursive purposes
"""
desc = cls.exclude_html_reg.sub('', param['description']).strip... | def create_param_doc(cls, param, prefix=None):
"""
Generate documentation for single parameter of function
:param param: dict contains info about parameter
:param sub: prefix string for recursive purposes
"""
desc = cls.exclude_html_reg.sub('', param['description']).strip... | [
"Generate",
"documentation",
"for",
"single",
"parameter",
"of",
"function",
":",
"param",
"param",
":",
"dict",
"contains",
"info",
"about",
"parameter",
":",
"param",
"sub",
":",
"prefix",
"string",
"for",
"recursive",
"purposes"
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L290-L309 | [
"def",
"create_param_doc",
"(",
"cls",
",",
"param",
",",
"prefix",
"=",
"None",
")",
":",
"desc",
"=",
"cls",
".",
"exclude_html_reg",
".",
"sub",
"(",
"''",
",",
"param",
"[",
"'description'",
"]",
")",
".",
"strip",
"(",
")",
"if",
"not",
"desc",
... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | MetaForeman.convert_plugin_def | This function parses one of the elements of the definitions dict for a
plugin and extracts the relevant information
:param http_method: HTTP method that uses (GET, POST, DELETE, ...)
:param funcs: functions related to that HTTP method | foreman/client.py | def convert_plugin_def(http_method, funcs):
"""
This function parses one of the elements of the definitions dict for a
plugin and extracts the relevant information
:param http_method: HTTP method that uses (GET, POST, DELETE, ...)
:param funcs: functions related to that HTTP met... | def convert_plugin_def(http_method, funcs):
"""
This function parses one of the elements of the definitions dict for a
plugin and extracts the relevant information
:param http_method: HTTP method that uses (GET, POST, DELETE, ...)
:param funcs: functions related to that HTTP met... | [
"This",
"function",
"parses",
"one",
"of",
"the",
"elements",
"of",
"the",
"definitions",
"dict",
"for",
"a",
"plugin",
"and",
"extracts",
"the",
"relevant",
"information"
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/foreman/client.py#L510-L542 | [
"def",
"convert_plugin_def",
"(",
"http_method",
",",
"funcs",
")",
":",
"methods",
"=",
"[",
"]",
"if",
"http_method",
"not",
"in",
"(",
"'GET'",
",",
"'PUT'",
",",
"'POST'",
",",
"'DELETE'",
")",
":",
"logger",
".",
"error",
"(",
"'Plugin load failure, H... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | get_current_version | Given a repo will return the version string, according to semantic
versioning, counting as non-backwards compatible commit any one with a
message header that matches (case insensitive)::
sem-ver: .*break.*
And as features any commit with a header matching::
sem-ver: feature
And count... | scripts/version_manager.py | def get_current_version(repo_path):
"""
Given a repo will return the version string, according to semantic
versioning, counting as non-backwards compatible commit any one with a
message header that matches (case insensitive)::
sem-ver: .*break.*
And as features any commit with a header mat... | def get_current_version(repo_path):
"""
Given a repo will return the version string, according to semantic
versioning, counting as non-backwards compatible commit any one with a
message header that matches (case insensitive)::
sem-ver: .*break.*
And as features any commit with a header mat... | [
"Given",
"a",
"repo",
"will",
"return",
"the",
"version",
"string",
"according",
"to",
"semantic",
"versioning",
"counting",
"as",
"non",
"-",
"backwards",
"compatible",
"commit",
"any",
"one",
"with",
"a",
"message",
"header",
"that",
"matches",
"(",
"case",
... | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/scripts/version_manager.py#L402-L435 | [
"def",
"get_current_version",
"(",
"repo_path",
")",
":",
"repo",
"=",
"dulwich",
".",
"repo",
".",
"Repo",
"(",
"repo_path",
")",
"tags",
"=",
"get_tags",
"(",
"repo",
")",
"maj_version",
"=",
"0",
"feat_version",
"=",
"0",
"fix_version",
"=",
"0",
"for... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | get_authors | Given a repo and optionally a base revision to start from, will return
the list of authors. | scripts/version_manager.py | def get_authors(repo_path, from_commit):
"""
Given a repo and optionally a base revision to start from, will return
the list of authors.
"""
repo = dulwich.repo.Repo(repo_path)
refs = get_refs(repo)
start_including = False
authors = set()
if from_commit is None:
start_includ... | def get_authors(repo_path, from_commit):
"""
Given a repo and optionally a base revision to start from, will return
the list of authors.
"""
repo = dulwich.repo.Repo(repo_path)
refs = get_refs(repo)
start_including = False
authors = set()
if from_commit is None:
start_includ... | [
"Given",
"a",
"repo",
"and",
"optionally",
"a",
"base",
"revision",
"to",
"start",
"from",
"will",
"return",
"the",
"list",
"of",
"authors",
"."
] | david-caro/python-foreman | python | https://github.com/david-caro/python-foreman/blob/a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8/scripts/version_manager.py#L438-L465 | [
"def",
"get_authors",
"(",
"repo_path",
",",
"from_commit",
")",
":",
"repo",
"=",
"dulwich",
".",
"repo",
".",
"Repo",
"(",
"repo_path",
")",
"refs",
"=",
"get_refs",
"(",
"repo",
")",
"start_including",
"=",
"False",
"authors",
"=",
"set",
"(",
")",
... | a81e4c99fe6a9ad56e9758dbe96dd55bca67d3b8 |
train | Spout.emit | Emit a spout Tuple message.
:param tup: the Tuple to send to Storm, should contain only
JSON-serializable data.
:type tup: list or tuple
:param tup_id: the ID for the Tuple. Leave this blank for an
unreliable emit.
:type tup_id: str
:pa... | pystorm/spout.py | def emit(
self, tup, tup_id=None, stream=None, direct_task=None, need_task_ids=False
):
"""Emit a spout Tuple message.
:param tup: the Tuple to send to Storm, should contain only
JSON-serializable data.
:type tup: list or tuple
:param tup_id: the ID for t... | def emit(
self, tup, tup_id=None, stream=None, direct_task=None, need_task_ids=False
):
"""Emit a spout Tuple message.
:param tup: the Tuple to send to Storm, should contain only
JSON-serializable data.
:type tup: list or tuple
:param tup_id: the ID for t... | [
"Emit",
"a",
"spout",
"Tuple",
"message",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/spout.py#L50-L82 | [
"def",
"emit",
"(",
"self",
",",
"tup",
",",
"tup_id",
"=",
"None",
",",
"stream",
"=",
"None",
",",
"direct_task",
"=",
"None",
",",
"need_task_ids",
"=",
"False",
")",
":",
"return",
"super",
"(",
"Spout",
",",
"self",
")",
".",
"emit",
"(",
"tup... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Spout._run | The inside of ``run``'s infinite loop.
Separated out so it can be properly unit tested. | pystorm/spout.py | def _run(self):
"""The inside of ``run``'s infinite loop.
Separated out so it can be properly unit tested.
"""
cmd = self.read_command()
if cmd["command"] == "next":
self.next_tuple()
elif cmd["command"] == "ack":
self.ack(cmd["id"])
elif ... | def _run(self):
"""The inside of ``run``'s infinite loop.
Separated out so it can be properly unit tested.
"""
cmd = self.read_command()
if cmd["command"] == "next":
self.next_tuple()
elif cmd["command"] == "ack":
self.ack(cmd["id"])
elif ... | [
"The",
"inside",
"of",
"run",
"s",
"infinite",
"loop",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/spout.py#L100-L118 | [
"def",
"_run",
"(",
"self",
")",
":",
"cmd",
"=",
"self",
".",
"read_command",
"(",
")",
"if",
"cmd",
"[",
"\"command\"",
"]",
"==",
"\"next\"",
":",
"self",
".",
"next_tuple",
"(",
")",
"elif",
"cmd",
"[",
"\"command\"",
"]",
"==",
"\"ack\"",
":",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | ReliableSpout.ack | Called when a bolt acknowledges a Tuple in the topology.
:param tup_id: the ID of the Tuple that has been fully acknowledged in
the topology.
:type tup_id: str | pystorm/spout.py | def ack(self, tup_id):
"""Called when a bolt acknowledges a Tuple in the topology.
:param tup_id: the ID of the Tuple that has been fully acknowledged in
the topology.
:type tup_id: str
"""
self.failed_tuples.pop(tup_id, None)
try:
del ... | def ack(self, tup_id):
"""Called when a bolt acknowledges a Tuple in the topology.
:param tup_id: the ID of the Tuple that has been fully acknowledged in
the topology.
:type tup_id: str
"""
self.failed_tuples.pop(tup_id, None)
try:
del ... | [
"Called",
"when",
"a",
"bolt",
"acknowledges",
"a",
"Tuple",
"in",
"the",
"topology",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/spout.py#L137-L148 | [
"def",
"ack",
"(",
"self",
",",
"tup_id",
")",
":",
"self",
".",
"failed_tuples",
".",
"pop",
"(",
"tup_id",
",",
"None",
")",
"try",
":",
"del",
"self",
".",
"unacked_tuples",
"[",
"tup_id",
"]",
"except",
"KeyError",
":",
"self",
".",
"logger",
"."... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | ReliableSpout.fail | Called when a Tuple fails in the topology
A reliable spout will replay a failed tuple up to ``max_fails`` times.
:param tup_id: the ID of the Tuple that has failed in the topology
either due to a bolt calling ``fail()`` or a Tuple
timing out.
:type... | pystorm/spout.py | def fail(self, tup_id):
"""Called when a Tuple fails in the topology
A reliable spout will replay a failed tuple up to ``max_fails`` times.
:param tup_id: the ID of the Tuple that has failed in the topology
either due to a bolt calling ``fail()`` or a Tuple
... | def fail(self, tup_id):
"""Called when a Tuple fails in the topology
A reliable spout will replay a failed tuple up to ``max_fails`` times.
:param tup_id: the ID of the Tuple that has failed in the topology
either due to a bolt calling ``fail()`` or a Tuple
... | [
"Called",
"when",
"a",
"Tuple",
"fails",
"in",
"the",
"topology"
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/spout.py#L150-L181 | [
"def",
"fail",
"(",
"self",
",",
"tup_id",
")",
":",
"saved_args",
"=",
"self",
".",
"unacked_tuples",
".",
"get",
"(",
"tup_id",
")",
"if",
"saved_args",
"is",
"None",
":",
"self",
".",
"logger",
".",
"error",
"(",
"\"Received fail for unknown tuple ID: %r\... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | ReliableSpout.emit | Emit a spout Tuple & add metadata about it to `unacked_tuples`.
In order for this to work, `tup_id` is a required parameter.
See :meth:`Bolt.emit`. | pystorm/spout.py | def emit(
self, tup, tup_id=None, stream=None, direct_task=None, need_task_ids=False
):
"""Emit a spout Tuple & add metadata about it to `unacked_tuples`.
In order for this to work, `tup_id` is a required parameter.
See :meth:`Bolt.emit`.
"""
if tup_id is None:
... | def emit(
self, tup, tup_id=None, stream=None, direct_task=None, need_task_ids=False
):
"""Emit a spout Tuple & add metadata about it to `unacked_tuples`.
In order for this to work, `tup_id` is a required parameter.
See :meth:`Bolt.emit`.
"""
if tup_id is None:
... | [
"Emit",
"a",
"spout",
"Tuple",
"&",
"add",
"metadata",
"about",
"it",
"to",
"unacked_tuples",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/spout.py#L183-L206 | [
"def",
"emit",
"(",
"self",
",",
"tup",
",",
"tup_id",
"=",
"None",
",",
"stream",
"=",
"None",
",",
"direct_task",
"=",
"None",
",",
"need_task_ids",
"=",
"False",
")",
":",
"if",
"tup_id",
"is",
"None",
":",
"raise",
"ValueError",
"(",
"\"You must pr... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | remote_pdb_handler | Handler to drop us into a remote debugger upon receiving SIGUSR1 | pystorm/component.py | def remote_pdb_handler(signum, frame):
""" Handler to drop us into a remote debugger upon receiving SIGUSR1 """
try:
from remote_pdb import RemotePdb
rdb = RemotePdb(host="127.0.0.1", port=0)
rdb.set_trace(frame=frame)
except ImportError:
log.warning(
"remote_pdb... | def remote_pdb_handler(signum, frame):
""" Handler to drop us into a remote debugger upon receiving SIGUSR1 """
try:
from remote_pdb import RemotePdb
rdb = RemotePdb(host="127.0.0.1", port=0)
rdb.set_trace(frame=frame)
except ImportError:
log.warning(
"remote_pdb... | [
"Handler",
"to",
"drop",
"us",
"into",
"a",
"remote",
"debugger",
"upon",
"receiving",
"SIGUSR1"
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L50-L63 | [
"def",
"remote_pdb_handler",
"(",
"signum",
",",
"frame",
")",
":",
"try",
":",
"from",
"remote_pdb",
"import",
"RemotePdb",
"rdb",
"=",
"RemotePdb",
"(",
"host",
"=",
"\"127.0.0.1\"",
",",
"port",
"=",
"0",
")",
"rdb",
".",
"set_trace",
"(",
"frame",
"=... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | StormHandler.emit | Emit a record.
If a formatter is specified, it is used to format the record.
If exception information is present, it is formatted using
traceback.print_exception and sent to Storm. | pystorm/component.py | def emit(self, record):
"""
Emit a record.
If a formatter is specified, it is used to format the record.
If exception information is present, it is formatted using
traceback.print_exception and sent to Storm.
"""
try:
msg = self.format(record)
... | def emit(self, record):
"""
Emit a record.
If a formatter is specified, it is used to format the record.
If exception information is present, it is formatted using
traceback.print_exception and sent to Storm.
"""
try:
msg = self.format(record)
... | [
"Emit",
"a",
"record",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L78-L93 | [
"def",
"emit",
"(",
"self",
",",
"record",
")",
":",
"try",
":",
"msg",
"=",
"self",
".",
"format",
"(",
"record",
")",
"level",
"=",
"_STORM_LOG_LEVELS",
".",
"get",
"(",
"record",
".",
"levelname",
".",
"lower",
"(",
")",
",",
"_STORM_LOG_INFO",
")... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component._setup_component | Add helpful instance variables to component after initial handshake
with Storm. Also configure logging. | pystorm/component.py | def _setup_component(self, storm_conf, context):
"""Add helpful instance variables to component after initial handshake
with Storm. Also configure logging.
"""
self.topology_name = storm_conf.get("topology.name", "")
self.task_id = context.get("taskid", "")
self.componen... | def _setup_component(self, storm_conf, context):
"""Add helpful instance variables to component after initial handshake
with Storm. Also configure logging.
"""
self.topology_name = storm_conf.get("topology.name", "")
self.task_id = context.get("taskid", "")
self.componen... | [
"Add",
"helpful",
"instance",
"variables",
"to",
"component",
"after",
"initial",
"handshake",
"with",
"Storm",
".",
"Also",
"configure",
"logging",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L230-L300 | [
"def",
"_setup_component",
"(",
"self",
",",
"storm_conf",
",",
"context",
")",
":",
"self",
".",
"topology_name",
"=",
"storm_conf",
".",
"get",
"(",
"\"topology.name\"",
",",
"\"\"",
")",
"self",
".",
"task_id",
"=",
"context",
".",
"get",
"(",
"\"taskid... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component.read_handshake | Read and process an initial handshake message from Storm. | pystorm/component.py | def read_handshake(self):
"""Read and process an initial handshake message from Storm."""
msg = self.read_message()
pid_dir, _conf, _context = msg["pidDir"], msg["conf"], msg["context"]
# Write a blank PID file out to the pidDir
open(join(pid_dir, str(self.pid)), "w").close()
... | def read_handshake(self):
"""Read and process an initial handshake message from Storm."""
msg = self.read_message()
pid_dir, _conf, _context = msg["pidDir"], msg["conf"], msg["context"]
# Write a blank PID file out to the pidDir
open(join(pid_dir, str(self.pid)), "w").close()
... | [
"Read",
"and",
"process",
"an",
"initial",
"handshake",
"message",
"from",
"Storm",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L326-L335 | [
"def",
"read_handshake",
"(",
"self",
")",
":",
"msg",
"=",
"self",
".",
"read_message",
"(",
")",
"pid_dir",
",",
"_conf",
",",
"_context",
"=",
"msg",
"[",
"\"pidDir\"",
"]",
",",
"msg",
"[",
"\"conf\"",
"]",
",",
"msg",
"[",
"\"context\"",
"]",
"#... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component.send_message | Send a message to Storm via stdout. | pystorm/component.py | def send_message(self, message):
"""Send a message to Storm via stdout."""
if not isinstance(message, dict):
logger = self.logger if self.logger else log
logger.error(
"%s.%d attempted to send a non dict message to Storm: " "%r",
self.component_nam... | def send_message(self, message):
"""Send a message to Storm via stdout."""
if not isinstance(message, dict):
logger = self.logger if self.logger else log
logger.error(
"%s.%d attempted to send a non dict message to Storm: " "%r",
self.component_nam... | [
"Send",
"a",
"message",
"to",
"Storm",
"via",
"stdout",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L337-L348 | [
"def",
"send_message",
"(",
"self",
",",
"message",
")",
":",
"if",
"not",
"isinstance",
"(",
"message",
",",
"dict",
")",
":",
"logger",
"=",
"self",
".",
"logger",
"if",
"self",
".",
"logger",
"else",
"log",
"logger",
".",
"error",
"(",
"\"%s.%d atte... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component.raise_exception | Report an exception back to Storm via logging.
:param exception: a Python exception.
:param tup: a :class:`Tuple` object. | pystorm/component.py | def raise_exception(self, exception, tup=None):
"""Report an exception back to Storm via logging.
:param exception: a Python exception.
:param tup: a :class:`Tuple` object.
"""
if tup:
message = (
"Python {exception_name} raised while processing Tuple... | def raise_exception(self, exception, tup=None):
"""Report an exception back to Storm via logging.
:param exception: a Python exception.
:param tup: a :class:`Tuple` object.
"""
if tup:
message = (
"Python {exception_name} raised while processing Tuple... | [
"Report",
"an",
"exception",
"back",
"to",
"Storm",
"via",
"logging",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L350-L367 | [
"def",
"raise_exception",
"(",
"self",
",",
"exception",
",",
"tup",
"=",
"None",
")",
":",
"if",
"tup",
":",
"message",
"=",
"(",
"\"Python {exception_name} raised while processing Tuple \"",
"\"{tup!r}\\n{traceback}\"",
")",
"else",
":",
"message",
"=",
"\"Python ... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component.log | Log a message to Storm optionally providing a logging level.
:param message: the log message to send to Storm.
:type message: str
:param level: the logging level that Storm should use when writing the
``message``. Can be one of: trace, debug, info, warn, or
... | pystorm/component.py | def log(self, message, level=None):
"""Log a message to Storm optionally providing a logging level.
:param message: the log message to send to Storm.
:type message: str
:param level: the logging level that Storm should use when writing the
``message``. Can be one o... | def log(self, message, level=None):
"""Log a message to Storm optionally providing a logging level.
:param message: the log message to send to Storm.
:type message: str
:param level: the logging level that Storm should use when writing the
``message``. Can be one o... | [
"Log",
"a",
"message",
"to",
"Storm",
"optionally",
"providing",
"a",
"logging",
"level",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L384-L404 | [
"def",
"log",
"(",
"self",
",",
"message",
",",
"level",
"=",
"None",
")",
":",
"level",
"=",
"_STORM_LOG_LEVELS",
".",
"get",
"(",
"level",
",",
"_STORM_LOG_INFO",
")",
"self",
".",
"send_message",
"(",
"{",
"\"command\"",
":",
"\"log\"",
",",
"\"msg\""... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component.emit | Emit a new Tuple to a stream.
:param tup: the Tuple payload to send to Storm, should contain only
JSON-serializable data.
:type tup: :class:`list` or :class:`pystorm.component.Tuple`
:param tup_id: the ID for the Tuple. If omitted by a
:class:`pystorm.... | pystorm/component.py | def emit(
self,
tup,
tup_id=None,
stream=None,
anchors=None,
direct_task=None,
need_task_ids=False,
):
"""Emit a new Tuple to a stream.
:param tup: the Tuple payload to send to Storm, should contain only
JSON-serializable d... | def emit(
self,
tup,
tup_id=None,
stream=None,
anchors=None,
direct_task=None,
need_task_ids=False,
):
"""Emit a new Tuple to a stream.
:param tup: the Tuple payload to send to Storm, should contain only
JSON-serializable d... | [
"Emit",
"a",
"new",
"Tuple",
"to",
"a",
"stream",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L406-L478 | [
"def",
"emit",
"(",
"self",
",",
"tup",
",",
"tup_id",
"=",
"None",
",",
"stream",
"=",
"None",
",",
"anchors",
"=",
"None",
",",
"direct_task",
"=",
"None",
",",
"need_task_ids",
"=",
"False",
",",
")",
":",
"if",
"not",
"isinstance",
"(",
"tup",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component.run | Main run loop for all components.
Performs initial handshake with Storm and reads Tuples handing them off
to subclasses. Any exceptions are caught and logged back to Storm
prior to the Python process exiting.
.. warning::
Subclasses should **not** override this method. | pystorm/component.py | def run(self):
"""Main run loop for all components.
Performs initial handshake with Storm and reads Tuples handing them off
to subclasses. Any exceptions are caught and logged back to Storm
prior to the Python process exiting.
.. warning::
Subclasses should **not*... | def run(self):
"""Main run loop for all components.
Performs initial handshake with Storm and reads Tuples handing them off
to subclasses. Any exceptions are caught and logged back to Storm
prior to the Python process exiting.
.. warning::
Subclasses should **not*... | [
"Main",
"run",
"loop",
"for",
"all",
"components",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L504-L542 | [
"def",
"run",
"(",
"self",
")",
":",
"storm_conf",
",",
"context",
"=",
"self",
".",
"read_handshake",
"(",
")",
"self",
".",
"_setup_component",
"(",
"storm_conf",
",",
"context",
")",
"self",
".",
"initialize",
"(",
"storm_conf",
",",
"context",
")",
"... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Component._exit | Properly kill Python process including zombie threads. | pystorm/component.py | def _exit(self, status_code):
"""Properly kill Python process including zombie threads."""
# If there are active threads still running infinite loops, sys.exit
# won't kill them but os._exit will. os._exit skips calling cleanup
# handlers, flushing stdio buffers, etc.
exit_func =... | def _exit(self, status_code):
"""Properly kill Python process including zombie threads."""
# If there are active threads still running infinite loops, sys.exit
# won't kill them but os._exit will. os._exit skips calling cleanup
# handlers, flushing stdio buffers, etc.
exit_func =... | [
"Properly",
"kill",
"Python",
"process",
"including",
"zombie",
"threads",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/component.py#L544-L550 | [
"def",
"_exit",
"(",
"self",
",",
"status_code",
")",
":",
"# If there are active threads still running infinite loops, sys.exit",
"# won't kill them but os._exit will. os._exit skips calling cleanup",
"# handlers, flushing stdio buffers, etc.",
"exit_func",
"=",
"os",
".",
"_exit",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | JSONSerializer._wrap_stream | Returns a TextIOWrapper around the given stream that handles UTF-8
encoding/decoding. | pystorm/serializers/json_serializer.py | def _wrap_stream(stream):
"""Returns a TextIOWrapper around the given stream that handles UTF-8
encoding/decoding.
"""
if hasattr(stream, "buffer"):
return io.TextIOWrapper(stream.buffer, encoding="utf-8")
elif hasattr(stream, "readable"):
return io.TextIO... | def _wrap_stream(stream):
"""Returns a TextIOWrapper around the given stream that handles UTF-8
encoding/decoding.
"""
if hasattr(stream, "buffer"):
return io.TextIOWrapper(stream.buffer, encoding="utf-8")
elif hasattr(stream, "readable"):
return io.TextIO... | [
"Returns",
"a",
"TextIOWrapper",
"around",
"the",
"given",
"stream",
"that",
"handles",
"UTF",
"-",
"8",
"encoding",
"/",
"decoding",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/serializers/json_serializer.py#L27-L37 | [
"def",
"_wrap_stream",
"(",
"stream",
")",
":",
"if",
"hasattr",
"(",
"stream",
",",
"\"buffer\"",
")",
":",
"return",
"io",
".",
"TextIOWrapper",
"(",
"stream",
".",
"buffer",
",",
"encoding",
"=",
"\"utf-8\"",
")",
"elif",
"hasattr",
"(",
"stream",
","... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | JSONSerializer.read_message | The Storm multilang protocol consists of JSON messages followed by
a newline and "end\n".
All of Storm's messages (for either bolts or spouts) should be of the
form::
'<command or task_id form prior emit>\\nend\\n'
Command example, an incoming Tuple to a bolt::
... | pystorm/serializers/json_serializer.py | def read_message(self):
"""The Storm multilang protocol consists of JSON messages followed by
a newline and "end\n".
All of Storm's messages (for either bolts or spouts) should be of the
form::
'<command or task_id form prior emit>\\nend\\n'
Command example, an inc... | def read_message(self):
"""The Storm multilang protocol consists of JSON messages followed by
a newline and "end\n".
All of Storm's messages (for either bolts or spouts) should be of the
form::
'<command or task_id form prior emit>\\nend\\n'
Command example, an inc... | [
"The",
"Storm",
"multilang",
"protocol",
"consists",
"of",
"JSON",
"messages",
"followed",
"by",
"a",
"newline",
"and",
"end",
"\\",
"n",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/serializers/json_serializer.py#L39-L91 | [
"def",
"read_message",
"(",
"self",
")",
":",
"msg",
"=",
"\"\"",
"num_blank_lines",
"=",
"0",
"while",
"True",
":",
"# readline will return trailing \\n so that output is unambigious, we",
"# should only have line == '' if we're at EOF",
"with",
"self",
".",
"_reader_lock",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | JSONSerializer.serialize_dict | Serialize to JSON a message dictionary. | pystorm/serializers/json_serializer.py | def serialize_dict(self, msg_dict):
"""Serialize to JSON a message dictionary."""
serialized = json.dumps(msg_dict, namedtuple_as_object=False)
if PY2:
serialized = serialized.decode("utf-8")
serialized = "{}\nend\n".format(serialized)
return serialized | def serialize_dict(self, msg_dict):
"""Serialize to JSON a message dictionary."""
serialized = json.dumps(msg_dict, namedtuple_as_object=False)
if PY2:
serialized = serialized.decode("utf-8")
serialized = "{}\nend\n".format(serialized)
return serialized | [
"Serialize",
"to",
"JSON",
"a",
"message",
"dictionary",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/serializers/json_serializer.py#L93-L99 | [
"def",
"serialize_dict",
"(",
"self",
",",
"msg_dict",
")",
":",
"serialized",
"=",
"json",
".",
"dumps",
"(",
"msg_dict",
",",
"namedtuple_as_object",
"=",
"False",
")",
"if",
"PY2",
":",
"serialized",
"=",
"serialized",
".",
"decode",
"(",
"\"utf-8\"",
"... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Bolt.read_tuple | Read a tuple from the pipe to Storm. | pystorm/bolt.py | def read_tuple(self):
"""Read a tuple from the pipe to Storm."""
cmd = self.read_command()
source = cmd["comp"]
stream = cmd["stream"]
values = cmd["tuple"]
val_type = self._source_tuple_types[source].get(stream)
return Tuple(
cmd["id"],
so... | def read_tuple(self):
"""Read a tuple from the pipe to Storm."""
cmd = self.read_command()
source = cmd["comp"]
stream = cmd["stream"]
values = cmd["tuple"]
val_type = self._source_tuple_types[source].get(stream)
return Tuple(
cmd["id"],
so... | [
"Read",
"a",
"tuple",
"from",
"the",
"pipe",
"to",
"Storm",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L90-L103 | [
"def",
"read_tuple",
"(",
"self",
")",
":",
"cmd",
"=",
"self",
".",
"read_command",
"(",
")",
"source",
"=",
"cmd",
"[",
"\"comp\"",
"]",
"stream",
"=",
"cmd",
"[",
"\"stream\"",
"]",
"values",
"=",
"cmd",
"[",
"\"tuple\"",
"]",
"val_type",
"=",
"se... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Bolt.emit | Emit a new Tuple to a stream.
:param tup: the Tuple payload to send to Storm, should contain only
JSON-serializable data.
:type tup: :class:`list` or :class:`pystorm.component.Tuple`
:param stream: the ID of the stream to emit this Tuple to. Specify
``... | pystorm/bolt.py | def emit(
self, tup, stream=None, anchors=None, direct_task=None, need_task_ids=False
):
"""Emit a new Tuple to a stream.
:param tup: the Tuple payload to send to Storm, should contain only
JSON-serializable data.
:type tup: :class:`list` or :class:`pystorm.compo... | def emit(
self, tup, stream=None, anchors=None, direct_task=None, need_task_ids=False
):
"""Emit a new Tuple to a stream.
:param tup: the Tuple payload to send to Storm, should contain only
JSON-serializable data.
:type tup: :class:`list` or :class:`pystorm.compo... | [
"Emit",
"a",
"new",
"Tuple",
"to",
"a",
"stream",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L136-L174 | [
"def",
"emit",
"(",
"self",
",",
"tup",
",",
"stream",
"=",
"None",
",",
"anchors",
"=",
"None",
",",
"direct_task",
"=",
"None",
",",
"need_task_ids",
"=",
"False",
")",
":",
"if",
"anchors",
"is",
"None",
":",
"anchors",
"=",
"self",
".",
"_current... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Bolt.ack | Indicate that processing of a Tuple has succeeded.
:param tup: the Tuple to acknowledge.
:type tup: :class:`str` or :class:`pystorm.component.Tuple` | pystorm/bolt.py | def ack(self, tup):
"""Indicate that processing of a Tuple has succeeded.
:param tup: the Tuple to acknowledge.
:type tup: :class:`str` or :class:`pystorm.component.Tuple`
"""
tup_id = tup.id if isinstance(tup, Tuple) else tup
self.send_message({"command": "ack", "id": t... | def ack(self, tup):
"""Indicate that processing of a Tuple has succeeded.
:param tup: the Tuple to acknowledge.
:type tup: :class:`str` or :class:`pystorm.component.Tuple`
"""
tup_id = tup.id if isinstance(tup, Tuple) else tup
self.send_message({"command": "ack", "id": t... | [
"Indicate",
"that",
"processing",
"of",
"a",
"Tuple",
"has",
"succeeded",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L176-L183 | [
"def",
"ack",
"(",
"self",
",",
"tup",
")",
":",
"tup_id",
"=",
"tup",
".",
"id",
"if",
"isinstance",
"(",
"tup",
",",
"Tuple",
")",
"else",
"tup",
"self",
".",
"send_message",
"(",
"{",
"\"command\"",
":",
"\"ack\"",
",",
"\"id\"",
":",
"tup_id",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Bolt.fail | Indicate that processing of a Tuple has failed.
:param tup: the Tuple to fail (its ``id`` if ``str``).
:type tup: :class:`str` or :class:`pystorm.component.Tuple` | pystorm/bolt.py | def fail(self, tup):
"""Indicate that processing of a Tuple has failed.
:param tup: the Tuple to fail (its ``id`` if ``str``).
:type tup: :class:`str` or :class:`pystorm.component.Tuple`
"""
tup_id = tup.id if isinstance(tup, Tuple) else tup
self.send_message({"command":... | def fail(self, tup):
"""Indicate that processing of a Tuple has failed.
:param tup: the Tuple to fail (its ``id`` if ``str``).
:type tup: :class:`str` or :class:`pystorm.component.Tuple`
"""
tup_id = tup.id if isinstance(tup, Tuple) else tup
self.send_message({"command":... | [
"Indicate",
"that",
"processing",
"of",
"a",
"Tuple",
"has",
"failed",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L185-L192 | [
"def",
"fail",
"(",
"self",
",",
"tup",
")",
":",
"tup_id",
"=",
"tup",
".",
"id",
"if",
"isinstance",
"(",
"tup",
",",
"Tuple",
")",
"else",
"tup",
"self",
".",
"send_message",
"(",
"{",
"\"command\"",
":",
"\"fail\"",
",",
"\"id\"",
":",
"tup_id",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Bolt._run | The inside of ``run``'s infinite loop.
Separated out so it can be properly unit tested. | pystorm/bolt.py | def _run(self):
"""The inside of ``run``'s infinite loop.
Separated out so it can be properly unit tested.
"""
tup = self.read_tuple()
self._current_tups = [tup]
if self.is_heartbeat(tup):
self.send_message({"command": "sync"})
elif self.is_tick(tup):... | def _run(self):
"""The inside of ``run``'s infinite loop.
Separated out so it can be properly unit tested.
"""
tup = self.read_tuple()
self._current_tups = [tup]
if self.is_heartbeat(tup):
self.send_message({"command": "sync"})
elif self.is_tick(tup):... | [
"The",
"inside",
"of",
"run",
"s",
"infinite",
"loop",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L194-L215 | [
"def",
"_run",
"(",
"self",
")",
":",
"tup",
"=",
"self",
".",
"read_tuple",
"(",
")",
"self",
".",
"_current_tups",
"=",
"[",
"tup",
"]",
"if",
"self",
".",
"is_heartbeat",
"(",
"tup",
")",
":",
"self",
".",
"send_message",
"(",
"{",
"\"command\"",
... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Bolt._handle_run_exception | Process an exception encountered while running the ``run()`` loop.
Called right before program exits. | pystorm/bolt.py | def _handle_run_exception(self, exc):
"""Process an exception encountered while running the ``run()`` loop.
Called right before program exits.
"""
if len(self._current_tups) == 1:
tup = self._current_tups[0]
self.raise_exception(exc, tup)
if self.auto... | def _handle_run_exception(self, exc):
"""Process an exception encountered while running the ``run()`` loop.
Called right before program exits.
"""
if len(self._current_tups) == 1:
tup = self._current_tups[0]
self.raise_exception(exc, tup)
if self.auto... | [
"Process",
"an",
"exception",
"encountered",
"while",
"running",
"the",
"run",
"()",
"loop",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L217-L226 | [
"def",
"_handle_run_exception",
"(",
"self",
",",
"exc",
")",
":",
"if",
"len",
"(",
"self",
".",
"_current_tups",
")",
"==",
"1",
":",
"tup",
"=",
"self",
".",
"_current_tups",
"[",
"0",
"]",
"self",
".",
"raise_exception",
"(",
"exc",
",",
"tup",
"... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | BatchingBolt.emit | Modified emit that will not return task IDs after emitting.
See :class:`pystorm.component.Bolt` for more information.
:returns: ``None``. | pystorm/bolt.py | def emit(self, tup, **kwargs):
"""Modified emit that will not return task IDs after emitting.
See :class:`pystorm.component.Bolt` for more information.
:returns: ``None``.
"""
kwargs["need_task_ids"] = False
return super(BatchingBolt, self).emit(tup, **kwargs) | def emit(self, tup, **kwargs):
"""Modified emit that will not return task IDs after emitting.
See :class:`pystorm.component.Bolt` for more information.
:returns: ``None``.
"""
kwargs["need_task_ids"] = False
return super(BatchingBolt, self).emit(tup, **kwargs) | [
"Modified",
"emit",
"that",
"will",
"not",
"return",
"task",
"IDs",
"after",
"emitting",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L316-L324 | [
"def",
"emit",
"(",
"self",
",",
"tup",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"\"need_task_ids\"",
"]",
"=",
"False",
"return",
"super",
"(",
"BatchingBolt",
",",
"self",
")",
".",
"emit",
"(",
"tup",
",",
"*",
"*",
"kwargs",
")"
] | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | BatchingBolt.process_tick | Increment tick counter, and call ``process_batch`` for all current
batches if tick counter exceeds ``ticks_between_batches``.
See :class:`pystorm.component.Bolt` for more information.
.. warning::
This method should **not** be overriden. If you want to tweak
how Tuples... | pystorm/bolt.py | def process_tick(self, tick_tup):
"""Increment tick counter, and call ``process_batch`` for all current
batches if tick counter exceeds ``ticks_between_batches``.
See :class:`pystorm.component.Bolt` for more information.
.. warning::
This method should **not** be overriden.... | def process_tick(self, tick_tup):
"""Increment tick counter, and call ``process_batch`` for all current
batches if tick counter exceeds ``ticks_between_batches``.
See :class:`pystorm.component.Bolt` for more information.
.. warning::
This method should **not** be overriden.... | [
"Increment",
"tick",
"counter",
"and",
"call",
"process_batch",
"for",
"all",
"current",
"batches",
"if",
"tick",
"counter",
"exceeds",
"ticks_between_batches",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L326-L341 | [
"def",
"process_tick",
"(",
"self",
",",
"tick_tup",
")",
":",
"self",
".",
"_tick_counter",
"+=",
"1",
"# ACK tick Tuple immediately, since it's just responsible for counter",
"self",
".",
"ack",
"(",
"tick_tup",
")",
"if",
"self",
".",
"_tick_counter",
">",
"self"... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | BatchingBolt.process_batches | Iterate through all batches, call process_batch on them, and ack.
Separated out for the rare instances when we want to subclass
BatchingBolt and customize what mechanism causes batches to be
processed. | pystorm/bolt.py | def process_batches(self):
"""Iterate through all batches, call process_batch on them, and ack.
Separated out for the rare instances when we want to subclass
BatchingBolt and customize what mechanism causes batches to be
processed.
"""
for key, batch in iteritems(self._b... | def process_batches(self):
"""Iterate through all batches, call process_batch on them, and ack.
Separated out for the rare instances when we want to subclass
BatchingBolt and customize what mechanism causes batches to be
processed.
"""
for key, batch in iteritems(self._b... | [
"Iterate",
"through",
"all",
"batches",
"call",
"process_batch",
"on",
"them",
"and",
"ack",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L343-L361 | [
"def",
"process_batches",
"(",
"self",
")",
":",
"for",
"key",
",",
"batch",
"in",
"iteritems",
"(",
"self",
".",
"_batches",
")",
":",
"self",
".",
"_current_tups",
"=",
"batch",
"self",
".",
"_current_key",
"=",
"key",
"self",
".",
"process_batch",
"("... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | BatchingBolt.process | Group non-tick Tuples into batches by ``group_key``.
.. warning::
This method should **not** be overriden. If you want to tweak
how Tuples are grouped into batches, override ``group_key``. | pystorm/bolt.py | def process(self, tup):
"""Group non-tick Tuples into batches by ``group_key``.
.. warning::
This method should **not** be overriden. If you want to tweak
how Tuples are grouped into batches, override ``group_key``.
"""
# Append latest Tuple to batches
g... | def process(self, tup):
"""Group non-tick Tuples into batches by ``group_key``.
.. warning::
This method should **not** be overriden. If you want to tweak
how Tuples are grouped into batches, override ``group_key``.
"""
# Append latest Tuple to batches
g... | [
"Group",
"non",
"-",
"tick",
"Tuples",
"into",
"batches",
"by",
"group_key",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L363-L372 | [
"def",
"process",
"(",
"self",
",",
"tup",
")",
":",
"# Append latest Tuple to batches",
"group_key",
"=",
"self",
".",
"group_key",
"(",
"tup",
")",
"self",
".",
"_batches",
"[",
"group_key",
"]",
".",
"append",
"(",
"tup",
")"
] | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | BatchingBolt._handle_run_exception | Process an exception encountered while running the ``run()`` loop.
Called right before program exits. | pystorm/bolt.py | def _handle_run_exception(self, exc):
"""Process an exception encountered while running the ``run()`` loop.
Called right before program exits.
"""
self.raise_exception(exc, self._current_tups)
if self.auto_fail:
failed = set()
for key, batch in iteritems... | def _handle_run_exception(self, exc):
"""Process an exception encountered while running the ``run()`` loop.
Called right before program exits.
"""
self.raise_exception(exc, self._current_tups)
if self.auto_fail:
failed = set()
for key, batch in iteritems... | [
"Process",
"an",
"exception",
"encountered",
"while",
"running",
"the",
"run",
"()",
"loop",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L391-L414 | [
"def",
"_handle_run_exception",
"(",
"self",
",",
"exc",
")",
":",
"self",
".",
"raise_exception",
"(",
"exc",
",",
"self",
".",
"_current_tups",
")",
"if",
"self",
".",
"auto_fail",
":",
"failed",
"=",
"set",
"(",
")",
"for",
"key",
",",
"batch",
"in"... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | TicklessBatchingBolt._batch_entry_run | The inside of ``_batch_entry``'s infinite loop.
Separated out so it can be properly unit tested. | pystorm/bolt.py | def _batch_entry_run(self):
"""The inside of ``_batch_entry``'s infinite loop.
Separated out so it can be properly unit tested.
"""
time.sleep(self.secs_between_batches)
with self._batch_lock:
self.process_batches() | def _batch_entry_run(self):
"""The inside of ``_batch_entry``'s infinite loop.
Separated out so it can be properly unit tested.
"""
time.sleep(self.secs_between_batches)
with self._batch_lock:
self.process_batches() | [
"The",
"inside",
"of",
"_batch_entry",
"s",
"infinite",
"loop",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L496-L503 | [
"def",
"_batch_entry_run",
"(",
"self",
")",
":",
"time",
".",
"sleep",
"(",
"self",
".",
"secs_between_batches",
")",
"with",
"self",
".",
"_batch_lock",
":",
"self",
".",
"process_batches",
"(",
")"
] | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | TicklessBatchingBolt._batch_entry | Entry point for the batcher thread. | pystorm/bolt.py | def _batch_entry(self):
"""Entry point for the batcher thread."""
try:
while True:
self._batch_entry_run()
except:
self.exc_info = sys.exc_info()
os.kill(self.pid, signal.SIGUSR1) | def _batch_entry(self):
"""Entry point for the batcher thread."""
try:
while True:
self._batch_entry_run()
except:
self.exc_info = sys.exc_info()
os.kill(self.pid, signal.SIGUSR1) | [
"Entry",
"point",
"for",
"the",
"batcher",
"thread",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L505-L512 | [
"def",
"_batch_entry",
"(",
"self",
")",
":",
"try",
":",
"while",
"True",
":",
"self",
".",
"_batch_entry_run",
"(",
")",
"except",
":",
"self",
".",
"exc_info",
"=",
"sys",
".",
"exc_info",
"(",
")",
"os",
".",
"kill",
"(",
"self",
".",
"pid",
",... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | TicklessBatchingBolt._run | The inside of ``run``'s infinite loop.
Separate from BatchingBolt's implementation because
we need to be able to acquire the batch lock after
reading the tuple.
We can't acquire the lock before reading the tuple because if
that hangs (i.e. the topology is shutting down) the loc... | pystorm/bolt.py | def _run(self):
"""The inside of ``run``'s infinite loop.
Separate from BatchingBolt's implementation because
we need to be able to acquire the batch lock after
reading the tuple.
We can't acquire the lock before reading the tuple because if
that hangs (i.e. the topolog... | def _run(self):
"""The inside of ``run``'s infinite loop.
Separate from BatchingBolt's implementation because
we need to be able to acquire the batch lock after
reading the tuple.
We can't acquire the lock before reading the tuple because if
that hangs (i.e. the topolog... | [
"The",
"inside",
"of",
"run",
"s",
"infinite",
"loop",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/bolt.py#L523-L546 | [
"def",
"_run",
"(",
"self",
")",
":",
"tup",
"=",
"self",
".",
"read_tuple",
"(",
")",
"with",
"self",
".",
"_batch_lock",
":",
"self",
".",
"_current_tups",
"=",
"[",
"tup",
"]",
"if",
"self",
".",
"is_heartbeat",
"(",
"tup",
")",
":",
"self",
"."... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | Serializer.send_message | Serialize a message dictionary and write it to the output stream. | pystorm/serializers/serializer.py | def send_message(self, msg_dict):
"""Serialize a message dictionary and write it to the output stream."""
with self._writer_lock:
try:
self.output_stream.flush()
self.output_stream.write(self.serialize_dict(msg_dict))
self.output_stream.flush()... | def send_message(self, msg_dict):
"""Serialize a message dictionary and write it to the output stream."""
with self._writer_lock:
try:
self.output_stream.flush()
self.output_stream.write(self.serialize_dict(msg_dict))
self.output_stream.flush()... | [
"Serialize",
"a",
"message",
"dictionary",
"and",
"write",
"it",
"to",
"the",
"output",
"stream",
"."
] | pystorm/pystorm | python | https://github.com/pystorm/pystorm/blob/0f853e007c79e03cefdb4a0794423f84dce4c2f3/pystorm/serializers/serializer.py#L27-L37 | [
"def",
"send_message",
"(",
"self",
",",
"msg_dict",
")",
":",
"with",
"self",
".",
"_writer_lock",
":",
"try",
":",
"self",
".",
"output_stream",
".",
"flush",
"(",
")",
"self",
".",
"output_stream",
".",
"write",
"(",
"self",
".",
"serialize_dict",
"("... | 0f853e007c79e03cefdb4a0794423f84dce4c2f3 |
train | _void_array_to_list | Convert the FFI result to Python data structures | convertbng/util.py | def _void_array_to_list(restuple, _func, _args):
""" Convert the FFI result to Python data structures """
shape = (restuple.e.len, 1)
array_size = np.prod(shape)
mem_size = 8 * array_size
array_str_e = string_at(restuple.e.data, mem_size)
array_str_n = string_at(restuple.n.data, mem_size)
... | def _void_array_to_list(restuple, _func, _args):
""" Convert the FFI result to Python data structures """
shape = (restuple.e.len, 1)
array_size = np.prod(shape)
mem_size = 8 * array_size
array_str_e = string_at(restuple.e.data, mem_size)
array_str_n = string_at(restuple.n.data, mem_size)
... | [
"Convert",
"the",
"FFI",
"result",
"to",
"Python",
"data",
"structures"
] | urschrei/convertbng | python | https://github.com/urschrei/convertbng/blob/b0f5ca8b4942a835a834aed4c1fdb4d827c72342/convertbng/util.py#L122-L134 | [
"def",
"_void_array_to_list",
"(",
"restuple",
",",
"_func",
",",
"_args",
")",
":",
"shape",
"=",
"(",
"restuple",
".",
"e",
".",
"len",
",",
"1",
")",
"array_size",
"=",
"np",
".",
"prod",
"(",
"shape",
")",
"mem_size",
"=",
"8",
"*",
"array_size",... | b0f5ca8b4942a835a834aed4c1fdb4d827c72342 |
train | load_data_file | Load a data file and return it as a list of lines.
Parameters:
filename: The name of the file (no directories included).
encoding: The file encoding. Defaults to utf-8. | dragonmapper/data/__init__.py | def load_data_file(filename, encoding='utf-8'):
"""Load a data file and return it as a list of lines.
Parameters:
filename: The name of the file (no directories included).
encoding: The file encoding. Defaults to utf-8.
"""
data = pkgutil.get_data(PACKAGE_NAME, os.path.join(DATA_DIR, f... | def load_data_file(filename, encoding='utf-8'):
"""Load a data file and return it as a list of lines.
Parameters:
filename: The name of the file (no directories included).
encoding: The file encoding. Defaults to utf-8.
"""
data = pkgutil.get_data(PACKAGE_NAME, os.path.join(DATA_DIR, f... | [
"Load",
"a",
"data",
"file",
"and",
"return",
"it",
"as",
"a",
"list",
"of",
"lines",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/data/__init__.py#L13-L22 | [
"def",
"load_data_file",
"(",
"filename",
",",
"encoding",
"=",
"'utf-8'",
")",
":",
"data",
"=",
"pkgutil",
".",
"get_data",
"(",
"PACKAGE_NAME",
",",
"os",
".",
"path",
".",
"join",
"(",
"DATA_DIR",
",",
"filename",
")",
")",
"return",
"data",
".",
"... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _load_data | Load the word and character mapping data into a dictionary.
In the data files, each line is formatted like this:
HANZI PINYIN_READING/PINYIN_READING
So, lines need to be split by '\t' and then the Pinyin readings need to be
split by '/'. | dragonmapper/hanzi.py | def _load_data():
"""Load the word and character mapping data into a dictionary.
In the data files, each line is formatted like this:
HANZI PINYIN_READING/PINYIN_READING
So, lines need to be split by '\t' and then the Pinyin readings need to be
split by '/'.
"""
data = {}
for na... | def _load_data():
"""Load the word and character mapping data into a dictionary.
In the data files, each line is formatted like this:
HANZI PINYIN_READING/PINYIN_READING
So, lines need to be split by '\t' and then the Pinyin readings need to be
split by '/'.
"""
data = {}
for na... | [
"Load",
"the",
"word",
"and",
"character",
"mapping",
"data",
"into",
"a",
"dictionary",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/hanzi.py#L36-L54 | [
"def",
"_load_data",
"(",
")",
":",
"data",
"=",
"{",
"}",
"for",
"name",
",",
"file_name",
"in",
"(",
"(",
"'words'",
",",
"'hanzi_pinyin_words.tsv'",
")",
",",
"(",
"'characters'",
",",
"'hanzi_pinyin_characters.tsv'",
")",
")",
":",
"# Split the lines by ta... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _hanzi_to_pinyin | Return the Pinyin reading for a Chinese word.
If the given string *hanzi* matches a CC-CEDICT word, the return value is
formatted like this: [WORD_READING1, WORD_READING2, ...]
If the given string *hanzi* doesn't match a CC-CEDICT word, the return
value is formatted like this: [[CHAR_READING1, CHAR_RE... | dragonmapper/hanzi.py | def _hanzi_to_pinyin(hanzi):
"""Return the Pinyin reading for a Chinese word.
If the given string *hanzi* matches a CC-CEDICT word, the return value is
formatted like this: [WORD_READING1, WORD_READING2, ...]
If the given string *hanzi* doesn't match a CC-CEDICT word, the return
value is formatted... | def _hanzi_to_pinyin(hanzi):
"""Return the Pinyin reading for a Chinese word.
If the given string *hanzi* matches a CC-CEDICT word, the return value is
formatted like this: [WORD_READING1, WORD_READING2, ...]
If the given string *hanzi* doesn't match a CC-CEDICT word, the return
value is formatted... | [
"Return",
"the",
"Pinyin",
"reading",
"for",
"a",
"Chinese",
"word",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/hanzi.py#L61-L77 | [
"def",
"_hanzi_to_pinyin",
"(",
"hanzi",
")",
":",
"try",
":",
"return",
"_HANZI_PINYIN_MAP",
"[",
"'words'",
"]",
"[",
"hanzi",
"]",
"except",
"KeyError",
":",
"return",
"[",
"_CHARACTERS",
".",
"get",
"(",
"character",
",",
"character",
")",
"for",
"char... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _enclose_readings | Enclose a reading within a container, e.g. '[]'. | dragonmapper/hanzi.py | def _enclose_readings(container, readings):
"""Enclose a reading within a container, e.g. '[]'."""
container_start, container_end = tuple(container)
enclosed_readings = '%(container_start)s%(readings)s%(container_end)s' % {
'container_start': container_start, 'container_end': container_end,
... | def _enclose_readings(container, readings):
"""Enclose a reading within a container, e.g. '[]'."""
container_start, container_end = tuple(container)
enclosed_readings = '%(container_start)s%(readings)s%(container_end)s' % {
'container_start': container_start, 'container_end': container_end,
... | [
"Enclose",
"a",
"reading",
"within",
"a",
"container",
"e",
".",
"g",
".",
"[]",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/hanzi.py#L80-L86 | [
"def",
"_enclose_readings",
"(",
"container",
",",
"readings",
")",
":",
"container_start",
",",
"container_end",
"=",
"tuple",
"(",
"container",
")",
"enclosed_readings",
"=",
"'%(container_start)s%(readings)s%(container_end)s'",
"%",
"{",
"'container_start'",
":",
"co... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | to_pinyin | Convert a string's Chinese characters to Pinyin readings.
*s* is a string containing Chinese characters. *accented* is a
boolean value indicating whether to return accented or numbered Pinyin
readings.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differenti... | dragonmapper/hanzi.py | def to_pinyin(s, delimiter=' ', all_readings=False, container='[]',
accented=True):
"""Convert a string's Chinese characters to Pinyin readings.
*s* is a string containing Chinese characters. *accented* is a
boolean value indicating whether to return accented or numbered Pinyin
readings.
... | def to_pinyin(s, delimiter=' ', all_readings=False, container='[]',
accented=True):
"""Convert a string's Chinese characters to Pinyin readings.
*s* is a string containing Chinese characters. *accented* is a
boolean value indicating whether to return accented or numbered Pinyin
readings.
... | [
"Convert",
"a",
"string",
"s",
"Chinese",
"characters",
"to",
"Pinyin",
"readings",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/hanzi.py#L89-L168 | [
"def",
"to_pinyin",
"(",
"s",
",",
"delimiter",
"=",
"' '",
",",
"all_readings",
"=",
"False",
",",
"container",
"=",
"'[]'",
",",
"accented",
"=",
"True",
")",
":",
"hanzi",
"=",
"s",
"pinyin",
"=",
"''",
"# Process the given string.",
"while",
"hanzi",
... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | to_zhuyin | Convert a string's Chinese characters to Zhuyin readings.
*s* is a string containing Chinese characters.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differentiate between words and characters so that a more
accurate reading can be returned.
*all_readings*... | dragonmapper/hanzi.py | def to_zhuyin(s, delimiter=' ', all_readings=False, container='[]'):
"""Convert a string's Chinese characters to Zhuyin readings.
*s* is a string containing Chinese characters.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differentiate between words and charact... | def to_zhuyin(s, delimiter=' ', all_readings=False, container='[]'):
"""Convert a string's Chinese characters to Zhuyin readings.
*s* is a string containing Chinese characters.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differentiate between words and charact... | [
"Convert",
"a",
"string",
"s",
"Chinese",
"characters",
"to",
"Zhuyin",
"readings",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/hanzi.py#L171-L191 | [
"def",
"to_zhuyin",
"(",
"s",
",",
"delimiter",
"=",
"' '",
",",
"all_readings",
"=",
"False",
",",
"container",
"=",
"'[]'",
")",
":",
"numbered_pinyin",
"=",
"to_pinyin",
"(",
"s",
",",
"delimiter",
",",
"all_readings",
",",
"container",
",",
"False",
... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | to_ipa | Convert a string's Chinese characters to IPA.
*s* is a string containing Chinese characters.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differentiate between words and characters so that a more
accurate reading can be returned.
*all_readings* is a boolea... | dragonmapper/hanzi.py | def to_ipa(s, delimiter=' ', all_readings=False, container='[]'):
"""Convert a string's Chinese characters to IPA.
*s* is a string containing Chinese characters.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differentiate between words and characters so that a m... | def to_ipa(s, delimiter=' ', all_readings=False, container='[]'):
"""Convert a string's Chinese characters to IPA.
*s* is a string containing Chinese characters.
*delimiter* is the character used to indicate word boundaries in *s*.
This is used to differentiate between words and characters so that a m... | [
"Convert",
"a",
"string",
"s",
"Chinese",
"characters",
"to",
"IPA",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/hanzi.py#L194-L214 | [
"def",
"to_ipa",
"(",
"s",
",",
"delimiter",
"=",
"' '",
",",
"all_readings",
"=",
"False",
",",
"container",
"=",
"'[]'",
")",
":",
"numbered_pinyin",
"=",
"to_pinyin",
"(",
"s",
",",
"delimiter",
",",
"all_readings",
",",
"container",
",",
"False",
")"... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _load_data | Load the transcription mapping data into a dictionary. | dragonmapper/transcriptions.py | def _load_data():
"""Load the transcription mapping data into a dictionary."""
lines = dragonmapper.data.load_data_file('transcriptions.csv')
pinyin_map, zhuyin_map, ipa_map = {}, {}, {}
for line in lines:
p, z, i = line.split(',')
pinyin_map[p] = {'Zhuyin': z, 'IPA': i}
zhuyin_m... | def _load_data():
"""Load the transcription mapping data into a dictionary."""
lines = dragonmapper.data.load_data_file('transcriptions.csv')
pinyin_map, zhuyin_map, ipa_map = {}, {}, {}
for line in lines:
p, z, i = line.split(',')
pinyin_map[p] = {'Zhuyin': z, 'IPA': i}
zhuyin_m... | [
"Load",
"the",
"transcription",
"mapping",
"data",
"into",
"a",
"dictionary",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L46-L55 | [
"def",
"_load_data",
"(",
")",
":",
"lines",
"=",
"dragonmapper",
".",
"data",
".",
"load_data_file",
"(",
"'transcriptions.csv'",
")",
"pinyin_map",
",",
"zhuyin_map",
",",
"ipa_map",
"=",
"{",
"}",
",",
"{",
"}",
",",
"{",
"}",
"for",
"line",
"in",
"... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _numbered_vowel_to_accented | Convert a numbered Pinyin vowel to an accented Pinyin vowel. | dragonmapper/transcriptions.py | def _numbered_vowel_to_accented(vowel, tone):
"""Convert a numbered Pinyin vowel to an accented Pinyin vowel."""
if isinstance(tone, int):
tone = str(tone)
return _PINYIN_TONES[vowel + tone] | def _numbered_vowel_to_accented(vowel, tone):
"""Convert a numbered Pinyin vowel to an accented Pinyin vowel."""
if isinstance(tone, int):
tone = str(tone)
return _PINYIN_TONES[vowel + tone] | [
"Convert",
"a",
"numbered",
"Pinyin",
"vowel",
"to",
"an",
"accented",
"Pinyin",
"vowel",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L69-L73 | [
"def",
"_numbered_vowel_to_accented",
"(",
"vowel",
",",
"tone",
")",
":",
"if",
"isinstance",
"(",
"tone",
",",
"int",
")",
":",
"tone",
"=",
"str",
"(",
"tone",
")",
"return",
"_PINYIN_TONES",
"[",
"vowel",
"+",
"tone",
"]"
] | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _accented_vowel_to_numbered | Convert an accented Pinyin vowel to a numbered Pinyin vowel. | dragonmapper/transcriptions.py | def _accented_vowel_to_numbered(vowel):
"""Convert an accented Pinyin vowel to a numbered Pinyin vowel."""
for numbered_vowel, accented_vowel in _PINYIN_TONES.items():
if vowel == accented_vowel:
return tuple(numbered_vowel) | def _accented_vowel_to_numbered(vowel):
"""Convert an accented Pinyin vowel to a numbered Pinyin vowel."""
for numbered_vowel, accented_vowel in _PINYIN_TONES.items():
if vowel == accented_vowel:
return tuple(numbered_vowel) | [
"Convert",
"an",
"accented",
"Pinyin",
"vowel",
"to",
"a",
"numbered",
"Pinyin",
"vowel",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L76-L80 | [
"def",
"_accented_vowel_to_numbered",
"(",
"vowel",
")",
":",
"for",
"numbered_vowel",
",",
"accented_vowel",
"in",
"_PINYIN_TONES",
".",
"items",
"(",
")",
":",
"if",
"vowel",
"==",
"accented_vowel",
":",
"return",
"tuple",
"(",
"numbered_vowel",
")"
] | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _parse_numbered_syllable | Return the syllable and tone of a numbered Pinyin syllable. | dragonmapper/transcriptions.py | def _parse_numbered_syllable(unparsed_syllable):
"""Return the syllable and tone of a numbered Pinyin syllable."""
tone_number = unparsed_syllable[-1]
if not tone_number.isdigit():
syllable, tone = unparsed_syllable, '5'
elif tone_number == '0':
syllable, tone = unparsed_syllable[:-1], '... | def _parse_numbered_syllable(unparsed_syllable):
"""Return the syllable and tone of a numbered Pinyin syllable."""
tone_number = unparsed_syllable[-1]
if not tone_number.isdigit():
syllable, tone = unparsed_syllable, '5'
elif tone_number == '0':
syllable, tone = unparsed_syllable[:-1], '... | [
"Return",
"the",
"syllable",
"and",
"tone",
"of",
"a",
"numbered",
"Pinyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L83-L94 | [
"def",
"_parse_numbered_syllable",
"(",
"unparsed_syllable",
")",
":",
"tone_number",
"=",
"unparsed_syllable",
"[",
"-",
"1",
"]",
"if",
"not",
"tone_number",
".",
"isdigit",
"(",
")",
":",
"syllable",
",",
"tone",
"=",
"unparsed_syllable",
",",
"'5'",
"elif"... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _parse_accented_syllable | Return the syllable and tone of an accented Pinyin syllable.
Any accented vowels are returned without their accents.
Implements the following algorithm:
1. If the syllable has an accent mark, convert that vowel to a
regular vowel and add the tone to the end of the syllable.
2. Otherwise, assu... | dragonmapper/transcriptions.py | def _parse_accented_syllable(unparsed_syllable):
"""Return the syllable and tone of an accented Pinyin syllable.
Any accented vowels are returned without their accents.
Implements the following algorithm:
1. If the syllable has an accent mark, convert that vowel to a
regular vowel and add the... | def _parse_accented_syllable(unparsed_syllable):
"""Return the syllable and tone of an accented Pinyin syllable.
Any accented vowels are returned without their accents.
Implements the following algorithm:
1. If the syllable has an accent mark, convert that vowel to a
regular vowel and add the... | [
"Return",
"the",
"syllable",
"and",
"tone",
"of",
"an",
"accented",
"Pinyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L97-L116 | [
"def",
"_parse_accented_syllable",
"(",
"unparsed_syllable",
")",
":",
"if",
"unparsed_syllable",
"[",
"0",
"]",
"==",
"'\\u00B7'",
":",
"# Special case for middle dot tone mark.",
"return",
"unparsed_syllable",
"[",
"1",
":",
"]",
",",
"'5'",
"for",
"character",
"i... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _parse_zhuyin_syllable | Return the syllable and tone of a Zhuyin syllable. | dragonmapper/transcriptions.py | def _parse_zhuyin_syllable(unparsed_syllable):
"""Return the syllable and tone of a Zhuyin syllable."""
zhuyin_tone = unparsed_syllable[-1]
if zhuyin_tone in zhon.zhuyin.characters:
syllable, tone = unparsed_syllable, '1'
elif zhuyin_tone in zhon.zhuyin.marks:
for tone_number, tone_mark ... | def _parse_zhuyin_syllable(unparsed_syllable):
"""Return the syllable and tone of a Zhuyin syllable."""
zhuyin_tone = unparsed_syllable[-1]
if zhuyin_tone in zhon.zhuyin.characters:
syllable, tone = unparsed_syllable, '1'
elif zhuyin_tone in zhon.zhuyin.marks:
for tone_number, tone_mark ... | [
"Return",
"the",
"syllable",
"and",
"tone",
"of",
"a",
"Zhuyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L132-L144 | [
"def",
"_parse_zhuyin_syllable",
"(",
"unparsed_syllable",
")",
":",
"zhuyin_tone",
"=",
"unparsed_syllable",
"[",
"-",
"1",
"]",
"if",
"zhuyin_tone",
"in",
"zhon",
".",
"zhuyin",
".",
"characters",
":",
"syllable",
",",
"tone",
"=",
"unparsed_syllable",
",",
... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _parse_ipa_syllable | Return the syllable and tone of an IPA syllable. | dragonmapper/transcriptions.py | def _parse_ipa_syllable(unparsed_syllable):
"""Return the syllable and tone of an IPA syllable."""
ipa_tone = re.search('[%(marks)s]+' % {'marks': _IPA_MARKS},
unparsed_syllable)
if not ipa_tone:
syllable, tone = unparsed_syllable, '5'
else:
for tone_number, tone... | def _parse_ipa_syllable(unparsed_syllable):
"""Return the syllable and tone of an IPA syllable."""
ipa_tone = re.search('[%(marks)s]+' % {'marks': _IPA_MARKS},
unparsed_syllable)
if not ipa_tone:
syllable, tone = unparsed_syllable, '5'
else:
for tone_number, tone... | [
"Return",
"the",
"syllable",
"and",
"tone",
"of",
"an",
"IPA",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L147-L159 | [
"def",
"_parse_ipa_syllable",
"(",
"unparsed_syllable",
")",
":",
"ipa_tone",
"=",
"re",
".",
"search",
"(",
"'[%(marks)s]+'",
"%",
"{",
"'marks'",
":",
"_IPA_MARKS",
"}",
",",
"unparsed_syllable",
")",
"if",
"not",
"ipa_tone",
":",
"syllable",
",",
"tone",
... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _restore_case | Restore a lowercase string's characters to their original case. | dragonmapper/transcriptions.py | def _restore_case(s, memory):
"""Restore a lowercase string's characters to their original case."""
cased_s = []
for i, c in enumerate(s):
if i + 1 > len(memory):
break
cased_s.append(c if memory[i] else c.upper())
return ''.join(cased_s) | def _restore_case(s, memory):
"""Restore a lowercase string's characters to their original case."""
cased_s = []
for i, c in enumerate(s):
if i + 1 > len(memory):
break
cased_s.append(c if memory[i] else c.upper())
return ''.join(cased_s) | [
"Restore",
"a",
"lowercase",
"string",
"s",
"characters",
"to",
"their",
"original",
"case",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L167-L174 | [
"def",
"_restore_case",
"(",
"s",
",",
"memory",
")",
":",
"cased_s",
"=",
"[",
"]",
"for",
"i",
",",
"c",
"in",
"enumerate",
"(",
"s",
")",
":",
"if",
"i",
"+",
"1",
">",
"len",
"(",
"memory",
")",
":",
"break",
"cased_s",
".",
"append",
"(",
... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | numbered_syllable_to_accented | Convert numbered Pinyin syllable *s* to an accented Pinyin syllable.
It implements the following algorithm to determine where to place tone
marks:
1. If the syllable has an 'a', 'e', or 'o' (in that order), put the
tone mark over that vowel.
2. Otherwise, put the tone mark on the last vowel. | dragonmapper/transcriptions.py | def numbered_syllable_to_accented(s):
"""Convert numbered Pinyin syllable *s* to an accented Pinyin syllable.
It implements the following algorithm to determine where to place tone
marks:
1. If the syllable has an 'a', 'e', or 'o' (in that order), put the
tone mark over that vowel.
2. Othe... | def numbered_syllable_to_accented(s):
"""Convert numbered Pinyin syllable *s* to an accented Pinyin syllable.
It implements the following algorithm to determine where to place tone
marks:
1. If the syllable has an 'a', 'e', or 'o' (in that order), put the
tone mark over that vowel.
2. Othe... | [
"Convert",
"numbered",
"Pinyin",
"syllable",
"*",
"s",
"*",
"to",
"an",
"accented",
"Pinyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L177-L209 | [
"def",
"numbered_syllable_to_accented",
"(",
"s",
")",
":",
"if",
"s",
"==",
"'r5'",
":",
"return",
"'r'",
"# Special case for 'r' suffix.",
"lowercase_syllable",
",",
"case_memory",
"=",
"_lower_case",
"(",
"s",
")",
"syllable",
",",
"tone",
"=",
"_parse_numbered... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | accented_syllable_to_numbered | Convert accented Pinyin syllable *s* to a numbered Pinyin syllable. | dragonmapper/transcriptions.py | def accented_syllable_to_numbered(s):
"""Convert accented Pinyin syllable *s* to a numbered Pinyin syllable."""
if s[0] == '\u00B7':
lowercase_syllable, case_memory = _lower_case(s[1:])
lowercase_syllable = '\u00B7' + lowercase_syllable
else:
lowercase_syllable, case_memory = _lower_... | def accented_syllable_to_numbered(s):
"""Convert accented Pinyin syllable *s* to a numbered Pinyin syllable."""
if s[0] == '\u00B7':
lowercase_syllable, case_memory = _lower_case(s[1:])
lowercase_syllable = '\u00B7' + lowercase_syllable
else:
lowercase_syllable, case_memory = _lower_... | [
"Convert",
"accented",
"Pinyin",
"syllable",
"*",
"s",
"*",
"to",
"a",
"numbered",
"Pinyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L212-L220 | [
"def",
"accented_syllable_to_numbered",
"(",
"s",
")",
":",
"if",
"s",
"[",
"0",
"]",
"==",
"'\\u00B7'",
":",
"lowercase_syllable",
",",
"case_memory",
"=",
"_lower_case",
"(",
"s",
"[",
"1",
":",
"]",
")",
"lowercase_syllable",
"=",
"'\\u00B7'",
"+",
"low... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | pinyin_syllable_to_zhuyin | Convert Pinyin syllable *s* to a Zhuyin syllable. | dragonmapper/transcriptions.py | def pinyin_syllable_to_zhuyin(s):
"""Convert Pinyin syllable *s* to a Zhuyin syllable."""
pinyin_syllable, tone = _parse_pinyin_syllable(s)
try:
zhuyin_syllable = _PINYIN_MAP[pinyin_syllable.lower()]['Zhuyin']
except KeyError:
raise ValueError('Not a valid syllable: %s' % s)
return z... | def pinyin_syllable_to_zhuyin(s):
"""Convert Pinyin syllable *s* to a Zhuyin syllable."""
pinyin_syllable, tone = _parse_pinyin_syllable(s)
try:
zhuyin_syllable = _PINYIN_MAP[pinyin_syllable.lower()]['Zhuyin']
except KeyError:
raise ValueError('Not a valid syllable: %s' % s)
return z... | [
"Convert",
"Pinyin",
"syllable",
"*",
"s",
"*",
"to",
"a",
"Zhuyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L223-L230 | [
"def",
"pinyin_syllable_to_zhuyin",
"(",
"s",
")",
":",
"pinyin_syllable",
",",
"tone",
"=",
"_parse_pinyin_syllable",
"(",
"s",
")",
"try",
":",
"zhuyin_syllable",
"=",
"_PINYIN_MAP",
"[",
"pinyin_syllable",
".",
"lower",
"(",
")",
"]",
"[",
"'Zhuyin'",
"]",
... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | pinyin_syllable_to_ipa | Convert Pinyin syllable *s* to an IPA syllable. | dragonmapper/transcriptions.py | def pinyin_syllable_to_ipa(s):
"""Convert Pinyin syllable *s* to an IPA syllable."""
pinyin_syllable, tone = _parse_pinyin_syllable(s)
try:
ipa_syllable = _PINYIN_MAP[pinyin_syllable.lower()]['IPA']
except KeyError:
raise ValueError('Not a valid syllable: %s' % s)
return ipa_syllable... | def pinyin_syllable_to_ipa(s):
"""Convert Pinyin syllable *s* to an IPA syllable."""
pinyin_syllable, tone = _parse_pinyin_syllable(s)
try:
ipa_syllable = _PINYIN_MAP[pinyin_syllable.lower()]['IPA']
except KeyError:
raise ValueError('Not a valid syllable: %s' % s)
return ipa_syllable... | [
"Convert",
"Pinyin",
"syllable",
"*",
"s",
"*",
"to",
"an",
"IPA",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L233-L240 | [
"def",
"pinyin_syllable_to_ipa",
"(",
"s",
")",
":",
"pinyin_syllable",
",",
"tone",
"=",
"_parse_pinyin_syllable",
"(",
"s",
")",
"try",
":",
"ipa_syllable",
"=",
"_PINYIN_MAP",
"[",
"pinyin_syllable",
".",
"lower",
"(",
")",
"]",
"[",
"'IPA'",
"]",
"except... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
train | _zhuyin_syllable_to_numbered | Convert Zhuyin syllable *s* to a numbered Pinyin syllable. | dragonmapper/transcriptions.py | def _zhuyin_syllable_to_numbered(s):
"""Convert Zhuyin syllable *s* to a numbered Pinyin syllable."""
zhuyin_syllable, tone = _parse_zhuyin_syllable(s)
try:
pinyin_syllable = _ZHUYIN_MAP[zhuyin_syllable]['Pinyin']
except KeyError:
raise ValueError('Not a valid syllable: %s' % s)
retu... | def _zhuyin_syllable_to_numbered(s):
"""Convert Zhuyin syllable *s* to a numbered Pinyin syllable."""
zhuyin_syllable, tone = _parse_zhuyin_syllable(s)
try:
pinyin_syllable = _ZHUYIN_MAP[zhuyin_syllable]['Pinyin']
except KeyError:
raise ValueError('Not a valid syllable: %s' % s)
retu... | [
"Convert",
"Zhuyin",
"syllable",
"*",
"s",
"*",
"to",
"a",
"numbered",
"Pinyin",
"syllable",
"."
] | tsroten/dragonmapper | python | https://github.com/tsroten/dragonmapper/blob/68eaf43c32725f4b4923c01284cfc0112079e8ab/dragonmapper/transcriptions.py#L243-L250 | [
"def",
"_zhuyin_syllable_to_numbered",
"(",
"s",
")",
":",
"zhuyin_syllable",
",",
"tone",
"=",
"_parse_zhuyin_syllable",
"(",
"s",
")",
"try",
":",
"pinyin_syllable",
"=",
"_ZHUYIN_MAP",
"[",
"zhuyin_syllable",
"]",
"[",
"'Pinyin'",
"]",
"except",
"KeyError",
"... | 68eaf43c32725f4b4923c01284cfc0112079e8ab |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.