repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
ome/omego | omego/fileutils.py | open_url | def open_url(url, httpuser=None, httppassword=None, method=None):
"""
Open a URL using an opener that will simulate a browser user-agent
url: The URL
httpuser, httppassword: HTTP authentication credentials (either both or
neither must be provided)
method: The HTTP method
Caller is reponsi... | python | def open_url(url, httpuser=None, httppassword=None, method=None):
"""
Open a URL using an opener that will simulate a browser user-agent
url: The URL
httpuser, httppassword: HTTP authentication credentials (either both or
neither must be provided)
method: The HTTP method
Caller is reponsi... | [
"def",
"open_url",
"(",
"url",
",",
"httpuser",
"=",
"None",
",",
"httppassword",
"=",
"None",
",",
"method",
"=",
"None",
")",
":",
"if",
"os",
".",
"getenv",
"(",
"'OMEGO_SSL_NO_VERIFY'",
")",
"==",
"'1'",
":",
"# This needs to come first to override the def... | Open a URL using an opener that will simulate a browser user-agent
url: The URL
httpuser, httppassword: HTTP authentication credentials (either both or
neither must be provided)
method: The HTTP method
Caller is reponsible for calling close() on the returned object | [
"Open",
"a",
"URL",
"using",
"an",
"opener",
"that",
"will",
"simulate",
"a",
"browser",
"user",
"-",
"agent",
"url",
":",
"The",
"URL",
"httpuser",
"httppassword",
":",
"HTTP",
"authentication",
"credentials",
"(",
"either",
"both",
"or",
"neither",
"must",... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L47-L92 | train |
ome/omego | omego/fileutils.py | dereference_url | def dereference_url(url):
"""
Makes a HEAD request to find the final destination of a URL after
following any redirects
"""
res = open_url(url, method='HEAD')
res.close()
return res.url | python | def dereference_url(url):
"""
Makes a HEAD request to find the final destination of a URL after
following any redirects
"""
res = open_url(url, method='HEAD')
res.close()
return res.url | [
"def",
"dereference_url",
"(",
"url",
")",
":",
"res",
"=",
"open_url",
"(",
"url",
",",
"method",
"=",
"'HEAD'",
")",
"res",
".",
"close",
"(",
")",
"return",
"res",
".",
"url"
] | Makes a HEAD request to find the final destination of a URL after
following any redirects | [
"Makes",
"a",
"HEAD",
"request",
"to",
"find",
"the",
"final",
"destination",
"of",
"a",
"URL",
"after",
"following",
"any",
"redirects"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L95-L102 | train |
ome/omego | omego/fileutils.py | read | def read(url, **kwargs):
"""
Read the contents of a URL into memory, return
"""
response = open_url(url, **kwargs)
try:
return response.read()
finally:
response.close() | python | def read(url, **kwargs):
"""
Read the contents of a URL into memory, return
"""
response = open_url(url, **kwargs)
try:
return response.read()
finally:
response.close() | [
"def",
"read",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"response",
"=",
"open_url",
"(",
"url",
",",
"*",
"*",
"kwargs",
")",
"try",
":",
"return",
"response",
".",
"read",
"(",
")",
"finally",
":",
"response",
".",
"close",
"(",
")"
] | Read the contents of a URL into memory, return | [
"Read",
"the",
"contents",
"of",
"a",
"URL",
"into",
"memory",
"return"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L105-L113 | train |
ome/omego | omego/fileutils.py | download | def download(url, filename=None, print_progress=0, delete_fail=True,
**kwargs):
"""
Download a file, optionally printing a simple progress bar
url: The URL to download
filename: The filename to save to, default is to use the URL basename
print_progress: The length of the progress bar, u... | python | def download(url, filename=None, print_progress=0, delete_fail=True,
**kwargs):
"""
Download a file, optionally printing a simple progress bar
url: The URL to download
filename: The filename to save to, default is to use the URL basename
print_progress: The length of the progress bar, u... | [
"def",
"download",
"(",
"url",
",",
"filename",
"=",
"None",
",",
"print_progress",
"=",
"0",
",",
"delete_fail",
"=",
"True",
",",
"*",
"*",
"kwargs",
")",
":",
"blocksize",
"=",
"1024",
"*",
"1024",
"downloaded",
"=",
"0",
"progress",
"=",
"None",
... | Download a file, optionally printing a simple progress bar
url: The URL to download
filename: The filename to save to, default is to use the URL basename
print_progress: The length of the progress bar, use 0 to disable
delete_fail: If True delete the file if the download was not successful,
defaul... | [
"Download",
"a",
"file",
"optionally",
"printing",
"a",
"simple",
"progress",
"bar",
"url",
":",
"The",
"URL",
"to",
"download",
"filename",
":",
"The",
"filename",
"to",
"save",
"to",
"default",
"is",
"to",
"use",
"the",
"URL",
"basename",
"print_progress",... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L116-L158 | train |
ome/omego | omego/fileutils.py | rename_backup | def rename_backup(name, suffix='.bak'):
"""
Append a backup prefix to a file or directory, with an increasing numeric
suffix (.N) if a file already exists
"""
newname = '%s%s' % (name, suffix)
n = 0
while os.path.exists(newname):
n += 1
newname = '%s%s.%d' % (name, suffix, n)... | python | def rename_backup(name, suffix='.bak'):
"""
Append a backup prefix to a file or directory, with an increasing numeric
suffix (.N) if a file already exists
"""
newname = '%s%s' % (name, suffix)
n = 0
while os.path.exists(newname):
n += 1
newname = '%s%s.%d' % (name, suffix, n)... | [
"def",
"rename_backup",
"(",
"name",
",",
"suffix",
"=",
"'.bak'",
")",
":",
"newname",
"=",
"'%s%s'",
"%",
"(",
"name",
",",
"suffix",
")",
"n",
"=",
"0",
"while",
"os",
".",
"path",
".",
"exists",
"(",
"newname",
")",
":",
"n",
"+=",
"1",
"newn... | Append a backup prefix to a file or directory, with an increasing numeric
suffix (.N) if a file already exists | [
"Append",
"a",
"backup",
"prefix",
"to",
"a",
"file",
"or",
"directory",
"with",
"an",
"increasing",
"numeric",
"suffix",
"(",
".",
"N",
")",
"if",
"a",
"file",
"already",
"exists"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L161-L173 | train |
ome/omego | omego/fileutils.py | timestamp_filename | def timestamp_filename(basename, ext=None):
"""
Return a string of the form [basename-TIMESTAMP.ext]
where TIMESTAMP is of the form YYYYMMDD-HHMMSS-MILSEC
"""
dt = datetime.now().strftime('%Y%m%d-%H%M%S-%f')
if ext:
return '%s-%s.%s' % (basename, dt, ext)
return '%s-%s' % (basename, ... | python | def timestamp_filename(basename, ext=None):
"""
Return a string of the form [basename-TIMESTAMP.ext]
where TIMESTAMP is of the form YYYYMMDD-HHMMSS-MILSEC
"""
dt = datetime.now().strftime('%Y%m%d-%H%M%S-%f')
if ext:
return '%s-%s.%s' % (basename, dt, ext)
return '%s-%s' % (basename, ... | [
"def",
"timestamp_filename",
"(",
"basename",
",",
"ext",
"=",
"None",
")",
":",
"dt",
"=",
"datetime",
".",
"now",
"(",
")",
".",
"strftime",
"(",
"'%Y%m%d-%H%M%S-%f'",
")",
"if",
"ext",
":",
"return",
"'%s-%s.%s'",
"%",
"(",
"basename",
",",
"dt",
",... | Return a string of the form [basename-TIMESTAMP.ext]
where TIMESTAMP is of the form YYYYMMDD-HHMMSS-MILSEC | [
"Return",
"a",
"string",
"of",
"the",
"form",
"[",
"basename",
"-",
"TIMESTAMP",
".",
"ext",
"]",
"where",
"TIMESTAMP",
"is",
"of",
"the",
"form",
"YYYYMMDD",
"-",
"HHMMSS",
"-",
"MILSEC"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L176-L184 | train |
ome/omego | omego/fileutils.py | check_extracted_paths | def check_extracted_paths(namelist, subdir=None):
"""
Check whether zip file paths are all relative, and optionally in a
specified subdirectory, raises an exception if not
namelist: A list of paths from the zip file
subdir: If specified then check whether all paths in the zip file are
under t... | python | def check_extracted_paths(namelist, subdir=None):
"""
Check whether zip file paths are all relative, and optionally in a
specified subdirectory, raises an exception if not
namelist: A list of paths from the zip file
subdir: If specified then check whether all paths in the zip file are
under t... | [
"def",
"check_extracted_paths",
"(",
"namelist",
",",
"subdir",
"=",
"None",
")",
":",
"def",
"relpath",
"(",
"p",
")",
":",
"# relpath strips a trailing sep",
"# Windows paths may also use unix sep",
"q",
"=",
"os",
".",
"path",
".",
"relpath",
"(",
"p",
")",
... | Check whether zip file paths are all relative, and optionally in a
specified subdirectory, raises an exception if not
namelist: A list of paths from the zip file
subdir: If specified then check whether all paths in the zip file are
under this subdirectory
Python docs are unclear about the securi... | [
"Check",
"whether",
"zip",
"file",
"paths",
"are",
"all",
"relative",
"and",
"optionally",
"in",
"a",
"specified",
"subdirectory",
"raises",
"an",
"exception",
"if",
"not"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L194-L228 | train |
ome/omego | omego/fileutils.py | unzip | def unzip(filename, match_dir=False, destdir=None):
"""
Extract all files from a zip archive
filename: The path to the zip file
match_dir: If True all files in the zip must be contained in a subdirectory
named after the archive file with extension removed
destdir: Extract the zip into this dir... | python | def unzip(filename, match_dir=False, destdir=None):
"""
Extract all files from a zip archive
filename: The path to the zip file
match_dir: If True all files in the zip must be contained in a subdirectory
named after the archive file with extension removed
destdir: Extract the zip into this dir... | [
"def",
"unzip",
"(",
"filename",
",",
"match_dir",
"=",
"False",
",",
"destdir",
"=",
"None",
")",
":",
"if",
"not",
"destdir",
":",
"destdir",
"=",
"'.'",
"z",
"=",
"zipfile",
".",
"ZipFile",
"(",
"filename",
")",
"unzipped",
"=",
"'.'",
"if",
"matc... | Extract all files from a zip archive
filename: The path to the zip file
match_dir: If True all files in the zip must be contained in a subdirectory
named after the archive file with extension removed
destdir: Extract the zip into this directory, default current directory
return: If match_dir is T... | [
"Extract",
"all",
"files",
"from",
"a",
"zip",
"archive",
"filename",
":",
"The",
"path",
"to",
"the",
"zip",
"file",
"match_dir",
":",
"If",
"True",
"all",
"files",
"in",
"the",
"zip",
"must",
"be",
"contained",
"in",
"a",
"subdirectory",
"named",
"afte... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L231-L266 | train |
ome/omego | omego/fileutils.py | zip | def zip(filename, paths, strip_prefix=''):
"""
Create a new zip archive containing files
filename: The name of the zip file to be created
paths: A list of files or directories
strip_dir: Remove this prefix from all file-paths before adding to zip
"""
if isinstance(paths, basestring):
... | python | def zip(filename, paths, strip_prefix=''):
"""
Create a new zip archive containing files
filename: The name of the zip file to be created
paths: A list of files or directories
strip_dir: Remove this prefix from all file-paths before adding to zip
"""
if isinstance(paths, basestring):
... | [
"def",
"zip",
"(",
"filename",
",",
"paths",
",",
"strip_prefix",
"=",
"''",
")",
":",
"if",
"isinstance",
"(",
"paths",
",",
"basestring",
")",
":",
"paths",
"=",
"[",
"paths",
"]",
"filelist",
"=",
"set",
"(",
")",
"for",
"p",
"in",
"paths",
":",... | Create a new zip archive containing files
filename: The name of the zip file to be created
paths: A list of files or directories
strip_dir: Remove this prefix from all file-paths before adding to zip | [
"Create",
"a",
"new",
"zip",
"archive",
"containing",
"files",
"filename",
":",
"The",
"name",
"of",
"the",
"zip",
"file",
"to",
"be",
"created",
"paths",
":",
"A",
"list",
"of",
"files",
"or",
"directories",
"strip_dir",
":",
"Remove",
"this",
"prefix",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L269-L298 | train |
ome/omego | omego/fileutils.py | get_as_local_path | def get_as_local_path(path, overwrite, progress=0,
httpuser=None, httppassword=None):
"""
Automatically handle local and remote URLs, files and directories
path: Either a local directory, file or remote URL. If a URL is given
it will be fetched. If this is a zip it will be autom... | python | def get_as_local_path(path, overwrite, progress=0,
httpuser=None, httppassword=None):
"""
Automatically handle local and remote URLs, files and directories
path: Either a local directory, file or remote URL. If a URL is given
it will be fetched. If this is a zip it will be autom... | [
"def",
"get_as_local_path",
"(",
"path",
",",
"overwrite",
",",
"progress",
"=",
"0",
",",
"httpuser",
"=",
"None",
",",
"httppassword",
"=",
"None",
")",
":",
"m",
"=",
"re",
".",
"match",
"(",
"'([A-Za-z]+)://'",
",",
"path",
")",
"if",
"m",
":",
"... | Automatically handle local and remote URLs, files and directories
path: Either a local directory, file or remote URL. If a URL is given
it will be fetched. If this is a zip it will be automatically
expanded by default.
overwrite: Whether to overwrite an existing file:
'error': Raise an except... | [
"Automatically",
"handle",
"local",
"and",
"remote",
"URLs",
"files",
"and",
"directories"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/fileutils.py#L301-L356 | train |
svartalf/python-opus | opus/api/encoder.py | create | def create(fs, channels, application):
"""Allocates and initializes an encoder state."""
result_code = ctypes.c_int()
result = _create(fs, channels, application, ctypes.byref(result_code))
if result_code.value is not constants.OK:
raise OpusError(result_code.value)
return result | python | def create(fs, channels, application):
"""Allocates and initializes an encoder state."""
result_code = ctypes.c_int()
result = _create(fs, channels, application, ctypes.byref(result_code))
if result_code.value is not constants.OK:
raise OpusError(result_code.value)
return result | [
"def",
"create",
"(",
"fs",
",",
"channels",
",",
"application",
")",
":",
"result_code",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"result",
"=",
"_create",
"(",
"fs",
",",
"channels",
",",
"application",
",",
"ctypes",
".",
"byref",
"(",
"result_code",
... | Allocates and initializes an encoder state. | [
"Allocates",
"and",
"initializes",
"an",
"encoder",
"state",
"."
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/encoder.py#L40-L49 | train |
svartalf/python-opus | opus/api/encoder.py | encode | def encode(encoder, pcm, frame_size, max_data_bytes):
"""Encodes an Opus frame
Returns string output payload
"""
pcm = ctypes.cast(pcm, c_int16_pointer)
data = (ctypes.c_char * max_data_bytes)()
result = _encode(encoder, pcm, frame_size, data, max_data_bytes)
if result < 0:
raise ... | python | def encode(encoder, pcm, frame_size, max_data_bytes):
"""Encodes an Opus frame
Returns string output payload
"""
pcm = ctypes.cast(pcm, c_int16_pointer)
data = (ctypes.c_char * max_data_bytes)()
result = _encode(encoder, pcm, frame_size, data, max_data_bytes)
if result < 0:
raise ... | [
"def",
"encode",
"(",
"encoder",
",",
"pcm",
",",
"frame_size",
",",
"max_data_bytes",
")",
":",
"pcm",
"=",
"ctypes",
".",
"cast",
"(",
"pcm",
",",
"c_int16_pointer",
")",
"data",
"=",
"(",
"ctypes",
".",
"c_char",
"*",
"max_data_bytes",
")",
"(",
")"... | Encodes an Opus frame
Returns string output payload | [
"Encodes",
"an",
"Opus",
"frame"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/encoder.py#L68-L81 | train |
svartalf/python-opus | opus/api/encoder.py | encode_float | def encode_float(encoder, pcm, frame_size, max_data_bytes):
"""Encodes an Opus frame from floating point input"""
pcm = ctypes.cast(pcm, c_float_pointer)
data = (ctypes.c_char * max_data_bytes)()
result = _encode_float(encoder, pcm, frame_size, data, max_data_bytes)
if result < 0:
raise Op... | python | def encode_float(encoder, pcm, frame_size, max_data_bytes):
"""Encodes an Opus frame from floating point input"""
pcm = ctypes.cast(pcm, c_float_pointer)
data = (ctypes.c_char * max_data_bytes)()
result = _encode_float(encoder, pcm, frame_size, data, max_data_bytes)
if result < 0:
raise Op... | [
"def",
"encode_float",
"(",
"encoder",
",",
"pcm",
",",
"frame_size",
",",
"max_data_bytes",
")",
":",
"pcm",
"=",
"ctypes",
".",
"cast",
"(",
"pcm",
",",
"c_float_pointer",
")",
"data",
"=",
"(",
"ctypes",
".",
"c_char",
"*",
"max_data_bytes",
")",
"(",... | Encodes an Opus frame from floating point input | [
"Encodes",
"an",
"Opus",
"frame",
"from",
"floating",
"point",
"input"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/encoder.py#L89-L99 | train |
buruzaemon/natto-py | natto/mecab.py | MeCab.__parse_tostr | def __parse_tostr(self, text, **kwargs):
'''Builds and returns the MeCab function for parsing Unicode text.
Args:
fn_name: MeCab function name that determines the function
behavior, either 'mecab_sparse_tostr' or
'mecab_nbest_sparse_tostr'.
Returns:
... | python | def __parse_tostr(self, text, **kwargs):
'''Builds and returns the MeCab function for parsing Unicode text.
Args:
fn_name: MeCab function name that determines the function
behavior, either 'mecab_sparse_tostr' or
'mecab_nbest_sparse_tostr'.
Returns:
... | [
"def",
"__parse_tostr",
"(",
"self",
",",
"text",
",",
"*",
"*",
"kwargs",
")",
":",
"n",
"=",
"self",
".",
"options",
".",
"get",
"(",
"'nbest'",
",",
"1",
")",
"if",
"self",
".",
"_KW_BOUNDARY",
"in",
"kwargs",
":",
"patt",
"=",
"kwargs",
".",
... | Builds and returns the MeCab function for parsing Unicode text.
Args:
fn_name: MeCab function name that determines the function
behavior, either 'mecab_sparse_tostr' or
'mecab_nbest_sparse_tostr'.
Returns:
A function definition, tailored to parsi... | [
"Builds",
"and",
"returns",
"the",
"MeCab",
"function",
"for",
"parsing",
"Unicode",
"text",
"."
] | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/mecab.py#L248-L322 | train |
buruzaemon/natto-py | natto/mecab.py | MeCab.__parse_tonodes | def __parse_tonodes(self, text, **kwargs):
'''Builds and returns the MeCab function for parsing to nodes using
morpheme boundary constraints.
Args:
format_feature: flag indicating whether or not to format the feature
value for each node yielded.
Returns:
... | python | def __parse_tonodes(self, text, **kwargs):
'''Builds and returns the MeCab function for parsing to nodes using
morpheme boundary constraints.
Args:
format_feature: flag indicating whether or not to format the feature
value for each node yielded.
Returns:
... | [
"def",
"__parse_tonodes",
"(",
"self",
",",
"text",
",",
"*",
"*",
"kwargs",
")",
":",
"n",
"=",
"self",
".",
"options",
".",
"get",
"(",
"'nbest'",
",",
"1",
")",
"try",
":",
"if",
"self",
".",
"_KW_BOUNDARY",
"in",
"kwargs",
":",
"patt",
"=",
"... | Builds and returns the MeCab function for parsing to nodes using
morpheme boundary constraints.
Args:
format_feature: flag indicating whether or not to format the feature
value for each node yielded.
Returns:
A function which returns a Generator, tailore... | [
"Builds",
"and",
"returns",
"the",
"MeCab",
"function",
"for",
"parsing",
"to",
"nodes",
"using",
"morpheme",
"boundary",
"constraints",
"."
] | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/mecab.py#L324-L427 | train |
buruzaemon/natto-py | natto/mecab.py | MeCab.parse | def parse(self, text, **kwargs):
'''Parse the given text and return result from MeCab.
:param text: the text to parse.
:type text: str
:param as_nodes: return generator of MeCabNodes if True;
or string if False.
:type as_nodes: bool, defaults to False
:param ... | python | def parse(self, text, **kwargs):
'''Parse the given text and return result from MeCab.
:param text: the text to parse.
:type text: str
:param as_nodes: return generator of MeCabNodes if True;
or string if False.
:type as_nodes: bool, defaults to False
:param ... | [
"def",
"parse",
"(",
"self",
",",
"text",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"text",
"is",
"None",
":",
"logger",
".",
"error",
"(",
"self",
".",
"_ERROR_EMPTY_STR",
")",
"raise",
"MeCabError",
"(",
"self",
".",
"_ERROR_EMPTY_STR",
")",
"elif",
... | Parse the given text and return result from MeCab.
:param text: the text to parse.
:type text: str
:param as_nodes: return generator of MeCabNodes if True;
or string if False.
:type as_nodes: bool, defaults to False
:param boundary_constraints: regular expression for... | [
"Parse",
"the",
"given",
"text",
"and",
"return",
"result",
"from",
"MeCab",
"."
] | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/mecab.py#L441-L488 | train |
ome/omego | omego/convert.py | parse | def parse(filename, MAX_TERM_COUNT=1000):
"""
MAX_TERM_COUNT = 10000 # There are 39,000 terms in the GO!
"""
with open(filename, "r") as f:
termId = None
name = None
desc = None
parents = []
termCount = 0
for l in f.readlines():
if l.st... | python | def parse(filename, MAX_TERM_COUNT=1000):
"""
MAX_TERM_COUNT = 10000 # There are 39,000 terms in the GO!
"""
with open(filename, "r") as f:
termId = None
name = None
desc = None
parents = []
termCount = 0
for l in f.readlines():
if l.st... | [
"def",
"parse",
"(",
"filename",
",",
"MAX_TERM_COUNT",
"=",
"1000",
")",
":",
"with",
"open",
"(",
"filename",
",",
"\"r\"",
")",
"as",
"f",
":",
"termId",
"=",
"None",
"name",
"=",
"None",
"desc",
"=",
"None",
"parents",
"=",
"[",
"]",
"termCount",... | MAX_TERM_COUNT = 10000 # There are 39,000 terms in the GO! | [
"MAX_TERM_COUNT",
"=",
"10000",
"#",
"There",
"are",
"39",
"000",
"terms",
"in",
"the",
"GO!"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/convert.py#L59-L109 | train |
ome/omego | omego/convert.py | generate | def generate(tagGroups, terms):
"""
create Tag Groups and Child Tags using data from terms dict
"""
rv = []
for pid in tagGroups:
# In testing we may not have complete set
if pid not in terms.keys():
continue
groupData = terms[pid]
groupName = "[%s] %s" ... | python | def generate(tagGroups, terms):
"""
create Tag Groups and Child Tags using data from terms dict
"""
rv = []
for pid in tagGroups:
# In testing we may not have complete set
if pid not in terms.keys():
continue
groupData = terms[pid]
groupName = "[%s] %s" ... | [
"def",
"generate",
"(",
"tagGroups",
",",
"terms",
")",
":",
"rv",
"=",
"[",
"]",
"for",
"pid",
"in",
"tagGroups",
":",
"# In testing we may not have complete set",
"if",
"pid",
"not",
"in",
"terms",
".",
"keys",
"(",
")",
":",
"continue",
"groupData",
"="... | create Tag Groups and Child Tags using data from terms dict | [
"create",
"Tag",
"Groups",
"and",
"Child",
"Tags",
"using",
"data",
"from",
"terms",
"dict"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/convert.py#L112-L137 | train |
ome/omego | omego/upgrade.py | Install._handle_args | def _handle_args(self, cmd, args):
"""
We need to support deprecated behaviour for now which makes this
quite complicated
Current behaviour:
- install: Installs a new server, existing server causes an error
- install --upgrade: Installs or upgrades a server
- ins... | python | def _handle_args(self, cmd, args):
"""
We need to support deprecated behaviour for now which makes this
quite complicated
Current behaviour:
- install: Installs a new server, existing server causes an error
- install --upgrade: Installs or upgrades a server
- ins... | [
"def",
"_handle_args",
"(",
"self",
",",
"cmd",
",",
"args",
")",
":",
"if",
"cmd",
"==",
"'install'",
":",
"if",
"args",
".",
"upgrade",
":",
"# Current behaviour: install or upgrade",
"if",
"args",
".",
"initdb",
"or",
"args",
".",
"upgradedb",
":",
"rai... | We need to support deprecated behaviour for now which makes this
quite complicated
Current behaviour:
- install: Installs a new server, existing server causes an error
- install --upgrade: Installs or upgrades a server
- install --managedb: Automatically initialise or upgrade th... | [
"We",
"need",
"to",
"support",
"deprecated",
"behaviour",
"for",
"now",
"which",
"makes",
"this",
"quite",
"complicated"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/upgrade.py#L75-L132 | train |
ome/omego | omego/upgrade.py | Install.get_server_dir | def get_server_dir(self):
"""
Either downloads and/or unzips the server if necessary
return: the directory of the unzipped server
"""
if not self.args.server:
if self.args.skipunzip:
raise Stop(0, 'Unzip disabled, exiting')
log.info('Downl... | python | def get_server_dir(self):
"""
Either downloads and/or unzips the server if necessary
return: the directory of the unzipped server
"""
if not self.args.server:
if self.args.skipunzip:
raise Stop(0, 'Unzip disabled, exiting')
log.info('Downl... | [
"def",
"get_server_dir",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"args",
".",
"server",
":",
"if",
"self",
".",
"args",
".",
"skipunzip",
":",
"raise",
"Stop",
"(",
"0",
",",
"'Unzip disabled, exiting'",
")",
"log",
".",
"info",
"(",
"'Downloa... | Either downloads and/or unzips the server if necessary
return: the directory of the unzipped server | [
"Either",
"downloads",
"and",
"/",
"or",
"unzips",
"the",
"server",
"if",
"necessary",
"return",
":",
"the",
"directory",
"of",
"the",
"unzipped",
"server"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/upgrade.py#L134-L169 | train |
ome/omego | omego/upgrade.py | Install.handle_database | def handle_database(self):
"""
Handle database initialisation and upgrade, taking into account
command line arguments
"""
# TODO: When initdb and upgradedb are dropped we can just test
# managedb, but for backwards compatibility we need to support
# initdb without... | python | def handle_database(self):
"""
Handle database initialisation and upgrade, taking into account
command line arguments
"""
# TODO: When initdb and upgradedb are dropped we can just test
# managedb, but for backwards compatibility we need to support
# initdb without... | [
"def",
"handle_database",
"(",
"self",
")",
":",
"# TODO: When initdb and upgradedb are dropped we can just test",
"# managedb, but for backwards compatibility we need to support",
"# initdb without upgradedb and vice-versa",
"if",
"self",
".",
"args",
".",
"initdb",
"or",
"self",
... | Handle database initialisation and upgrade, taking into account
command line arguments | [
"Handle",
"database",
"initialisation",
"and",
"upgrade",
"taking",
"into",
"account",
"command",
"line",
"arguments"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/upgrade.py#L263-L302 | train |
ome/omego | omego/upgrade.py | Install.run | def run(self, command):
"""
Runs a command as if from the command-line
without the need for using popen or subprocess
"""
if isinstance(command, basestring):
command = command.split()
else:
command = list(command)
self.external.omero_cli(co... | python | def run(self, command):
"""
Runs a command as if from the command-line
without the need for using popen or subprocess
"""
if isinstance(command, basestring):
command = command.split()
else:
command = list(command)
self.external.omero_cli(co... | [
"def",
"run",
"(",
"self",
",",
"command",
")",
":",
"if",
"isinstance",
"(",
"command",
",",
"basestring",
")",
":",
"command",
"=",
"command",
".",
"split",
"(",
")",
"else",
":",
"command",
"=",
"list",
"(",
"command",
")",
"self",
".",
"external"... | Runs a command as if from the command-line
without the need for using popen or subprocess | [
"Runs",
"a",
"command",
"as",
"if",
"from",
"the",
"command",
"-",
"line",
"without",
"the",
"need",
"for",
"using",
"popen",
"or",
"subprocess"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/upgrade.py#L314-L323 | train |
ome/omego | omego/upgrade.py | Install.bin | def bin(self, command):
"""
Runs the omero command-line client with an array of arguments using the
old environment
"""
if isinstance(command, basestring):
command = command.split()
self.external.omero_bin(command) | python | def bin(self, command):
"""
Runs the omero command-line client with an array of arguments using the
old environment
"""
if isinstance(command, basestring):
command = command.split()
self.external.omero_bin(command) | [
"def",
"bin",
"(",
"self",
",",
"command",
")",
":",
"if",
"isinstance",
"(",
"command",
",",
"basestring",
")",
":",
"command",
"=",
"command",
".",
"split",
"(",
")",
"self",
".",
"external",
".",
"omero_bin",
"(",
"command",
")"
] | Runs the omero command-line client with an array of arguments using the
old environment | [
"Runs",
"the",
"omero",
"command",
"-",
"line",
"client",
"with",
"an",
"array",
"of",
"arguments",
"using",
"the",
"old",
"environment"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/upgrade.py#L325-L332 | train |
ome/omego | omego/upgrade.py | Install.symlink_check_and_set | def symlink_check_and_set(self):
"""
The default symlink was changed from OMERO-CURRENT to OMERO.server.
If `--sym` was not specified and OMERO-CURRENT exists in the current
directory stop and warn.
"""
if self.args.sym == '':
if os.path.exists('OMERO-CURRENT'... | python | def symlink_check_and_set(self):
"""
The default symlink was changed from OMERO-CURRENT to OMERO.server.
If `--sym` was not specified and OMERO-CURRENT exists in the current
directory stop and warn.
"""
if self.args.sym == '':
if os.path.exists('OMERO-CURRENT'... | [
"def",
"symlink_check_and_set",
"(",
"self",
")",
":",
"if",
"self",
".",
"args",
".",
"sym",
"==",
"''",
":",
"if",
"os",
".",
"path",
".",
"exists",
"(",
"'OMERO-CURRENT'",
")",
":",
"log",
".",
"error",
"(",
"'Deprecated OMERO-CURRENT found but --sym not ... | The default symlink was changed from OMERO-CURRENT to OMERO.server.
If `--sym` was not specified and OMERO-CURRENT exists in the current
directory stop and warn. | [
"The",
"default",
"symlink",
"was",
"changed",
"from",
"OMERO",
"-",
"CURRENT",
"to",
"OMERO",
".",
"server",
".",
"If",
"--",
"sym",
"was",
"not",
"specified",
"and",
"OMERO",
"-",
"CURRENT",
"exists",
"in",
"the",
"current",
"directory",
"stop",
"and",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/upgrade.py#L334-L348 | train |
svartalf/python-opus | opus/api/ctl.py | query | def query(request):
"""Query encoder/decoder with a request value"""
def inner(func, obj):
result_code = func(obj, request)
if result_code is not constants.OK:
raise OpusError(result_code)
return result_code
return inner | python | def query(request):
"""Query encoder/decoder with a request value"""
def inner(func, obj):
result_code = func(obj, request)
if result_code is not constants.OK:
raise OpusError(result_code)
return result_code
return inner | [
"def",
"query",
"(",
"request",
")",
":",
"def",
"inner",
"(",
"func",
",",
"obj",
")",
":",
"result_code",
"=",
"func",
"(",
"obj",
",",
"request",
")",
"if",
"result_code",
"is",
"not",
"constants",
".",
"OK",
":",
"raise",
"OpusError",
"(",
"resul... | Query encoder/decoder with a request value | [
"Query",
"encoder",
"/",
"decoder",
"with",
"a",
"request",
"value"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/ctl.py#L19-L30 | train |
svartalf/python-opus | opus/api/ctl.py | get | def get(request, result_type):
"""Get CTL value from a encoder/decoder"""
def inner(func, obj):
result = result_type()
result_code = func(obj, request, ctypes.byref(result))
if result_code is not constants.OK:
raise OpusError(result_code)
return result.value
r... | python | def get(request, result_type):
"""Get CTL value from a encoder/decoder"""
def inner(func, obj):
result = result_type()
result_code = func(obj, request, ctypes.byref(result))
if result_code is not constants.OK:
raise OpusError(result_code)
return result.value
r... | [
"def",
"get",
"(",
"request",
",",
"result_type",
")",
":",
"def",
"inner",
"(",
"func",
",",
"obj",
")",
":",
"result",
"=",
"result_type",
"(",
")",
"result_code",
"=",
"func",
"(",
"obj",
",",
"request",
",",
"ctypes",
".",
"byref",
"(",
"result",... | Get CTL value from a encoder/decoder | [
"Get",
"CTL",
"value",
"from",
"a",
"encoder",
"/",
"decoder"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/ctl.py#L33-L45 | train |
svartalf/python-opus | opus/api/ctl.py | set | def set(request):
"""Set new CTL value to a encoder/decoder"""
def inner(func, obj, value):
result_code = func(obj, request, value)
if result_code is not constants.OK:
raise OpusError(result_code)
return inner | python | def set(request):
"""Set new CTL value to a encoder/decoder"""
def inner(func, obj, value):
result_code = func(obj, request, value)
if result_code is not constants.OK:
raise OpusError(result_code)
return inner | [
"def",
"set",
"(",
"request",
")",
":",
"def",
"inner",
"(",
"func",
",",
"obj",
",",
"value",
")",
":",
"result_code",
"=",
"func",
"(",
"obj",
",",
"request",
",",
"value",
")",
"if",
"result_code",
"is",
"not",
"constants",
".",
"OK",
":",
"rais... | Set new CTL value to a encoder/decoder | [
"Set",
"new",
"CTL",
"value",
"to",
"a",
"encoder",
"/",
"decoder"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/ctl.py#L48-L56 | train |
ome/omego | omego/db.py | sort_schemas | def sort_schemas(schemas):
"""Sort a list of SQL schemas in order"""
def keyfun(v):
x = SQL_SCHEMA_REGEXP.match(v).groups()
# x3: 'DEV' should come before ''
return (int(x[0]), x[1], int(x[2]) if x[2] else None,
x[3] if x[3] else 'zzz', int(x[4]))
return sorted(schem... | python | def sort_schemas(schemas):
"""Sort a list of SQL schemas in order"""
def keyfun(v):
x = SQL_SCHEMA_REGEXP.match(v).groups()
# x3: 'DEV' should come before ''
return (int(x[0]), x[1], int(x[2]) if x[2] else None,
x[3] if x[3] else 'zzz', int(x[4]))
return sorted(schem... | [
"def",
"sort_schemas",
"(",
"schemas",
")",
":",
"def",
"keyfun",
"(",
"v",
")",
":",
"x",
"=",
"SQL_SCHEMA_REGEXP",
".",
"match",
"(",
"v",
")",
".",
"groups",
"(",
")",
"# x3: 'DEV' should come before ''",
"return",
"(",
"int",
"(",
"x",
"[",
"0",
"]... | Sort a list of SQL schemas in order | [
"Sort",
"a",
"list",
"of",
"SQL",
"schemas",
"in",
"order"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L31-L39 | train |
ome/omego | omego/db.py | parse_schema_files | def parse_schema_files(files):
"""
Parse a list of SQL files and return a dictionary of valid schema
files where each key is a valid schema file and the corresponding value is
a tuple containing the source and the target schema.
"""
f_dict = {}
for f in files:
root, ext = os.path.spl... | python | def parse_schema_files(files):
"""
Parse a list of SQL files and return a dictionary of valid schema
files where each key is a valid schema file and the corresponding value is
a tuple containing the source and the target schema.
"""
f_dict = {}
for f in files:
root, ext = os.path.spl... | [
"def",
"parse_schema_files",
"(",
"files",
")",
":",
"f_dict",
"=",
"{",
"}",
"for",
"f",
"in",
"files",
":",
"root",
",",
"ext",
"=",
"os",
".",
"path",
".",
"splitext",
"(",
"f",
")",
"if",
"ext",
"!=",
"\".sql\"",
":",
"continue",
"vto",
",",
... | Parse a list of SQL files and return a dictionary of valid schema
files where each key is a valid schema file and the corresponding value is
a tuple containing the source and the target schema. | [
"Parse",
"a",
"list",
"of",
"SQL",
"files",
"and",
"return",
"a",
"dictionary",
"of",
"valid",
"schema",
"files",
"where",
"each",
"key",
"is",
"a",
"valid",
"schema",
"file",
"and",
"the",
"corresponding",
"value",
"is",
"a",
"tuple",
"containing",
"the",... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L42-L57 | train |
ome/omego | omego/db.py | DbAdmin.dump | def dump(self):
"""
Dump the database using the postgres custom format
"""
dumpfile = self.args.dumpfile
if not dumpfile:
db, env = self.get_db_args_env()
dumpfile = fileutils.timestamp_filename(
'omero-database-%s' % db['name'], 'pgdump')
... | python | def dump(self):
"""
Dump the database using the postgres custom format
"""
dumpfile = self.args.dumpfile
if not dumpfile:
db, env = self.get_db_args_env()
dumpfile = fileutils.timestamp_filename(
'omero-database-%s' % db['name'], 'pgdump')
... | [
"def",
"dump",
"(",
"self",
")",
":",
"dumpfile",
"=",
"self",
".",
"args",
".",
"dumpfile",
"if",
"not",
"dumpfile",
":",
"db",
",",
"env",
"=",
"self",
".",
"get_db_args_env",
"(",
")",
"dumpfile",
"=",
"fileutils",
".",
"timestamp_filename",
"(",
"'... | Dump the database using the postgres custom format | [
"Dump",
"the",
"database",
"using",
"the",
"postgres",
"custom",
"format"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L206-L218 | train |
ome/omego | omego/db.py | DbAdmin.get_db_args_env | def get_db_args_env(self):
"""
Get a dictionary of database connection parameters, and create an
environment for running postgres commands.
Falls back to omego defaults.
"""
db = {
'name': self.args.dbname,
'host': self.args.dbhost,
'us... | python | def get_db_args_env(self):
"""
Get a dictionary of database connection parameters, and create an
environment for running postgres commands.
Falls back to omego defaults.
"""
db = {
'name': self.args.dbname,
'host': self.args.dbhost,
'us... | [
"def",
"get_db_args_env",
"(",
"self",
")",
":",
"db",
"=",
"{",
"'name'",
":",
"self",
".",
"args",
".",
"dbname",
",",
"'host'",
":",
"self",
".",
"args",
".",
"dbhost",
",",
"'user'",
":",
"self",
".",
"args",
".",
"dbuser",
",",
"'pass'",
":",
... | Get a dictionary of database connection parameters, and create an
environment for running postgres commands.
Falls back to omego defaults. | [
"Get",
"a",
"dictionary",
"of",
"database",
"connection",
"parameters",
"and",
"create",
"an",
"environment",
"for",
"running",
"postgres",
"commands",
".",
"Falls",
"back",
"to",
"omego",
"defaults",
"."
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L220-L253 | train |
ome/omego | omego/db.py | DbAdmin.psql | def psql(self, *psqlargs):
"""
Run a psql command
"""
db, env = self.get_db_args_env()
args = [
'-v', 'ON_ERROR_STOP=on',
'-d', db['name'],
'-h', db['host'],
'-U', db['user'],
'-w', '-A', '-t'
] + list(psqla... | python | def psql(self, *psqlargs):
"""
Run a psql command
"""
db, env = self.get_db_args_env()
args = [
'-v', 'ON_ERROR_STOP=on',
'-d', db['name'],
'-h', db['host'],
'-U', db['user'],
'-w', '-A', '-t'
] + list(psqla... | [
"def",
"psql",
"(",
"self",
",",
"*",
"psqlargs",
")",
":",
"db",
",",
"env",
"=",
"self",
".",
"get_db_args_env",
"(",
")",
"args",
"=",
"[",
"'-v'",
",",
"'ON_ERROR_STOP=on'",
",",
"'-d'",
",",
"db",
"[",
"'name'",
"]",
",",
"'-h'",
",",
"db",
... | Run a psql command | [
"Run",
"a",
"psql",
"command"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L255-L272 | train |
ome/omego | omego/db.py | DbAdmin.pgdump | def pgdump(self, *pgdumpargs):
"""
Run a pg_dump command
"""
db, env = self.get_db_args_env()
args = ['-d', db['name'], '-h', db['host'], '-U', db['user'], '-w'
] + list(pgdumpargs)
stdout, stderr = External.run(
'pg_dump', args, capturestd=Tr... | python | def pgdump(self, *pgdumpargs):
"""
Run a pg_dump command
"""
db, env = self.get_db_args_env()
args = ['-d', db['name'], '-h', db['host'], '-U', db['user'], '-w'
] + list(pgdumpargs)
stdout, stderr = External.run(
'pg_dump', args, capturestd=Tr... | [
"def",
"pgdump",
"(",
"self",
",",
"*",
"pgdumpargs",
")",
":",
"db",
",",
"env",
"=",
"self",
".",
"get_db_args_env",
"(",
")",
"args",
"=",
"[",
"'-d'",
",",
"db",
"[",
"'name'",
"]",
",",
"'-h'",
",",
"db",
"[",
"'host'",
"]",
",",
"'-U'",
"... | Run a pg_dump command | [
"Run",
"a",
"pg_dump",
"command"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/db.py#L274-L287 | train |
ome/omego | omego/external.py | External.set_server_dir | def set_server_dir(self, dir):
"""
Set the directory of the server to be controlled
"""
self.dir = os.path.abspath(dir)
config = os.path.join(self.dir, 'etc', 'grid', 'config.xml')
self.configured = os.path.exists(config) | python | def set_server_dir(self, dir):
"""
Set the directory of the server to be controlled
"""
self.dir = os.path.abspath(dir)
config = os.path.join(self.dir, 'etc', 'grid', 'config.xml')
self.configured = os.path.exists(config) | [
"def",
"set_server_dir",
"(",
"self",
",",
"dir",
")",
":",
"self",
".",
"dir",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"dir",
")",
"config",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"dir",
",",
"'etc'",
",",
"'grid'",
",",
"... | Set the directory of the server to be controlled | [
"Set",
"the",
"directory",
"of",
"the",
"server",
"to",
"be",
"controlled"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L55-L61 | train |
ome/omego | omego/external.py | External.get_config | def get_config(self, force=False):
"""
Returns a dictionary of all config.xml properties
If `force = True` then ignore any cached state and read config.xml
if possible
setup_omero_cli() must be called before this method to import the
correct omero module to minimise the... | python | def get_config(self, force=False):
"""
Returns a dictionary of all config.xml properties
If `force = True` then ignore any cached state and read config.xml
if possible
setup_omero_cli() must be called before this method to import the
correct omero module to minimise the... | [
"def",
"get_config",
"(",
"self",
",",
"force",
"=",
"False",
")",
":",
"if",
"not",
"force",
"and",
"not",
"self",
".",
"has_config",
"(",
")",
":",
"raise",
"Exception",
"(",
"'No config file'",
")",
"configxml",
"=",
"os",
".",
"path",
".",
"join",
... | Returns a dictionary of all config.xml properties
If `force = True` then ignore any cached state and read config.xml
if possible
setup_omero_cli() must be called before this method to import the
correct omero module to minimise the possibility of version conflicts | [
"Returns",
"a",
"dictionary",
"of",
"all",
"config",
".",
"xml",
"properties"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L74-L102 | train |
ome/omego | omego/external.py | External.setup_omero_cli | def setup_omero_cli(self):
"""
Imports the omero CLI module so that commands can be run directly.
Note Python does not allow a module to be imported multiple times,
so this will only work with a single omero instance.
This can have several surprising effects, so setup_omero_cli(... | python | def setup_omero_cli(self):
"""
Imports the omero CLI module so that commands can be run directly.
Note Python does not allow a module to be imported multiple times,
so this will only work with a single omero instance.
This can have several surprising effects, so setup_omero_cli(... | [
"def",
"setup_omero_cli",
"(",
"self",
")",
":",
"if",
"not",
"self",
".",
"dir",
":",
"raise",
"Exception",
"(",
"'No server directory set'",
")",
"if",
"'omero.cli'",
"in",
"sys",
".",
"modules",
":",
"raise",
"Exception",
"(",
"'omero.cli can only be imported... | Imports the omero CLI module so that commands can be run directly.
Note Python does not allow a module to be imported multiple times,
so this will only work with a single omero instance.
This can have several surprising effects, so setup_omero_cli()
must be explcitly called. | [
"Imports",
"the",
"omero",
"CLI",
"module",
"so",
"that",
"commands",
"can",
"be",
"run",
"directly",
".",
"Note",
"Python",
"does",
"not",
"allow",
"a",
"module",
"to",
"be",
"imported",
"multiple",
"times",
"so",
"this",
"will",
"only",
"work",
"with",
... | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L104-L132 | train |
ome/omego | omego/external.py | External.setup_previous_omero_env | def setup_previous_omero_env(self, olddir, savevarsfile):
"""
Create a copy of the current environment for interacting with the
current OMERO server installation
"""
env = self.get_environment(savevarsfile)
def addpath(varname, p):
if not os.path.exists(p):
... | python | def setup_previous_omero_env(self, olddir, savevarsfile):
"""
Create a copy of the current environment for interacting with the
current OMERO server installation
"""
env = self.get_environment(savevarsfile)
def addpath(varname, p):
if not os.path.exists(p):
... | [
"def",
"setup_previous_omero_env",
"(",
"self",
",",
"olddir",
",",
"savevarsfile",
")",
":",
"env",
"=",
"self",
".",
"get_environment",
"(",
"savevarsfile",
")",
"def",
"addpath",
"(",
"varname",
",",
"p",
")",
":",
"if",
"not",
"os",
".",
"path",
".",... | Create a copy of the current environment for interacting with the
current OMERO server installation | [
"Create",
"a",
"copy",
"of",
"the",
"current",
"environment",
"for",
"interacting",
"with",
"the",
"current",
"OMERO",
"server",
"installation"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L134-L155 | train |
ome/omego | omego/external.py | External.omero_cli | def omero_cli(self, command):
"""
Runs a command as if from the OMERO command-line without the need
for using popen or subprocess.
"""
assert isinstance(command, list)
if not self.cli:
raise Exception('omero.cli not initialised')
log.info("Invoking CLI... | python | def omero_cli(self, command):
"""
Runs a command as if from the OMERO command-line without the need
for using popen or subprocess.
"""
assert isinstance(command, list)
if not self.cli:
raise Exception('omero.cli not initialised')
log.info("Invoking CLI... | [
"def",
"omero_cli",
"(",
"self",
",",
"command",
")",
":",
"assert",
"isinstance",
"(",
"command",
",",
"list",
")",
"if",
"not",
"self",
".",
"cli",
":",
"raise",
"Exception",
"(",
"'omero.cli not initialised'",
")",
"log",
".",
"info",
"(",
"\"Invoking C... | Runs a command as if from the OMERO command-line without the need
for using popen or subprocess. | [
"Runs",
"a",
"command",
"as",
"if",
"from",
"the",
"OMERO",
"command",
"-",
"line",
"without",
"the",
"need",
"for",
"using",
"popen",
"or",
"subprocess",
"."
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L157-L166 | train |
ome/omego | omego/external.py | External.omero_bin | def omero_bin(self, command):
"""
Runs the omero command-line client with an array of arguments using the
old environment
"""
assert isinstance(command, list)
if not self.old_env:
raise Exception('Old environment not initialised')
log.info("Running [ol... | python | def omero_bin(self, command):
"""
Runs the omero command-line client with an array of arguments using the
old environment
"""
assert isinstance(command, list)
if not self.old_env:
raise Exception('Old environment not initialised')
log.info("Running [ol... | [
"def",
"omero_bin",
"(",
"self",
",",
"command",
")",
":",
"assert",
"isinstance",
"(",
"command",
",",
"list",
")",
"if",
"not",
"self",
".",
"old_env",
":",
"raise",
"Exception",
"(",
"'Old environment not initialised'",
")",
"log",
".",
"info",
"(",
"\"... | Runs the omero command-line client with an array of arguments using the
old environment | [
"Runs",
"the",
"omero",
"command",
"-",
"line",
"client",
"with",
"an",
"array",
"of",
"arguments",
"using",
"the",
"old",
"environment"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L168-L177 | train |
ome/omego | omego/external.py | External.run | def run(exe, args, capturestd=False, env=None):
"""
Runs an executable with an array of arguments, optionally in the
specified environment.
Returns stdout and stderr
"""
command = [exe] + args
if env:
log.info("Executing [custom environment]: %s", " ".... | python | def run(exe, args, capturestd=False, env=None):
"""
Runs an executable with an array of arguments, optionally in the
specified environment.
Returns stdout and stderr
"""
command = [exe] + args
if env:
log.info("Executing [custom environment]: %s", " ".... | [
"def",
"run",
"(",
"exe",
",",
"args",
",",
"capturestd",
"=",
"False",
",",
"env",
"=",
"None",
")",
":",
"command",
"=",
"[",
"exe",
"]",
"+",
"args",
"if",
"env",
":",
"log",
".",
"info",
"(",
"\"Executing [custom environment]: %s\"",
",",
"\" \"",
... | Runs an executable with an array of arguments, optionally in the
specified environment.
Returns stdout and stderr | [
"Runs",
"an",
"executable",
"with",
"an",
"array",
"of",
"arguments",
"optionally",
"in",
"the",
"specified",
"environment",
".",
"Returns",
"stdout",
"and",
"stderr"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/external.py#L180-L225 | train |
buruzaemon/natto-py | natto/support.py | string_support | def string_support(py3enc):
'''Create byte-to-string and string-to-byte conversion functions for
internal use.
:param py3enc: Encoding used by Python 3 environment.
:type py3enc: str
'''
if sys.version < '3':
def bytes2str(b):
'''Identity, returns the argument string (bytes)... | python | def string_support(py3enc):
'''Create byte-to-string and string-to-byte conversion functions for
internal use.
:param py3enc: Encoding used by Python 3 environment.
:type py3enc: str
'''
if sys.version < '3':
def bytes2str(b):
'''Identity, returns the argument string (bytes)... | [
"def",
"string_support",
"(",
"py3enc",
")",
":",
"if",
"sys",
".",
"version",
"<",
"'3'",
":",
"def",
"bytes2str",
"(",
"b",
")",
":",
"'''Identity, returns the argument string (bytes).'''",
"return",
"b",
"def",
"str2bytes",
"(",
"s",
")",
":",
"'''Identity,... | Create byte-to-string and string-to-byte conversion functions for
internal use.
:param py3enc: Encoding used by Python 3 environment.
:type py3enc: str | [
"Create",
"byte",
"-",
"to",
"-",
"string",
"and",
"string",
"-",
"to",
"-",
"byte",
"conversion",
"functions",
"for",
"internal",
"use",
"."
] | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/support.py#L9-L30 | train |
buruzaemon/natto-py | natto/support.py | splitter_support | def splitter_support(py2enc):
'''Create tokenizer for use in boundary constraint parsing.
:param py2enc: Encoding used by Python 2 environment.
:type py2enc: str
'''
if sys.version < '3':
def _fn_sentence(pattern, sentence):
if REGEXTYPE == type(pattern):
if patt... | python | def splitter_support(py2enc):
'''Create tokenizer for use in boundary constraint parsing.
:param py2enc: Encoding used by Python 2 environment.
:type py2enc: str
'''
if sys.version < '3':
def _fn_sentence(pattern, sentence):
if REGEXTYPE == type(pattern):
if patt... | [
"def",
"splitter_support",
"(",
"py2enc",
")",
":",
"if",
"sys",
".",
"version",
"<",
"'3'",
":",
"def",
"_fn_sentence",
"(",
"pattern",
",",
"sentence",
")",
":",
"if",
"REGEXTYPE",
"==",
"type",
"(",
"pattern",
")",
":",
"if",
"pattern",
".",
"flags"... | Create tokenizer for use in boundary constraint parsing.
:param py2enc: Encoding used by Python 2 environment.
:type py2enc: str | [
"Create",
"tokenizer",
"for",
"use",
"in",
"boundary",
"constraint",
"parsing",
"."
] | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/support.py#L32-L96 | train |
yougov/elastic-doc-manager | mongo_connector/doc_managers/elastic_doc_manager.py | DocManager.update | def update(self, document_id, update_spec, namespace, timestamp):
"""Apply updates given in update_spec to the document whose id
matches that of doc.
"""
index, doc_type = self._index_and_mapping(namespace)
with self.lock:
# Check if document source is stored in loca... | python | def update(self, document_id, update_spec, namespace, timestamp):
"""Apply updates given in update_spec to the document whose id
matches that of doc.
"""
index, doc_type = self._index_and_mapping(namespace)
with self.lock:
# Check if document source is stored in loca... | [
"def",
"update",
"(",
"self",
",",
"document_id",
",",
"update_spec",
",",
"namespace",
",",
"timestamp",
")",
":",
"index",
",",
"doc_type",
"=",
"self",
".",
"_index_and_mapping",
"(",
"namespace",
")",
"with",
"self",
".",
"lock",
":",
"# Check if documen... | Apply updates given in update_spec to the document whose id
matches that of doc. | [
"Apply",
"updates",
"given",
"in",
"update_spec",
"to",
"the",
"document",
"whose",
"id",
"matches",
"that",
"of",
"doc",
"."
] | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L243-L268 | train |
yougov/elastic-doc-manager | mongo_connector/doc_managers/elastic_doc_manager.py | DocManager.upsert | def upsert(self, doc, namespace, timestamp, update_spec=None):
"""Insert a document into Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
# No need to duplicate '_id' in source document
doc_id = u(doc.pop("_id"))
metadata = {
'ns': namespace,
... | python | def upsert(self, doc, namespace, timestamp, update_spec=None):
"""Insert a document into Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
# No need to duplicate '_id' in source document
doc_id = u(doc.pop("_id"))
metadata = {
'ns': namespace,
... | [
"def",
"upsert",
"(",
"self",
",",
"doc",
",",
"namespace",
",",
"timestamp",
",",
"update_spec",
"=",
"None",
")",
":",
"index",
",",
"doc_type",
"=",
"self",
".",
"_index_and_mapping",
"(",
"namespace",
")",
"# No need to duplicate '_id' in source document",
"... | Insert a document into Elasticsearch. | [
"Insert",
"a",
"document",
"into",
"Elasticsearch",
"."
] | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L271-L301 | train |
yougov/elastic-doc-manager | mongo_connector/doc_managers/elastic_doc_manager.py | DocManager.bulk_upsert | def bulk_upsert(self, docs, namespace, timestamp):
"""Insert multiple documents into Elasticsearch."""
def docs_to_upsert():
doc = None
for doc in docs:
# Remove metadata and redundant _id
index, doc_type = self._index_and_mapping(namespace)
... | python | def bulk_upsert(self, docs, namespace, timestamp):
"""Insert multiple documents into Elasticsearch."""
def docs_to_upsert():
doc = None
for doc in docs:
# Remove metadata and redundant _id
index, doc_type = self._index_and_mapping(namespace)
... | [
"def",
"bulk_upsert",
"(",
"self",
",",
"docs",
",",
"namespace",
",",
"timestamp",
")",
":",
"def",
"docs_to_upsert",
"(",
")",
":",
"doc",
"=",
"None",
"for",
"doc",
"in",
"docs",
":",
"# Remove metadata and redundant _id",
"index",
",",
"doc_type",
"=",
... | Insert multiple documents into Elasticsearch. | [
"Insert",
"multiple",
"documents",
"into",
"Elasticsearch",
"."
] | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L304-L352 | train |
yougov/elastic-doc-manager | mongo_connector/doc_managers/elastic_doc_manager.py | DocManager.remove | def remove(self, document_id, namespace, timestamp):
"""Remove a document from Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
action = {
'_op_type': 'delete',
'_index': index,
'_type': doc_type,
'_id': u(document_id)
... | python | def remove(self, document_id, namespace, timestamp):
"""Remove a document from Elasticsearch."""
index, doc_type = self._index_and_mapping(namespace)
action = {
'_op_type': 'delete',
'_index': index,
'_type': doc_type,
'_id': u(document_id)
... | [
"def",
"remove",
"(",
"self",
",",
"document_id",
",",
"namespace",
",",
"timestamp",
")",
":",
"index",
",",
"doc_type",
"=",
"self",
".",
"_index_and_mapping",
"(",
"namespace",
")",
"action",
"=",
"{",
"'_op_type'",
":",
"'delete'",
",",
"'_index'",
":"... | Remove a document from Elasticsearch. | [
"Remove",
"a",
"document",
"from",
"Elasticsearch",
"."
] | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L398-L416 | train |
yougov/elastic-doc-manager | mongo_connector/doc_managers/elastic_doc_manager.py | DocManager.send_buffered_operations | def send_buffered_operations(self):
"""Send buffered operations to Elasticsearch.
This method is periodically called by the AutoCommitThread.
"""
with self.lock:
try:
action_buffer = self.BulkBuffer.get_buffer()
if action_buffer:
... | python | def send_buffered_operations(self):
"""Send buffered operations to Elasticsearch.
This method is periodically called by the AutoCommitThread.
"""
with self.lock:
try:
action_buffer = self.BulkBuffer.get_buffer()
if action_buffer:
... | [
"def",
"send_buffered_operations",
"(",
"self",
")",
":",
"with",
"self",
".",
"lock",
":",
"try",
":",
"action_buffer",
"=",
"self",
".",
"BulkBuffer",
".",
"get_buffer",
"(",
")",
"if",
"action_buffer",
":",
"successes",
",",
"errors",
"=",
"bulk",
"(",
... | Send buffered operations to Elasticsearch.
This method is periodically called by the AutoCommitThread. | [
"Send",
"buffered",
"operations",
"to",
"Elasticsearch",
"."
] | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L454-L470 | train |
yougov/elastic-doc-manager | mongo_connector/doc_managers/elastic_doc_manager.py | DocManager.get_last_doc | def get_last_doc(self):
"""Get the most recently modified document from Elasticsearch.
This method is used to help define a time window within which documents
may be in conflict after a MongoDB rollback.
"""
try:
result = self.elastic.search(
index=se... | python | def get_last_doc(self):
"""Get the most recently modified document from Elasticsearch.
This method is used to help define a time window within which documents
may be in conflict after a MongoDB rollback.
"""
try:
result = self.elastic.search(
index=se... | [
"def",
"get_last_doc",
"(",
"self",
")",
":",
"try",
":",
"result",
"=",
"self",
".",
"elastic",
".",
"search",
"(",
"index",
"=",
"self",
".",
"meta_index_name",
",",
"body",
"=",
"{",
"\"query\"",
":",
"{",
"\"match_all\"",
":",
"{",
"}",
"}",
",",... | Get the most recently modified document from Elasticsearch.
This method is used to help define a time window within which documents
may be in conflict after a MongoDB rollback. | [
"Get",
"the",
"most",
"recently",
"modified",
"document",
"from",
"Elasticsearch",
"."
] | 17c35f4dd3d081b171c45ba0eb9616da9dc89e82 | https://github.com/yougov/elastic-doc-manager/blob/17c35f4dd3d081b171c45ba0eb9616da9dc89e82/mongo_connector/doc_managers/elastic_doc_manager.py#L478-L498 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | split_sig | def split_sig(params):
"""
Split a list of parameters/types by commas,
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]']
"""
result = []
current = ''
level = 0
f... | python | def split_sig(params):
"""
Split a list of parameters/types by commas,
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]']
"""
result = []
current = ''
level = 0
f... | [
"def",
"split_sig",
"(",
"params",
")",
":",
"result",
"=",
"[",
"]",
"current",
"=",
"''",
"level",
"=",
"0",
"for",
"char",
"in",
"params",
":",
"if",
"char",
"in",
"(",
"'<'",
",",
"'{'",
",",
"'['",
")",
":",
"level",
"+=",
"1",
"elif",
"ch... | Split a list of parameters/types by commas,
whilst respecting brackets.
For example:
String arg0, int arg2 = 1, List<int> arg3 = [1, 2, 3]
=> ['String arg0', 'int arg2 = 1', 'List<int> arg3 = [1, 2, 3]'] | [
"Split",
"a",
"list",
"of",
"parameters",
"/",
"types",
"by",
"commas",
"whilst",
"respecting",
"brackets",
"."
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L39-L63 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | parse_method_signature | def parse_method_signature(sig):
""" Parse a method signature of the form: modifier* type name (params) """
match = METH_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Method signature invalid: ' + sig)
modifiers, return_type, name, generic_types, params = match.groups()
if para... | python | def parse_method_signature(sig):
""" Parse a method signature of the form: modifier* type name (params) """
match = METH_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Method signature invalid: ' + sig)
modifiers, return_type, name, generic_types, params = match.groups()
if para... | [
"def",
"parse_method_signature",
"(",
"sig",
")",
":",
"match",
"=",
"METH_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Method signature invalid: '",
"+",
"sig",
")",
"modifiers",
... | Parse a method signature of the form: modifier* type name (params) | [
"Parse",
"a",
"method",
"signature",
"of",
"the",
"form",
":",
"modifier",
"*",
"type",
"name",
"(",
"params",
")"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L66-L77 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | parse_property_signature | def parse_property_signature(sig):
""" Parse a property signature of the form:
modifier* type name { (get;)? (set;)? } """
match = PROP_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Property signature invalid: ' + sig)
groups = match.groups()
if groups[0] is not None:
... | python | def parse_property_signature(sig):
""" Parse a property signature of the form:
modifier* type name { (get;)? (set;)? } """
match = PROP_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Property signature invalid: ' + sig)
groups = match.groups()
if groups[0] is not None:
... | [
"def",
"parse_property_signature",
"(",
"sig",
")",
":",
"match",
"=",
"PROP_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Property signature invalid: '",
"+",
"sig",
")",
"groups",... | Parse a property signature of the form:
modifier* type name { (get;)? (set;)? } | [
"Parse",
"a",
"property",
"signature",
"of",
"the",
"form",
":",
"modifier",
"*",
"type",
"name",
"{",
"(",
"get",
";",
")",
"?",
"(",
"set",
";",
")",
"?",
"}"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L80-L94 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | parse_indexer_signature | def parse_indexer_signature(sig):
""" Parse a indexer signature of the form:
modifier* type this[params] { (get;)? (set;)? } """
match = IDXR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Indexer signature invalid: ' + sig)
modifiers, return_type, params, getter, setter = m... | python | def parse_indexer_signature(sig):
""" Parse a indexer signature of the form:
modifier* type this[params] { (get;)? (set;)? } """
match = IDXR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Indexer signature invalid: ' + sig)
modifiers, return_type, params, getter, setter = m... | [
"def",
"parse_indexer_signature",
"(",
"sig",
")",
":",
"match",
"=",
"IDXR_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Indexer signature invalid: '",
"+",
"sig",
")",
"modifiers"... | Parse a indexer signature of the form:
modifier* type this[params] { (get;)? (set;)? } | [
"Parse",
"a",
"indexer",
"signature",
"of",
"the",
"form",
":",
"modifier",
"*",
"type",
"this",
"[",
"params",
"]",
"{",
"(",
"get",
";",
")",
"?",
"(",
"set",
";",
")",
"?",
"}"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L97-L107 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | parse_param_signature | def parse_param_signature(sig):
""" Parse a parameter signature of the form: type name (= default)? """
match = PARAM_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Parameter signature invalid, got ' + sig)
groups = match.groups()
modifiers = groups[0].split()
typ, name, _, ... | python | def parse_param_signature(sig):
""" Parse a parameter signature of the form: type name (= default)? """
match = PARAM_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Parameter signature invalid, got ' + sig)
groups = match.groups()
modifiers = groups[0].split()
typ, name, _, ... | [
"def",
"parse_param_signature",
"(",
"sig",
")",
":",
"match",
"=",
"PARAM_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Parameter signature invalid, got '",
"+",
"sig",
")",
"group... | Parse a parameter signature of the form: type name (= default)? | [
"Parse",
"a",
"parameter",
"signature",
"of",
"the",
"form",
":",
"type",
"name",
"(",
"=",
"default",
")",
"?"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L110-L119 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | parse_type_signature | def parse_type_signature(sig):
""" Parse a type signature """
match = TYPE_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Type signature invalid, got ' + sig)
groups = match.groups()
typ = groups[0]
generic_types = groups[1]
if not generic_types:
generic_types = ... | python | def parse_type_signature(sig):
""" Parse a type signature """
match = TYPE_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Type signature invalid, got ' + sig)
groups = match.groups()
typ = groups[0]
generic_types = groups[1]
if not generic_types:
generic_types = ... | [
"def",
"parse_type_signature",
"(",
"sig",
")",
":",
"match",
"=",
"TYPE_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Type signature invalid, got '",
"+",
"sig",
")",
"groups",
"... | Parse a type signature | [
"Parse",
"a",
"type",
"signature"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L122-L135 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | parse_attr_signature | def parse_attr_signature(sig):
""" Parse an attribute signature """
match = ATTR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Attribute signature invalid, got ' + sig)
name, _, params = match.groups()
if params is not None and params.strip() != '':
params = split_sig(p... | python | def parse_attr_signature(sig):
""" Parse an attribute signature """
match = ATTR_SIG_RE.match(sig.strip())
if not match:
raise RuntimeError('Attribute signature invalid, got ' + sig)
name, _, params = match.groups()
if params is not None and params.strip() != '':
params = split_sig(p... | [
"def",
"parse_attr_signature",
"(",
"sig",
")",
":",
"match",
"=",
"ATTR_SIG_RE",
".",
"match",
"(",
"sig",
".",
"strip",
"(",
")",
")",
"if",
"not",
"match",
":",
"raise",
"RuntimeError",
"(",
"'Attribute signature invalid, got '",
"+",
"sig",
")",
"name",
... | Parse an attribute signature | [
"Parse",
"an",
"attribute",
"signature"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L138-L149 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | get_msdn_ref | def get_msdn_ref(name):
""" Try and create a reference to a type on MSDN """
in_msdn = False
if name in MSDN_VALUE_TYPES:
name = MSDN_VALUE_TYPES[name]
in_msdn = True
if name.startswith('System.'):
in_msdn = True
if in_msdn:
link = name.split('<')[0]
if link i... | python | def get_msdn_ref(name):
""" Try and create a reference to a type on MSDN """
in_msdn = False
if name in MSDN_VALUE_TYPES:
name = MSDN_VALUE_TYPES[name]
in_msdn = True
if name.startswith('System.'):
in_msdn = True
if in_msdn:
link = name.split('<')[0]
if link i... | [
"def",
"get_msdn_ref",
"(",
"name",
")",
":",
"in_msdn",
"=",
"False",
"if",
"name",
"in",
"MSDN_VALUE_TYPES",
":",
"name",
"=",
"MSDN_VALUE_TYPES",
"[",
"name",
"]",
"in_msdn",
"=",
"True",
"if",
"name",
".",
"startswith",
"(",
"'System.'",
")",
":",
"i... | Try and create a reference to a type on MSDN | [
"Try",
"and",
"create",
"a",
"reference",
"to",
"a",
"type",
"on",
"MSDN"
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L172-L192 | train |
djungelorm/sphinx-csharp | sphinx_csharp/csharp.py | shorten_type | def shorten_type(typ):
""" Shorten a type. E.g. drops 'System.' """
offset = 0
for prefix in SHORTEN_TYPE_PREFIXES:
if typ.startswith(prefix):
if len(prefix) > offset:
offset = len(prefix)
return typ[offset:] | python | def shorten_type(typ):
""" Shorten a type. E.g. drops 'System.' """
offset = 0
for prefix in SHORTEN_TYPE_PREFIXES:
if typ.startswith(prefix):
if len(prefix) > offset:
offset = len(prefix)
return typ[offset:] | [
"def",
"shorten_type",
"(",
"typ",
")",
":",
"offset",
"=",
"0",
"for",
"prefix",
"in",
"SHORTEN_TYPE_PREFIXES",
":",
"if",
"typ",
".",
"startswith",
"(",
"prefix",
")",
":",
"if",
"len",
"(",
"prefix",
")",
">",
"offset",
":",
"offset",
"=",
"len",
... | Shorten a type. E.g. drops 'System.' | [
"Shorten",
"a",
"type",
".",
"E",
".",
"g",
".",
"drops",
"System",
"."
] | aaa0c5fbe514d7f0b1a89625185fc608e5d30702 | https://github.com/djungelorm/sphinx-csharp/blob/aaa0c5fbe514d7f0b1a89625185fc608e5d30702/sphinx_csharp/csharp.py#L201-L208 | train |
buruzaemon/natto-py | natto/option_parse.py | OptionParse.parse_mecab_options | def parse_mecab_options(self, options):
'''Parses the MeCab options, returning them in a dictionary.
Lattice-level option has been deprecated; please use marginal or nbest
instead.
:options string or dictionary of options to use when instantiating
the MeCab insta... | python | def parse_mecab_options(self, options):
'''Parses the MeCab options, returning them in a dictionary.
Lattice-level option has been deprecated; please use marginal or nbest
instead.
:options string or dictionary of options to use when instantiating
the MeCab insta... | [
"def",
"parse_mecab_options",
"(",
"self",
",",
"options",
")",
":",
"class",
"MeCabArgumentParser",
"(",
"argparse",
".",
"ArgumentParser",
")",
":",
"'''MeCab option parser for natto-py.'''",
"def",
"error",
"(",
"self",
",",
"message",
")",
":",
"'''error(message... | Parses the MeCab options, returning them in a dictionary.
Lattice-level option has been deprecated; please use marginal or nbest
instead.
:options string or dictionary of options to use when instantiating
the MeCab instance. May be in short- or long-form, or in a
... | [
"Parses",
"the",
"MeCab",
"options",
"returning",
"them",
"in",
"a",
"dictionary",
".",
"Lattice",
"-",
"level",
"option",
"has",
"been",
"deprecated",
";",
"please",
"use",
"marginal",
"or",
"nbest",
"instead",
".",
":",
"options",
"string",
"or",
"dictiona... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/option_parse.py#L47-L173 | train |
buruzaemon/natto-py | natto/option_parse.py | OptionParse.build_options_str | def build_options_str(self, options):
'''Returns a string concatenation of the MeCab options.
Args:
options: dictionary of options to use when instantiating the MeCab
instance.
Returns:
A string concatenation of the options used when instantiatin... | python | def build_options_str(self, options):
'''Returns a string concatenation of the MeCab options.
Args:
options: dictionary of options to use when instantiating the MeCab
instance.
Returns:
A string concatenation of the options used when instantiatin... | [
"def",
"build_options_str",
"(",
"self",
",",
"options",
")",
":",
"opts",
"=",
"[",
"]",
"for",
"name",
"in",
"iter",
"(",
"list",
"(",
"self",
".",
"_SUPPORTED_OPTS",
".",
"values",
"(",
")",
")",
")",
":",
"if",
"name",
"in",
"options",
":",
"ke... | Returns a string concatenation of the MeCab options.
Args:
options: dictionary of options to use when instantiating the MeCab
instance.
Returns:
A string concatenation of the options used when instantiating the
MeCab instance, in long-form. | [
"Returns",
"a",
"string",
"concatenation",
"of",
"the",
"MeCab",
"options",
".",
"Args",
":",
"options",
":",
"dictionary",
"of",
"options",
"to",
"use",
"when",
"instantiating",
"the",
"MeCab",
"instance",
".",
"Returns",
":",
"A",
"string",
"concatenation",
... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/option_parse.py#L175-L196 | train |
svartalf/python-opus | opus/api/decoder.py | create | def create(fs, channels):
"""Allocates and initializes a decoder state"""
result_code = ctypes.c_int()
result = _create(fs, channels, ctypes.byref(result_code))
if result_code.value is not 0:
raise OpusError(result_code.value)
return result | python | def create(fs, channels):
"""Allocates and initializes a decoder state"""
result_code = ctypes.c_int()
result = _create(fs, channels, ctypes.byref(result_code))
if result_code.value is not 0:
raise OpusError(result_code.value)
return result | [
"def",
"create",
"(",
"fs",
",",
"channels",
")",
":",
"result_code",
"=",
"ctypes",
".",
"c_int",
"(",
")",
"result",
"=",
"_create",
"(",
"fs",
",",
"channels",
",",
"ctypes",
".",
"byref",
"(",
"result_code",
")",
")",
"if",
"result_code",
".",
"v... | Allocates and initializes a decoder state | [
"Allocates",
"and",
"initializes",
"a",
"decoder",
"state"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L32-L41 | train |
svartalf/python-opus | opus/api/decoder.py | packet_get_bandwidth | def packet_get_bandwidth(data):
"""Gets the bandwidth of an Opus packet."""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_bandwidth(data_pointer)
if result < 0:
raise OpusError(result)
return result | python | def packet_get_bandwidth(data):
"""Gets the bandwidth of an Opus packet."""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_bandwidth(data_pointer)
if result < 0:
raise OpusError(result)
return result | [
"def",
"packet_get_bandwidth",
"(",
"data",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"result",
"=",
"_packet_get_bandwidth",
"(",
"data_pointer",
")",
"if",
"result",
"<",
"0",
":",
"raise",
"OpusError",
"(",
"result",
")",... | Gets the bandwidth of an Opus packet. | [
"Gets",
"the",
"bandwidth",
"of",
"an",
"Opus",
"packet",
"."
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L49-L58 | train |
svartalf/python-opus | opus/api/decoder.py | packet_get_nb_channels | def packet_get_nb_channels(data):
"""Gets the number of channels from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_channels(data_pointer)
if result < 0:
raise OpusError(result)
return result | python | def packet_get_nb_channels(data):
"""Gets the number of channels from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_channels(data_pointer)
if result < 0:
raise OpusError(result)
return result | [
"def",
"packet_get_nb_channels",
"(",
"data",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"result",
"=",
"_packet_get_nb_channels",
"(",
"data_pointer",
")",
"if",
"result",
"<",
"0",
":",
"raise",
"OpusError",
"(",
"result",
... | Gets the number of channels from an Opus packet | [
"Gets",
"the",
"number",
"of",
"channels",
"from",
"an",
"Opus",
"packet"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L66-L75 | train |
svartalf/python-opus | opus/api/decoder.py | packet_get_nb_frames | def packet_get_nb_frames(data, length=None):
"""Gets the number of frames in an Opus packet"""
data_pointer = ctypes.c_char_p(data)
if length is None:
length = len(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(length))
if result < 0:
raise OpusError(result)
r... | python | def packet_get_nb_frames(data, length=None):
"""Gets the number of frames in an Opus packet"""
data_pointer = ctypes.c_char_p(data)
if length is None:
length = len(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(length))
if result < 0:
raise OpusError(result)
r... | [
"def",
"packet_get_nb_frames",
"(",
"data",
",",
"length",
"=",
"None",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"if",
"length",
"is",
"None",
":",
"length",
"=",
"len",
"(",
"data",
")",
"result",
"=",
"_packet_get_nb_... | Gets the number of frames in an Opus packet | [
"Gets",
"the",
"number",
"of",
"frames",
"in",
"an",
"Opus",
"packet"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L83-L94 | train |
svartalf/python-opus | opus/api/decoder.py | packet_get_samples_per_frame | def packet_get_samples_per_frame(data, fs):
"""Gets the number of samples per frame from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(fs))
if result < 0:
raise OpusError(result)
return result | python | def packet_get_samples_per_frame(data, fs):
"""Gets the number of samples per frame from an Opus packet"""
data_pointer = ctypes.c_char_p(data)
result = _packet_get_nb_frames(data_pointer, ctypes.c_int(fs))
if result < 0:
raise OpusError(result)
return result | [
"def",
"packet_get_samples_per_frame",
"(",
"data",
",",
"fs",
")",
":",
"data_pointer",
"=",
"ctypes",
".",
"c_char_p",
"(",
"data",
")",
"result",
"=",
"_packet_get_nb_frames",
"(",
"data_pointer",
",",
"ctypes",
".",
"c_int",
"(",
"fs",
")",
")",
"if",
... | Gets the number of samples per frame from an Opus packet | [
"Gets",
"the",
"number",
"of",
"samples",
"per",
"frame",
"from",
"an",
"Opus",
"packet"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L102-L111 | train |
svartalf/python-opus | opus/api/decoder.py | decode | def decode(decoder, data, length, frame_size, decode_fec, channels=2):
"""Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame
"""
pcm_size = frame_size * channels * ctypes.sizeof(ctypes... | python | def decode(decoder, data, length, frame_size, decode_fec, channels=2):
"""Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame
"""
pcm_size = frame_size * channels * ctypes.sizeof(ctypes... | [
"def",
"decode",
"(",
"decoder",
",",
"data",
",",
"length",
",",
"frame_size",
",",
"decode_fec",
",",
"channels",
"=",
"2",
")",
":",
"pcm_size",
"=",
"frame_size",
"*",
"channels",
"*",
"ctypes",
".",
"sizeof",
"(",
"ctypes",
".",
"c_int16",
")",
"p... | Decode an Opus frame
Unlike the `opus_decode` function , this function takes an additional parameter `channels`,
which indicates the number of channels in the frame | [
"Decode",
"an",
"Opus",
"frame"
] | a3c1d556d2772b5be659ddd08c033ddd4d566b3a | https://github.com/svartalf/python-opus/blob/a3c1d556d2772b5be659ddd08c033ddd4d566b3a/opus/api/decoder.py#L132-L150 | train |
ome/omego | omego/artifacts.py | JenkinsArtifacts.label_list_parser | def label_list_parser(self, url):
"""
Extracts comma separate tag=value pairs from a string
Assumes all characters other than / and , are valid
"""
labels = re.findall('([^/,]+=[^/,]+)', url)
slabels = set(labels)
if '' in slabels:
slabels.remove('')
... | python | def label_list_parser(self, url):
"""
Extracts comma separate tag=value pairs from a string
Assumes all characters other than / and , are valid
"""
labels = re.findall('([^/,]+=[^/,]+)', url)
slabels = set(labels)
if '' in slabels:
slabels.remove('')
... | [
"def",
"label_list_parser",
"(",
"self",
",",
"url",
")",
":",
"labels",
"=",
"re",
".",
"findall",
"(",
"'([^/,]+=[^/,]+)'",
",",
"url",
")",
"slabels",
"=",
"set",
"(",
"labels",
")",
"if",
"''",
"in",
"slabels",
":",
"slabels",
".",
"remove",
"(",
... | Extracts comma separate tag=value pairs from a string
Assumes all characters other than / and , are valid | [
"Extracts",
"comma",
"separate",
"tag",
"=",
"value",
"pairs",
"from",
"a",
"string",
"Assumes",
"all",
"characters",
"other",
"than",
"/",
"and",
"are",
"valid"
] | 2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb | https://github.com/ome/omego/blob/2dadbf3c6342b6c995f9e0dceaf3c0b7fab030fb/omego/artifacts.py#L327-L336 | train |
stevelittlefish/flaskfilemanager | flaskfilemanager/filemanager.py | init | def init(app, register_blueprint=True, url_prefix='/fm', access_control_function=None,
custom_config_json_path=None, custom_init_js_path=None):
"""
:param app: The Flask app
:param register_blueprint: Override to False to stop the blueprint from automatically being registered to the
... | python | def init(app, register_blueprint=True, url_prefix='/fm', access_control_function=None,
custom_config_json_path=None, custom_init_js_path=None):
"""
:param app: The Flask app
:param register_blueprint: Override to False to stop the blueprint from automatically being registered to the
... | [
"def",
"init",
"(",
"app",
",",
"register_blueprint",
"=",
"True",
",",
"url_prefix",
"=",
"'/fm'",
",",
"access_control_function",
"=",
"None",
",",
"custom_config_json_path",
"=",
"None",
",",
"custom_init_js_path",
"=",
"None",
")",
":",
"global",
"_initialis... | :param app: The Flask app
:param register_blueprint: Override to False to stop the blueprint from automatically being registered to the
app
:param url_prefix: The URL prefix for the blueprint, defaults to /fm
:param access_control_function: Pass in a function here to implement... | [
":",
"param",
"app",
":",
"The",
"Flask",
"app",
":",
"param",
"register_blueprint",
":",
"Override",
"to",
"False",
"to",
"stop",
"the",
"blueprint",
"from",
"automatically",
"being",
"registered",
"to",
"the",
"app",
":",
"param",
"url_prefix",
":",
"The",... | e37faf5cb4c1370e069bf009ce65c88ad8ee0e94 | https://github.com/stevelittlefish/flaskfilemanager/blob/e37faf5cb4c1370e069bf009ce65c88ad8ee0e94/flaskfilemanager/filemanager.py#L48-L93 | train |
stevelittlefish/flaskfilemanager | flaskfilemanager/filemanager.py | get_file | def get_file(path=None, content=None):
"""
:param path: relative path, or None to get from request
:param content: file content, output in data. Used for editfile
"""
if path is None:
path = request.args.get('path')
if path is None:
return error('No path in request')
fi... | python | def get_file(path=None, content=None):
"""
:param path: relative path, or None to get from request
:param content: file content, output in data. Used for editfile
"""
if path is None:
path = request.args.get('path')
if path is None:
return error('No path in request')
fi... | [
"def",
"get_file",
"(",
"path",
"=",
"None",
",",
"content",
"=",
"None",
")",
":",
"if",
"path",
"is",
"None",
":",
"path",
"=",
"request",
".",
"args",
".",
"get",
"(",
"'path'",
")",
"if",
"path",
"is",
"None",
":",
"return",
"error",
"(",
"'N... | :param path: relative path, or None to get from request
:param content: file content, output in data. Used for editfile | [
":",
"param",
"path",
":",
"relative",
"path",
"or",
"None",
"to",
"get",
"from",
"request",
":",
"param",
"content",
":",
"file",
"content",
"output",
"in",
"data",
".",
"Used",
"for",
"editfile"
] | e37faf5cb4c1370e069bf009ce65c88ad8ee0e94 | https://github.com/stevelittlefish/flaskfilemanager/blob/e37faf5cb4c1370e069bf009ce65c88ad8ee0e94/flaskfilemanager/filemanager.py#L274-L329 | train |
buruzaemon/natto-py | natto/environment.py | MeCabEnv.__get_charset | def __get_charset(self):
'''Return the character encoding (charset) used internally by MeCab.
Charset is that of the system dictionary used by MeCab. Will defer to
the user-specified MECAB_CHARSET environment variable, if set.
Defaults to shift-jis on Windows.
Defaults t... | python | def __get_charset(self):
'''Return the character encoding (charset) used internally by MeCab.
Charset is that of the system dictionary used by MeCab. Will defer to
the user-specified MECAB_CHARSET environment variable, if set.
Defaults to shift-jis on Windows.
Defaults t... | [
"def",
"__get_charset",
"(",
"self",
")",
":",
"cset",
"=",
"os",
".",
"getenv",
"(",
"self",
".",
"MECAB_CHARSET",
")",
"if",
"cset",
":",
"logger",
".",
"debug",
"(",
"self",
".",
"_DEBUG_CSET_DEFAULT",
".",
"format",
"(",
"cset",
")",
")",
"return",... | Return the character encoding (charset) used internally by MeCab.
Charset is that of the system dictionary used by MeCab. Will defer to
the user-specified MECAB_CHARSET environment variable, if set.
Defaults to shift-jis on Windows.
Defaults to utf-8 on Mac OS.
Defaults ... | [
"Return",
"the",
"character",
"encoding",
"(",
"charset",
")",
"used",
"internally",
"by",
"MeCab",
".",
"Charset",
"is",
"that",
"of",
"the",
"system",
"dictionary",
"used",
"by",
"MeCab",
".",
"Will",
"defer",
"to",
"the",
"user",
"-",
"specified",
"MECA... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/environment.py#L55-L96 | train |
buruzaemon/natto-py | natto/environment.py | MeCabEnv.__get_libpath | def __get_libpath(self):
'''Return the absolute path to the MeCab library.
On Windows, the path to the system dictionary is used to deduce the
path to libmecab.dll.
Otherwise, mecab-config is used find the libmecab shared object or
dynamic library (*NIX or Mac OS, respec... | python | def __get_libpath(self):
'''Return the absolute path to the MeCab library.
On Windows, the path to the system dictionary is used to deduce the
path to libmecab.dll.
Otherwise, mecab-config is used find the libmecab shared object or
dynamic library (*NIX or Mac OS, respec... | [
"def",
"__get_libpath",
"(",
"self",
")",
":",
"libp",
"=",
"os",
".",
"getenv",
"(",
"self",
".",
"MECAB_PATH",
")",
"if",
"libp",
":",
"return",
"os",
".",
"path",
".",
"abspath",
"(",
"libp",
")",
"else",
":",
"plat",
"=",
"sys",
".",
"platform"... | Return the absolute path to the MeCab library.
On Windows, the path to the system dictionary is used to deduce the
path to libmecab.dll.
Otherwise, mecab-config is used find the libmecab shared object or
dynamic library (*NIX or Mac OS, respectively).
Will defer to the... | [
"Return",
"the",
"absolute",
"path",
"to",
"the",
"MeCab",
"library",
".",
"On",
"Windows",
"the",
"path",
"to",
"the",
"system",
"dictionary",
"is",
"used",
"to",
"deduce",
"the",
"path",
"to",
"libmecab",
".",
"dll",
".",
"Otherwise",
"mecab",
"-",
"co... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/environment.py#L98-L162 | train |
buruzaemon/natto-py | natto/environment.py | MeCabEnv.__regkey_value | def __regkey_value(self, path, name='', start_key=None):
r'''Return the data of value mecabrc at MeCab HKEY node.
On Windows, the path to the mecabrc as set in the Windows Registry is
used to deduce the path to libmecab.dll.
Returns:
The full path to the mecabrc on W... | python | def __regkey_value(self, path, name='', start_key=None):
r'''Return the data of value mecabrc at MeCab HKEY node.
On Windows, the path to the mecabrc as set in the Windows Registry is
used to deduce the path to libmecab.dll.
Returns:
The full path to the mecabrc on W... | [
"def",
"__regkey_value",
"(",
"self",
",",
"path",
",",
"name",
"=",
"''",
",",
"start_key",
"=",
"None",
")",
":",
"if",
"sys",
".",
"version",
"<",
"'3'",
":",
"import",
"_winreg",
"as",
"reg",
"else",
":",
"import",
"winreg",
"as",
"reg",
"def",
... | r'''Return the data of value mecabrc at MeCab HKEY node.
On Windows, the path to the mecabrc as set in the Windows Registry is
used to deduce the path to libmecab.dll.
Returns:
The full path to the mecabrc on Windows.
Raises:
WindowsError: A problem wa... | [
"r",
"Return",
"the",
"data",
"of",
"value",
"mecabrc",
"at",
"MeCab",
"HKEY",
"node",
".",
"On",
"Windows",
"the",
"path",
"to",
"the",
"mecabrc",
"as",
"set",
"in",
"the",
"Windows",
"Registry",
"is",
"used",
"to",
"deduce",
"the",
"path",
"to",
"lib... | 018fe004c47c45c66bdf2e03fe24e981ae089b76 | https://github.com/buruzaemon/natto-py/blob/018fe004c47c45c66bdf2e03fe24e981ae089b76/natto/environment.py#L164-L199 | train |
christian-oudard/htmltreediff | htmltreediff/html.py | diff | def diff(old_html, new_html, cutoff=0.0, plaintext=False, pretty=False):
"""Show the differences between the old and new html document, as html.
Return the document html with extra tags added to show changes. Add <ins>
tags around newly added sections, and <del> tags to show sections that have
been del... | python | def diff(old_html, new_html, cutoff=0.0, plaintext=False, pretty=False):
"""Show the differences between the old and new html document, as html.
Return the document html with extra tags added to show changes. Add <ins>
tags around newly added sections, and <del> tags to show sections that have
been del... | [
"def",
"diff",
"(",
"old_html",
",",
"new_html",
",",
"cutoff",
"=",
"0.0",
",",
"plaintext",
"=",
"False",
",",
"pretty",
"=",
"False",
")",
":",
"if",
"plaintext",
":",
"old_dom",
"=",
"parse_text",
"(",
"old_html",
")",
"new_dom",
"=",
"parse_text",
... | Show the differences between the old and new html document, as html.
Return the document html with extra tags added to show changes. Add <ins>
tags around newly added sections, and <del> tags to show sections that have
been deleted. | [
"Show",
"the",
"differences",
"between",
"the",
"old",
"and",
"new",
"html",
"document",
"as",
"html",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/html.py#L12-L42 | train |
christian-oudard/htmltreediff | htmltreediff/diff_core.py | adjusted_ops | def adjusted_ops(opcodes):
"""
Iterate through opcodes, turning them into a series of insert and delete
operations, adjusting indices to account for the size of insertions and
deletions.
>>> def sequence_opcodes(old, new): return difflib.SequenceMatcher(a=old, b=new).get_opcodes()
>>> list(adju... | python | def adjusted_ops(opcodes):
"""
Iterate through opcodes, turning them into a series of insert and delete
operations, adjusting indices to account for the size of insertions and
deletions.
>>> def sequence_opcodes(old, new): return difflib.SequenceMatcher(a=old, b=new).get_opcodes()
>>> list(adju... | [
"def",
"adjusted_ops",
"(",
"opcodes",
")",
":",
"while",
"opcodes",
":",
"op",
"=",
"opcodes",
".",
"pop",
"(",
"0",
")",
"tag",
",",
"i1",
",",
"i2",
",",
"j1",
",",
"j2",
"=",
"op",
"shift",
"=",
"0",
"if",
"tag",
"==",
"'equal'",
":",
"cont... | Iterate through opcodes, turning them into a series of insert and delete
operations, adjusting indices to account for the size of insertions and
deletions.
>>> def sequence_opcodes(old, new): return difflib.SequenceMatcher(a=old, b=new).get_opcodes()
>>> list(adjusted_ops(sequence_opcodes('abc', 'b')))... | [
"Iterate",
"through",
"opcodes",
"turning",
"them",
"into",
"a",
"series",
"of",
"insert",
"and",
"delete",
"operations",
"adjusting",
"indices",
"to",
"account",
"for",
"the",
"size",
"of",
"insertions",
"and",
"deletions",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L161-L209 | train |
christian-oudard/htmltreediff | htmltreediff/diff_core.py | match_indices | def match_indices(match):
"""Yield index tuples (old_index, new_index) for each place in the match."""
a, b, size = match
for i in range(size):
yield a + i, b + i | python | def match_indices(match):
"""Yield index tuples (old_index, new_index) for each place in the match."""
a, b, size = match
for i in range(size):
yield a + i, b + i | [
"def",
"match_indices",
"(",
"match",
")",
":",
"a",
",",
"b",
",",
"size",
"=",
"match",
"for",
"i",
"in",
"range",
"(",
"size",
")",
":",
"yield",
"a",
"+",
"i",
",",
"b",
"+",
"i"
] | Yield index tuples (old_index, new_index) for each place in the match. | [
"Yield",
"index",
"tuples",
"(",
"old_index",
"new_index",
")",
"for",
"each",
"place",
"in",
"the",
"match",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L224-L228 | train |
christian-oudard/htmltreediff | htmltreediff/diff_core.py | get_opcodes | def get_opcodes(matching_blocks):
"""Use difflib to get the opcodes for a set of matching blocks."""
sm = difflib.SequenceMatcher(a=[], b=[])
sm.matching_blocks = matching_blocks
return sm.get_opcodes() | python | def get_opcodes(matching_blocks):
"""Use difflib to get the opcodes for a set of matching blocks."""
sm = difflib.SequenceMatcher(a=[], b=[])
sm.matching_blocks = matching_blocks
return sm.get_opcodes() | [
"def",
"get_opcodes",
"(",
"matching_blocks",
")",
":",
"sm",
"=",
"difflib",
".",
"SequenceMatcher",
"(",
"a",
"=",
"[",
"]",
",",
"b",
"=",
"[",
"]",
")",
"sm",
".",
"matching_blocks",
"=",
"matching_blocks",
"return",
"sm",
".",
"get_opcodes",
"(",
... | Use difflib to get the opcodes for a set of matching blocks. | [
"Use",
"difflib",
"to",
"get",
"the",
"opcodes",
"for",
"a",
"set",
"of",
"matching",
"blocks",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L230-L234 | train |
christian-oudard/htmltreediff | htmltreediff/diff_core.py | match_blocks | def match_blocks(hash_func, old_children, new_children):
"""Use difflib to find matching blocks."""
sm = difflib.SequenceMatcher(
_is_junk,
a=[hash_func(c) for c in old_children],
b=[hash_func(c) for c in new_children],
)
return sm | python | def match_blocks(hash_func, old_children, new_children):
"""Use difflib to find matching blocks."""
sm = difflib.SequenceMatcher(
_is_junk,
a=[hash_func(c) for c in old_children],
b=[hash_func(c) for c in new_children],
)
return sm | [
"def",
"match_blocks",
"(",
"hash_func",
",",
"old_children",
",",
"new_children",
")",
":",
"sm",
"=",
"difflib",
".",
"SequenceMatcher",
"(",
"_is_junk",
",",
"a",
"=",
"[",
"hash_func",
"(",
"c",
")",
"for",
"c",
"in",
"old_children",
"]",
",",
"b",
... | Use difflib to find matching blocks. | [
"Use",
"difflib",
"to",
"find",
"matching",
"blocks",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L246-L253 | train |
christian-oudard/htmltreediff | htmltreediff/diff_core.py | get_nonmatching_blocks | def get_nonmatching_blocks(matching_blocks):
"""Given a list of matching blocks, output the gaps between them.
Non-matches have the format (alo, ahi, blo, bhi). This specifies two index
ranges, one in the A sequence, and one in the B sequence.
"""
i = j = 0
for match in matching_blocks:
... | python | def get_nonmatching_blocks(matching_blocks):
"""Given a list of matching blocks, output the gaps between them.
Non-matches have the format (alo, ahi, blo, bhi). This specifies two index
ranges, one in the A sequence, and one in the B sequence.
"""
i = j = 0
for match in matching_blocks:
... | [
"def",
"get_nonmatching_blocks",
"(",
"matching_blocks",
")",
":",
"i",
"=",
"j",
"=",
"0",
"for",
"match",
"in",
"matching_blocks",
":",
"a",
",",
"b",
",",
"size",
"=",
"match",
"yield",
"(",
"i",
",",
"a",
",",
"j",
",",
"b",
")",
"i",
"=",
"a... | Given a list of matching blocks, output the gaps between them.
Non-matches have the format (alo, ahi, blo, bhi). This specifies two index
ranges, one in the A sequence, and one in the B sequence. | [
"Given",
"a",
"list",
"of",
"matching",
"blocks",
"output",
"the",
"gaps",
"between",
"them",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L255-L266 | train |
christian-oudard/htmltreediff | htmltreediff/diff_core.py | merge_blocks | def merge_blocks(a_blocks, b_blocks):
"""Given two lists of blocks, combine them, in the proper order.
Ensure that there are no overlaps, and that they are for sequences of the
same length.
"""
# Check sentinels for sequence length.
assert a_blocks[-1][2] == b_blocks[-1][2] == 0 # sentinel size... | python | def merge_blocks(a_blocks, b_blocks):
"""Given two lists of blocks, combine them, in the proper order.
Ensure that there are no overlaps, and that they are for sequences of the
same length.
"""
# Check sentinels for sequence length.
assert a_blocks[-1][2] == b_blocks[-1][2] == 0 # sentinel size... | [
"def",
"merge_blocks",
"(",
"a_blocks",
",",
"b_blocks",
")",
":",
"# Check sentinels for sequence length.",
"assert",
"a_blocks",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"==",
"b_blocks",
"[",
"-",
"1",
"]",
"[",
"2",
"]",
"==",
"0",
"# sentinel size is 0",
"a... | Given two lists of blocks, combine them, in the proper order.
Ensure that there are no overlaps, and that they are for sequences of the
same length. | [
"Given",
"two",
"lists",
"of",
"blocks",
"combine",
"them",
"in",
"the",
"proper",
"order",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/diff_core.py#L268-L285 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | remove_comments | def remove_comments(xml):
"""
Remove comments, as they can break the xml parser.
See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ).
>>> remove_comments('<!-- -->')
''
>>> remove_comments('<!--\\n-->')
''
>>> remove_comments('<p>stuff<!-- \\n -->stuff</p... | python | def remove_comments(xml):
"""
Remove comments, as they can break the xml parser.
See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ).
>>> remove_comments('<!-- -->')
''
>>> remove_comments('<!--\\n-->')
''
>>> remove_comments('<p>stuff<!-- \\n -->stuff</p... | [
"def",
"remove_comments",
"(",
"xml",
")",
":",
"regex",
"=",
"re",
".",
"compile",
"(",
"r'<!--.*?-->'",
",",
"re",
".",
"DOTALL",
")",
"return",
"regex",
".",
"sub",
"(",
"''",
",",
"xml",
")"
] | Remove comments, as they can break the xml parser.
See html5lib issue #122 ( http://code.google.com/p/html5lib/issues/detail?id=122 ).
>>> remove_comments('<!-- -->')
''
>>> remove_comments('<!--\\n-->')
''
>>> remove_comments('<p>stuff<!-- \\n -->stuff</p>')
'<p>stuffstuff</p>' | [
"Remove",
"comments",
"as",
"they",
"can",
"break",
"the",
"xml",
"parser",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L74-L88 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | remove_newlines | def remove_newlines(xml):
r"""Remove newlines in the xml.
If the newline separates words in text, then replace with a space instead.
>>> remove_newlines('<p>para one</p>\n<p>para two</p>')
'<p>para one</p><p>para two</p>'
>>> remove_newlines('<p>line one\nline two</p>')
'<p>line one line two</... | python | def remove_newlines(xml):
r"""Remove newlines in the xml.
If the newline separates words in text, then replace with a space instead.
>>> remove_newlines('<p>para one</p>\n<p>para two</p>')
'<p>para one</p><p>para two</p>'
>>> remove_newlines('<p>line one\nline two</p>')
'<p>line one line two</... | [
"def",
"remove_newlines",
"(",
"xml",
")",
":",
"# Normalize newlines.",
"xml",
"=",
"xml",
".",
"replace",
"(",
"'\\r\\n'",
",",
"'\\n'",
")",
"xml",
"=",
"xml",
".",
"replace",
"(",
"'\\r'",
",",
"'\\n'",
")",
"# Remove newlines that don't separate text. The r... | r"""Remove newlines in the xml.
If the newline separates words in text, then replace with a space instead.
>>> remove_newlines('<p>para one</p>\n<p>para two</p>')
'<p>para one</p><p>para two</p>'
>>> remove_newlines('<p>line one\nline two</p>')
'<p>line one line two</p>'
>>> remove_newlines('o... | [
"r",
"Remove",
"newlines",
"in",
"the",
"xml",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L90-L110 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | remove_insignificant_text_nodes | def remove_insignificant_text_nodes(dom):
"""
For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space.
"""
nodes_to_remove = []
for node in walk_dom(dom):
if is_text(node):
... | python | def remove_insignificant_text_nodes(dom):
"""
For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space.
"""
nodes_to_remove = []
for node in walk_dom(dom):
if is_text(node):
... | [
"def",
"remove_insignificant_text_nodes",
"(",
"dom",
")",
":",
"nodes_to_remove",
"=",
"[",
"]",
"for",
"node",
"in",
"walk_dom",
"(",
"dom",
")",
":",
"if",
"is_text",
"(",
"node",
")",
":",
"text",
"=",
"node",
".",
"nodeValue",
"if",
"node",
".",
"... | For html elements that should not have text nodes inside them, remove all
whitespace. For elements that may have text, collapse multiple spaces to a
single space. | [
"For",
"html",
"elements",
"that",
"should",
"not",
"have",
"text",
"nodes",
"inside",
"them",
"remove",
"all",
"whitespace",
".",
"For",
"elements",
"that",
"may",
"have",
"text",
"collapse",
"multiple",
"spaces",
"to",
"a",
"single",
"space",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L229-L244 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | get_child | def get_child(parent, child_index):
"""
Get the child at the given index, or return None if it doesn't exist.
"""
if child_index < 0 or child_index >= len(parent.childNodes):
return None
return parent.childNodes[child_index] | python | def get_child(parent, child_index):
"""
Get the child at the given index, or return None if it doesn't exist.
"""
if child_index < 0 or child_index >= len(parent.childNodes):
return None
return parent.childNodes[child_index] | [
"def",
"get_child",
"(",
"parent",
",",
"child_index",
")",
":",
"if",
"child_index",
"<",
"0",
"or",
"child_index",
">=",
"len",
"(",
"parent",
".",
"childNodes",
")",
":",
"return",
"None",
"return",
"parent",
".",
"childNodes",
"[",
"child_index",
"]"
] | Get the child at the given index, or return None if it doesn't exist. | [
"Get",
"the",
"child",
"at",
"the",
"given",
"index",
"or",
"return",
"None",
"if",
"it",
"doesn",
"t",
"exist",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L253-L259 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | get_location | def get_location(dom, location):
"""
Get the node at the specified location in the dom.
Location is a sequence of child indices, starting at the children of the
root element. If there is no node at this location, raise a ValueError.
"""
node = dom.documentElement
for i in location:
n... | python | def get_location(dom, location):
"""
Get the node at the specified location in the dom.
Location is a sequence of child indices, starting at the children of the
root element. If there is no node at this location, raise a ValueError.
"""
node = dom.documentElement
for i in location:
n... | [
"def",
"get_location",
"(",
"dom",
",",
"location",
")",
":",
"node",
"=",
"dom",
".",
"documentElement",
"for",
"i",
"in",
"location",
":",
"node",
"=",
"get_child",
"(",
"node",
",",
"i",
")",
"if",
"not",
"node",
":",
"raise",
"ValueError",
"(",
"... | Get the node at the specified location in the dom.
Location is a sequence of child indices, starting at the children of the
root element. If there is no node at this location, raise a ValueError. | [
"Get",
"the",
"node",
"at",
"the",
"specified",
"location",
"in",
"the",
"dom",
".",
"Location",
"is",
"a",
"sequence",
"of",
"child",
"indices",
"starting",
"at",
"the",
"children",
"of",
"the",
"root",
"element",
".",
"If",
"there",
"is",
"no",
"node",... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L261-L272 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | check_text_similarity | def check_text_similarity(a_dom, b_dom, cutoff):
"""Check whether two dom trees have similar text or not."""
a_words = list(tree_words(a_dom))
b_words = list(tree_words(b_dom))
sm = WordMatcher(a=a_words, b=b_words)
if sm.text_ratio() >= cutoff:
return True
return False | python | def check_text_similarity(a_dom, b_dom, cutoff):
"""Check whether two dom trees have similar text or not."""
a_words = list(tree_words(a_dom))
b_words = list(tree_words(b_dom))
sm = WordMatcher(a=a_words, b=b_words)
if sm.text_ratio() >= cutoff:
return True
return False | [
"def",
"check_text_similarity",
"(",
"a_dom",
",",
"b_dom",
",",
"cutoff",
")",
":",
"a_words",
"=",
"list",
"(",
"tree_words",
"(",
"a_dom",
")",
")",
"b_words",
"=",
"list",
"(",
"tree_words",
"(",
"b_dom",
")",
")",
"sm",
"=",
"WordMatcher",
"(",
"a... | Check whether two dom trees have similar text or not. | [
"Check",
"whether",
"two",
"dom",
"trees",
"have",
"similar",
"text",
"or",
"not",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L295-L303 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | tree_words | def tree_words(node):
"""Return all the significant text below the given node as a list of words.
>>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>')))
['one', 'two', 'three', 'four']
"""
for word in split_text(tree_text(node)):
word = word.strip()
if ... | python | def tree_words(node):
"""Return all the significant text below the given node as a list of words.
>>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>')))
['one', 'two', 'three', 'four']
"""
for word in split_text(tree_text(node)):
word = word.strip()
if ... | [
"def",
"tree_words",
"(",
"node",
")",
":",
"for",
"word",
"in",
"split_text",
"(",
"tree_text",
"(",
"node",
")",
")",
":",
"word",
"=",
"word",
".",
"strip",
"(",
")",
"if",
"word",
":",
"yield",
"word"
] | Return all the significant text below the given node as a list of words.
>>> list(tree_words(parse_minidom('<h1>one</h1> two <div>three<em>four</em></div>')))
['one', 'two', 'three', 'four'] | [
"Return",
"all",
"the",
"significant",
"text",
"below",
"the",
"given",
"node",
"as",
"a",
"list",
"of",
"words",
".",
">>>",
"list",
"(",
"tree_words",
"(",
"parse_minidom",
"(",
"<h1",
">",
"one<",
"/",
"h1",
">",
"two",
"<div",
">",
"three<em",
">",... | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L305-L313 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | tree_text | def tree_text(node):
"""
>>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>'))
'one two three four'
"""
text = []
for descendant in walk_dom(node):
if is_text(descendant):
text.append(descendant.nodeValue)
return ' '.join(text) | python | def tree_text(node):
"""
>>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>'))
'one two three four'
"""
text = []
for descendant in walk_dom(node):
if is_text(descendant):
text.append(descendant.nodeValue)
return ' '.join(text) | [
"def",
"tree_text",
"(",
"node",
")",
":",
"text",
"=",
"[",
"]",
"for",
"descendant",
"in",
"walk_dom",
"(",
"node",
")",
":",
"if",
"is_text",
"(",
"descendant",
")",
":",
"text",
".",
"append",
"(",
"descendant",
".",
"nodeValue",
")",
"return",
"... | >>> tree_text(parse_minidom('<h1>one</h1>two<div>three<em>four</em></div>'))
'one two three four' | [
">>>",
"tree_text",
"(",
"parse_minidom",
"(",
"<h1",
">",
"one<",
"/",
"h1",
">",
"two<div",
">",
"three<em",
">",
"four<",
"/",
"em",
">",
"<",
"/",
"div",
">",
"))",
"one",
"two",
"three",
"four"
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L315-L324 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | insert_or_append | def insert_or_append(parent, node, next_sibling):
"""
Insert the node before next_sibling. If next_sibling is None, append the node last instead.
"""
# simple insert
if next_sibling:
parent.insertBefore(node, next_sibling)
else:
parent.appendChild(node) | python | def insert_or_append(parent, node, next_sibling):
"""
Insert the node before next_sibling. If next_sibling is None, append the node last instead.
"""
# simple insert
if next_sibling:
parent.insertBefore(node, next_sibling)
else:
parent.appendChild(node) | [
"def",
"insert_or_append",
"(",
"parent",
",",
"node",
",",
"next_sibling",
")",
":",
"# simple insert",
"if",
"next_sibling",
":",
"parent",
".",
"insertBefore",
"(",
"node",
",",
"next_sibling",
")",
"else",
":",
"parent",
".",
"appendChild",
"(",
"node",
... | Insert the node before next_sibling. If next_sibling is None, append the node last instead. | [
"Insert",
"the",
"node",
"before",
"next_sibling",
".",
"If",
"next_sibling",
"is",
"None",
"append",
"the",
"node",
"last",
"instead",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L339-L347 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | wrap | def wrap(node, tag):
"""Wrap the given tag around a node."""
wrap_node = node.ownerDocument.createElement(tag)
parent = node.parentNode
if parent:
parent.replaceChild(wrap_node, node)
wrap_node.appendChild(node)
return wrap_node | python | def wrap(node, tag):
"""Wrap the given tag around a node."""
wrap_node = node.ownerDocument.createElement(tag)
parent = node.parentNode
if parent:
parent.replaceChild(wrap_node, node)
wrap_node.appendChild(node)
return wrap_node | [
"def",
"wrap",
"(",
"node",
",",
"tag",
")",
":",
"wrap_node",
"=",
"node",
".",
"ownerDocument",
".",
"createElement",
"(",
"tag",
")",
"parent",
"=",
"node",
".",
"parentNode",
"if",
"parent",
":",
"parent",
".",
"replaceChild",
"(",
"wrap_node",
",",
... | Wrap the given tag around a node. | [
"Wrap",
"the",
"given",
"tag",
"around",
"a",
"node",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L349-L356 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | wrap_inner | def wrap_inner(node, tag):
"""Wrap the given tag around the contents of a node."""
children = list(node.childNodes)
wrap_node = node.ownerDocument.createElement(tag)
for c in children:
wrap_node.appendChild(c)
node.appendChild(wrap_node) | python | def wrap_inner(node, tag):
"""Wrap the given tag around the contents of a node."""
children = list(node.childNodes)
wrap_node = node.ownerDocument.createElement(tag)
for c in children:
wrap_node.appendChild(c)
node.appendChild(wrap_node) | [
"def",
"wrap_inner",
"(",
"node",
",",
"tag",
")",
":",
"children",
"=",
"list",
"(",
"node",
".",
"childNodes",
")",
"wrap_node",
"=",
"node",
".",
"ownerDocument",
".",
"createElement",
"(",
"tag",
")",
"for",
"c",
"in",
"children",
":",
"wrap_node",
... | Wrap the given tag around the contents of a node. | [
"Wrap",
"the",
"given",
"tag",
"around",
"the",
"contents",
"of",
"a",
"node",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L358-L364 | train |
christian-oudard/htmltreediff | htmltreediff/util.py | unwrap | def unwrap(node):
"""Remove a node, replacing it with its children."""
for child in list(node.childNodes):
node.parentNode.insertBefore(child, node)
remove_node(node) | python | def unwrap(node):
"""Remove a node, replacing it with its children."""
for child in list(node.childNodes):
node.parentNode.insertBefore(child, node)
remove_node(node) | [
"def",
"unwrap",
"(",
"node",
")",
":",
"for",
"child",
"in",
"list",
"(",
"node",
".",
"childNodes",
")",
":",
"node",
".",
"parentNode",
".",
"insertBefore",
"(",
"child",
",",
"node",
")",
"remove_node",
"(",
"node",
")"
] | Remove a node, replacing it with its children. | [
"Remove",
"a",
"node",
"replacing",
"it",
"with",
"its",
"children",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/util.py#L366-L370 | train |
christian-oudard/htmltreediff | htmltreediff/text.py | full_split | def full_split(text, regex):
"""
Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.
>>> list(full_split('word', re.compile('&.*?')))
['word']
"""
while text:
m = regex.search(text)
if not m:
yield text
... | python | def full_split(text, regex):
"""
Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.
>>> list(full_split('word', re.compile('&.*?')))
['word']
"""
while text:
m = regex.search(text)
if not m:
yield text
... | [
"def",
"full_split",
"(",
"text",
",",
"regex",
")",
":",
"while",
"text",
":",
"m",
"=",
"regex",
".",
"search",
"(",
"text",
")",
"if",
"not",
"m",
":",
"yield",
"text",
"break",
"left",
"=",
"text",
"[",
":",
"m",
".",
"start",
"(",
")",
"]"... | Split the text by the regex, keeping all parts.
The parts should re-join back into the original text.
>>> list(full_split('word', re.compile('&.*?')))
['word'] | [
"Split",
"the",
"text",
"by",
"the",
"regex",
"keeping",
"all",
"parts",
".",
"The",
"parts",
"should",
"re",
"-",
"join",
"back",
"into",
"the",
"original",
"text",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L4-L24 | train |
christian-oudard/htmltreediff | htmltreediff/text.py | multi_split | def multi_split(text, regexes):
"""
Split the text by the given regexes, in priority order.
Make sure that the regex is parenthesized so that matches are returned in
re.split().
Splitting on a single regex works like normal split.
>>> '|'.join(multi_split('one two three', [r'\w+']))
'one| ... | python | def multi_split(text, regexes):
"""
Split the text by the given regexes, in priority order.
Make sure that the regex is parenthesized so that matches are returned in
re.split().
Splitting on a single regex works like normal split.
>>> '|'.join(multi_split('one two three', [r'\w+']))
'one| ... | [
"def",
"multi_split",
"(",
"text",
",",
"regexes",
")",
":",
"def",
"make_regex",
"(",
"s",
")",
":",
"return",
"re",
".",
"compile",
"(",
"s",
")",
"if",
"isinstance",
"(",
"s",
",",
"basestring",
")",
"else",
"s",
"regexes",
"=",
"[",
"make_regex",... | Split the text by the given regexes, in priority order.
Make sure that the regex is parenthesized so that matches are returned in
re.split().
Splitting on a single regex works like normal split.
>>> '|'.join(multi_split('one two three', [r'\w+']))
'one| |two| |three'
Splitting on digits first... | [
"Split",
"the",
"text",
"by",
"the",
"given",
"regexes",
"in",
"priority",
"order",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L26-L69 | train |
christian-oudard/htmltreediff | htmltreediff/text.py | WordMatcher.text_ratio | def text_ratio(self):
"""Return a measure of the sequences' word similarity (float in [0,1]).
Each word has weight equal to its length for this measure
>>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same
>>> '%.3f' % m.ratio() # normal ratio fails
... | python | def text_ratio(self):
"""Return a measure of the sequences' word similarity (float in [0,1]).
Each word has weight equal to its length for this measure
>>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same
>>> '%.3f' % m.ratio() # normal ratio fails
... | [
"def",
"text_ratio",
"(",
"self",
")",
":",
"return",
"_calculate_ratio",
"(",
"self",
".",
"match_length",
"(",
")",
",",
"self",
".",
"_text_length",
"(",
"self",
".",
"a",
")",
"+",
"self",
".",
"_text_length",
"(",
"self",
".",
"b",
")",
",",
")"... | Return a measure of the sequences' word similarity (float in [0,1]).
Each word has weight equal to its length for this measure
>>> m = WordMatcher(a=['abcdef', '12'], b=['abcdef', '34']) # 3/4 of the text is the same
>>> '%.3f' % m.ratio() # normal ratio fails
'0.500'
>>> '%.3f... | [
"Return",
"a",
"measure",
"of",
"the",
"sequences",
"word",
"similarity",
"(",
"float",
"in",
"[",
"0",
"1",
"]",
")",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L124-L138 | train |
christian-oudard/htmltreediff | htmltreediff/text.py | WordMatcher.match_length | def match_length(self):
""" Find the total length of all words that match between the two sequences."""
length = 0
for match in self.get_matching_blocks():
a, b, size = match
length += self._text_length(self.a[a:a+size])
return length | python | def match_length(self):
""" Find the total length of all words that match between the two sequences."""
length = 0
for match in self.get_matching_blocks():
a, b, size = match
length += self._text_length(self.a[a:a+size])
return length | [
"def",
"match_length",
"(",
"self",
")",
":",
"length",
"=",
"0",
"for",
"match",
"in",
"self",
".",
"get_matching_blocks",
"(",
")",
":",
"a",
",",
"b",
",",
"size",
"=",
"match",
"length",
"+=",
"self",
".",
"_text_length",
"(",
"self",
".",
"a",
... | Find the total length of all words that match between the two sequences. | [
"Find",
"the",
"total",
"length",
"of",
"all",
"words",
"that",
"match",
"between",
"the",
"two",
"sequences",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/text.py#L140-L146 | train |
christian-oudard/htmltreediff | htmltreediff/edit_script_runner.py | EditScriptRunner.run_edit_script | def run_edit_script(self):
"""
Run an xml edit script, and return the new html produced.
"""
for action, location, properties in self.edit_script:
if action == 'delete':
node = get_location(self.dom, location)
self.action_delete(node)
... | python | def run_edit_script(self):
"""
Run an xml edit script, and return the new html produced.
"""
for action, location, properties in self.edit_script:
if action == 'delete':
node = get_location(self.dom, location)
self.action_delete(node)
... | [
"def",
"run_edit_script",
"(",
"self",
")",
":",
"for",
"action",
",",
"location",
",",
"properties",
"in",
"self",
".",
"edit_script",
":",
"if",
"action",
"==",
"'delete'",
":",
"node",
"=",
"get_location",
"(",
"self",
".",
"dom",
",",
"location",
")"... | Run an xml edit script, and return the new html produced. | [
"Run",
"an",
"xml",
"edit",
"script",
"and",
"return",
"the",
"new",
"html",
"produced",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/edit_script_runner.py#L48-L60 | train |
christian-oudard/htmltreediff | htmltreediff/changes.py | add_changes_markup | def add_changes_markup(dom, ins_nodes, del_nodes):
"""
Add <ins> and <del> tags to the dom to show changes.
"""
# add markup for inserted and deleted sections
for node in reversed(del_nodes):
# diff algorithm deletes nodes in reverse order, so un-reverse the
# order for this iteratio... | python | def add_changes_markup(dom, ins_nodes, del_nodes):
"""
Add <ins> and <del> tags to the dom to show changes.
"""
# add markup for inserted and deleted sections
for node in reversed(del_nodes):
# diff algorithm deletes nodes in reverse order, so un-reverse the
# order for this iteratio... | [
"def",
"add_changes_markup",
"(",
"dom",
",",
"ins_nodes",
",",
"del_nodes",
")",
":",
"# add markup for inserted and deleted sections",
"for",
"node",
"in",
"reversed",
"(",
"del_nodes",
")",
":",
"# diff algorithm deletes nodes in reverse order, so un-reverse the",
"# order... | Add <ins> and <del> tags to the dom to show changes. | [
"Add",
"<ins",
">",
"and",
"<del",
">",
"tags",
"to",
"the",
"dom",
"to",
"show",
"changes",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L48-L65 | train |
christian-oudard/htmltreediff | htmltreediff/changes.py | remove_nesting | def remove_nesting(dom, tag_name):
"""
Unwrap items in the node list that have ancestors with the same tag.
"""
for node in dom.getElementsByTagName(tag_name):
for ancestor in ancestors(node):
if ancestor is node:
continue
if ancestor is dom.documentElemen... | python | def remove_nesting(dom, tag_name):
"""
Unwrap items in the node list that have ancestors with the same tag.
"""
for node in dom.getElementsByTagName(tag_name):
for ancestor in ancestors(node):
if ancestor is node:
continue
if ancestor is dom.documentElemen... | [
"def",
"remove_nesting",
"(",
"dom",
",",
"tag_name",
")",
":",
"for",
"node",
"in",
"dom",
".",
"getElementsByTagName",
"(",
"tag_name",
")",
":",
"for",
"ancestor",
"in",
"ancestors",
"(",
"node",
")",
":",
"if",
"ancestor",
"is",
"node",
":",
"continu... | Unwrap items in the node list that have ancestors with the same tag. | [
"Unwrap",
"items",
"in",
"the",
"node",
"list",
"that",
"have",
"ancestors",
"with",
"the",
"same",
"tag",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L67-L79 | train |
christian-oudard/htmltreediff | htmltreediff/changes.py | sort_nodes | def sort_nodes(dom, cmp_func):
"""
Sort the nodes of the dom in-place, based on a comparison function.
"""
dom.normalize()
for node in list(walk_dom(dom, elements_only=True)):
prev_sib = node.previousSibling
while prev_sib and cmp_func(prev_sib, node) == 1:
node.parentNod... | python | def sort_nodes(dom, cmp_func):
"""
Sort the nodes of the dom in-place, based on a comparison function.
"""
dom.normalize()
for node in list(walk_dom(dom, elements_only=True)):
prev_sib = node.previousSibling
while prev_sib and cmp_func(prev_sib, node) == 1:
node.parentNod... | [
"def",
"sort_nodes",
"(",
"dom",
",",
"cmp_func",
")",
":",
"dom",
".",
"normalize",
"(",
")",
"for",
"node",
"in",
"list",
"(",
"walk_dom",
"(",
"dom",
",",
"elements_only",
"=",
"True",
")",
")",
":",
"prev_sib",
"=",
"node",
".",
"previousSibling",
... | Sort the nodes of the dom in-place, based on a comparison function. | [
"Sort",
"the",
"nodes",
"of",
"the",
"dom",
"in",
"-",
"place",
"based",
"on",
"a",
"comparison",
"function",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L81-L90 | train |
christian-oudard/htmltreediff | htmltreediff/changes.py | merge_adjacent | def merge_adjacent(dom, tag_name):
"""
Merge all adjacent tags with the specified tag name.
Return the number of merges performed.
"""
for node in dom.getElementsByTagName(tag_name):
prev_sib = node.previousSibling
if prev_sib and prev_sib.nodeName == node.tagName:
for ch... | python | def merge_adjacent(dom, tag_name):
"""
Merge all adjacent tags with the specified tag name.
Return the number of merges performed.
"""
for node in dom.getElementsByTagName(tag_name):
prev_sib = node.previousSibling
if prev_sib and prev_sib.nodeName == node.tagName:
for ch... | [
"def",
"merge_adjacent",
"(",
"dom",
",",
"tag_name",
")",
":",
"for",
"node",
"in",
"dom",
".",
"getElementsByTagName",
"(",
"tag_name",
")",
":",
"prev_sib",
"=",
"node",
".",
"previousSibling",
"if",
"prev_sib",
"and",
"prev_sib",
".",
"nodeName",
"==",
... | Merge all adjacent tags with the specified tag name.
Return the number of merges performed. | [
"Merge",
"all",
"adjacent",
"tags",
"with",
"the",
"specified",
"tag",
"name",
".",
"Return",
"the",
"number",
"of",
"merges",
"performed",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L104-L114 | train |
christian-oudard/htmltreediff | htmltreediff/changes.py | distribute | def distribute(node):
"""
Wrap a copy of the given element around the contents of each of its
children, removing the node in the process.
"""
children = list(c for c in node.childNodes if is_element(c))
unwrap(node)
tag_name = node.tagName
for c in children:
wrap_inner(c, tag_nam... | python | def distribute(node):
"""
Wrap a copy of the given element around the contents of each of its
children, removing the node in the process.
"""
children = list(c for c in node.childNodes if is_element(c))
unwrap(node)
tag_name = node.tagName
for c in children:
wrap_inner(c, tag_nam... | [
"def",
"distribute",
"(",
"node",
")",
":",
"children",
"=",
"list",
"(",
"c",
"for",
"c",
"in",
"node",
".",
"childNodes",
"if",
"is_element",
"(",
"c",
")",
")",
"unwrap",
"(",
"node",
")",
"tag_name",
"=",
"node",
".",
"tagName",
"for",
"c",
"in... | Wrap a copy of the given element around the contents of each of its
children, removing the node in the process. | [
"Wrap",
"a",
"copy",
"of",
"the",
"given",
"element",
"around",
"the",
"contents",
"of",
"each",
"of",
"its",
"children",
"removing",
"the",
"node",
"in",
"the",
"process",
"."
] | 0e28f56492ae7e69bb0f74f9a79a8909a5ad588d | https://github.com/christian-oudard/htmltreediff/blob/0e28f56492ae7e69bb0f74f9a79a8909a5ad588d/htmltreediff/changes.py#L116-L125 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.