repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
django-salesforce/django-salesforce | salesforce/utils.py | get_soap_client | def get_soap_client(db_alias, client_class=None):
"""
Create the SOAP client for the current user logged in the db_alias
The default created client is "beatbox.PythonClient", but an
alternative client is possible. (i.e. other subtype of beatbox.XMLClient)
"""
if not beatbox:
raise Inter... | python | def get_soap_client(db_alias, client_class=None):
"""
Create the SOAP client for the current user logged in the db_alias
The default created client is "beatbox.PythonClient", but an
alternative client is possible. (i.e. other subtype of beatbox.XMLClient)
"""
if not beatbox:
raise Inter... | [
"def",
"get_soap_client",
"(",
"db_alias",
",",
"client_class",
"=",
"None",
")",
":",
"if",
"not",
"beatbox",
":",
"raise",
"InterfaceError",
"(",
"\"To use SOAP API, you'll need to install the Beatbox package.\"",
")",
"if",
"client_class",
"is",
"None",
":",
"clien... | Create the SOAP client for the current user logged in the db_alias
The default created client is "beatbox.PythonClient", but an
alternative client is possible. (i.e. other subtype of beatbox.XMLClient) | [
"Create",
"the",
"SOAP",
"client",
"for",
"the",
"current",
"user",
"logged",
"in",
"the",
"db_alias"
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/utils.py#L20-L46 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | signalize_extensions | def signalize_extensions():
"""DB API 2.0 extension are reported by warnings at run-time."""
warnings.warn("DB-API extension cursor.rownumber used", SalesforceWarning)
warnings.warn("DB-API extension connection.<exception> used", SalesforceWarning) # TODO
warnings.warn("DB-API extension cursor.connecti... | python | def signalize_extensions():
"""DB API 2.0 extension are reported by warnings at run-time."""
warnings.warn("DB-API extension cursor.rownumber used", SalesforceWarning)
warnings.warn("DB-API extension connection.<exception> used", SalesforceWarning) # TODO
warnings.warn("DB-API extension cursor.connecti... | [
"def",
"signalize_extensions",
"(",
")",
":",
"warnings",
".",
"warn",
"(",
"\"DB-API extension cursor.rownumber used\"",
",",
"SalesforceWarning",
")",
"warnings",
".",
"warn",
"(",
"\"DB-API extension connection.<exception> used\"",
",",
"SalesforceWarning",
")",
"# TODO"... | DB API 2.0 extension are reported by warnings at run-time. | [
"DB",
"API",
"2",
".",
"0",
"extension",
"are",
"reported",
"by",
"warnings",
"at",
"run",
"-",
"time",
"."
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L670-L681 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | arg_to_soql | def arg_to_soql(arg):
"""
Perform necessary SOQL quoting on the arg.
"""
conversion = sql_conversions.get(type(arg))
if conversion:
return conversion(arg)
for type_ in subclass_conversions:
if isinstance(arg, type_):
return sql_conversions[type_](arg)
return sql_c... | python | def arg_to_soql(arg):
"""
Perform necessary SOQL quoting on the arg.
"""
conversion = sql_conversions.get(type(arg))
if conversion:
return conversion(arg)
for type_ in subclass_conversions:
if isinstance(arg, type_):
return sql_conversions[type_](arg)
return sql_c... | [
"def",
"arg_to_soql",
"(",
"arg",
")",
":",
"conversion",
"=",
"sql_conversions",
".",
"get",
"(",
"type",
"(",
"arg",
")",
")",
"if",
"conversion",
":",
"return",
"conversion",
"(",
"arg",
")",
"for",
"type_",
"in",
"subclass_conversions",
":",
"if",
"i... | Perform necessary SOQL quoting on the arg. | [
"Perform",
"necessary",
"SOQL",
"quoting",
"on",
"the",
"arg",
"."
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L735-L745 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | arg_to_json | def arg_to_json(arg):
"""
Perform necessary JSON conversion on the arg.
"""
conversion = json_conversions.get(type(arg))
if conversion:
return conversion(arg)
for type_ in subclass_conversions:
if isinstance(arg, type_):
return json_conversions[type_](arg)
return ... | python | def arg_to_json(arg):
"""
Perform necessary JSON conversion on the arg.
"""
conversion = json_conversions.get(type(arg))
if conversion:
return conversion(arg)
for type_ in subclass_conversions:
if isinstance(arg, type_):
return json_conversions[type_](arg)
return ... | [
"def",
"arg_to_json",
"(",
"arg",
")",
":",
"conversion",
"=",
"json_conversions",
".",
"get",
"(",
"type",
"(",
"arg",
")",
")",
"if",
"conversion",
":",
"return",
"conversion",
"(",
"arg",
")",
"for",
"type_",
"in",
"subclass_conversions",
":",
"if",
"... | Perform necessary JSON conversion on the arg. | [
"Perform",
"necessary",
"JSON",
"conversion",
"on",
"the",
"arg",
"."
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L748-L758 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | merge_dict | def merge_dict(dict_1, *other, **kw):
"""Merge two or more dict including kw into result dict."""
tmp = dict_1.copy()
for x in other:
tmp.update(x)
tmp.update(kw)
return tmp | python | def merge_dict(dict_1, *other, **kw):
"""Merge two or more dict including kw into result dict."""
tmp = dict_1.copy()
for x in other:
tmp.update(x)
tmp.update(kw)
return tmp | [
"def",
"merge_dict",
"(",
"dict_1",
",",
"*",
"other",
",",
"*",
"*",
"kw",
")",
":",
"tmp",
"=",
"dict_1",
".",
"copy",
"(",
")",
"for",
"x",
"in",
"other",
":",
"tmp",
".",
"update",
"(",
"x",
")",
"tmp",
".",
"update",
"(",
"kw",
")",
"ret... | Merge two or more dict including kw into result dict. | [
"Merge",
"two",
"or",
"more",
"dict",
"including",
"kw",
"into",
"result",
"dict",
"."
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L792-L798 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | RawConnection.make_session | def make_session(self):
"""Authenticate and get the name of assigned SFDC data server"""
with connect_lock:
if self._sf_session is None:
sf_session = requests.Session()
# TODO configurable class Salesforce***Auth
sf_session.auth = SalesforcePas... | python | def make_session(self):
"""Authenticate and get the name of assigned SFDC data server"""
with connect_lock:
if self._sf_session is None:
sf_session = requests.Session()
# TODO configurable class Salesforce***Auth
sf_session.auth = SalesforcePas... | [
"def",
"make_session",
"(",
"self",
")",
":",
"with",
"connect_lock",
":",
"if",
"self",
".",
"_sf_session",
"is",
"None",
":",
"sf_session",
"=",
"requests",
".",
"Session",
"(",
")",
"# TODO configurable class Salesforce***Auth",
"sf_session",
".",
"auth",
"="... | Authenticate and get the name of assigned SFDC data server | [
"Authenticate",
"and",
"get",
"the",
"name",
"of",
"assigned",
"SFDC",
"data",
"server"
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L159-L172 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | RawConnection.rest_api_url | def rest_api_url(self, *url_parts, **kwargs):
"""Join the URL of REST_API
parameters:
upl_parts: strings that are joined to the url by "/".
a REST url like https://na1.salesforce.com/services/data/v44.0/
is usually added, but not if the first string starts w... | python | def rest_api_url(self, *url_parts, **kwargs):
"""Join the URL of REST_API
parameters:
upl_parts: strings that are joined to the url by "/".
a REST url like https://na1.salesforce.com/services/data/v44.0/
is usually added, but not if the first string starts w... | [
"def",
"rest_api_url",
"(",
"self",
",",
"*",
"url_parts",
",",
"*",
"*",
"kwargs",
")",
":",
"url_parts",
"=",
"list",
"(",
"url_parts",
")",
"if",
"url_parts",
"and",
"re",
".",
"match",
"(",
"r'^(?:https|mock)://'",
",",
"url_parts",
"[",
"0",
"]",
... | Join the URL of REST_API
parameters:
upl_parts: strings that are joined to the url by "/".
a REST url like https://na1.salesforce.com/services/data/v44.0/
is usually added, but not if the first string starts with https://
api_ver: API version that shoul... | [
"Join",
"the",
"URL",
"of",
"REST_API"
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L174-L216 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | RawConnection.raise_errors | def raise_errors(self, response):
"""The innermost part - report errors by exceptions"""
# Errors: 400, 403 permissions or REQUEST_LIMIT_EXCEEDED, 404, 405, 415, 500)
# TODO extract a case ID for Salesforce support from code 500 messages
# TODO disabled 'debug_verbs' temporarily, after ... | python | def raise_errors(self, response):
"""The innermost part - report errors by exceptions"""
# Errors: 400, 403 permissions or REQUEST_LIMIT_EXCEEDED, 404, 405, 415, 500)
# TODO extract a case ID for Salesforce support from code 500 messages
# TODO disabled 'debug_verbs' temporarily, after ... | [
"def",
"raise_errors",
"(",
"self",
",",
"response",
")",
":",
"# Errors: 400, 403 permissions or REQUEST_LIMIT_EXCEEDED, 404, 405, 415, 500)",
"# TODO extract a case ID for Salesforce support from code 500 messages",
"# TODO disabled 'debug_verbs' temporarily, after writing better default messa... | The innermost part - report errors by exceptions | [
"The",
"innermost",
"part",
"-",
"report",
"errors",
"by",
"exceptions"
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L287-L322 | train |
django-salesforce/django-salesforce | salesforce/dbapi/driver.py | RawConnection.composite_request | def composite_request(self, data):
"""Call a 'composite' request with subrequests, error handling
A fake object for request/response is created for a subrequest in case
of error, to be possible to use the same error hanler with a clear
message as with an individual request.
"""
... | python | def composite_request(self, data):
"""Call a 'composite' request with subrequests, error handling
A fake object for request/response is created for a subrequest in case
of error, to be possible to use the same error hanler with a clear
message as with an individual request.
"""
... | [
"def",
"composite_request",
"(",
"self",
",",
"data",
")",
":",
"post_data",
"=",
"{",
"'compositeRequest'",
":",
"data",
",",
"'allOrNone'",
":",
"True",
"}",
"resp",
"=",
"self",
".",
"handle_api_exceptions",
"(",
"'POST'",
",",
"'composite'",
",",
"json",... | Call a 'composite' request with subrequests, error handling
A fake object for request/response is created for a subrequest in case
of error, to be possible to use the same error hanler with a clear
message as with an individual request. | [
"Call",
"a",
"composite",
"request",
"with",
"subrequests",
"error",
"handling"
] | 6fd5643dba69d49c5881de50875cf90204a8f808 | https://github.com/django-salesforce/django-salesforce/blob/6fd5643dba69d49c5881de50875cf90204a8f808/salesforce/dbapi/driver.py#L324-L359 | train |
crs4/pydoop | pydoop/avrolib.py | SeekableDataFileReader.align_after | def align_after(self, offset):
"""
Search for a sync point after offset and align just after that.
"""
f = self.reader
if offset <= 0: # FIXME what is a negative offset??
f.seek(0)
self._block_count = 0
self._read_header() # FIXME we can't ex... | python | def align_after(self, offset):
"""
Search for a sync point after offset and align just after that.
"""
f = self.reader
if offset <= 0: # FIXME what is a negative offset??
f.seek(0)
self._block_count = 0
self._read_header() # FIXME we can't ex... | [
"def",
"align_after",
"(",
"self",
",",
"offset",
")",
":",
"f",
"=",
"self",
".",
"reader",
"if",
"offset",
"<=",
"0",
":",
"# FIXME what is a negative offset??",
"f",
".",
"seek",
"(",
"0",
")",
"self",
".",
"_block_count",
"=",
"0",
"self",
".",
"_r... | Search for a sync point after offset and align just after that. | [
"Search",
"for",
"a",
"sync",
"point",
"after",
"offset",
"and",
"align",
"just",
"after",
"that",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/avrolib.py#L77-L98 | train |
crs4/pydoop | pydoop/avrolib.py | AvroReader.get_progress | def get_progress(self):
"""
Give a rough estimate of the progress done.
"""
pos = self.reader.reader.tell()
return min((pos - self.region_start) /
float(self.region_end - self.region_start),
1.0) | python | def get_progress(self):
"""
Give a rough estimate of the progress done.
"""
pos = self.reader.reader.tell()
return min((pos - self.region_start) /
float(self.region_end - self.region_start),
1.0) | [
"def",
"get_progress",
"(",
"self",
")",
":",
"pos",
"=",
"self",
".",
"reader",
".",
"reader",
".",
"tell",
"(",
")",
"return",
"min",
"(",
"(",
"pos",
"-",
"self",
".",
"region_start",
")",
"/",
"float",
"(",
"self",
".",
"region_end",
"-",
"self... | Give a rough estimate of the progress done. | [
"Give",
"a",
"rough",
"estimate",
"of",
"the",
"progress",
"done",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/avrolib.py#L124-L131 | train |
crs4/pydoop | pydoop/hadoop_utils.py | is_exe | def is_exe(fpath):
"""
Path references an executable file.
"""
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | python | def is_exe(fpath):
"""
Path references an executable file.
"""
return os.path.isfile(fpath) and os.access(fpath, os.X_OK) | [
"def",
"is_exe",
"(",
"fpath",
")",
":",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"fpath",
")",
"and",
"os",
".",
"access",
"(",
"fpath",
",",
"os",
".",
"X_OK",
")"
] | Path references an executable file. | [
"Path",
"references",
"an",
"executable",
"file",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadoop_utils.py#L265-L269 | train |
crs4/pydoop | pydoop/hadoop_utils.py | is_readable | def is_readable(fpath):
"""
Path references a readable file.
"""
return os.path.isfile(fpath) and os.access(fpath, os.R_OK) | python | def is_readable(fpath):
"""
Path references a readable file.
"""
return os.path.isfile(fpath) and os.access(fpath, os.R_OK) | [
"def",
"is_readable",
"(",
"fpath",
")",
":",
"return",
"os",
".",
"path",
".",
"isfile",
"(",
"fpath",
")",
"and",
"os",
".",
"access",
"(",
"fpath",
",",
"os",
".",
"R_OK",
")"
] | Path references a readable file. | [
"Path",
"references",
"a",
"readable",
"file",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadoop_utils.py#L272-L276 | train |
crs4/pydoop | pydoop/hadoop_utils.py | PathFinder.is_local | def is_local(self, hadoop_conf=None, hadoop_home=None):
"""\
Is Hadoop configured to run in local mode?
By default, it is. [pseudo-]distributed mode must be
explicitly configured.
"""
conf = self.hadoop_params(hadoop_conf, hadoop_home)
keys = ('mapreduce.framewor... | python | def is_local(self, hadoop_conf=None, hadoop_home=None):
"""\
Is Hadoop configured to run in local mode?
By default, it is. [pseudo-]distributed mode must be
explicitly configured.
"""
conf = self.hadoop_params(hadoop_conf, hadoop_home)
keys = ('mapreduce.framewor... | [
"def",
"is_local",
"(",
"self",
",",
"hadoop_conf",
"=",
"None",
",",
"hadoop_home",
"=",
"None",
")",
":",
"conf",
"=",
"self",
".",
"hadoop_params",
"(",
"hadoop_conf",
",",
"hadoop_home",
")",
"keys",
"=",
"(",
"'mapreduce.framework.name'",
",",
"'mapredu... | \
Is Hadoop configured to run in local mode?
By default, it is. [pseudo-]distributed mode must be
explicitly configured. | [
"\\",
"Is",
"Hadoop",
"configured",
"to",
"run",
"in",
"local",
"mode?"
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadoop_utils.py#L562-L576 | train |
crs4/pydoop | pydoop/hdfs/path.py | abspath | def abspath(hdfs_path, user=None, local=False):
"""
Return an absolute path for ``hdfs_path``.
The ``user`` arg is passed to :func:`split`. The ``local`` argument
forces ``hdfs_path`` to be interpreted as an ordinary local path:
.. code-block:: python
>>> import os
>>> os.chdir('/tmp'... | python | def abspath(hdfs_path, user=None, local=False):
"""
Return an absolute path for ``hdfs_path``.
The ``user`` arg is passed to :func:`split`. The ``local`` argument
forces ``hdfs_path`` to be interpreted as an ordinary local path:
.. code-block:: python
>>> import os
>>> os.chdir('/tmp'... | [
"def",
"abspath",
"(",
"hdfs_path",
",",
"user",
"=",
"None",
",",
"local",
"=",
"False",
")",
":",
"if",
"local",
":",
"return",
"'file:%s'",
"%",
"os",
".",
"path",
".",
"abspath",
"(",
"hdfs_path",
")",
"if",
"isfull",
"(",
"hdfs_path",
")",
":",
... | Return an absolute path for ``hdfs_path``.
The ``user`` arg is passed to :func:`split`. The ``local`` argument
forces ``hdfs_path`` to be interpreted as an ordinary local path:
.. code-block:: python
>>> import os
>>> os.chdir('/tmp')
>>> import pydoop.hdfs.path as hpath
>>> hpath... | [
"Return",
"an",
"absolute",
"path",
"for",
"hdfs_path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/path.py#L242-L278 | train |
crs4/pydoop | pydoop/hdfs/path.py | dirname | def dirname(hdfs_path):
"""
Return the directory component of ``hdfs_path``.
"""
scheme, netloc, path = parse(hdfs_path)
return unparse(scheme, netloc, os.path.dirname(path)) | python | def dirname(hdfs_path):
"""
Return the directory component of ``hdfs_path``.
"""
scheme, netloc, path = parse(hdfs_path)
return unparse(scheme, netloc, os.path.dirname(path)) | [
"def",
"dirname",
"(",
"hdfs_path",
")",
":",
"scheme",
",",
"netloc",
",",
"path",
"=",
"parse",
"(",
"hdfs_path",
")",
"return",
"unparse",
"(",
"scheme",
",",
"netloc",
",",
"os",
".",
"path",
".",
"dirname",
"(",
"path",
")",
")"
] | Return the directory component of ``hdfs_path``. | [
"Return",
"the",
"directory",
"component",
"of",
"hdfs_path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/path.py#L296-L301 | train |
crs4/pydoop | pydoop/hdfs/path.py | expanduser | def expanduser(path):
"""
Replace initial ``~`` or ``~user`` with the user's home directory.
**NOTE:** if the default file system is HDFS, the ``~user`` form is
expanded regardless of the user's existence.
"""
if hdfs_fs.default_is_local():
return os.path.expanduser(path)
m = re.mat... | python | def expanduser(path):
"""
Replace initial ``~`` or ``~user`` with the user's home directory.
**NOTE:** if the default file system is HDFS, the ``~user`` form is
expanded regardless of the user's existence.
"""
if hdfs_fs.default_is_local():
return os.path.expanduser(path)
m = re.mat... | [
"def",
"expanduser",
"(",
"path",
")",
":",
"if",
"hdfs_fs",
".",
"default_is_local",
"(",
")",
":",
"return",
"os",
".",
"path",
".",
"expanduser",
"(",
"path",
")",
"m",
"=",
"re",
".",
"match",
"(",
"r'^~([^/]*)'",
",",
"path",
")",
"if",
"m",
"... | Replace initial ``~`` or ``~user`` with the user's home directory.
**NOTE:** if the default file system is HDFS, the ``~user`` form is
expanded regardless of the user's existence. | [
"Replace",
"initial",
"~",
"or",
"~user",
"with",
"the",
"user",
"s",
"home",
"directory",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/path.py#L355-L368 | train |
crs4/pydoop | pydoop/hdfs/path.py | normpath | def normpath(path):
"""
Normalize ``path``, collapsing redundant separators and up-level refs.
"""
scheme, netloc, path_ = parse(path)
return unparse(scheme, netloc, os.path.normpath(path_)) | python | def normpath(path):
"""
Normalize ``path``, collapsing redundant separators and up-level refs.
"""
scheme, netloc, path_ = parse(path)
return unparse(scheme, netloc, os.path.normpath(path_)) | [
"def",
"normpath",
"(",
"path",
")",
":",
"scheme",
",",
"netloc",
",",
"path_",
"=",
"parse",
"(",
"path",
")",
"return",
"unparse",
"(",
"scheme",
",",
"netloc",
",",
"os",
".",
"path",
".",
"normpath",
"(",
"path_",
")",
")"
] | Normalize ``path``, collapsing redundant separators and up-level refs. | [
"Normalize",
"path",
"collapsing",
"redundant",
"separators",
"and",
"up",
"-",
"level",
"refs",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/path.py#L480-L485 | train |
crs4/pydoop | pydoop/hdfs/path.py | realpath | def realpath(path):
"""
Return ``path`` with symlinks resolved.
Currently this function returns non-local paths unchanged.
"""
scheme, netloc, path_ = parse(path)
if scheme == 'file' or hdfs_fs.default_is_local():
return unparse(scheme, netloc, os.path.realpath(path_))
return path | python | def realpath(path):
"""
Return ``path`` with symlinks resolved.
Currently this function returns non-local paths unchanged.
"""
scheme, netloc, path_ = parse(path)
if scheme == 'file' or hdfs_fs.default_is_local():
return unparse(scheme, netloc, os.path.realpath(path_))
return path | [
"def",
"realpath",
"(",
"path",
")",
":",
"scheme",
",",
"netloc",
",",
"path_",
"=",
"parse",
"(",
"path",
")",
"if",
"scheme",
"==",
"'file'",
"or",
"hdfs_fs",
".",
"default_is_local",
"(",
")",
":",
"return",
"unparse",
"(",
"scheme",
",",
"netloc",... | Return ``path`` with symlinks resolved.
Currently this function returns non-local paths unchanged. | [
"Return",
"path",
"with",
"symlinks",
"resolved",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/path.py#L488-L497 | train |
crs4/pydoop | pydoop/hdfs/fs.py | default_is_local | def default_is_local(hadoop_conf=None, hadoop_home=None):
"""\
Is Hadoop configured to use the local file system?
By default, it is. A DFS must be explicitly configured.
"""
params = pydoop.hadoop_params(hadoop_conf, hadoop_home)
for k in 'fs.defaultFS', 'fs.default.name':
if not params... | python | def default_is_local(hadoop_conf=None, hadoop_home=None):
"""\
Is Hadoop configured to use the local file system?
By default, it is. A DFS must be explicitly configured.
"""
params = pydoop.hadoop_params(hadoop_conf, hadoop_home)
for k in 'fs.defaultFS', 'fs.default.name':
if not params... | [
"def",
"default_is_local",
"(",
"hadoop_conf",
"=",
"None",
",",
"hadoop_home",
"=",
"None",
")",
":",
"params",
"=",
"pydoop",
".",
"hadoop_params",
"(",
"hadoop_conf",
",",
"hadoop_home",
")",
"for",
"k",
"in",
"'fs.defaultFS'",
",",
"'fs.default.name'",
":"... | \
Is Hadoop configured to use the local file system?
By default, it is. A DFS must be explicitly configured. | [
"\\",
"Is",
"Hadoop",
"configured",
"to",
"use",
"the",
"local",
"file",
"system?"
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L93-L103 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.open_file | def open_file(self, path,
mode="r",
buff_size=0,
replication=0,
blocksize=0,
encoding=None,
errors=None):
"""
Open an HDFS file.
Supported opening modes are "r", "w", "a". In addition, a
... | python | def open_file(self, path,
mode="r",
buff_size=0,
replication=0,
blocksize=0,
encoding=None,
errors=None):
"""
Open an HDFS file.
Supported opening modes are "r", "w", "a". In addition, a
... | [
"def",
"open_file",
"(",
"self",
",",
"path",
",",
"mode",
"=",
"\"r\"",
",",
"buff_size",
"=",
"0",
",",
"replication",
"=",
"0",
",",
"blocksize",
"=",
"0",
",",
"encoding",
"=",
"None",
",",
"errors",
"=",
"None",
")",
":",
"_complain_ifclosed",
"... | Open an HDFS file.
Supported opening modes are "r", "w", "a". In addition, a
trailing "t" can be added to specify text mode (e.g., "rt" =
open for reading text).
Pass 0 as ``buff_size``, ``replication`` or ``blocksize`` if you want
to use the "configured" values, i.e., the ones... | [
"Open",
"an",
"HDFS",
"file",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L235-L280 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.capacity | def capacity(self):
"""
Return the raw capacity of the filesystem.
:rtype: int
:return: filesystem capacity
"""
_complain_ifclosed(self.closed)
if not self.__status.host:
raise RuntimeError('Capacity is not defined for a local fs')
return self... | python | def capacity(self):
"""
Return the raw capacity of the filesystem.
:rtype: int
:return: filesystem capacity
"""
_complain_ifclosed(self.closed)
if not self.__status.host:
raise RuntimeError('Capacity is not defined for a local fs')
return self... | [
"def",
"capacity",
"(",
"self",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"if",
"not",
"self",
".",
"__status",
".",
"host",
":",
"raise",
"RuntimeError",
"(",
"'Capacity is not defined for a local fs'",
")",
"return",
"self",
".",
"fs",... | Return the raw capacity of the filesystem.
:rtype: int
:return: filesystem capacity | [
"Return",
"the",
"raw",
"capacity",
"of",
"the",
"filesystem",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L282-L292 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.copy | def copy(self, from_path, to_hdfs, to_path):
"""
Copy file from one filesystem to another.
:type from_path: str
:param from_path: the path of the source file
:type to_hdfs: :class:`hdfs`
:param to_hdfs: destination filesystem
:type to_path: str
:param to_... | python | def copy(self, from_path, to_hdfs, to_path):
"""
Copy file from one filesystem to another.
:type from_path: str
:param from_path: the path of the source file
:type to_hdfs: :class:`hdfs`
:param to_hdfs: destination filesystem
:type to_path: str
:param to_... | [
"def",
"copy",
"(",
"self",
",",
"from_path",
",",
"to_hdfs",
",",
"to_path",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"if",
"isinstance",
"(",
"to_hdfs",
",",
"self",
".",
"__class__",
")",
":",
"to_hdfs",
"=",
"to_hdfs",
".",
... | Copy file from one filesystem to another.
:type from_path: str
:param from_path: the path of the source file
:type to_hdfs: :class:`hdfs`
:param to_hdfs: destination filesystem
:type to_path: str
:param to_path: the path of the destination file
:raises: :exc:`~ex... | [
"Copy",
"file",
"from",
"one",
"filesystem",
"to",
"another",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L294-L309 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.delete | def delete(self, path, recursive=True):
"""
Delete ``path``.
:type path: str
:param path: the path of the file or directory
:type recursive: bool
:param recursive: if ``path`` is a directory, delete it recursively
when :obj:`True`
:raises: :exc:`~except... | python | def delete(self, path, recursive=True):
"""
Delete ``path``.
:type path: str
:param path: the path of the file or directory
:type recursive: bool
:param recursive: if ``path`` is a directory, delete it recursively
when :obj:`True`
:raises: :exc:`~except... | [
"def",
"delete",
"(",
"self",
",",
"path",
",",
"recursive",
"=",
"True",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"delete",
"(",
"path",
",",
"recursive",
")"
] | Delete ``path``.
:type path: str
:param path: the path of the file or directory
:type recursive: bool
:param recursive: if ``path`` is a directory, delete it recursively
when :obj:`True`
:raises: :exc:`~exceptions.IOError` when ``recursive`` is
:obj:`False` a... | [
"Delete",
"path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L333-L346 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.exists | def exists(self, path):
"""
Check if a given path exists on the filesystem.
:type path: str
:param path: the path to look for
:rtype: bool
:return: :obj:`True` if ``path`` exists
"""
_complain_ifclosed(self.closed)
return self.fs.exists(path) | python | def exists(self, path):
"""
Check if a given path exists on the filesystem.
:type path: str
:param path: the path to look for
:rtype: bool
:return: :obj:`True` if ``path`` exists
"""
_complain_ifclosed(self.closed)
return self.fs.exists(path) | [
"def",
"exists",
"(",
"self",
",",
"path",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"exists",
"(",
"path",
")"
] | Check if a given path exists on the filesystem.
:type path: str
:param path: the path to look for
:rtype: bool
:return: :obj:`True` if ``path`` exists | [
"Check",
"if",
"a",
"given",
"path",
"exists",
"on",
"the",
"filesystem",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L348-L358 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.get_path_info | def get_path_info(self, path):
"""
Get information about ``path`` as a dict of properties.
The return value, based upon ``fs.FileStatus`` from the Java API,
has the following fields:
* ``block_size``: HDFS block size of ``path``
* ``group``: group associated with ``path... | python | def get_path_info(self, path):
"""
Get information about ``path`` as a dict of properties.
The return value, based upon ``fs.FileStatus`` from the Java API,
has the following fields:
* ``block_size``: HDFS block size of ``path``
* ``group``: group associated with ``path... | [
"def",
"get_path_info",
"(",
"self",
",",
"path",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"get_path_info",
"(",
"path",
")"
] | Get information about ``path`` as a dict of properties.
The return value, based upon ``fs.FileStatus`` from the Java API,
has the following fields:
* ``block_size``: HDFS block size of ``path``
* ``group``: group associated with ``path``
* ``kind``: ``'file'`` or ``'directory'`... | [
"Get",
"information",
"about",
"path",
"as",
"a",
"dict",
"of",
"properties",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L378-L403 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.list_directory | def list_directory(self, path):
r"""
Get list of files and directories for ``path``\ .
:type path: str
:param path: the path of the directory
:rtype: list
:return: list of files and directories in ``path``
:raises: :exc:`~exceptions.IOError`
"""
_... | python | def list_directory(self, path):
r"""
Get list of files and directories for ``path``\ .
:type path: str
:param path: the path of the directory
:rtype: list
:return: list of files and directories in ``path``
:raises: :exc:`~exceptions.IOError`
"""
_... | [
"def",
"list_directory",
"(",
"self",
",",
"path",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"list_directory",
"(",
"path",
")"
] | r"""
Get list of files and directories for ``path``\ .
:type path: str
:param path: the path of the directory
:rtype: list
:return: list of files and directories in ``path``
:raises: :exc:`~exceptions.IOError` | [
"r",
"Get",
"list",
"of",
"files",
"and",
"directories",
"for",
"path",
"\\",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L405-L416 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.rename | def rename(self, from_path, to_path):
"""
Rename file.
:type from_path: str
:param from_path: the path of the source file
:type to_path: str
:param to_path: the path of the destination file
:raises: :exc:`~exceptions.IOError`
"""
_complain_ifclose... | python | def rename(self, from_path, to_path):
"""
Rename file.
:type from_path: str
:param from_path: the path of the source file
:type to_path: str
:param to_path: the path of the destination file
:raises: :exc:`~exceptions.IOError`
"""
_complain_ifclose... | [
"def",
"rename",
"(",
"self",
",",
"from_path",
",",
"to_path",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"rename",
"(",
"from_path",
",",
"to_path",
")"
] | Rename file.
:type from_path: str
:param from_path: the path of the source file
:type to_path: str
:param to_path: the path of the destination file
:raises: :exc:`~exceptions.IOError` | [
"Rename",
"file",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L435-L446 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.set_replication | def set_replication(self, path, replication):
r"""
Set the replication of ``path`` to ``replication``\ .
:type path: str
:param path: the path of the file
:type replication: int
:param replication: the replication value
:raises: :exc:`~exceptions.IOError`
... | python | def set_replication(self, path, replication):
r"""
Set the replication of ``path`` to ``replication``\ .
:type path: str
:param path: the path of the file
:type replication: int
:param replication: the replication value
:raises: :exc:`~exceptions.IOError`
... | [
"def",
"set_replication",
"(",
"self",
",",
"path",
",",
"replication",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"set_replication",
"(",
"path",
",",
"replication",
")"
] | r"""
Set the replication of ``path`` to ``replication``\ .
:type path: str
:param path: the path of the file
:type replication: int
:param replication: the replication value
:raises: :exc:`~exceptions.IOError` | [
"r",
"Set",
"the",
"replication",
"of",
"path",
"to",
"replication",
"\\",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L448-L459 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.set_working_directory | def set_working_directory(self, path):
r"""
Set the working directory to ``path``\ . All relative paths will
be resolved relative to it.
:type path: str
:param path: the path of the directory
:raises: :exc:`~exceptions.IOError`
"""
_complain_ifclosed(self... | python | def set_working_directory(self, path):
r"""
Set the working directory to ``path``\ . All relative paths will
be resolved relative to it.
:type path: str
:param path: the path of the directory
:raises: :exc:`~exceptions.IOError`
"""
_complain_ifclosed(self... | [
"def",
"set_working_directory",
"(",
"self",
",",
"path",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"set_working_directory",
"(",
"path",
")"
] | r"""
Set the working directory to ``path``\ . All relative paths will
be resolved relative to it.
:type path: str
:param path: the path of the directory
:raises: :exc:`~exceptions.IOError` | [
"r",
"Set",
"the",
"working",
"directory",
"to",
"path",
"\\",
".",
"All",
"relative",
"paths",
"will",
"be",
"resolved",
"relative",
"to",
"it",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L461-L471 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.working_directory | def working_directory(self):
"""
Get the current working directory.
:rtype: str
:return: current working directory
"""
_complain_ifclosed(self.closed)
wd = self.fs.get_working_directory()
return wd | python | def working_directory(self):
"""
Get the current working directory.
:rtype: str
:return: current working directory
"""
_complain_ifclosed(self.closed)
wd = self.fs.get_working_directory()
return wd | [
"def",
"working_directory",
"(",
"self",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"wd",
"=",
"self",
".",
"fs",
".",
"get_working_directory",
"(",
")",
"return",
"wd"
] | Get the current working directory.
:rtype: str
:return: current working directory | [
"Get",
"the",
"current",
"working",
"directory",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L483-L492 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.__compute_mode_from_string | def __compute_mode_from_string(self, path, mode_string):
"""
Scan a unix-style mode string and apply it to ``path``.
:type mode_string: str
:param mode_string: see ``man chmod`` for details. ``X``, ``s``
and ``t`` modes are not supported. The string should match the
... | python | def __compute_mode_from_string(self, path, mode_string):
"""
Scan a unix-style mode string and apply it to ``path``.
:type mode_string: str
:param mode_string: see ``man chmod`` for details. ``X``, ``s``
and ``t`` modes are not supported. The string should match the
... | [
"def",
"__compute_mode_from_string",
"(",
"self",
",",
"path",
",",
"mode_string",
")",
":",
"Char_to_perm_byte",
"=",
"{",
"'r'",
":",
"4",
",",
"'w'",
":",
"2",
",",
"'x'",
":",
"1",
"}",
"Fields",
"=",
"(",
"(",
"'u'",
",",
"6",
")",
",",
"(",
... | Scan a unix-style mode string and apply it to ``path``.
:type mode_string: str
:param mode_string: see ``man chmod`` for details. ``X``, ``s``
and ``t`` modes are not supported. The string should match the
following regular expression: ``[ugoa]*[-+=]([rwx]*)``.
:rtype: int
... | [
"Scan",
"a",
"unix",
"-",
"style",
"mode",
"string",
"and",
"apply",
"it",
"to",
"path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L515-L576 | train |
crs4/pydoop | pydoop/hdfs/fs.py | hdfs.utime | def utime(self, path, mtime, atime):
"""
Change file last access and modification times.
:type path: str
:param path: the path to the file or directory
:type mtime: int
:param mtime: new modification time in seconds
:type atime: int
:param atime: new acce... | python | def utime(self, path, mtime, atime):
"""
Change file last access and modification times.
:type path: str
:param path: the path to the file or directory
:type mtime: int
:param mtime: new modification time in seconds
:type atime: int
:param atime: new acce... | [
"def",
"utime",
"(",
"self",
",",
"path",
",",
"mtime",
",",
"atime",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"fs",
".",
"utime",
"(",
"path",
",",
"int",
"(",
"mtime",
")",
",",
"int",
"(",
"atime",
... | Change file last access and modification times.
:type path: str
:param path: the path to the file or directory
:type mtime: int
:param mtime: new modification time in seconds
:type atime: int
:param atime: new access time in seconds
:raises: :exc:`~exceptions.IOE... | [
"Change",
"file",
"last",
"access",
"and",
"modification",
"times",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/fs.py#L595-L608 | train |
crs4/pydoop | setup.py | rm_rf | def rm_rf(path, dry_run=False):
"""
Remove a file or directory tree.
Won't throw an exception, even if the removal fails.
"""
log.info("removing %s" % path)
if dry_run:
return
try:
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path)
e... | python | def rm_rf(path, dry_run=False):
"""
Remove a file or directory tree.
Won't throw an exception, even if the removal fails.
"""
log.info("removing %s" % path)
if dry_run:
return
try:
if os.path.isdir(path) and not os.path.islink(path):
shutil.rmtree(path)
e... | [
"def",
"rm_rf",
"(",
"path",
",",
"dry_run",
"=",
"False",
")",
":",
"log",
".",
"info",
"(",
"\"removing %s\"",
"%",
"path",
")",
"if",
"dry_run",
":",
"return",
"try",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"path",
")",
"and",
"not",
... | Remove a file or directory tree.
Won't throw an exception, even if the removal fails. | [
"Remove",
"a",
"file",
"or",
"directory",
"tree",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/setup.py#L93-L108 | train |
crs4/pydoop | setup.py | BuildPydoopExt.__finalize_hdfs | def __finalize_hdfs(self, ext):
"""\
Adds a few bits that depend on the specific environment.
Delaying this until the build_ext phase allows non-build commands
(e.g., sdist) to be run without java.
"""
java_home = jvm.get_java_home()
jvm_lib_path, _ = jvm.get_jvm... | python | def __finalize_hdfs(self, ext):
"""\
Adds a few bits that depend on the specific environment.
Delaying this until the build_ext phase allows non-build commands
(e.g., sdist) to be run without java.
"""
java_home = jvm.get_java_home()
jvm_lib_path, _ = jvm.get_jvm... | [
"def",
"__finalize_hdfs",
"(",
"self",
",",
"ext",
")",
":",
"java_home",
"=",
"jvm",
".",
"get_java_home",
"(",
")",
"jvm_lib_path",
",",
"_",
"=",
"jvm",
".",
"get_jvm_lib_path_and_name",
"(",
"java_home",
")",
"ext",
".",
"include_dirs",
"=",
"jvm",
"."... | \
Adds a few bits that depend on the specific environment.
Delaying this until the build_ext phase allows non-build commands
(e.g., sdist) to be run without java. | [
"\\",
"Adds",
"a",
"few",
"bits",
"that",
"depend",
"on",
"the",
"specific",
"environment",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/setup.py#L286-L306 | train |
crs4/pydoop | pydoop/hadut.py | run_tool_cmd | def run_tool_cmd(tool, cmd, args=None, properties=None, hadoop_conf_dir=None,
logger=None, keep_streams=True):
"""
Run a Hadoop command.
If ``keep_streams`` is set to :obj:`True` (the default), the
stdout and stderr of the command will be buffered in memory. If
the command succeed... | python | def run_tool_cmd(tool, cmd, args=None, properties=None, hadoop_conf_dir=None,
logger=None, keep_streams=True):
"""
Run a Hadoop command.
If ``keep_streams`` is set to :obj:`True` (the default), the
stdout and stderr of the command will be buffered in memory. If
the command succeed... | [
"def",
"run_tool_cmd",
"(",
"tool",
",",
"cmd",
",",
"args",
"=",
"None",
",",
"properties",
"=",
"None",
",",
"hadoop_conf_dir",
"=",
"None",
",",
"logger",
"=",
"None",
",",
"keep_streams",
"=",
"True",
")",
":",
"if",
"logger",
"is",
"None",
":",
... | Run a Hadoop command.
If ``keep_streams`` is set to :obj:`True` (the default), the
stdout and stderr of the command will be buffered in memory. If
the command succeeds, the former will be returned; if it fails, a
``RunCmdError`` will be raised with the latter as the message.
This mode is appropria... | [
"Run",
"a",
"Hadoop",
"command",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L118-L175 | train |
crs4/pydoop | pydoop/hadut.py | get_task_trackers | def get_task_trackers(properties=None, hadoop_conf_dir=None, offline=False):
"""
Get the list of task trackers in the Hadoop cluster.
Each element in the returned list is in the ``(host, port)`` format.
All arguments are passed to :func:`run_class`.
If ``offline`` is :obj:`True`, try getting the l... | python | def get_task_trackers(properties=None, hadoop_conf_dir=None, offline=False):
"""
Get the list of task trackers in the Hadoop cluster.
Each element in the returned list is in the ``(host, port)`` format.
All arguments are passed to :func:`run_class`.
If ``offline`` is :obj:`True`, try getting the l... | [
"def",
"get_task_trackers",
"(",
"properties",
"=",
"None",
",",
"hadoop_conf_dir",
"=",
"None",
",",
"offline",
"=",
"False",
")",
":",
"if",
"offline",
":",
"if",
"not",
"hadoop_conf_dir",
":",
"hadoop_conf_dir",
"=",
"pydoop",
".",
"hadoop_conf",
"(",
")"... | Get the list of task trackers in the Hadoop cluster.
Each element in the returned list is in the ``(host, port)`` format.
All arguments are passed to :func:`run_class`.
If ``offline`` is :obj:`True`, try getting the list of task trackers from
the ``slaves`` file in Hadoop's configuration directory (no... | [
"Get",
"the",
"list",
"of",
"task",
"trackers",
"in",
"the",
"Hadoop",
"cluster",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L194-L227 | train |
crs4/pydoop | pydoop/hadut.py | get_num_nodes | def get_num_nodes(properties=None, hadoop_conf_dir=None, offline=False):
"""
Get the number of task trackers in the Hadoop cluster.
All arguments are passed to :func:`get_task_trackers`.
"""
return len(get_task_trackers(properties, hadoop_conf_dir, offline)) | python | def get_num_nodes(properties=None, hadoop_conf_dir=None, offline=False):
"""
Get the number of task trackers in the Hadoop cluster.
All arguments are passed to :func:`get_task_trackers`.
"""
return len(get_task_trackers(properties, hadoop_conf_dir, offline)) | [
"def",
"get_num_nodes",
"(",
"properties",
"=",
"None",
",",
"hadoop_conf_dir",
"=",
"None",
",",
"offline",
"=",
"False",
")",
":",
"return",
"len",
"(",
"get_task_trackers",
"(",
"properties",
",",
"hadoop_conf_dir",
",",
"offline",
")",
")"
] | Get the number of task trackers in the Hadoop cluster.
All arguments are passed to :func:`get_task_trackers`. | [
"Get",
"the",
"number",
"of",
"task",
"trackers",
"in",
"the",
"Hadoop",
"cluster",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L230-L236 | train |
crs4/pydoop | pydoop/hadut.py | dfs | def dfs(args=None, properties=None, hadoop_conf_dir=None):
"""
Run the Hadoop file system shell.
All arguments are passed to :func:`run_class`.
"""
# run FsShell directly (avoids "hadoop dfs" deprecation)
return run_class(
"org.apache.hadoop.fs.FsShell", args, properties,
hadoop... | python | def dfs(args=None, properties=None, hadoop_conf_dir=None):
"""
Run the Hadoop file system shell.
All arguments are passed to :func:`run_class`.
"""
# run FsShell directly (avoids "hadoop dfs" deprecation)
return run_class(
"org.apache.hadoop.fs.FsShell", args, properties,
hadoop... | [
"def",
"dfs",
"(",
"args",
"=",
"None",
",",
"properties",
"=",
"None",
",",
"hadoop_conf_dir",
"=",
"None",
")",
":",
"# run FsShell directly (avoids \"hadoop dfs\" deprecation)",
"return",
"run_class",
"(",
"\"org.apache.hadoop.fs.FsShell\"",
",",
"args",
",",
"prop... | Run the Hadoop file system shell.
All arguments are passed to :func:`run_class`. | [
"Run",
"the",
"Hadoop",
"file",
"system",
"shell",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L239-L249 | train |
crs4/pydoop | pydoop/hadut.py | run_pipes | def run_pipes(executable, input_path, output_path, more_args=None,
properties=None, force_pydoop_submitter=False,
hadoop_conf_dir=None, logger=None, keep_streams=False):
"""
Run a pipes command.
``more_args`` (after setting input/output path) and ``properties``
are passed to... | python | def run_pipes(executable, input_path, output_path, more_args=None,
properties=None, force_pydoop_submitter=False,
hadoop_conf_dir=None, logger=None, keep_streams=False):
"""
Run a pipes command.
``more_args`` (after setting input/output path) and ``properties``
are passed to... | [
"def",
"run_pipes",
"(",
"executable",
",",
"input_path",
",",
"output_path",
",",
"more_args",
"=",
"None",
",",
"properties",
"=",
"None",
",",
"force_pydoop_submitter",
"=",
"False",
",",
"hadoop_conf_dir",
"=",
"None",
",",
"logger",
"=",
"None",
",",
"k... | Run a pipes command.
``more_args`` (after setting input/output path) and ``properties``
are passed to :func:`run_cmd`.
If not specified otherwise, this function sets the properties
``mapreduce.pipes.isjavarecordreader`` and
``mapreduce.pipes.isjavarecordwriter`` to ``"true"``.
This function w... | [
"Run",
"a",
"pipes",
"command",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L338-L395 | train |
crs4/pydoop | pydoop/hadut.py | collect_output | def collect_output(mr_out_dir, out_file=None):
"""
Return all mapreduce output in ``mr_out_dir``.
Append the output to ``out_file`` if provided. Otherwise, return
the result as a single string (it is the caller's responsibility to
ensure that the amount of data retrieved fits into memory).
"""... | python | def collect_output(mr_out_dir, out_file=None):
"""
Return all mapreduce output in ``mr_out_dir``.
Append the output to ``out_file`` if provided. Otherwise, return
the result as a single string (it is the caller's responsibility to
ensure that the amount of data retrieved fits into memory).
"""... | [
"def",
"collect_output",
"(",
"mr_out_dir",
",",
"out_file",
"=",
"None",
")",
":",
"if",
"out_file",
"is",
"None",
":",
"output",
"=",
"[",
"]",
"for",
"fn",
"in",
"iter_mr_out_files",
"(",
"mr_out_dir",
")",
":",
"with",
"hdfs",
".",
"open",
"(",
"fn... | Return all mapreduce output in ``mr_out_dir``.
Append the output to ``out_file`` if provided. Otherwise, return
the result as a single string (it is the caller's responsibility to
ensure that the amount of data retrieved fits into memory). | [
"Return",
"all",
"mapreduce",
"output",
"in",
"mr_out_dir",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L425-L447 | train |
crs4/pydoop | pydoop/hadut.py | PipesRunner.set_output | def set_output(self, output):
"""
Set the output path for the job. Optional if the runner has been
instantiated with a prefix.
"""
self.output = output
self.logger.info("assigning output to %s", self.output) | python | def set_output(self, output):
"""
Set the output path for the job. Optional if the runner has been
instantiated with a prefix.
"""
self.output = output
self.logger.info("assigning output to %s", self.output) | [
"def",
"set_output",
"(",
"self",
",",
"output",
")",
":",
"self",
".",
"output",
"=",
"output",
"self",
".",
"logger",
".",
"info",
"(",
"\"assigning output to %s\"",
",",
"self",
".",
"output",
")"
] | Set the output path for the job. Optional if the runner has been
instantiated with a prefix. | [
"Set",
"the",
"output",
"path",
"for",
"the",
"job",
".",
"Optional",
"if",
"the",
"runner",
"has",
"been",
"instantiated",
"with",
"a",
"prefix",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L504-L510 | train |
crs4/pydoop | pydoop/hadut.py | PipesRunner.set_exe | def set_exe(self, pipes_code):
"""
Dump launcher code to the distributed file system.
"""
if not self.output:
raise RuntimeError("no output directory, can't create launcher")
parent = hdfs.path.dirname(hdfs.path.abspath(self.output.rstrip("/")))
self.exe = hdf... | python | def set_exe(self, pipes_code):
"""
Dump launcher code to the distributed file system.
"""
if not self.output:
raise RuntimeError("no output directory, can't create launcher")
parent = hdfs.path.dirname(hdfs.path.abspath(self.output.rstrip("/")))
self.exe = hdf... | [
"def",
"set_exe",
"(",
"self",
",",
"pipes_code",
")",
":",
"if",
"not",
"self",
".",
"output",
":",
"raise",
"RuntimeError",
"(",
"\"no output directory, can't create launcher\"",
")",
"parent",
"=",
"hdfs",
".",
"path",
".",
"dirname",
"(",
"hdfs",
".",
"p... | Dump launcher code to the distributed file system. | [
"Dump",
"launcher",
"code",
"to",
"the",
"distributed",
"file",
"system",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hadut.py#L512-L520 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | dump | def dump(data, hdfs_path, **kwargs):
"""\
Write ``data`` to ``hdfs_path``.
Keyword arguments are passed to :func:`open`, except for ``mode``,
which is forced to ``"w"`` (or ``"wt"`` for text data).
"""
kwargs["mode"] = "w" if isinstance(data, bintype) else "wt"
with open(hdfs_path, **kwargs... | python | def dump(data, hdfs_path, **kwargs):
"""\
Write ``data`` to ``hdfs_path``.
Keyword arguments are passed to :func:`open`, except for ``mode``,
which is forced to ``"w"`` (or ``"wt"`` for text data).
"""
kwargs["mode"] = "w" if isinstance(data, bintype) else "wt"
with open(hdfs_path, **kwargs... | [
"def",
"dump",
"(",
"data",
",",
"hdfs_path",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"\"mode\"",
"]",
"=",
"\"w\"",
"if",
"isinstance",
"(",
"data",
",",
"bintype",
")",
"else",
"\"wt\"",
"with",
"open",
"(",
"hdfs_path",
",",
"*",
"*",
... | \
Write ``data`` to ``hdfs_path``.
Keyword arguments are passed to :func:`open`, except for ``mode``,
which is forced to ``"w"`` (or ``"wt"`` for text data). | [
"\\",
"Write",
"data",
"to",
"hdfs_path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L129-L143 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | load | def load(hdfs_path, **kwargs):
"""\
Read the content of ``hdfs_path`` and return it.
Keyword arguments are passed to :func:`open`. The `"mode"` kwarg
must be readonly.
"""
m, _ = common.parse_mode(kwargs.get("mode", "r"))
if m != "r":
raise ValueError("opening mode must be readonly"... | python | def load(hdfs_path, **kwargs):
"""\
Read the content of ``hdfs_path`` and return it.
Keyword arguments are passed to :func:`open`. The `"mode"` kwarg
must be readonly.
"""
m, _ = common.parse_mode(kwargs.get("mode", "r"))
if m != "r":
raise ValueError("opening mode must be readonly"... | [
"def",
"load",
"(",
"hdfs_path",
",",
"*",
"*",
"kwargs",
")",
":",
"m",
",",
"_",
"=",
"common",
".",
"parse_mode",
"(",
"kwargs",
".",
"get",
"(",
"\"mode\"",
",",
"\"r\"",
")",
")",
"if",
"m",
"!=",
"\"r\"",
":",
"raise",
"ValueError",
"(",
"\... | \
Read the content of ``hdfs_path`` and return it.
Keyword arguments are passed to :func:`open`. The `"mode"` kwarg
must be readonly. | [
"\\",
"Read",
"the",
"content",
"of",
"hdfs_path",
"and",
"return",
"it",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L146-L159 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | cp | def cp(src_hdfs_path, dest_hdfs_path, **kwargs):
"""\
Copy the contents of ``src_hdfs_path`` to ``dest_hdfs_path``.
If ``src_hdfs_path`` is a directory, its contents will be copied
recursively. Source file(s) are opened for reading and copies are
opened for writing. Additional keyword arguments, if... | python | def cp(src_hdfs_path, dest_hdfs_path, **kwargs):
"""\
Copy the contents of ``src_hdfs_path`` to ``dest_hdfs_path``.
If ``src_hdfs_path`` is a directory, its contents will be copied
recursively. Source file(s) are opened for reading and copies are
opened for writing. Additional keyword arguments, if... | [
"def",
"cp",
"(",
"src_hdfs_path",
",",
"dest_hdfs_path",
",",
"*",
"*",
"kwargs",
")",
":",
"src",
",",
"dest",
"=",
"{",
"}",
",",
"{",
"}",
"try",
":",
"for",
"d",
",",
"p",
"in",
"(",
"(",
"src",
",",
"src_hdfs_path",
")",
",",
"(",
"dest",... | \
Copy the contents of ``src_hdfs_path`` to ``dest_hdfs_path``.
If ``src_hdfs_path`` is a directory, its contents will be copied
recursively. Source file(s) are opened for reading and copies are
opened for writing. Additional keyword arguments, if any, are
handled like in :func:`open`. | [
"\\",
"Copy",
"the",
"contents",
"of",
"src_hdfs_path",
"to",
"dest_hdfs_path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L177-L230 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | put | def put(src_path, dest_hdfs_path, **kwargs):
"""\
Copy the contents of ``src_path`` to ``dest_hdfs_path``.
``src_path`` is forced to be interpreted as an ordinary local path
(see :func:`~path.abspath`). The source file is opened for reading
and the copy is opened for writing. Additional keyword arg... | python | def put(src_path, dest_hdfs_path, **kwargs):
"""\
Copy the contents of ``src_path`` to ``dest_hdfs_path``.
``src_path`` is forced to be interpreted as an ordinary local path
(see :func:`~path.abspath`). The source file is opened for reading
and the copy is opened for writing. Additional keyword arg... | [
"def",
"put",
"(",
"src_path",
",",
"dest_hdfs_path",
",",
"*",
"*",
"kwargs",
")",
":",
"cp",
"(",
"path",
".",
"abspath",
"(",
"src_path",
",",
"local",
"=",
"True",
")",
",",
"dest_hdfs_path",
",",
"*",
"*",
"kwargs",
")"
] | \
Copy the contents of ``src_path`` to ``dest_hdfs_path``.
``src_path`` is forced to be interpreted as an ordinary local path
(see :func:`~path.abspath`). The source file is opened for reading
and the copy is opened for writing. Additional keyword arguments,
if any, are handled like in :func:`open`... | [
"\\",
"Copy",
"the",
"contents",
"of",
"src_path",
"to",
"dest_hdfs_path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L233-L242 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | get | def get(src_hdfs_path, dest_path, **kwargs):
"""\
Copy the contents of ``src_hdfs_path`` to ``dest_path``.
``dest_path`` is forced to be interpreted as an ordinary local
path (see :func:`~path.abspath`). The source file is opened for
reading and the copy is opened for writing. Additional keyword
... | python | def get(src_hdfs_path, dest_path, **kwargs):
"""\
Copy the contents of ``src_hdfs_path`` to ``dest_path``.
``dest_path`` is forced to be interpreted as an ordinary local
path (see :func:`~path.abspath`). The source file is opened for
reading and the copy is opened for writing. Additional keyword
... | [
"def",
"get",
"(",
"src_hdfs_path",
",",
"dest_path",
",",
"*",
"*",
"kwargs",
")",
":",
"cp",
"(",
"src_hdfs_path",
",",
"path",
".",
"abspath",
"(",
"dest_path",
",",
"local",
"=",
"True",
")",
",",
"*",
"*",
"kwargs",
")"
] | \
Copy the contents of ``src_hdfs_path`` to ``dest_path``.
``dest_path`` is forced to be interpreted as an ordinary local
path (see :func:`~path.abspath`). The source file is opened for
reading and the copy is opened for writing. Additional keyword
arguments, if any, are handled like in :func:`open... | [
"\\",
"Copy",
"the",
"contents",
"of",
"src_hdfs_path",
"to",
"dest_path",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L245-L254 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | mkdir | def mkdir(hdfs_path, user=None):
"""
Create a directory and its parents as needed.
"""
host, port, path_ = path.split(hdfs_path, user)
fs = hdfs(host, port, user)
retval = fs.create_directory(path_)
fs.close()
return retval | python | def mkdir(hdfs_path, user=None):
"""
Create a directory and its parents as needed.
"""
host, port, path_ = path.split(hdfs_path, user)
fs = hdfs(host, port, user)
retval = fs.create_directory(path_)
fs.close()
return retval | [
"def",
"mkdir",
"(",
"hdfs_path",
",",
"user",
"=",
"None",
")",
":",
"host",
",",
"port",
",",
"path_",
"=",
"path",
".",
"split",
"(",
"hdfs_path",
",",
"user",
")",
"fs",
"=",
"hdfs",
"(",
"host",
",",
"port",
",",
"user",
")",
"retval",
"=",
... | Create a directory and its parents as needed. | [
"Create",
"a",
"directory",
"and",
"its",
"parents",
"as",
"needed",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L257-L265 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | lsl | def lsl(hdfs_path, user=None, recursive=False):
"""
Return a list of dictionaries of file properties.
If ``hdfs_path`` is a file, there is only one item corresponding to
the file itself; if it is a directory and ``recursive`` is
:obj:`False`, each list item corresponds to a file or directory
co... | python | def lsl(hdfs_path, user=None, recursive=False):
"""
Return a list of dictionaries of file properties.
If ``hdfs_path`` is a file, there is only one item corresponding to
the file itself; if it is a directory and ``recursive`` is
:obj:`False`, each list item corresponds to a file or directory
co... | [
"def",
"lsl",
"(",
"hdfs_path",
",",
"user",
"=",
"None",
",",
"recursive",
"=",
"False",
")",
":",
"host",
",",
"port",
",",
"path_",
"=",
"path",
".",
"split",
"(",
"hdfs_path",
",",
"user",
")",
"fs",
"=",
"hdfs",
"(",
"host",
",",
"port",
","... | Return a list of dictionaries of file properties.
If ``hdfs_path`` is a file, there is only one item corresponding to
the file itself; if it is a directory and ``recursive`` is
:obj:`False`, each list item corresponds to a file or directory
contained by it; if it is a directory and ``recursive`` is
... | [
"Return",
"a",
"list",
"of",
"dictionaries",
"of",
"file",
"properties",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L287-L310 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | ls | def ls(hdfs_path, user=None, recursive=False):
"""
Return a list of hdfs paths.
Works in the same way as :func:`lsl`, except for the fact that list
items are hdfs paths instead of dictionaries of properties.
"""
dir_list = lsl(hdfs_path, user, recursive)
return [d["name"] for d in dir_list] | python | def ls(hdfs_path, user=None, recursive=False):
"""
Return a list of hdfs paths.
Works in the same way as :func:`lsl`, except for the fact that list
items are hdfs paths instead of dictionaries of properties.
"""
dir_list = lsl(hdfs_path, user, recursive)
return [d["name"] for d in dir_list] | [
"def",
"ls",
"(",
"hdfs_path",
",",
"user",
"=",
"None",
",",
"recursive",
"=",
"False",
")",
":",
"dir_list",
"=",
"lsl",
"(",
"hdfs_path",
",",
"user",
",",
"recursive",
")",
"return",
"[",
"d",
"[",
"\"name\"",
"]",
"for",
"d",
"in",
"dir_list",
... | Return a list of hdfs paths.
Works in the same way as :func:`lsl`, except for the fact that list
items are hdfs paths instead of dictionaries of properties. | [
"Return",
"a",
"list",
"of",
"hdfs",
"paths",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L313-L321 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | move | def move(src, dest, user=None):
"""
Move or rename src to dest.
"""
src_host, src_port, src_path = path.split(src, user)
dest_host, dest_port, dest_path = path.split(dest, user)
src_fs = hdfs(src_host, src_port, user)
dest_fs = hdfs(dest_host, dest_port, user)
try:
retval = src_f... | python | def move(src, dest, user=None):
"""
Move or rename src to dest.
"""
src_host, src_port, src_path = path.split(src, user)
dest_host, dest_port, dest_path = path.split(dest, user)
src_fs = hdfs(src_host, src_port, user)
dest_fs = hdfs(dest_host, dest_port, user)
try:
retval = src_f... | [
"def",
"move",
"(",
"src",
",",
"dest",
",",
"user",
"=",
"None",
")",
":",
"src_host",
",",
"src_port",
",",
"src_path",
"=",
"path",
".",
"split",
"(",
"src",
",",
"user",
")",
"dest_host",
",",
"dest_port",
",",
"dest_path",
"=",
"path",
".",
"s... | Move or rename src to dest. | [
"Move",
"or",
"rename",
"src",
"to",
"dest",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L340-L353 | train |
crs4/pydoop | pydoop/hdfs/__init__.py | renames | def renames(from_path, to_path, user=None):
"""
Rename ``from_path`` to ``to_path``, creating parents as needed.
"""
to_dir = path.dirname(to_path)
if to_dir:
mkdir(to_dir, user=user)
rename(from_path, to_path, user=user) | python | def renames(from_path, to_path, user=None):
"""
Rename ``from_path`` to ``to_path``, creating parents as needed.
"""
to_dir = path.dirname(to_path)
if to_dir:
mkdir(to_dir, user=user)
rename(from_path, to_path, user=user) | [
"def",
"renames",
"(",
"from_path",
",",
"to_path",
",",
"user",
"=",
"None",
")",
":",
"to_dir",
"=",
"path",
".",
"dirname",
"(",
"to_path",
")",
"if",
"to_dir",
":",
"mkdir",
"(",
"to_dir",
",",
"user",
"=",
"user",
")",
"rename",
"(",
"from_path"... | Rename ``from_path`` to ``to_path``, creating parents as needed. | [
"Rename",
"from_path",
"to",
"to_path",
"creating",
"parents",
"as",
"needed",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/__init__.py#L381-L388 | train |
crs4/pydoop | pydoop/hdfs/file.py | FileIO.readline | def readline(self):
"""
Read and return a line of text.
:rtype: str
:return: the next line of text in the file, including the
newline character
"""
_complain_ifclosed(self.closed)
line = self.f.readline()
if self.__encoding:
return l... | python | def readline(self):
"""
Read and return a line of text.
:rtype: str
:return: the next line of text in the file, including the
newline character
"""
_complain_ifclosed(self.closed)
line = self.f.readline()
if self.__encoding:
return l... | [
"def",
"readline",
"(",
"self",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"line",
"=",
"self",
".",
"f",
".",
"readline",
"(",
")",
"if",
"self",
".",
"__encoding",
":",
"return",
"line",
".",
"decode",
"(",
"self",
".",
"__enc... | Read and return a line of text.
:rtype: str
:return: the next line of text in the file, including the
newline character | [
"Read",
"and",
"return",
"a",
"line",
"of",
"text",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/file.py#L107-L120 | train |
crs4/pydoop | pydoop/hdfs/file.py | FileIO.pread | def pread(self, position, length):
r"""
Read ``length`` bytes of data from the file, starting from
``position``\ .
:type position: int
:param position: position from which to read
:type length: int
:param length: the number of bytes to read
:rtype: string... | python | def pread(self, position, length):
r"""
Read ``length`` bytes of data from the file, starting from
``position``\ .
:type position: int
:param position: position from which to read
:type length: int
:param length: the number of bytes to read
:rtype: string... | [
"def",
"pread",
"(",
"self",
",",
"position",
",",
"length",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"if",
"position",
">",
"self",
".",
"size",
":",
"raise",
"IOError",
"(",
"\"position cannot be past EOF\"",
")",
"if",
"length",
... | r"""
Read ``length`` bytes of data from the file, starting from
``position``\ .
:type position: int
:param position: position from which to read
:type length: int
:param length: the number of bytes to read
:rtype: string
:return: the chunk of data read fr... | [
"r",
"Read",
"length",
"bytes",
"of",
"data",
"from",
"the",
"file",
"starting",
"from",
"position",
"\\",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/file.py#L165-L186 | train |
crs4/pydoop | pydoop/hdfs/file.py | FileIO.read | def read(self, length=-1):
"""
Read ``length`` bytes from the file. If ``length`` is negative or
omitted, read all data until EOF.
:type length: int
:param length: the number of bytes to read
:rtype: string
:return: the chunk of data read from the file
"... | python | def read(self, length=-1):
"""
Read ``length`` bytes from the file. If ``length`` is negative or
omitted, read all data until EOF.
:type length: int
:param length: the number of bytes to read
:rtype: string
:return: the chunk of data read from the file
"... | [
"def",
"read",
"(",
"self",
",",
"length",
"=",
"-",
"1",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"# NOTE: libhdfs read stops at block boundaries: it is *essential*",
"# to ensure that we actually read the required number of bytes.",
"if",
"length",
... | Read ``length`` bytes from the file. If ``length`` is negative or
omitted, read all data until EOF.
:type length: int
:param length: the number of bytes to read
:rtype: string
:return: the chunk of data read from the file | [
"Read",
"length",
"bytes",
"from",
"the",
"file",
".",
"If",
"length",
"is",
"negative",
"or",
"omitted",
"read",
"all",
"data",
"until",
"EOF",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/file.py#L188-L216 | train |
crs4/pydoop | pydoop/hdfs/file.py | FileIO.seek | def seek(self, position, whence=os.SEEK_SET):
"""
Seek to ``position`` in file.
:type position: int
:param position: offset in bytes to seek to
:type whence: int
:param whence: defaults to ``os.SEEK_SET`` (absolute); other
values are ``os.SEEK_CUR`` (relative t... | python | def seek(self, position, whence=os.SEEK_SET):
"""
Seek to ``position`` in file.
:type position: int
:param position: offset in bytes to seek to
:type whence: int
:param whence: defaults to ``os.SEEK_SET`` (absolute); other
values are ``os.SEEK_CUR`` (relative t... | [
"def",
"seek",
"(",
"self",
",",
"position",
",",
"whence",
"=",
"os",
".",
"SEEK_SET",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"return",
"self",
".",
"f",
".",
"seek",
"(",
"position",
",",
"whence",
")"
] | Seek to ``position`` in file.
:type position: int
:param position: offset in bytes to seek to
:type whence: int
:param whence: defaults to ``os.SEEK_SET`` (absolute); other
values are ``os.SEEK_CUR`` (relative to the current position)
and ``os.SEEK_END`` (relative to... | [
"Seek",
"to",
"position",
"in",
"file",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/file.py#L218-L230 | train |
crs4/pydoop | pydoop/hdfs/file.py | FileIO.write | def write(self, data):
"""
Write ``data`` to the file.
:type data: bytes
:param data: the data to be written to the file
:rtype: int
:return: the number of bytes written
"""
_complain_ifclosed(self.closed)
if self.__encoding:
self.f.wr... | python | def write(self, data):
"""
Write ``data`` to the file.
:type data: bytes
:param data: the data to be written to the file
:rtype: int
:return: the number of bytes written
"""
_complain_ifclosed(self.closed)
if self.__encoding:
self.f.wr... | [
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"_complain_ifclosed",
"(",
"self",
".",
"closed",
")",
"if",
"self",
".",
"__encoding",
":",
"self",
".",
"f",
".",
"write",
"(",
"data",
".",
"encode",
"(",
"self",
".",
"__encoding",
",",
"self",
... | Write ``data`` to the file.
:type data: bytes
:param data: the data to be written to the file
:rtype: int
:return: the number of bytes written | [
"Write",
"data",
"to",
"the",
"file",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/hdfs/file.py#L242-L256 | train |
crs4/pydoop | pydoop/app/submit.py | PydoopSubmitter.set_args | def set_args(self, args, unknown_args=None):
"""
Configure job, based on the arguments provided.
"""
if unknown_args is None:
unknown_args = []
self.logger.setLevel(getattr(logging, args.log_level))
parent = hdfs.path.dirname(hdfs.path.abspath(args.output.rst... | python | def set_args(self, args, unknown_args=None):
"""
Configure job, based on the arguments provided.
"""
if unknown_args is None:
unknown_args = []
self.logger.setLevel(getattr(logging, args.log_level))
parent = hdfs.path.dirname(hdfs.path.abspath(args.output.rst... | [
"def",
"set_args",
"(",
"self",
",",
"args",
",",
"unknown_args",
"=",
"None",
")",
":",
"if",
"unknown_args",
"is",
"None",
":",
"unknown_args",
"=",
"[",
"]",
"self",
".",
"logger",
".",
"setLevel",
"(",
"getattr",
"(",
"logging",
",",
"args",
".",
... | Configure job, based on the arguments provided. | [
"Configure",
"job",
"based",
"on",
"the",
"arguments",
"provided",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/app/submit.py#L136-L164 | train |
crs4/pydoop | pydoop/app/submit.py | PydoopSubmitter.__warn_user_if_wd_maybe_unreadable | def __warn_user_if_wd_maybe_unreadable(self, abs_remote_path):
"""
Check directories above the remote module and issue a warning if
they are not traversable by all users.
The reasoning behind this is mainly aimed at set-ups with a
centralized Hadoop cluster, accessed by all user... | python | def __warn_user_if_wd_maybe_unreadable(self, abs_remote_path):
"""
Check directories above the remote module and issue a warning if
they are not traversable by all users.
The reasoning behind this is mainly aimed at set-ups with a
centralized Hadoop cluster, accessed by all user... | [
"def",
"__warn_user_if_wd_maybe_unreadable",
"(",
"self",
",",
"abs_remote_path",
")",
":",
"host",
",",
"port",
",",
"path",
"=",
"hdfs",
".",
"path",
".",
"split",
"(",
"abs_remote_path",
")",
"if",
"host",
"==",
"''",
"and",
"port",
"==",
"0",
":",
"#... | Check directories above the remote module and issue a warning if
they are not traversable by all users.
The reasoning behind this is mainly aimed at set-ups with a
centralized Hadoop cluster, accessed by all users, and where
the Hadoop task tracker user is not a superuser; an example
... | [
"Check",
"directories",
"above",
"the",
"remote",
"module",
"and",
"issue",
"a",
"warning",
"if",
"they",
"are",
"not",
"traversable",
"by",
"all",
"users",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/app/submit.py#L166-L202 | train |
crs4/pydoop | pydoop/app/submit.py | PydoopSubmitter.__setup_remote_paths | def __setup_remote_paths(self):
"""
Actually create the working directory and copy the module into it.
Note: the script has to be readable by Hadoop; though this may not
generally be a problem on HDFS, where the Hadoop user is usually
the superuser, things may be different if ou... | python | def __setup_remote_paths(self):
"""
Actually create the working directory and copy the module into it.
Note: the script has to be readable by Hadoop; though this may not
generally be a problem on HDFS, where the Hadoop user is usually
the superuser, things may be different if ou... | [
"def",
"__setup_remote_paths",
"(",
"self",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"\"remote_wd: %s\"",
",",
"self",
".",
"remote_wd",
")",
"self",
".",
"logger",
".",
"debug",
"(",
"\"remote_exe: %s\"",
",",
"self",
".",
"remote_exe",
")",
"s... | Actually create the working directory and copy the module into it.
Note: the script has to be readable by Hadoop; though this may not
generally be a problem on HDFS, where the Hadoop user is usually
the superuser, things may be different if our working directory is
on a shared POSIX fil... | [
"Actually",
"create",
"the",
"working",
"directory",
"and",
"copy",
"the",
"module",
"into",
"it",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/app/submit.py#L295-L325 | train |
crs4/pydoop | dev_tools/docker/scripts/share_etc_hosts.py | docker_client | def docker_client():
"""
Returns a docker-py client configured using environment variables
according to the same logic as the official Docker client.
"""
cert_path = os.environ.get('DOCKER_CERT_PATH', '')
if cert_path == '':
cert_path = os.path.join(os.environ.get('HOME', ''), '.docker')... | python | def docker_client():
"""
Returns a docker-py client configured using environment variables
according to the same logic as the official Docker client.
"""
cert_path = os.environ.get('DOCKER_CERT_PATH', '')
if cert_path == '':
cert_path = os.path.join(os.environ.get('HOME', ''), '.docker')... | [
"def",
"docker_client",
"(",
")",
":",
"cert_path",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"'DOCKER_CERT_PATH'",
",",
"''",
")",
"if",
"cert_path",
"==",
"''",
":",
"cert_path",
"=",
"os",
".",
"path",
".",
"join",
"(",
"os",
".",
"environ",
"."... | Returns a docker-py client configured using environment variables
according to the same logic as the official Docker client. | [
"Returns",
"a",
"docker",
"-",
"py",
"client",
"configured",
"using",
"environment",
"variables",
"according",
"to",
"the",
"same",
"logic",
"as",
"the",
"official",
"Docker",
"client",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/dev_tools/docker/scripts/share_etc_hosts.py#L44-L75 | train |
crs4/pydoop | pydoop/utils/jvm.py | get_java_home | def get_java_home():
"""\
Try getting JAVA_HOME from system properties.
We are interested in the JDK home, containing include/jni.h, while the
java.home property points to the JRE home. If a JDK is installed, however,
the two are (usually) related: the JDK home is either the same directory
as t... | python | def get_java_home():
"""\
Try getting JAVA_HOME from system properties.
We are interested in the JDK home, containing include/jni.h, while the
java.home property points to the JRE home. If a JDK is installed, however,
the two are (usually) related: the JDK home is either the same directory
as t... | [
"def",
"get_java_home",
"(",
")",
":",
"error",
"=",
"RuntimeError",
"(",
"\"java home not found, try setting JAVA_HOME\"",
")",
"try",
":",
"return",
"os",
".",
"environ",
"[",
"\"JAVA_HOME\"",
"]",
"except",
"KeyError",
":",
"wd",
"=",
"tempfile",
".",
"mkdtem... | \
Try getting JAVA_HOME from system properties.
We are interested in the JDK home, containing include/jni.h, while the
java.home property points to the JRE home. If a JDK is installed, however,
the two are (usually) related: the JDK home is either the same directory
as the JRE home (recent java ver... | [
"\\",
"Try",
"getting",
"JAVA_HOME",
"from",
"system",
"properties",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/utils/jvm.py#L37-L71 | train |
crs4/pydoop | pydoop/mapreduce/pipes.py | run_task | def run_task(factory, **kwargs):
"""\
Run a MapReduce task.
Available keyword arguments:
* ``raw_keys`` (default: :obj:`False`): pass map input keys to context
as byte strings (ignore any type information)
* ``raw_values`` (default: :obj:`False`): pass map input values to context
as by... | python | def run_task(factory, **kwargs):
"""\
Run a MapReduce task.
Available keyword arguments:
* ``raw_keys`` (default: :obj:`False`): pass map input keys to context
as byte strings (ignore any type information)
* ``raw_values`` (default: :obj:`False`): pass map input values to context
as by... | [
"def",
"run_task",
"(",
"factory",
",",
"*",
"*",
"kwargs",
")",
":",
"context",
"=",
"TaskContext",
"(",
"factory",
",",
"*",
"*",
"kwargs",
")",
"pstats_dir",
"=",
"kwargs",
".",
"get",
"(",
"\"pstats_dir\"",
",",
"os",
".",
"getenv",
"(",
"PSTATS_DI... | \
Run a MapReduce task.
Available keyword arguments:
* ``raw_keys`` (default: :obj:`False`): pass map input keys to context
as byte strings (ignore any type information)
* ``raw_values`` (default: :obj:`False`): pass map input values to context
as byte strings (ignore any type information)... | [
"\\",
"Run",
"a",
"MapReduce",
"task",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/mapreduce/pipes.py#L414-L462 | train |
crs4/pydoop | pydoop/mapreduce/pipes.py | TaskContext.progress | def progress(self):
"""\
Report progress to the Java side.
This needs to flush the uplink stream, but too many flushes can
disrupt performance, so we actually talk to upstream once per second.
"""
now = time()
if now - self.last_progress_t > 1:
self.l... | python | def progress(self):
"""\
Report progress to the Java side.
This needs to flush the uplink stream, but too many flushes can
disrupt performance, so we actually talk to upstream once per second.
"""
now = time()
if now - self.last_progress_t > 1:
self.l... | [
"def",
"progress",
"(",
"self",
")",
":",
"now",
"=",
"time",
"(",
")",
"if",
"now",
"-",
"self",
".",
"last_progress_t",
">",
"1",
":",
"self",
".",
"last_progress_t",
"=",
"now",
"if",
"self",
".",
"status",
":",
"self",
".",
"uplink",
".",
"stat... | \
Report progress to the Java side.
This needs to flush the uplink stream, but too many flushes can
disrupt performance, so we actually talk to upstream once per second. | [
"\\",
"Report",
"progress",
"to",
"the",
"Java",
"side",
"."
] | f375be2a06f9c67eaae3ce6f605195dbca143b2b | https://github.com/crs4/pydoop/blob/f375be2a06f9c67eaae3ce6f605195dbca143b2b/pydoop/mapreduce/pipes.py#L210-L225 | train |
Bouke/docx-mailmerge | mailmerge.py | MailMerge.merge_pages | def merge_pages(self, replacements):
"""
Deprecated method.
"""
warnings.warn("merge_pages has been deprecated in favour of merge_templates",
category=DeprecationWarning,
stacklevel=2)
self.merge_templates(replacements, "p... | python | def merge_pages(self, replacements):
"""
Deprecated method.
"""
warnings.warn("merge_pages has been deprecated in favour of merge_templates",
category=DeprecationWarning,
stacklevel=2)
self.merge_templates(replacements, "p... | [
"def",
"merge_pages",
"(",
"self",
",",
"replacements",
")",
":",
"warnings",
".",
"warn",
"(",
"\"merge_pages has been deprecated in favour of merge_templates\"",
",",
"category",
"=",
"DeprecationWarning",
",",
"stacklevel",
"=",
"2",
")",
"self",
".",
"merge_templa... | Deprecated method. | [
"Deprecated",
"method",
"."
] | 6900b686794b4bf85b662488add8df0880114b99 | https://github.com/Bouke/docx-mailmerge/blob/6900b686794b4bf85b662488add8df0880114b99/mailmerge.py#L236-L243 | train |
bashu/django-easy-maps | easy_maps/utils.py | importpath | def importpath(path, error_text=None):
"""
Import value by specified ``path``.
Value can represent module, class, object, attribute or method.
If ``error_text`` is not None and import will
raise ImproperlyConfigured with user friendly text.
"""
result = None
attrs = []
parts = path.... | python | def importpath(path, error_text=None):
"""
Import value by specified ``path``.
Value can represent module, class, object, attribute or method.
If ``error_text`` is not None and import will
raise ImproperlyConfigured with user friendly text.
"""
result = None
attrs = []
parts = path.... | [
"def",
"importpath",
"(",
"path",
",",
"error_text",
"=",
"None",
")",
":",
"result",
"=",
"None",
"attrs",
"=",
"[",
"]",
"parts",
"=",
"path",
".",
"split",
"(",
"'.'",
")",
"exception",
"=",
"None",
"while",
"parts",
":",
"try",
":",
"result",
"... | Import value by specified ``path``.
Value can represent module, class, object, attribute or method.
If ``error_text`` is not None and import will
raise ImproperlyConfigured with user friendly text. | [
"Import",
"value",
"by",
"specified",
"path",
".",
"Value",
"can",
"represent",
"module",
"class",
"object",
"attribute",
"or",
"method",
".",
"If",
"error_text",
"is",
"not",
"None",
"and",
"import",
"will",
"raise",
"ImproperlyConfigured",
"with",
"user",
"f... | 32f4f3274443219e8828d93d09a406bf2a126982 | https://github.com/bashu/django-easy-maps/blob/32f4f3274443219e8828d93d09a406bf2a126982/easy_maps/utils.py#L6-L37 | train |
bitlabstudio/django-booking | booking/utils.py | get_booking | def get_booking(request):
"""
Returns the booking that is in progress for the current user or None
We assume that a user can only have one booking that is in-progress.
TODO: This implementation assumes that there is a status called
'inprogress' and that there should only be one such booking for a ... | python | def get_booking(request):
"""
Returns the booking that is in progress for the current user or None
We assume that a user can only have one booking that is in-progress.
TODO: This implementation assumes that there is a status called
'inprogress' and that there should only be one such booking for a ... | [
"def",
"get_booking",
"(",
"request",
")",
":",
"booking",
"=",
"None",
"if",
"request",
".",
"user",
".",
"is_authenticated",
"(",
")",
":",
"try",
":",
"booking",
"=",
"Booking",
".",
"objects",
".",
"get",
"(",
"user",
"=",
"request",
".",
"user",
... | Returns the booking that is in progress for the current user or None
We assume that a user can only have one booking that is in-progress.
TODO: This implementation assumes that there is a status called
'inprogress' and that there should only be one such booking for a given
user. We need to see if this... | [
"Returns",
"the",
"booking",
"that",
"is",
"in",
"progress",
"for",
"the",
"current",
"user",
"or",
"None"
] | 7bb5fdddb28b52b62b86f1d05b19a7654b5ffe00 | https://github.com/bitlabstudio/django-booking/blob/7bb5fdddb28b52b62b86f1d05b19a7654b5ffe00/booking/utils.py#L7-L37 | train |
bitlabstudio/django-booking | booking/utils.py | persist_booking | def persist_booking(booking, user):
"""
Ties an in-progress booking from a session to a user when the user logs in.
If we don't do this, the booking will be lost, because on a login, the
old session will be deleted and a new one will be created. Since the
booking has a FK to the session, it would b... | python | def persist_booking(booking, user):
"""
Ties an in-progress booking from a session to a user when the user logs in.
If we don't do this, the booking will be lost, because on a login, the
old session will be deleted and a new one will be created. Since the
booking has a FK to the session, it would b... | [
"def",
"persist_booking",
"(",
"booking",
",",
"user",
")",
":",
"if",
"booking",
"is",
"not",
"None",
":",
"existing_bookings",
"=",
"Booking",
".",
"objects",
".",
"filter",
"(",
"user",
"=",
"user",
",",
"booking_status__slug",
"=",
"'inprogress'",
")",
... | Ties an in-progress booking from a session to a user when the user logs in.
If we don't do this, the booking will be lost, because on a login, the
old session will be deleted and a new one will be created. Since the
booking has a FK to the session, it would be deleted as well when the user
logs in.
... | [
"Ties",
"an",
"in",
"-",
"progress",
"booking",
"from",
"a",
"session",
"to",
"a",
"user",
"when",
"the",
"user",
"logs",
"in",
"."
] | 7bb5fdddb28b52b62b86f1d05b19a7654b5ffe00 | https://github.com/bitlabstudio/django-booking/blob/7bb5fdddb28b52b62b86f1d05b19a7654b5ffe00/booking/utils.py#L40-L68 | train |
spotify/pyfg | pyFG/forticonfig.py | FortiConfig.compare_config | def compare_config(self, target, init=True, indent_level=0):
"""
This method will return all the necessary commands to get from the config we are in to the target
config.
Args:
* **target** (:class:`~pyFG.forticonfig.FortiConfig`) - Target config.
* **init** (boo... | python | def compare_config(self, target, init=True, indent_level=0):
"""
This method will return all the necessary commands to get from the config we are in to the target
config.
Args:
* **target** (:class:`~pyFG.forticonfig.FortiConfig`) - Target config.
* **init** (boo... | [
"def",
"compare_config",
"(",
"self",
",",
"target",
",",
"init",
"=",
"True",
",",
"indent_level",
"=",
"0",
")",
":",
"if",
"init",
":",
"fwd",
"=",
"self",
".",
"full_path_fwd",
"bwd",
"=",
"self",
".",
"full_path_bwd",
"else",
":",
"fwd",
"=",
"s... | This method will return all the necessary commands to get from the config we are in to the target
config.
Args:
* **target** (:class:`~pyFG.forticonfig.FortiConfig`) - Target config.
* **init** (bool) - This tells to the method if this is the first call to the method or if we ar... | [
"This",
"method",
"will",
"return",
"all",
"the",
"necessary",
"commands",
"to",
"get",
"from",
"the",
"config",
"we",
"are",
"in",
"to",
"the",
"target",
"config",
"."
] | 518668539146e7f998a37d75994a4278adf79897 | https://github.com/spotify/pyfg/blob/518668539146e7f998a37d75994a4278adf79897/pyFG/forticonfig.py#L103-L173 | train |
spotify/pyfg | pyFG/forticonfig.py | FortiConfig.to_text | def to_text(self, relative=False, indent_level=0, clean_empty_block=False):
"""
This method returns the object model in text format. You should be able to copy&paste this text into any
device running a supported version of FortiOS.
Args:
- **relative** (bool):
... | python | def to_text(self, relative=False, indent_level=0, clean_empty_block=False):
"""
This method returns the object model in text format. You should be able to copy&paste this text into any
device running a supported version of FortiOS.
Args:
- **relative** (bool):
... | [
"def",
"to_text",
"(",
"self",
",",
"relative",
"=",
"False",
",",
"indent_level",
"=",
"0",
",",
"clean_empty_block",
"=",
"False",
")",
":",
"if",
"relative",
":",
"fwd",
"=",
"self",
".",
"rel_path_fwd",
"bwd",
"=",
"self",
".",
"rel_path_bwd",
"else"... | This method returns the object model in text format. You should be able to copy&paste this text into any
device running a supported version of FortiOS.
Args:
- **relative** (bool):
* If ``True`` the text returned will assume that you are one block away
* If ... | [
"This",
"method",
"returns",
"the",
"object",
"model",
"in",
"text",
"format",
".",
"You",
"should",
"be",
"able",
"to",
"copy&paste",
"this",
"text",
"into",
"any",
"device",
"running",
"a",
"supported",
"version",
"of",
"FortiOS",
"."
] | 518668539146e7f998a37d75994a4278adf79897 | https://github.com/spotify/pyfg/blob/518668539146e7f998a37d75994a4278adf79897/pyFG/forticonfig.py#L305-L341 | train |
spotify/pyfg | pyFG/fortios.py | FortiOS.open | def open(self):
"""
Opens the ssh session with the device.
"""
logger.debug('Connecting to device %s, vdom %s' % (self.hostname, self.vdom))
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
cfg = {
'host... | python | def open(self):
"""
Opens the ssh session with the device.
"""
logger.debug('Connecting to device %s, vdom %s' % (self.hostname, self.vdom))
self.ssh = paramiko.SSHClient()
self.ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
cfg = {
'host... | [
"def",
"open",
"(",
"self",
")",
":",
"logger",
".",
"debug",
"(",
"'Connecting to device %s, vdom %s'",
"%",
"(",
"self",
".",
"hostname",
",",
"self",
".",
"vdom",
")",
")",
"self",
".",
"ssh",
"=",
"paramiko",
".",
"SSHClient",
"(",
")",
"self",
"."... | Opens the ssh session with the device. | [
"Opens",
"the",
"ssh",
"session",
"with",
"the",
"device",
"."
] | 518668539146e7f998a37d75994a4278adf79897 | https://github.com/spotify/pyfg/blob/518668539146e7f998a37d75994a4278adf79897/pyFG/fortios.py#L68-L103 | train |
spotify/pyfg | pyFG/fortios.py | FortiOS._read_wrapper | def _read_wrapper(data):
"""Ensure unicode always returned on read."""
# Paramiko (strangely) in PY3 returns an int here.
if isinstance(data, int):
data = chr(data)
# Ensure unicode
return py23_compat.text_type(data) | python | def _read_wrapper(data):
"""Ensure unicode always returned on read."""
# Paramiko (strangely) in PY3 returns an int here.
if isinstance(data, int):
data = chr(data)
# Ensure unicode
return py23_compat.text_type(data) | [
"def",
"_read_wrapper",
"(",
"data",
")",
":",
"# Paramiko (strangely) in PY3 returns an int here.",
"if",
"isinstance",
"(",
"data",
",",
"int",
")",
":",
"data",
"=",
"chr",
"(",
"data",
")",
"# Ensure unicode",
"return",
"py23_compat",
".",
"text_type",
"(",
... | Ensure unicode always returned on read. | [
"Ensure",
"unicode",
"always",
"returned",
"on",
"read",
"."
] | 518668539146e7f998a37d75994a4278adf79897 | https://github.com/spotify/pyfg/blob/518668539146e7f998a37d75994a4278adf79897/pyFG/fortios.py#L114-L120 | train |
spotify/pyfg | pyFG/fortios.py | FortiOS._parse_batch_lastlog | def _parse_batch_lastlog(last_log):
"""
This static method will help reading the result of the commit, command by command.
Args:
last_log(list): A list containing, line by line, the result of committing the changes.
Returns:
A list of tuples that went wrong. The... | python | def _parse_batch_lastlog(last_log):
"""
This static method will help reading the result of the commit, command by command.
Args:
last_log(list): A list containing, line by line, the result of committing the changes.
Returns:
A list of tuples that went wrong. The... | [
"def",
"_parse_batch_lastlog",
"(",
"last_log",
")",
":",
"regexp",
"=",
"re",
".",
"compile",
"(",
"'(-?[0-9]\\d*):\\W+(.*)'",
")",
"wrong_commands",
"=",
"list",
"(",
")",
"for",
"line",
"in",
"last_log",
":",
"result",
"=",
"regexp",
".",
"match",
"(",
... | This static method will help reading the result of the commit, command by command.
Args:
last_log(list): A list containing, line by line, the result of committing the changes.
Returns:
A list of tuples that went wrong. The tuple will contain (*status_code*, *command*) | [
"This",
"static",
"method",
"will",
"help",
"reading",
"the",
"result",
"of",
"the",
"commit",
"command",
"by",
"command",
"."
] | 518668539146e7f998a37d75994a4278adf79897 | https://github.com/spotify/pyfg/blob/518668539146e7f998a37d75994a4278adf79897/pyFG/fortios.py#L349-L370 | train |
spotify/pyfg | pyFG/fortios.py | FortiOS._reload_config | def _reload_config(self, reload_original_config):
"""
This command will update the running config from the live device.
Args:
* reload_original_config:
* If ``True`` the original config will be loaded with the running config before reloading the\
orig... | python | def _reload_config(self, reload_original_config):
"""
This command will update the running config from the live device.
Args:
* reload_original_config:
* If ``True`` the original config will be loaded with the running config before reloading the\
orig... | [
"def",
"_reload_config",
"(",
"self",
",",
"reload_original_config",
")",
":",
"# We don't want to reload the config under some circumstances",
"if",
"reload_original_config",
":",
"self",
".",
"original_config",
"=",
"self",
".",
"running_config",
"self",
".",
"original_co... | This command will update the running config from the live device.
Args:
* reload_original_config:
* If ``True`` the original config will be loaded with the running config before reloading the\
original config.
* If ``False`` the original config will r... | [
"This",
"command",
"will",
"update",
"the",
"running",
"config",
"from",
"the",
"live",
"device",
"."
] | 518668539146e7f998a37d75994a4278adf79897 | https://github.com/spotify/pyfg/blob/518668539146e7f998a37d75994a4278adf79897/pyFG/fortios.py#L372-L392 | train |
mattjj/pyslds | pyslds/states.py | _SLDSStates.generate_states | def generate_states(self, initial_condition=None, with_noise=True, stateseq=None):
"""
Jointly sample the discrete and continuous states
"""
from pybasicbayes.util.stats import sample_discrete
# Generate from the prior and raise exception if unstable
T, K, n = self.T, sel... | python | def generate_states(self, initial_condition=None, with_noise=True, stateseq=None):
"""
Jointly sample the discrete and continuous states
"""
from pybasicbayes.util.stats import sample_discrete
# Generate from the prior and raise exception if unstable
T, K, n = self.T, sel... | [
"def",
"generate_states",
"(",
"self",
",",
"initial_condition",
"=",
"None",
",",
"with_noise",
"=",
"True",
",",
"stateseq",
"=",
"None",
")",
":",
"from",
"pybasicbayes",
".",
"util",
".",
"stats",
"import",
"sample_discrete",
"# Generate from the prior and rai... | Jointly sample the discrete and continuous states | [
"Jointly",
"sample",
"the",
"discrete",
"and",
"continuous",
"states"
] | c505c2bd05a5549d450b518f02493b68ed12e590 | https://github.com/mattjj/pyslds/blob/c505c2bd05a5549d450b518f02493b68ed12e590/pyslds/states.py#L35-L78 | train |
mattjj/pyslds | pyslds/states.py | _SLDSStatesMaskedData.heldout_log_likelihood | def heldout_log_likelihood(self, test_mask=None):
"""
Compute the log likelihood of the masked data given the latent
discrete and continuous states.
"""
if test_mask is None:
# If a test mask is not supplied, use the negation of this object's mask
if self.... | python | def heldout_log_likelihood(self, test_mask=None):
"""
Compute the log likelihood of the masked data given the latent
discrete and continuous states.
"""
if test_mask is None:
# If a test mask is not supplied, use the negation of this object's mask
if self.... | [
"def",
"heldout_log_likelihood",
"(",
"self",
",",
"test_mask",
"=",
"None",
")",
":",
"if",
"test_mask",
"is",
"None",
":",
"# If a test mask is not supplied, use the negation of this object's mask",
"if",
"self",
".",
"mask",
"is",
"None",
":",
"return",
"0",
"els... | Compute the log likelihood of the masked data given the latent
discrete and continuous states. | [
"Compute",
"the",
"log",
"likelihood",
"of",
"the",
"masked",
"data",
"given",
"the",
"latent",
"discrete",
"and",
"continuous",
"states",
"."
] | c505c2bd05a5549d450b518f02493b68ed12e590 | https://github.com/mattjj/pyslds/blob/c505c2bd05a5549d450b518f02493b68ed12e590/pyslds/states.py#L853-L874 | train |
mattjj/pyslds | pyslds/states.py | _SLDSStatesCountData.empirical_rate | def empirical_rate(data, sigma=3.0):
"""
Smooth count data to get an empirical rate
"""
from scipy.ndimage.filters import gaussian_filter1d
return 0.001 + gaussian_filter1d(data.astype(np.float), sigma, axis=0) | python | def empirical_rate(data, sigma=3.0):
"""
Smooth count data to get an empirical rate
"""
from scipy.ndimage.filters import gaussian_filter1d
return 0.001 + gaussian_filter1d(data.astype(np.float), sigma, axis=0) | [
"def",
"empirical_rate",
"(",
"data",
",",
"sigma",
"=",
"3.0",
")",
":",
"from",
"scipy",
".",
"ndimage",
".",
"filters",
"import",
"gaussian_filter1d",
"return",
"0.001",
"+",
"gaussian_filter1d",
"(",
"data",
".",
"astype",
"(",
"np",
".",
"float",
")",... | Smooth count data to get an empirical rate | [
"Smooth",
"count",
"data",
"to",
"get",
"an",
"empirical",
"rate"
] | c505c2bd05a5549d450b518f02493b68ed12e590 | https://github.com/mattjj/pyslds/blob/c505c2bd05a5549d450b518f02493b68ed12e590/pyslds/states.py#L1251-L1256 | train |
mattjj/pyslds | pyslds/util.py | get_empirical_ar_params | def get_empirical_ar_params(train_datas, params):
"""
Estimate the parameters of an AR observation model
by fitting a single AR model to the entire dataset.
"""
assert isinstance(train_datas, list) and len(train_datas) > 0
datadimension = train_datas[0].shape[1]
assert params["nu_0"] > datad... | python | def get_empirical_ar_params(train_datas, params):
"""
Estimate the parameters of an AR observation model
by fitting a single AR model to the entire dataset.
"""
assert isinstance(train_datas, list) and len(train_datas) > 0
datadimension = train_datas[0].shape[1]
assert params["nu_0"] > datad... | [
"def",
"get_empirical_ar_params",
"(",
"train_datas",
",",
"params",
")",
":",
"assert",
"isinstance",
"(",
"train_datas",
",",
"list",
")",
"and",
"len",
"(",
"train_datas",
")",
">",
"0",
"datadimension",
"=",
"train_datas",
"[",
"0",
"]",
".",
"shape",
... | Estimate the parameters of an AR observation model
by fitting a single AR model to the entire dataset. | [
"Estimate",
"the",
"parameters",
"of",
"an",
"AR",
"observation",
"model",
"by",
"fitting",
"a",
"single",
"AR",
"model",
"to",
"the",
"entire",
"dataset",
"."
] | c505c2bd05a5549d450b518f02493b68ed12e590 | https://github.com/mattjj/pyslds/blob/c505c2bd05a5549d450b518f02493b68ed12e590/pyslds/util.py#L6-L32 | train |
pastpages/savepagenow | savepagenow/api.py | capture | def capture(
target_url,
user_agent="savepagenow (https://github.com/pastpages/savepagenow)",
accept_cache=False
):
"""
Archives the provided URL using archive.org's Wayback Machine.
Returns the archive.org URL where the capture is stored.
Raises a CachedPage exception if archive.org decli... | python | def capture(
target_url,
user_agent="savepagenow (https://github.com/pastpages/savepagenow)",
accept_cache=False
):
"""
Archives the provided URL using archive.org's Wayback Machine.
Returns the archive.org URL where the capture is stored.
Raises a CachedPage exception if archive.org decli... | [
"def",
"capture",
"(",
"target_url",
",",
"user_agent",
"=",
"\"savepagenow (https://github.com/pastpages/savepagenow)\"",
",",
"accept_cache",
"=",
"False",
")",
":",
"# Put together the URL that will save our request",
"domain",
"=",
"\"https://web.archive.org\"",
"save_url",
... | Archives the provided URL using archive.org's Wayback Machine.
Returns the archive.org URL where the capture is stored.
Raises a CachedPage exception if archive.org declines to conduct a new
capture and returns a previous snapshot instead.
To silence that exception, pass into True to the ``accept_cac... | [
"Archives",
"the",
"provided",
"URL",
"using",
"archive",
".",
"org",
"s",
"Wayback",
"Machine",
"."
] | 9555ffb10905fe1b0d2452be2bd8a7d4338a8379 | https://github.com/pastpages/savepagenow/blob/9555ffb10905fe1b0d2452be2bd8a7d4338a8379/savepagenow/api.py#L8-L65 | train |
pastpages/savepagenow | savepagenow/api.py | capture_or_cache | def capture_or_cache(
target_url,
user_agent="savepagenow (https://github.com/pastpages/savepagenow)"
):
"""
Archives the provided URL using archive.org's Wayback Machine, unless
the page has been recently captured.
Returns a tuple with the archive.org URL where the capture is stored,
along... | python | def capture_or_cache(
target_url,
user_agent="savepagenow (https://github.com/pastpages/savepagenow)"
):
"""
Archives the provided URL using archive.org's Wayback Machine, unless
the page has been recently captured.
Returns a tuple with the archive.org URL where the capture is stored,
along... | [
"def",
"capture_or_cache",
"(",
"target_url",
",",
"user_agent",
"=",
"\"savepagenow (https://github.com/pastpages/savepagenow)\"",
")",
":",
"try",
":",
"return",
"capture",
"(",
"target_url",
",",
"user_agent",
"=",
"user_agent",
",",
"accept_cache",
"=",
"False",
"... | Archives the provided URL using archive.org's Wayback Machine, unless
the page has been recently captured.
Returns a tuple with the archive.org URL where the capture is stored,
along with a boolean indicating if a new capture was conducted.
If the boolean is True, archive.org conducted a new capture. ... | [
"Archives",
"the",
"provided",
"URL",
"using",
"archive",
".",
"org",
"s",
"Wayback",
"Machine",
"unless",
"the",
"page",
"has",
"been",
"recently",
"captured",
"."
] | 9555ffb10905fe1b0d2452be2bd8a7d4338a8379 | https://github.com/pastpages/savepagenow/blob/9555ffb10905fe1b0d2452be2bd8a7d4338a8379/savepagenow/api.py#L68-L86 | train |
quandyfactory/dicttoxml | dicttoxml.py | get_unique_id | def get_unique_id(element):
"""Returns a unique id for a given element"""
this_id = make_id(element)
dup = True
while dup:
if this_id not in ids:
dup = False
ids.append(this_id)
else:
this_id = make_id(element)
return ids[-1] | python | def get_unique_id(element):
"""Returns a unique id for a given element"""
this_id = make_id(element)
dup = True
while dup:
if this_id not in ids:
dup = False
ids.append(this_id)
else:
this_id = make_id(element)
return ids[-1] | [
"def",
"get_unique_id",
"(",
"element",
")",
":",
"this_id",
"=",
"make_id",
"(",
"element",
")",
"dup",
"=",
"True",
"while",
"dup",
":",
"if",
"this_id",
"not",
"in",
"ids",
":",
"dup",
"=",
"False",
"ids",
".",
"append",
"(",
"this_id",
")",
"else... | Returns a unique id for a given element | [
"Returns",
"a",
"unique",
"id",
"for",
"a",
"given",
"element"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L70-L80 | train |
quandyfactory/dicttoxml | dicttoxml.py | get_xml_type | def get_xml_type(val):
"""Returns the data type for the xml type attribute"""
if type(val).__name__ in ('str', 'unicode'):
return 'str'
if type(val).__name__ in ('int', 'long'):
return 'int'
if type(val).__name__ == 'float':
return 'float'
if type(val).__name__ == 'bool':
... | python | def get_xml_type(val):
"""Returns the data type for the xml type attribute"""
if type(val).__name__ in ('str', 'unicode'):
return 'str'
if type(val).__name__ in ('int', 'long'):
return 'int'
if type(val).__name__ == 'float':
return 'float'
if type(val).__name__ == 'bool':
... | [
"def",
"get_xml_type",
"(",
"val",
")",
":",
"if",
"type",
"(",
"val",
")",
".",
"__name__",
"in",
"(",
"'str'",
",",
"'unicode'",
")",
":",
"return",
"'str'",
"if",
"type",
"(",
"val",
")",
".",
"__name__",
"in",
"(",
"'int'",
",",
"'long'",
")",
... | Returns the data type for the xml type attribute | [
"Returns",
"the",
"data",
"type",
"for",
"the",
"xml",
"type",
"attribute"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L83-L101 | train |
quandyfactory/dicttoxml | dicttoxml.py | make_attrstring | def make_attrstring(attr):
"""Returns an attribute string in the form key="val" """
attrstring = ' '.join(['%s="%s"' % (k, v) for k, v in attr.items()])
return '%s%s' % (' ' if attrstring != '' else '', attrstring) | python | def make_attrstring(attr):
"""Returns an attribute string in the form key="val" """
attrstring = ' '.join(['%s="%s"' % (k, v) for k, v in attr.items()])
return '%s%s' % (' ' if attrstring != '' else '', attrstring) | [
"def",
"make_attrstring",
"(",
"attr",
")",
":",
"attrstring",
"=",
"' '",
".",
"join",
"(",
"[",
"'%s=\"%s\"'",
"%",
"(",
"k",
",",
"v",
")",
"for",
"k",
",",
"v",
"in",
"attr",
".",
"items",
"(",
")",
"]",
")",
"return",
"'%s%s'",
"%",
"(",
"... | Returns an attribute string in the form key="val" | [
"Returns",
"an",
"attribute",
"string",
"in",
"the",
"form",
"key",
"=",
"val"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L115-L118 | train |
quandyfactory/dicttoxml | dicttoxml.py | key_is_valid_xml | def key_is_valid_xml(key):
"""Checks that a key is a valid XML name"""
LOG.info('Inside key_is_valid_xml(). Testing "%s"' % (unicode_me(key)))
test_xml = '<?xml version="1.0" encoding="UTF-8" ?><%s>foo</%s>' % (key, key)
try:
parseString(test_xml)
return True
except Exception: # mini... | python | def key_is_valid_xml(key):
"""Checks that a key is a valid XML name"""
LOG.info('Inside key_is_valid_xml(). Testing "%s"' % (unicode_me(key)))
test_xml = '<?xml version="1.0" encoding="UTF-8" ?><%s>foo</%s>' % (key, key)
try:
parseString(test_xml)
return True
except Exception: # mini... | [
"def",
"key_is_valid_xml",
"(",
"key",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside key_is_valid_xml(). Testing \"%s\"'",
"%",
"(",
"unicode_me",
"(",
"key",
")",
")",
")",
"test_xml",
"=",
"'<?xml version=\"1.0\" encoding=\"UTF-8\" ?><%s>foo</%s>'",
"%",
"(",
"key",
... | Checks that a key is a valid XML name | [
"Checks",
"that",
"a",
"key",
"is",
"a",
"valid",
"XML",
"name"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L121-L129 | train |
quandyfactory/dicttoxml | dicttoxml.py | make_valid_xml_name | def make_valid_xml_name(key, attr):
"""Tests an XML name and fixes it if invalid"""
LOG.info('Inside make_valid_xml_name(). Testing key "%s" with attr "%s"' % (
unicode_me(key), unicode_me(attr))
)
key = escape_xml(key)
attr = escape_xml(attr)
# pass through if key is already valid
... | python | def make_valid_xml_name(key, attr):
"""Tests an XML name and fixes it if invalid"""
LOG.info('Inside make_valid_xml_name(). Testing key "%s" with attr "%s"' % (
unicode_me(key), unicode_me(attr))
)
key = escape_xml(key)
attr = escape_xml(attr)
# pass through if key is already valid
... | [
"def",
"make_valid_xml_name",
"(",
"key",
",",
"attr",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside make_valid_xml_name(). Testing key \"%s\" with attr \"%s\"'",
"%",
"(",
"unicode_me",
"(",
"key",
")",
",",
"unicode_me",
"(",
"attr",
")",
")",
")",
"key",
"=",
... | Tests an XML name and fixes it if invalid | [
"Tests",
"an",
"XML",
"name",
"and",
"fixes",
"it",
"if",
"invalid"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L132-L155 | train |
quandyfactory/dicttoxml | dicttoxml.py | convert | def convert(obj, ids, attr_type, item_func, cdata, parent='root'):
"""Routes the elements of an object to the right function to convert them
based on their data type"""
LOG.info('Inside convert(). obj type is: "%s", obj="%s"' % (type(obj).__name__, unicode_me(obj)))
item_name = item_func(pare... | python | def convert(obj, ids, attr_type, item_func, cdata, parent='root'):
"""Routes the elements of an object to the right function to convert them
based on their data type"""
LOG.info('Inside convert(). obj type is: "%s", obj="%s"' % (type(obj).__name__, unicode_me(obj)))
item_name = item_func(pare... | [
"def",
"convert",
"(",
"obj",
",",
"ids",
",",
"attr_type",
",",
"item_func",
",",
"cdata",
",",
"parent",
"=",
"'root'",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside convert(). obj type is: \"%s\", obj=\"%s\"'",
"%",
"(",
"type",
"(",
"obj",
")",
".",
"__n... | Routes the elements of an object to the right function to convert them
based on their data type | [
"Routes",
"the",
"elements",
"of",
"an",
"object",
"to",
"the",
"right",
"function",
"to",
"convert",
"them",
"based",
"on",
"their",
"data",
"type"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L168-L194 | train |
quandyfactory/dicttoxml | dicttoxml.py | convert_dict | def convert_dict(obj, ids, parent, attr_type, item_func, cdata):
"""Converts a dict into an XML string."""
LOG.info('Inside convert_dict(): obj type is: "%s", obj="%s"' % (
type(obj).__name__, unicode_me(obj))
)
output = []
addline = output.append
item_name = item_func(parent)
... | python | def convert_dict(obj, ids, parent, attr_type, item_func, cdata):
"""Converts a dict into an XML string."""
LOG.info('Inside convert_dict(): obj type is: "%s", obj="%s"' % (
type(obj).__name__, unicode_me(obj))
)
output = []
addline = output.append
item_name = item_func(parent)
... | [
"def",
"convert_dict",
"(",
"obj",
",",
"ids",
",",
"parent",
",",
"attr_type",
",",
"item_func",
",",
"cdata",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside convert_dict(): obj type is: \"%s\", obj=\"%s\"'",
"%",
"(",
"type",
"(",
"obj",
")",
".",
"__name__",
... | Converts a dict into an XML string. | [
"Converts",
"a",
"dict",
"into",
"an",
"XML",
"string",
"."
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L197-L254 | train |
quandyfactory/dicttoxml | dicttoxml.py | convert_list | def convert_list(items, ids, parent, attr_type, item_func, cdata):
"""Converts a list into an XML string."""
LOG.info('Inside convert_list()')
output = []
addline = output.append
item_name = item_func(parent)
if ids:
this_id = get_unique_id(parent)
for i, item in enumerate(items):... | python | def convert_list(items, ids, parent, attr_type, item_func, cdata):
"""Converts a list into an XML string."""
LOG.info('Inside convert_list()')
output = []
addline = output.append
item_name = item_func(parent)
if ids:
this_id = get_unique_id(parent)
for i, item in enumerate(items):... | [
"def",
"convert_list",
"(",
"items",
",",
"ids",
",",
"parent",
",",
"attr_type",
",",
"item_func",
",",
"cdata",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside convert_list()'",
")",
"output",
"=",
"[",
"]",
"addline",
"=",
"output",
".",
"append",
"item_n... | Converts a list into an XML string. | [
"Converts",
"a",
"list",
"into",
"an",
"XML",
"string",
"."
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L257-L321 | train |
quandyfactory/dicttoxml | dicttoxml.py | convert_kv | def convert_kv(key, val, attr_type, attr={}, cdata=False):
"""Converts a number or string into an XML element"""
LOG.info('Inside convert_kv(): key="%s", val="%s", type(val) is: "%s"' % (
unicode_me(key), unicode_me(val), type(val).__name__)
)
key, attr = make_valid_xml_name(key, attr)
if ... | python | def convert_kv(key, val, attr_type, attr={}, cdata=False):
"""Converts a number or string into an XML element"""
LOG.info('Inside convert_kv(): key="%s", val="%s", type(val) is: "%s"' % (
unicode_me(key), unicode_me(val), type(val).__name__)
)
key, attr = make_valid_xml_name(key, attr)
if ... | [
"def",
"convert_kv",
"(",
"key",
",",
"val",
",",
"attr_type",
",",
"attr",
"=",
"{",
"}",
",",
"cdata",
"=",
"False",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside convert_kv(): key=\"%s\", val=\"%s\", type(val) is: \"%s\"'",
"%",
"(",
"unicode_me",
"(",
"key",... | Converts a number or string into an XML element | [
"Converts",
"a",
"number",
"or",
"string",
"into",
"an",
"XML",
"element"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L324-L339 | train |
quandyfactory/dicttoxml | dicttoxml.py | convert_bool | def convert_bool(key, val, attr_type, attr={}, cdata=False):
"""Converts a boolean into an XML element"""
LOG.info('Inside convert_bool(): key="%s", val="%s", type(val) is: "%s"' % (
unicode_me(key), unicode_me(val), type(val).__name__)
)
key, attr = make_valid_xml_name(key, attr)
if attr_... | python | def convert_bool(key, val, attr_type, attr={}, cdata=False):
"""Converts a boolean into an XML element"""
LOG.info('Inside convert_bool(): key="%s", val="%s", type(val) is: "%s"' % (
unicode_me(key), unicode_me(val), type(val).__name__)
)
key, attr = make_valid_xml_name(key, attr)
if attr_... | [
"def",
"convert_bool",
"(",
"key",
",",
"val",
",",
"attr_type",
",",
"attr",
"=",
"{",
"}",
",",
"cdata",
"=",
"False",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside convert_bool(): key=\"%s\", val=\"%s\", type(val) is: \"%s\"'",
"%",
"(",
"unicode_me",
"(",
"k... | Converts a boolean into an XML element | [
"Converts",
"a",
"boolean",
"into",
"an",
"XML",
"element"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L342-L353 | train |
quandyfactory/dicttoxml | dicttoxml.py | convert_none | def convert_none(key, val, attr_type, attr={}, cdata=False):
"""Converts a null value into an XML element"""
LOG.info('Inside convert_none(): key="%s"' % (unicode_me(key)))
key, attr = make_valid_xml_name(key, attr)
if attr_type:
attr['type'] = get_xml_type(val)
attrstring = make_attrstrin... | python | def convert_none(key, val, attr_type, attr={}, cdata=False):
"""Converts a null value into an XML element"""
LOG.info('Inside convert_none(): key="%s"' % (unicode_me(key)))
key, attr = make_valid_xml_name(key, attr)
if attr_type:
attr['type'] = get_xml_type(val)
attrstring = make_attrstrin... | [
"def",
"convert_none",
"(",
"key",
",",
"val",
",",
"attr_type",
",",
"attr",
"=",
"{",
"}",
",",
"cdata",
"=",
"False",
")",
":",
"LOG",
".",
"info",
"(",
"'Inside convert_none(): key=\"%s\"'",
"%",
"(",
"unicode_me",
"(",
"key",
")",
")",
")",
"key",... | Converts a null value into an XML element | [
"Converts",
"a",
"null",
"value",
"into",
"an",
"XML",
"element"
] | 2016fe9817ad03b26aa5f1a475f5b79ad6757b96 | https://github.com/quandyfactory/dicttoxml/blob/2016fe9817ad03b26aa5f1a475f5b79ad6757b96/dicttoxml.py#L356-L365 | train |
gruns/icecream | icecream/icecream.py | getCallSourceLines | def getCallSourceLines(callFrame, icNames, icMethod):
"""Raises NoSourceAvailableError."""
code = callFrame.f_code
# inspect.getblock(), which is called internally by inspect.getsource(),
# only returns the first line of <code> when <code> represents a top-level
# module, not the entire module's so... | python | def getCallSourceLines(callFrame, icNames, icMethod):
"""Raises NoSourceAvailableError."""
code = callFrame.f_code
# inspect.getblock(), which is called internally by inspect.getsource(),
# only returns the first line of <code> when <code> represents a top-level
# module, not the entire module's so... | [
"def",
"getCallSourceLines",
"(",
"callFrame",
",",
"icNames",
",",
"icMethod",
")",
":",
"code",
"=",
"callFrame",
".",
"f_code",
"# inspect.getblock(), which is called internally by inspect.getsource(),",
"# only returns the first line of <code> when <code> represents a top-level",... | Raises NoSourceAvailableError. | [
"Raises",
"NoSourceAvailableError",
"."
] | cb4f3d50ec747637721fe58b80f2cc2a2baedabf | https://github.com/gruns/icecream/blob/cb4f3d50ec747637721fe58b80f2cc2a2baedabf/icecream/icecream.py#L275-L366 | train |
Vaelor/python-mattermost-driver | src/mattermostdriver/driver.py | Driver.init_websocket | def init_websocket(self, event_handler, websocket_cls=Websocket):
"""
Will initialize the websocket connection to the mattermost server.
This should be run after login(), because the websocket needs to make
an authentification.
See https://api.mattermost.com/v4/#tag/WebSocket for which
websocket events ma... | python | def init_websocket(self, event_handler, websocket_cls=Websocket):
"""
Will initialize the websocket connection to the mattermost server.
This should be run after login(), because the websocket needs to make
an authentification.
See https://api.mattermost.com/v4/#tag/WebSocket for which
websocket events ma... | [
"def",
"init_websocket",
"(",
"self",
",",
"event_handler",
",",
"websocket_cls",
"=",
"Websocket",
")",
":",
"self",
".",
"websocket",
"=",
"websocket_cls",
"(",
"self",
".",
"options",
",",
"self",
".",
"client",
".",
"token",
")",
"loop",
"=",
"asyncio"... | Will initialize the websocket connection to the mattermost server.
This should be run after login(), because the websocket needs to make
an authentification.
See https://api.mattermost.com/v4/#tag/WebSocket for which
websocket events mattermost sends.
Example of a really simple event_handler function
..... | [
"Will",
"initialize",
"the",
"websocket",
"connection",
"to",
"the",
"mattermost",
"server",
"."
] | ad1a936130096e39c2e1b76d78913e5950e06ca5 | https://github.com/Vaelor/python-mattermost-driver/blob/ad1a936130096e39c2e1b76d78913e5950e06ca5/src/mattermostdriver/driver.py#L114-L140 | train |
Vaelor/python-mattermost-driver | src/mattermostdriver/driver.py | Driver.login | def login(self):
"""
Logs the user in.
The log in information is saved in the client
- userid
- username
- cookies
:return: The raw response from the request
"""
if self.options['token']:
self.client.token = self.options['token']
result = self.users.get_user('me')
else:
response = self... | python | def login(self):
"""
Logs the user in.
The log in information is saved in the client
- userid
- username
- cookies
:return: The raw response from the request
"""
if self.options['token']:
self.client.token = self.options['token']
result = self.users.get_user('me')
else:
response = self... | [
"def",
"login",
"(",
"self",
")",
":",
"if",
"self",
".",
"options",
"[",
"'token'",
"]",
":",
"self",
".",
"client",
".",
"token",
"=",
"self",
".",
"options",
"[",
"'token'",
"]",
"result",
"=",
"self",
".",
"users",
".",
"get_user",
"(",
"'me'",... | Logs the user in.
The log in information is saved in the client
- userid
- username
- cookies
:return: The raw response from the request | [
"Logs",
"the",
"user",
"in",
"."
] | ad1a936130096e39c2e1b76d78913e5950e06ca5 | https://github.com/Vaelor/python-mattermost-driver/blob/ad1a936130096e39c2e1b76d78913e5950e06ca5/src/mattermostdriver/driver.py#L142-L178 | train |
Vaelor/python-mattermost-driver | src/mattermostdriver/websocket.py | Websocket.connect | def connect(self, event_handler):
"""
Connect to the websocket and authenticate it.
When the authentication has finished, start the loop listening for messages,
sending a ping to the server to keep the connection alive.
:param event_handler: Every websocket event will be passed there. Takes one argument.
:... | python | def connect(self, event_handler):
"""
Connect to the websocket and authenticate it.
When the authentication has finished, start the loop listening for messages,
sending a ping to the server to keep the connection alive.
:param event_handler: Every websocket event will be passed there. Takes one argument.
:... | [
"def",
"connect",
"(",
"self",
",",
"event_handler",
")",
":",
"context",
"=",
"ssl",
".",
"create_default_context",
"(",
"purpose",
"=",
"ssl",
".",
"Purpose",
".",
"CLIENT_AUTH",
")",
"if",
"not",
"self",
".",
"options",
"[",
"'verify'",
"]",
":",
"con... | Connect to the websocket and authenticate it.
When the authentication has finished, start the loop listening for messages,
sending a ping to the server to keep the connection alive.
:param event_handler: Every websocket event will be passed there. Takes one argument.
:type event_handler: Function(message)
:r... | [
"Connect",
"to",
"the",
"websocket",
"and",
"authenticate",
"it",
".",
"When",
"the",
"authentication",
"has",
"finished",
"start",
"the",
"loop",
"listening",
"for",
"messages",
"sending",
"a",
"ping",
"to",
"the",
"server",
"to",
"keep",
"the",
"connection",... | ad1a936130096e39c2e1b76d78913e5950e06ca5 | https://github.com/Vaelor/python-mattermost-driver/blob/ad1a936130096e39c2e1b76d78913e5950e06ca5/src/mattermostdriver/websocket.py#L19-L51 | train |
Vaelor/python-mattermost-driver | src/mattermostdriver/websocket.py | Websocket._authenticate_websocket | def _authenticate_websocket(self, websocket, event_handler):
"""
Sends a authentication challenge over a websocket.
This is not needed when we just send the cookie we got on login
when connecting to the websocket.
"""
log.debug('Authenticating websocket')
json_data = json.dumps({
"seq": 1,
"action":... | python | def _authenticate_websocket(self, websocket, event_handler):
"""
Sends a authentication challenge over a websocket.
This is not needed when we just send the cookie we got on login
when connecting to the websocket.
"""
log.debug('Authenticating websocket')
json_data = json.dumps({
"seq": 1,
"action":... | [
"def",
"_authenticate_websocket",
"(",
"self",
",",
"websocket",
",",
"event_handler",
")",
":",
"log",
".",
"debug",
"(",
"'Authenticating websocket'",
")",
"json_data",
"=",
"json",
".",
"dumps",
"(",
"{",
"\"seq\"",
":",
"1",
",",
"\"action\"",
":",
"\"au... | Sends a authentication challenge over a websocket.
This is not needed when we just send the cookie we got on login
when connecting to the websocket. | [
"Sends",
"a",
"authentication",
"challenge",
"over",
"a",
"websocket",
".",
"This",
"is",
"not",
"needed",
"when",
"we",
"just",
"send",
"the",
"cookie",
"we",
"got",
"on",
"login",
"when",
"connecting",
"to",
"the",
"websocket",
"."
] | ad1a936130096e39c2e1b76d78913e5950e06ca5 | https://github.com/Vaelor/python-mattermost-driver/blob/ad1a936130096e39c2e1b76d78913e5950e06ca5/src/mattermostdriver/websocket.py#L73-L100 | train |
paulgb/runipy | runipy/notebook_runner.py | NotebookRunner.run_cell | def run_cell(self, cell):
"""Run a notebook cell and update the output of that cell in-place."""
logging.info('Running cell:\n%s\n', cell.input)
self.kc.execute(cell.input)
reply = self.kc.get_shell_msg()
status = reply['content']['status']
traceback_text = ''
if ... | python | def run_cell(self, cell):
"""Run a notebook cell and update the output of that cell in-place."""
logging.info('Running cell:\n%s\n', cell.input)
self.kc.execute(cell.input)
reply = self.kc.get_shell_msg()
status = reply['content']['status']
traceback_text = ''
if ... | [
"def",
"run_cell",
"(",
"self",
",",
"cell",
")",
":",
"logging",
".",
"info",
"(",
"'Running cell:\\n%s\\n'",
",",
"cell",
".",
"input",
")",
"self",
".",
"kc",
".",
"execute",
"(",
"cell",
".",
"input",
")",
"reply",
"=",
"self",
".",
"kc",
".",
... | Run a notebook cell and update the output of that cell in-place. | [
"Run",
"a",
"notebook",
"cell",
"and",
"update",
"the",
"output",
"of",
"that",
"cell",
"in",
"-",
"place",
"."
] | d48c4c522bd1d66dcc5c1c09e70a92bfb58360fe | https://github.com/paulgb/runipy/blob/d48c4c522bd1d66dcc5c1c09e70a92bfb58360fe/runipy/notebook_runner.py#L138-L226 | train |
paulgb/runipy | runipy/notebook_runner.py | NotebookRunner.iter_code_cells | def iter_code_cells(self):
"""Iterate over the notebook cells containing code."""
for ws in self.nb.worksheets:
for cell in ws.cells:
if cell.cell_type == 'code':
yield cell | python | def iter_code_cells(self):
"""Iterate over the notebook cells containing code."""
for ws in self.nb.worksheets:
for cell in ws.cells:
if cell.cell_type == 'code':
yield cell | [
"def",
"iter_code_cells",
"(",
"self",
")",
":",
"for",
"ws",
"in",
"self",
".",
"nb",
".",
"worksheets",
":",
"for",
"cell",
"in",
"ws",
".",
"cells",
":",
"if",
"cell",
".",
"cell_type",
"==",
"'code'",
":",
"yield",
"cell"
] | Iterate over the notebook cells containing code. | [
"Iterate",
"over",
"the",
"notebook",
"cells",
"containing",
"code",
"."
] | d48c4c522bd1d66dcc5c1c09e70a92bfb58360fe | https://github.com/paulgb/runipy/blob/d48c4c522bd1d66dcc5c1c09e70a92bfb58360fe/runipy/notebook_runner.py#L228-L233 | train |
paulgb/runipy | runipy/notebook_runner.py | NotebookRunner.run_notebook | def run_notebook(self, skip_exceptions=False, progress_callback=None):
"""
Run all the notebook cells in order and update the outputs in-place.
If ``skip_exceptions`` is set, then if exceptions occur in a cell, the
subsequent cells are run (by default, the notebook execution stops).
... | python | def run_notebook(self, skip_exceptions=False, progress_callback=None):
"""
Run all the notebook cells in order and update the outputs in-place.
If ``skip_exceptions`` is set, then if exceptions occur in a cell, the
subsequent cells are run (by default, the notebook execution stops).
... | [
"def",
"run_notebook",
"(",
"self",
",",
"skip_exceptions",
"=",
"False",
",",
"progress_callback",
"=",
"None",
")",
":",
"for",
"i",
",",
"cell",
"in",
"enumerate",
"(",
"self",
".",
"iter_code_cells",
"(",
")",
")",
":",
"try",
":",
"self",
".",
"ru... | Run all the notebook cells in order and update the outputs in-place.
If ``skip_exceptions`` is set, then if exceptions occur in a cell, the
subsequent cells are run (by default, the notebook execution stops). | [
"Run",
"all",
"the",
"notebook",
"cells",
"in",
"order",
"and",
"update",
"the",
"outputs",
"in",
"-",
"place",
"."
] | d48c4c522bd1d66dcc5c1c09e70a92bfb58360fe | https://github.com/paulgb/runipy/blob/d48c4c522bd1d66dcc5c1c09e70a92bfb58360fe/runipy/notebook_runner.py#L235-L249 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.