repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 3
values | summary stringlengths 4 350 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
mottosso/be | be/lib.py | parse_environment | def parse_environment(fields, context, topics):
"""Resolve the be.yaml environment key
Features:
- Lists, e.g. ["/path1", "/path2"]
- Environment variable references, via $
- Replacement field references, e.g. {key}
- Topic references, e.g. {1}
"""
def _resolve_environ... | python | def parse_environment(fields, context, topics):
"""Resolve the be.yaml environment key
Features:
- Lists, e.g. ["/path1", "/path2"]
- Environment variable references, via $
- Replacement field references, e.g. {key}
- Topic references, e.g. {1}
"""
def _resolve_environ... | [
"def",
"parse_environment",
"(",
"fields",
",",
"context",
",",
"topics",
")",
":",
"def",
"_resolve_environment_lists",
"(",
"context",
")",
":",
"\"\"\"Concatenate environment lists\"\"\"",
"for",
"key",
",",
"value",
"in",
"context",
".",
"copy",
"(",
")",
".... | Resolve the be.yaml environment key
Features:
- Lists, e.g. ["/path1", "/path2"]
- Environment variable references, via $
- Replacement field references, e.g. {key}
- Topic references, e.g. {1} | [
"Resolve",
"the",
"be",
".",
"yaml",
"environment",
"key"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/lib.py#L555-L633 | train | Resolve environment variables and fields from the be. yaml file. |
mottosso/be | be/lib.py | parse_redirect | def parse_redirect(redirect, topics, context):
"""Resolve the be.yaml redirect key
Arguments:
redirect (dict): Source/destination pairs, e.g. {BE_ACTIVE: ACTIVE}
topics (tuple): Topics from which to sample, e.g. (project, item, task)
context (dict): Context from which to sample
"""... | python | def parse_redirect(redirect, topics, context):
"""Resolve the be.yaml redirect key
Arguments:
redirect (dict): Source/destination pairs, e.g. {BE_ACTIVE: ACTIVE}
topics (tuple): Topics from which to sample, e.g. (project, item, task)
context (dict): Context from which to sample
"""... | [
"def",
"parse_redirect",
"(",
"redirect",
",",
"topics",
",",
"context",
")",
":",
"for",
"map_source",
",",
"map_dest",
"in",
"redirect",
".",
"items",
"(",
")",
":",
"if",
"re",
".",
"match",
"(",
"\"{\\d+}\"",
",",
"map_source",
")",
":",
"topics_inde... | Resolve the be.yaml redirect key
Arguments:
redirect (dict): Source/destination pairs, e.g. {BE_ACTIVE: ACTIVE}
topics (tuple): Topics from which to sample, e.g. (project, item, task)
context (dict): Context from which to sample | [
"Resolve",
"the",
"be",
".",
"yaml",
"redirect",
"key"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/lib.py#L636-L653 | train | Resolve the be. yaml redirect key
|
mottosso/be | be/lib.py | slice | def slice(index, template):
"""Slice a template based on it's positional argument
Arguments:
index (int): Position at which to slice
template (str): Template to slice
Example:
>>> slice(0, "{cwd}/{0}/assets/{1}/{2}")
'{cwd}/{0}'
>>> slice(1, "{cwd}/{0}/assets/{1}/{2... | python | def slice(index, template):
"""Slice a template based on it's positional argument
Arguments:
index (int): Position at which to slice
template (str): Template to slice
Example:
>>> slice(0, "{cwd}/{0}/assets/{1}/{2}")
'{cwd}/{0}'
>>> slice(1, "{cwd}/{0}/assets/{1}/{2... | [
"def",
"slice",
"(",
"index",
",",
"template",
")",
":",
"try",
":",
"return",
"re",
".",
"match",
"(",
"\"^.*{[%i]}\"",
"%",
"index",
",",
"template",
")",
".",
"group",
"(",
")",
"except",
"AttributeError",
":",
"raise",
"ValueError",
"(",
"\"Index %i ... | Slice a template based on it's positional argument
Arguments:
index (int): Position at which to slice
template (str): Template to slice
Example:
>>> slice(0, "{cwd}/{0}/assets/{1}/{2}")
'{cwd}/{0}'
>>> slice(1, "{cwd}/{0}/assets/{1}/{2}")
'{cwd}/{0}/assets/{1}' | [
"Slice",
"a",
"template",
"based",
"on",
"it",
"s",
"positional",
"argument"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/lib.py#L656-L675 | train | Slice a template based on it s positional argument |
mottosso/be | be/vendor/requests/adapters.py | HTTPAdapter.proxy_manager_for | def proxy_manager_for(self, proxy, **proxy_kwargs):
"""Return urllib3 ProxyManager for the given proxy.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param proxy: The prox... | python | def proxy_manager_for(self, proxy, **proxy_kwargs):
"""Return urllib3 ProxyManager for the given proxy.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param proxy: The prox... | [
"def",
"proxy_manager_for",
"(",
"self",
",",
"proxy",
",",
"*",
"*",
"proxy_kwargs",
")",
":",
"if",
"not",
"proxy",
"in",
"self",
".",
"proxy_manager",
":",
"proxy_headers",
"=",
"self",
".",
"proxy_headers",
"(",
"proxy",
")",
"self",
".",
"proxy_manage... | Return urllib3 ProxyManager for the given proxy.
This method should not be called from user code, and is only
exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param proxy: The proxy to return a urllib3 ProxyManager for.
:param proxy_kw... | [
"Return",
"urllib3",
"ProxyManager",
"for",
"the",
"given",
"proxy",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/adapters.py#L136-L157 | train | Returns a urllib3 ProxyManager for the given proxy. |
mottosso/be | be/vendor/requests/adapters.py | HTTPAdapter.cert_verify | def cert_verify(self, conn, url, verify, cert):
"""Verify a SSL certificate. This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param conn: The urllib3 connection object associated with... | python | def cert_verify(self, conn, url, verify, cert):
"""Verify a SSL certificate. This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param conn: The urllib3 connection object associated with... | [
"def",
"cert_verify",
"(",
"self",
",",
"conn",
",",
"url",
",",
"verify",
",",
"cert",
")",
":",
"if",
"url",
".",
"lower",
"(",
")",
".",
"startswith",
"(",
"'https'",
")",
"and",
"verify",
":",
"cert_loc",
"=",
"None",
"# Allow self-specified cert loc... | Verify a SSL certificate. This method should not be called from user
code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param conn: The urllib3 connection object associated with the cert.
:param url: The requested URL.
:... | [
"Verify",
"a",
"SSL",
"certificate",
".",
"This",
"method",
"should",
"not",
"be",
"called",
"from",
"user",
"code",
"and",
"is",
"only",
"exposed",
"for",
"use",
"when",
"subclassing",
"the",
":",
"class",
":",
"HTTPAdapter",
"<requests",
".",
"adapters",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/adapters.py#L159-L194 | train | Verify a SSL certificate. |
mottosso/be | be/vendor/requests/adapters.py | HTTPAdapter.get_connection | def get_connection(self, url, proxies=None):
"""Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param url: The URL to connect to.
:pa... | python | def get_connection(self, url, proxies=None):
"""Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param url: The URL to connect to.
:pa... | [
"def",
"get_connection",
"(",
"self",
",",
"url",
",",
"proxies",
"=",
"None",
")",
":",
"proxies",
"=",
"proxies",
"or",
"{",
"}",
"proxy",
"=",
"proxies",
".",
"get",
"(",
"urlparse",
"(",
"url",
".",
"lower",
"(",
")",
")",
".",
"scheme",
")",
... | Returns a urllib3 connection for the given URL. This should not be
called from user code, and is only exposed for use when subclassing the
:class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.
:param url: The URL to connect to.
:param proxies: (optional) A Requests-style dictionary of p... | [
"Returns",
"a",
"urllib3",
"connection",
"for",
"the",
"given",
"URL",
".",
"This",
"should",
"not",
"be",
"called",
"from",
"user",
"code",
"and",
"is",
"only",
"exposed",
"for",
"use",
"when",
"subclassing",
"the",
":",
"class",
":",
"HTTPAdapter",
"<req... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/adapters.py#L232-L253 | train | Returns a urllib3 connection for the given URL. |
mottosso/be | be/vendor/requests/adapters.py | HTTPAdapter.request_url | def request_url(self, request, proxies):
"""Obtain the url to use when making the final request.
If the message is being sent through a HTTP proxy, the full URL has to
be used. Otherwise, we should only use the path portion of the URL.
This should not be called from user code, and is o... | python | def request_url(self, request, proxies):
"""Obtain the url to use when making the final request.
If the message is being sent through a HTTP proxy, the full URL has to
be used. Otherwise, we should only use the path portion of the URL.
This should not be called from user code, and is o... | [
"def",
"request_url",
"(",
"self",
",",
"request",
",",
"proxies",
")",
":",
"proxies",
"=",
"proxies",
"or",
"{",
"}",
"scheme",
"=",
"urlparse",
"(",
"request",
".",
"url",
")",
".",
"scheme",
"proxy",
"=",
"proxies",
".",
"get",
"(",
"scheme",
")"... | Obtain the url to use when making the final request.
If the message is being sent through a HTTP proxy, the full URL has to
be used. Otherwise, we should only use the path portion of the URL.
This should not be called from user code, and is only exposed for use
when subclassing the
... | [
"Obtain",
"the",
"url",
"to",
"use",
"when",
"making",
"the",
"final",
"request",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/adapters.py#L263-L285 | train | Obtain the url to use when making the final request. |
mottosso/be | be/vendor/requests/adapters.py | HTTPAdapter.proxy_headers | def proxy_headers(self, proxy):
"""Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used.
This should not be c... | python | def proxy_headers(self, proxy):
"""Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used.
This should not be c... | [
"def",
"proxy_headers",
"(",
"self",
",",
"proxy",
")",
":",
"headers",
"=",
"{",
"}",
"username",
",",
"password",
"=",
"get_auth_from_url",
"(",
"proxy",
")",
"if",
"username",
"and",
"password",
":",
"headers",
"[",
"'Proxy-Authorization'",
"]",
"=",
"_... | Returns a dictionary of the headers to add to any request sent
through a proxy. This works with urllib3 magic to ensure that they are
correctly sent to the proxy, rather than in a tunnelled request if
CONNECT is being used.
This should not be called from user code, and is only exposed f... | [
"Returns",
"a",
"dictionary",
"of",
"the",
"headers",
"to",
"add",
"to",
"any",
"request",
"sent",
"through",
"a",
"proxy",
".",
"This",
"works",
"with",
"urllib3",
"magic",
"to",
"ensure",
"that",
"they",
"are",
"correctly",
"sent",
"to",
"the",
"proxy",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/adapters.py#L301-L321 | train | Returns a dictionary of the headers to add to any request sent
through a proxy. |
mottosso/be | be/vendor/requests/api.py | request | def request(method, url, **kwargs):
"""Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`... | python | def request(method, url, **kwargs):
"""Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`... | [
"def",
"request",
"(",
"method",
",",
"url",
",",
"*",
"*",
"kwargs",
")",
":",
"session",
"=",
"sessions",
".",
"Session",
"(",
")",
"response",
"=",
"session",
".",
"request",
"(",
"method",
"=",
"method",
",",
"url",
"=",
"url",
",",
"*",
"*",
... | Constructs and sends a :class:`Request <Request>`.
:param method: method for the new :class:`Request` object.
:param url: URL for the new :class:`Request` object.
:param params: (optional) Dictionary or bytes to be sent in the query string for the :class:`Request`.
:param data: (optional) Dictionary, b... | [
"Constructs",
"and",
"sends",
"a",
":",
"class",
":",
"Request",
"<Request",
">",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/api.py#L17-L55 | train | Constructs and sends a new request object. |
mottosso/be | be/vendor/requests/packages/urllib3/util/connection.py | is_connection_dropped | def is_connection_dropped(conn): # Platform-specific
"""
Returns True if the connection is dropped and should be closed.
:param conn:
:class:`httplib.HTTPConnection` object.
Note: For platforms like AppEngine, this will always return ``False`` to
let the platform handle connection recycli... | python | def is_connection_dropped(conn): # Platform-specific
"""
Returns True if the connection is dropped and should be closed.
:param conn:
:class:`httplib.HTTPConnection` object.
Note: For platforms like AppEngine, this will always return ``False`` to
let the platform handle connection recycli... | [
"def",
"is_connection_dropped",
"(",
"conn",
")",
":",
"# Platform-specific",
"sock",
"=",
"getattr",
"(",
"conn",
",",
"'sock'",
",",
"False",
")",
"if",
"sock",
"is",
"False",
":",
"# Platform-specific: AppEngine",
"return",
"False",
"if",
"sock",
"is",
"Non... | Returns True if the connection is dropped and should be closed.
:param conn:
:class:`httplib.HTTPConnection` object.
Note: For platforms like AppEngine, this will always return ``False`` to
let the platform handle connection recycling transparently for us. | [
"Returns",
"True",
"if",
"the",
"connection",
"is",
"dropped",
"and",
"should",
"be",
"closed",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/connection.py#L12-L43 | train | Returns True if the connection is dropped and should be closed. |
mottosso/be | be/vendor/requests/cookies.py | morsel_to_cookie | def morsel_to_cookie(morsel):
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
expires = None
if morsel['max-age']:
expires = time.time() + morsel['max-age']
elif morsel['expires']:
time_template = '%a, %d-%b-%Y %H:%M:%S GMT'
expires = time.mktime(
... | python | def morsel_to_cookie(morsel):
"""Convert a Morsel object into a Cookie containing the one k/v pair."""
expires = None
if morsel['max-age']:
expires = time.time() + morsel['max-age']
elif morsel['expires']:
time_template = '%a, %d-%b-%Y %H:%M:%S GMT'
expires = time.mktime(
... | [
"def",
"morsel_to_cookie",
"(",
"morsel",
")",
":",
"expires",
"=",
"None",
"if",
"morsel",
"[",
"'max-age'",
"]",
":",
"expires",
"=",
"time",
".",
"time",
"(",
")",
"+",
"morsel",
"[",
"'max-age'",
"]",
"elif",
"morsel",
"[",
"'expires'",
"]",
":",
... | Convert a Morsel object into a Cookie containing the one k/v pair. | [
"Convert",
"a",
"Morsel",
"object",
"into",
"a",
"Cookie",
"containing",
"the",
"one",
"k",
"/",
"v",
"pair",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/cookies.py#L397-L421 | train | Convert a Morsel object into a Cookie containing the one k - v pair. |
mottosso/be | be/vendor/requests/cookies.py | RequestsCookieJar.get_dict | def get_dict(self, domain=None, path=None):
"""Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements."""
dictionary = {}
for cookie in iter(self):
if (domain is None or cookie.dom... | python | def get_dict(self, domain=None, path=None):
"""Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements."""
dictionary = {}
for cookie in iter(self):
if (domain is None or cookie.dom... | [
"def",
"get_dict",
"(",
"self",
",",
"domain",
"=",
"None",
",",
"path",
"=",
"None",
")",
":",
"dictionary",
"=",
"{",
"}",
"for",
"cookie",
"in",
"iter",
"(",
"self",
")",
":",
"if",
"(",
"domain",
"is",
"None",
"or",
"cookie",
".",
"domain",
"... | Takes as an argument an optional domain and path and returns a plain
old Python dict of name-value pairs of cookies that meet the
requirements. | [
"Takes",
"as",
"an",
"argument",
"an",
"optional",
"domain",
"and",
"path",
"and",
"returns",
"a",
"plain",
"old",
"Python",
"dict",
"of",
"name",
"-",
"value",
"pairs",
"of",
"cookies",
"that",
"meet",
"the",
"requirements",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/cookies.py#L264-L273 | train | Takes as an argument an optional domain and path and returns a plain
old Python dict of name - value pairs of cookies that meet the
requirements. |
mottosso/be | be/vendor/requests/packages/chardet/chardistribution.py | CharDistributionAnalysis.feed | def feed(self, aBuf, aCharLen):
"""feed a character with known length"""
if aCharLen == 2:
# we only care about 2-bytes character in our distribution analysis
order = self.get_order(aBuf)
else:
order = -1
if order >= 0:
self._mTotalChars +=... | python | def feed(self, aBuf, aCharLen):
"""feed a character with known length"""
if aCharLen == 2:
# we only care about 2-bytes character in our distribution analysis
order = self.get_order(aBuf)
else:
order = -1
if order >= 0:
self._mTotalChars +=... | [
"def",
"feed",
"(",
"self",
",",
"aBuf",
",",
"aCharLen",
")",
":",
"if",
"aCharLen",
"==",
"2",
":",
"# we only care about 2-bytes character in our distribution analysis",
"order",
"=",
"self",
".",
"get_order",
"(",
"aBuf",
")",
"else",
":",
"order",
"=",
"-... | feed a character with known length | [
"feed",
"a",
"character",
"with",
"known",
"length"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/chardet/chardistribution.py#L68-L80 | train | feed a character with known length |
mottosso/be | be/vendor/requests/packages/chardet/chardistribution.py | CharDistributionAnalysis.get_confidence | def get_confidence(self):
"""return confidence based on existing data"""
# if we didn't receive any character in our consideration range,
# return negative answer
if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD:
return SURE_NO
if self._mTotalC... | python | def get_confidence(self):
"""return confidence based on existing data"""
# if we didn't receive any character in our consideration range,
# return negative answer
if self._mTotalChars <= 0 or self._mFreqChars <= MINIMUM_DATA_THRESHOLD:
return SURE_NO
if self._mTotalC... | [
"def",
"get_confidence",
"(",
"self",
")",
":",
"# if we didn't receive any character in our consideration range,",
"# return negative answer",
"if",
"self",
".",
"_mTotalChars",
"<=",
"0",
"or",
"self",
".",
"_mFreqChars",
"<=",
"MINIMUM_DATA_THRESHOLD",
":",
"return",
"... | return confidence based on existing data | [
"return",
"confidence",
"based",
"on",
"existing",
"data"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/chardet/chardistribution.py#L82-L96 | train | return confidence based on existing data |
mottosso/be | be/vendor/requests/packages/urllib3/__init__.py | add_stderr_logger | def add_stderr_logger(level=logging.DEBUG):
"""
Helper for quickly adding a StreamHandler to the logger. Useful for
debugging.
Returns the handler after adding it.
"""
# This method needs to be in this __init__.py to get the __name__ correct
# even if urllib3 is vendored within another pack... | python | def add_stderr_logger(level=logging.DEBUG):
"""
Helper for quickly adding a StreamHandler to the logger. Useful for
debugging.
Returns the handler after adding it.
"""
# This method needs to be in this __init__.py to get the __name__ correct
# even if urllib3 is vendored within another pack... | [
"def",
"add_stderr_logger",
"(",
"level",
"=",
"logging",
".",
"DEBUG",
")",
":",
"# This method needs to be in this __init__.py to get the __name__ correct",
"# even if urllib3 is vendored within another package.",
"logger",
"=",
"logging",
".",
"getLogger",
"(",
"__name__",
"... | Helper for quickly adding a StreamHandler to the logger. Useful for
debugging.
Returns the handler after adding it. | [
"Helper",
"for",
"quickly",
"adding",
"a",
"StreamHandler",
"to",
"the",
"logger",
".",
"Useful",
"for",
"debugging",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/__init__.py#L37-L52 | train | Helper for quickly adding a StreamHandler to the logger. Useful for debugging. |
mottosso/be | be/vendor/requests/packages/urllib3/util/ssl_.py | assert_fingerprint | def assert_fingerprint(cert, fingerprint):
"""
Checks if given fingerprint matches the supplied certificate.
:param cert:
Certificate as bytes object.
:param fingerprint:
Fingerprint as string of hexdigits, can be interspersed by colons.
"""
# Maps the length of a digest to a p... | python | def assert_fingerprint(cert, fingerprint):
"""
Checks if given fingerprint matches the supplied certificate.
:param cert:
Certificate as bytes object.
:param fingerprint:
Fingerprint as string of hexdigits, can be interspersed by colons.
"""
# Maps the length of a digest to a p... | [
"def",
"assert_fingerprint",
"(",
"cert",
",",
"fingerprint",
")",
":",
"# Maps the length of a digest to a possible hash function producing",
"# this digest.",
"hashfunc_map",
"=",
"{",
"16",
":",
"md5",
",",
"20",
":",
"sha1",
",",
"32",
":",
"sha256",
",",
"}",
... | Checks if given fingerprint matches the supplied certificate.
:param cert:
Certificate as bytes object.
:param fingerprint:
Fingerprint as string of hexdigits, can be interspersed by colons. | [
"Checks",
"if",
"given",
"fingerprint",
"matches",
"the",
"supplied",
"certificate",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/ssl_.py#L94-L128 | train | Checks if given fingerprint matches the supplied certificate. |
mottosso/be | be/vendor/requests/packages/urllib3/util/ssl_.py | create_urllib3_context | def create_urllib3_context(ssl_version=None, cert_reqs=ssl.CERT_REQUIRED,
options=None, ciphers=None):
"""All arguments have the same meaning as ``ssl_wrap_socket``.
By default, this function does a lot of the same work that
``ssl.create_default_context`` does on Python 3.4+. It:... | python | def create_urllib3_context(ssl_version=None, cert_reqs=ssl.CERT_REQUIRED,
options=None, ciphers=None):
"""All arguments have the same meaning as ``ssl_wrap_socket``.
By default, this function does a lot of the same work that
``ssl.create_default_context`` does on Python 3.4+. It:... | [
"def",
"create_urllib3_context",
"(",
"ssl_version",
"=",
"None",
",",
"cert_reqs",
"=",
"ssl",
".",
"CERT_REQUIRED",
",",
"options",
"=",
"None",
",",
"ciphers",
"=",
"None",
")",
":",
"context",
"=",
"SSLContext",
"(",
"ssl_version",
"or",
"ssl",
".",
"P... | All arguments have the same meaning as ``ssl_wrap_socket``.
By default, this function does a lot of the same work that
``ssl.create_default_context`` does on Python 3.4+. It:
- Disables SSLv2, SSLv3, and compression
- Sets a restricted set of server ciphers
If you wish to enable SSLv3, you can do... | [
"All",
"arguments",
"have",
"the",
"same",
"meaning",
"as",
"ssl_wrap_socket",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/ssl_.py#L170-L227 | train | Creates a new SSLContext object with the specified options and cipher suites. |
mottosso/be | be/vendor/requests/packages/urllib3/util/ssl_.py | ssl_wrap_socket | def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
ca_certs=None, server_hostname=None,
ssl_version=None, ciphers=None, ssl_context=None):
"""
All arguments except for server_hostname and ssl_context have the same
meaning as they do when using :fun... | python | def ssl_wrap_socket(sock, keyfile=None, certfile=None, cert_reqs=None,
ca_certs=None, server_hostname=None,
ssl_version=None, ciphers=None, ssl_context=None):
"""
All arguments except for server_hostname and ssl_context have the same
meaning as they do when using :fun... | [
"def",
"ssl_wrap_socket",
"(",
"sock",
",",
"keyfile",
"=",
"None",
",",
"certfile",
"=",
"None",
",",
"cert_reqs",
"=",
"None",
",",
"ca_certs",
"=",
"None",
",",
"server_hostname",
"=",
"None",
",",
"ssl_version",
"=",
"None",
",",
"ciphers",
"=",
"Non... | All arguments except for server_hostname and ssl_context have the same
meaning as they do when using :func:`ssl.wrap_socket`.
:param server_hostname:
When SNI is supported, the expected hostname of the certificate
:param ssl_context:
A pre-made :class:`SSLContext` object. If none is provide... | [
"All",
"arguments",
"except",
"for",
"server_hostname",
"and",
"ssl_context",
"have",
"the",
"same",
"meaning",
"as",
"they",
"do",
"when",
"using",
":",
"func",
":",
"ssl",
".",
"wrap_socket",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/util/ssl_.py#L230-L266 | train | Wrapper for ssl. wrap_socket. |
mottosso/be | be/vendor/requests/packages/urllib3/connectionpool.py | connection_from_url | def connection_from_url(url, **kw):
"""
Given a url, return an :class:`.ConnectionPool` instance of its host.
This is a shortcut for not having to parse out the scheme, host, and port
of the url before creating an :class:`.ConnectionPool` instance.
:param url:
Absolute URL string that must... | python | def connection_from_url(url, **kw):
"""
Given a url, return an :class:`.ConnectionPool` instance of its host.
This is a shortcut for not having to parse out the scheme, host, and port
of the url before creating an :class:`.ConnectionPool` instance.
:param url:
Absolute URL string that must... | [
"def",
"connection_from_url",
"(",
"url",
",",
"*",
"*",
"kw",
")",
":",
"scheme",
",",
"host",
",",
"port",
"=",
"get_host",
"(",
"url",
")",
"if",
"scheme",
"==",
"'https'",
":",
"return",
"HTTPSConnectionPool",
"(",
"host",
",",
"port",
"=",
"port",... | Given a url, return an :class:`.ConnectionPool` instance of its host.
This is a shortcut for not having to parse out the scheme, host, and port
of the url before creating an :class:`.ConnectionPool` instance.
:param url:
Absolute URL string that must include the scheme. Port is optional.
:par... | [
"Given",
"a",
"url",
"return",
"an",
":",
"class",
":",
".",
"ConnectionPool",
"instance",
"of",
"its",
"host",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/connectionpool.py#L772-L796 | train | Given a url return an instance of a : class :. ConnectionPool instance of its host. |
mottosso/be | be/vendor/requests/packages/urllib3/connectionpool.py | HTTPConnectionPool._put_conn | def _put_conn(self, conn):
"""
Put a connection back into the pool.
:param conn:
Connection object for the current host and port as returned by
:meth:`._new_conn` or :meth:`._get_conn`.
If the pool is already full, the connection is closed and discarded
... | python | def _put_conn(self, conn):
"""
Put a connection back into the pool.
:param conn:
Connection object for the current host and port as returned by
:meth:`._new_conn` or :meth:`._get_conn`.
If the pool is already full, the connection is closed and discarded
... | [
"def",
"_put_conn",
"(",
"self",
",",
"conn",
")",
":",
"try",
":",
"self",
".",
"pool",
".",
"put",
"(",
"conn",
",",
"block",
"=",
"False",
")",
"return",
"# Everything is dandy, done.",
"except",
"AttributeError",
":",
"# self.pool is None.",
"pass",
"exc... | Put a connection back into the pool.
:param conn:
Connection object for the current host and port as returned by
:meth:`._new_conn` or :meth:`._get_conn`.
If the pool is already full, the connection is closed and discarded
because we exceeded maxsize. If connections are... | [
"Put",
"a",
"connection",
"back",
"into",
"the",
"pool",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/connectionpool.py#L248-L276 | train | Put a connection into the pool. |
mottosso/be | be/vendor/requests/packages/urllib3/connectionpool.py | HTTPConnectionPool._make_request | def _make_request(self, conn, method, url, timeout=_Default,
**httplib_request_kw):
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param timeout:
... | python | def _make_request(self, conn, method, url, timeout=_Default,
**httplib_request_kw):
"""
Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param timeout:
... | [
"def",
"_make_request",
"(",
"self",
",",
"conn",
",",
"method",
",",
"url",
",",
"timeout",
"=",
"_Default",
",",
"*",
"*",
"httplib_request_kw",
")",
":",
"self",
".",
"num_requests",
"+=",
"1",
"timeout_obj",
"=",
"self",
".",
"_get_timeout",
"(",
"ti... | Perform a request on a given urllib connection object taken from our
pool.
:param conn:
a connection from one of our connection pools
:param timeout:
Socket timeout in seconds for the request. This can be a
float or integer, which will set the same timeout v... | [
"Perform",
"a",
"request",
"on",
"a",
"given",
"urllib",
"connection",
"object",
"taken",
"from",
"our",
"pool",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/connectionpool.py#L317-L384 | train | Perform a request on a given urllib connection object. |
mottosso/be | be/vendor/requests/packages/urllib3/connectionpool.py | HTTPConnectionPool.urlopen | def urlopen(self, method, url, body=None, headers=None, retries=None,
redirect=True, assert_same_host=True, timeout=_Default,
pool_timeout=None, release_conn=None, **response_kw):
"""
Get a connection from the pool and perform an HTTP request. This is the
lowest l... | python | def urlopen(self, method, url, body=None, headers=None, retries=None,
redirect=True, assert_same_host=True, timeout=_Default,
pool_timeout=None, release_conn=None, **response_kw):
"""
Get a connection from the pool and perform an HTTP request. This is the
lowest l... | [
"def",
"urlopen",
"(",
"self",
",",
"method",
",",
"url",
",",
"body",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"retries",
"=",
"None",
",",
"redirect",
"=",
"True",
",",
"assert_same_host",
"=",
"True",
",",
"timeout",
"=",
"_Default",
",",
"p... | Get a connection from the pool and perform an HTTP request. This is the
lowest level call for making a request, so you'll need to specify all
the raw details.
.. note::
More commonly, it's appropriate to use a convenience method provided
by :class:`.RequestMethods`, such ... | [
"Get",
"a",
"connection",
"from",
"the",
"pool",
"and",
"perform",
"an",
"HTTP",
"request",
".",
"This",
"is",
"the",
"lowest",
"level",
"call",
"for",
"making",
"a",
"request",
"so",
"you",
"ll",
"need",
"to",
"specify",
"all",
"the",
"raw",
"details",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/connectionpool.py#L421-L650 | train | A method that returns a response from the HTTP connection pool. |
mottosso/be | be/vendor/requests/packages/urllib3/connectionpool.py | HTTPSConnectionPool._new_conn | def _new_conn(self):
"""
Return a fresh :class:`httplib.HTTPSConnection`.
"""
self.num_connections += 1
log.info("Starting new HTTPS connection (%d): %s"
% (self.num_connections, self.host))
if not self.ConnectionCls or self.ConnectionCls is DummyConnect... | python | def _new_conn(self):
"""
Return a fresh :class:`httplib.HTTPSConnection`.
"""
self.num_connections += 1
log.info("Starting new HTTPS connection (%d): %s"
% (self.num_connections, self.host))
if not self.ConnectionCls or self.ConnectionCls is DummyConnect... | [
"def",
"_new_conn",
"(",
"self",
")",
":",
"self",
".",
"num_connections",
"+=",
"1",
"log",
".",
"info",
"(",
"\"Starting new HTTPS connection (%d): %s\"",
"%",
"(",
"self",
".",
"num_connections",
",",
"self",
".",
"host",
")",
")",
"if",
"not",
"self",
... | Return a fresh :class:`httplib.HTTPSConnection`. | [
"Return",
"a",
"fresh",
":",
"class",
":",
"httplib",
".",
"HTTPSConnection",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/connectionpool.py#L729-L752 | train | Create a new connection. |
mottosso/be | be/vendor/requests/packages/urllib3/connectionpool.py | HTTPSConnectionPool._validate_conn | def _validate_conn(self, conn):
"""
Called right before a request is made, after the socket is created.
"""
super(HTTPSConnectionPool, self)._validate_conn(conn)
# Force connect early to allow us to validate the connection.
if not getattr(conn, 'sock', None): # AppEngin... | python | def _validate_conn(self, conn):
"""
Called right before a request is made, after the socket is created.
"""
super(HTTPSConnectionPool, self)._validate_conn(conn)
# Force connect early to allow us to validate the connection.
if not getattr(conn, 'sock', None): # AppEngin... | [
"def",
"_validate_conn",
"(",
"self",
",",
"conn",
")",
":",
"super",
"(",
"HTTPSConnectionPool",
",",
"self",
")",
".",
"_validate_conn",
"(",
"conn",
")",
"# Force connect early to allow us to validate the connection.",
"if",
"not",
"getattr",
"(",
"conn",
",",
... | Called right before a request is made, after the socket is created. | [
"Called",
"right",
"before",
"a",
"request",
"is",
"made",
"after",
"the",
"socket",
"is",
"created",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/connectionpool.py#L754-L769 | train | Called right before a request is made after the socket is created. |
mottosso/be | be/vendor/requests/packages/chardet/chardetect.py | description_of | def description_of(lines, name='stdin'):
"""
Return a string describing the probable encoding of a file or
list of strings.
:param lines: The lines to get the encoding of.
:type lines: Iterable of bytes
:param name: Name of file or collection of lines
:type name: str
"""
u = Univers... | python | def description_of(lines, name='stdin'):
"""
Return a string describing the probable encoding of a file or
list of strings.
:param lines: The lines to get the encoding of.
:type lines: Iterable of bytes
:param name: Name of file or collection of lines
:type name: str
"""
u = Univers... | [
"def",
"description_of",
"(",
"lines",
",",
"name",
"=",
"'stdin'",
")",
":",
"u",
"=",
"UniversalDetector",
"(",
")",
"for",
"line",
"in",
"lines",
":",
"u",
".",
"feed",
"(",
"line",
")",
"u",
".",
"close",
"(",
")",
"result",
"=",
"u",
".",
"r... | Return a string describing the probable encoding of a file or
list of strings.
:param lines: The lines to get the encoding of.
:type lines: Iterable of bytes
:param name: Name of file or collection of lines
:type name: str | [
"Return",
"a",
"string",
"describing",
"the",
"probable",
"encoding",
"of",
"a",
"file",
"or",
"list",
"of",
"strings",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/chardet/chardetect.py#L26-L45 | train | Returns a string describing the probable encoding of a file or a list of strings. |
mottosso/be | be/vendor/requests/packages/chardet/chardetect.py | main | def main(argv=None):
'''
Handles command line arguments and gets things started.
:param argv: List of arguments, as if specified on the command-line.
If None, ``sys.argv[1:]`` is used instead.
:type argv: list of str
'''
# Get command line arguments
parser = argparse.Argume... | python | def main(argv=None):
'''
Handles command line arguments and gets things started.
:param argv: List of arguments, as if specified on the command-line.
If None, ``sys.argv[1:]`` is used instead.
:type argv: list of str
'''
# Get command line arguments
parser = argparse.Argume... | [
"def",
"main",
"(",
"argv",
"=",
"None",
")",
":",
"# Get command line arguments",
"parser",
"=",
"argparse",
".",
"ArgumentParser",
"(",
"description",
"=",
"\"Takes one or more file paths and reports their detected \\\n encodings\"",
",",
"formatter_class"... | Handles command line arguments and gets things started.
:param argv: List of arguments, as if specified on the command-line.
If None, ``sys.argv[1:]`` is used instead.
:type argv: list of str | [
"Handles",
"command",
"line",
"arguments",
"and",
"gets",
"things",
"started",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/chardet/chardetect.py#L48-L76 | train | Entry point for the main function. |
mottosso/be | be/vendor/click/termui.py | get_terminal_size | def get_terminal_size():
"""Returns the current size of the terminal as tuple in the form
``(width, height)`` in columns and rows.
"""
# If shutil has get_terminal_size() (Python 3.3 and later) use that
if sys.version_info >= (3, 3):
import shutil
shutil_get_terminal_size = getattr(s... | python | def get_terminal_size():
"""Returns the current size of the terminal as tuple in the form
``(width, height)`` in columns and rows.
"""
# If shutil has get_terminal_size() (Python 3.3 and later) use that
if sys.version_info >= (3, 3):
import shutil
shutil_get_terminal_size = getattr(s... | [
"def",
"get_terminal_size",
"(",
")",
":",
"# If shutil has get_terminal_size() (Python 3.3 and later) use that",
"if",
"sys",
".",
"version_info",
">=",
"(",
"3",
",",
"3",
")",
":",
"import",
"shutil",
"shutil_get_terminal_size",
"=",
"getattr",
"(",
"shutil",
",",
... | Returns the current size of the terminal as tuple in the form
``(width, height)`` in columns and rows. | [
"Returns",
"the",
"current",
"size",
"of",
"the",
"terminal",
"as",
"tuple",
"in",
"the",
"form",
"(",
"width",
"height",
")",
"in",
"columns",
"and",
"rows",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/termui.py#L148-L186 | train | Returns the current size of the terminal as tuple in the form
( width height ) in columns and rows. |
mottosso/be | be/vendor/click/termui.py | style | def style(text, fg=None, bg=None, bold=None, dim=None, underline=None,
blink=None, reverse=None, reset=True):
"""Styles a text with ANSI styles and returns the new string. By
default the styling is self contained which means that at the end
of the string a reset code is issued. This can be preve... | python | def style(text, fg=None, bg=None, bold=None, dim=None, underline=None,
blink=None, reverse=None, reset=True):
"""Styles a text with ANSI styles and returns the new string. By
default the styling is self contained which means that at the end
of the string a reset code is issued. This can be preve... | [
"def",
"style",
"(",
"text",
",",
"fg",
"=",
"None",
",",
"bg",
"=",
"None",
",",
"bold",
"=",
"None",
",",
"dim",
"=",
"None",
",",
"underline",
"=",
"None",
",",
"blink",
"=",
"None",
",",
"reverse",
"=",
"None",
",",
"reset",
"=",
"True",
")... | Styles a text with ANSI styles and returns the new string. By
default the styling is self contained which means that at the end
of the string a reset code is issued. This can be prevented by
passing ``reset=False``.
Examples::
click.echo(click.style('Hello World!', fg='green'))
click... | [
"Styles",
"a",
"text",
"with",
"ANSI",
"styles",
"and",
"returns",
"the",
"new",
"string",
".",
"By",
"default",
"the",
"styling",
"is",
"self",
"contained",
"which",
"means",
"that",
"at",
"the",
"end",
"of",
"the",
"string",
"a",
"reset",
"code",
"is",... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/termui.py#L316-L382 | train | Style a string with ANSI codes and returns the new string. |
mottosso/be | be/vendor/click/termui.py | secho | def secho(text, file=None, nl=True, err=False, color=None, **styles):
"""This function combines :func:`echo` and :func:`style` into one
call. As such the following two calls are the same::
click.secho('Hello World!', fg='green')
click.echo(click.style('Hello World!', fg='green'))
All keyw... | python | def secho(text, file=None, nl=True, err=False, color=None, **styles):
"""This function combines :func:`echo` and :func:`style` into one
call. As such the following two calls are the same::
click.secho('Hello World!', fg='green')
click.echo(click.style('Hello World!', fg='green'))
All keyw... | [
"def",
"secho",
"(",
"text",
",",
"file",
"=",
"None",
",",
"nl",
"=",
"True",
",",
"err",
"=",
"False",
",",
"color",
"=",
"None",
",",
"*",
"*",
"styles",
")",
":",
"return",
"echo",
"(",
"style",
"(",
"text",
",",
"*",
"*",
"styles",
")",
... | This function combines :func:`echo` and :func:`style` into one
call. As such the following two calls are the same::
click.secho('Hello World!', fg='green')
click.echo(click.style('Hello World!', fg='green'))
All keyword arguments are forwarded to the underlying functions
depending on whic... | [
"This",
"function",
"combines",
":",
"func",
":",
"echo",
"and",
":",
"func",
":",
"style",
"into",
"one",
"call",
".",
"As",
"such",
"the",
"following",
"two",
"calls",
"are",
"the",
"same",
"::"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/termui.py#L397-L409 | train | A wrapper around click. secho and click. style |
mottosso/be | be/vendor/requests/sessions.py | merge_setting | def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
"""
Determines appropriate setting for a given request, taking into account the
explicit setting on that request, and the setting in the session. If a
setting is a dictionary, they will be merged together using `dict_class`
... | python | def merge_setting(request_setting, session_setting, dict_class=OrderedDict):
"""
Determines appropriate setting for a given request, taking into account the
explicit setting on that request, and the setting in the session. If a
setting is a dictionary, they will be merged together using `dict_class`
... | [
"def",
"merge_setting",
"(",
"request_setting",
",",
"session_setting",
",",
"dict_class",
"=",
"OrderedDict",
")",
":",
"if",
"session_setting",
"is",
"None",
":",
"return",
"request_setting",
"if",
"request_setting",
"is",
"None",
":",
"return",
"session_setting",... | Determines appropriate setting for a given request, taking into account the
explicit setting on that request, and the setting in the session. If a
setting is a dictionary, they will be merged together using `dict_class` | [
"Determines",
"appropriate",
"setting",
"for",
"a",
"given",
"request",
"taking",
"into",
"account",
"the",
"explicit",
"setting",
"on",
"that",
"request",
"and",
"the",
"setting",
"in",
"the",
"session",
".",
"If",
"a",
"setting",
"is",
"a",
"dictionary",
"... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/sessions.py#L42-L72 | train | Merges two settings into one. |
mottosso/be | be/vendor/requests/sessions.py | SessionRedirectMixin.resolve_redirects | def resolve_redirects(self, resp, req, stream=False, timeout=None,
verify=True, cert=None, proxies=None):
"""Receives a Response. Returns a generator of Responses."""
i = 0
hist = [] # keep track of history
while resp.is_redirect:
prepared_request ... | python | def resolve_redirects(self, resp, req, stream=False, timeout=None,
verify=True, cert=None, proxies=None):
"""Receives a Response. Returns a generator of Responses."""
i = 0
hist = [] # keep track of history
while resp.is_redirect:
prepared_request ... | [
"def",
"resolve_redirects",
"(",
"self",
",",
"resp",
",",
"req",
",",
"stream",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"verify",
"=",
"True",
",",
"cert",
"=",
"None",
",",
"proxies",
"=",
"None",
")",
":",
"i",
"=",
"0",
"hist",
"=",
"... | Receives a Response. Returns a generator of Responses. | [
"Receives",
"a",
"Response",
".",
"Returns",
"a",
"generator",
"of",
"Responses",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/sessions.py#L92-L201 | train | Resolves the redirects in a response. |
mottosso/be | be/vendor/requests/sessions.py | Session.send | def send(self, request, **kwargs):
"""Send a given PreparedRequest."""
# Set defaults that the hooks can utilize to ensure they always have
# the correct parameters to reproduce the previous request.
kwargs.setdefault('stream', self.stream)
kwargs.setdefault('verify', self.verify... | python | def send(self, request, **kwargs):
"""Send a given PreparedRequest."""
# Set defaults that the hooks can utilize to ensure they always have
# the correct parameters to reproduce the previous request.
kwargs.setdefault('stream', self.stream)
kwargs.setdefault('verify', self.verify... | [
"def",
"send",
"(",
"self",
",",
"request",
",",
"*",
"*",
"kwargs",
")",
":",
"# Set defaults that the hooks can utilize to ensure they always have",
"# the correct parameters to reproduce the previous request.",
"kwargs",
".",
"setdefault",
"(",
"'stream'",
",",
"self",
"... | Send a given PreparedRequest. | [
"Send",
"a",
"given",
"PreparedRequest",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/sessions.py#L538-L615 | train | Send a PreparedRequest object to the local cache. |
mottosso/be | be/vendor/requests/packages/urllib3/response.py | HTTPResponse.stream | def stream(self, amt=2**16, decode_content=None):
"""
A generator wrapper for the read() method. A call will block until
``amt`` bytes have been read from the connection or until the
connection is closed.
:param amt:
How much of the content to read. The generator wil... | python | def stream(self, amt=2**16, decode_content=None):
"""
A generator wrapper for the read() method. A call will block until
``amt`` bytes have been read from the connection or until the
connection is closed.
:param amt:
How much of the content to read. The generator wil... | [
"def",
"stream",
"(",
"self",
",",
"amt",
"=",
"2",
"**",
"16",
",",
"decode_content",
"=",
"None",
")",
":",
"while",
"not",
"is_fp_closed",
"(",
"self",
".",
"_fp",
")",
":",
"data",
"=",
"self",
".",
"read",
"(",
"amt",
"=",
"amt",
",",
"decod... | A generator wrapper for the read() method. A call will block until
``amt`` bytes have been read from the connection or until the
connection is closed.
:param amt:
How much of the content to read. The generator will return up to
much data per iteration, but may return les... | [
"A",
"generator",
"wrapper",
"for",
"the",
"read",
"()",
"method",
".",
"A",
"call",
"will",
"block",
"until",
"amt",
"bytes",
"have",
"been",
"read",
"from",
"the",
"connection",
"or",
"until",
"the",
"connection",
"is",
"closed",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/response.py#L256-L276 | train | A generator for the read method. |
mottosso/be | be/vendor/requests/models.py | PreparedRequest.prepare_method | def prepare_method(self, method):
"""Prepares the given HTTP method."""
self.method = method
if self.method is not None:
self.method = self.method.upper() | python | def prepare_method(self, method):
"""Prepares the given HTTP method."""
self.method = method
if self.method is not None:
self.method = self.method.upper() | [
"def",
"prepare_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"method",
"=",
"method",
"if",
"self",
".",
"method",
"is",
"not",
"None",
":",
"self",
".",
"method",
"=",
"self",
".",
"method",
".",
"upper",
"(",
")"
] | Prepares the given HTTP method. | [
"Prepares",
"the",
"given",
"HTTP",
"method",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L328-L332 | train | Prepares the given HTTP method. |
mottosso/be | be/vendor/requests/models.py | PreparedRequest.prepare_headers | def prepare_headers(self, headers):
"""Prepares the given HTTP headers."""
if headers:
self.headers = CaseInsensitiveDict((to_native_string(name), value) for name, value in headers.items())
else:
self.headers = CaseInsensitiveDict() | python | def prepare_headers(self, headers):
"""Prepares the given HTTP headers."""
if headers:
self.headers = CaseInsensitiveDict((to_native_string(name), value) for name, value in headers.items())
else:
self.headers = CaseInsensitiveDict() | [
"def",
"prepare_headers",
"(",
"self",
",",
"headers",
")",
":",
"if",
"headers",
":",
"self",
".",
"headers",
"=",
"CaseInsensitiveDict",
"(",
"(",
"to_native_string",
"(",
"name",
")",
",",
"value",
")",
"for",
"name",
",",
"value",
"in",
"headers",
".... | Prepares the given HTTP headers. | [
"Prepares",
"the",
"given",
"HTTP",
"headers",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L406-L412 | train | Prepares the given HTTP headers. |
mottosso/be | be/vendor/requests/models.py | Response.iter_content | def iter_content(self, chunk_size=1, decode_unicode=False):
"""Iterates over the response data. When stream=True is set on the
request, this avoids reading the content at once into memory for
large responses. The chunk size is the number of bytes it should
read into memory. This is no... | python | def iter_content(self, chunk_size=1, decode_unicode=False):
"""Iterates over the response data. When stream=True is set on the
request, this avoids reading the content at once into memory for
large responses. The chunk size is the number of bytes it should
read into memory. This is no... | [
"def",
"iter_content",
"(",
"self",
",",
"chunk_size",
"=",
"1",
",",
"decode_unicode",
"=",
"False",
")",
":",
"def",
"generate",
"(",
")",
":",
"try",
":",
"# Special case for urllib3.",
"try",
":",
"for",
"chunk",
"in",
"self",
".",
"raw",
".",
"strea... | Iterates over the response data. When stream=True is set on the
request, this avoids reading the content at once into memory for
large responses. The chunk size is the number of bytes it should
read into memory. This is not necessarily the length of each item
returned as decoding can ... | [
"Iterates",
"over",
"the",
"response",
"data",
".",
"When",
"stream",
"=",
"True",
"is",
"set",
"on",
"the",
"request",
"this",
"avoids",
"reading",
"the",
"content",
"at",
"once",
"into",
"memory",
"for",
"large",
"responses",
".",
"The",
"chunk",
"size",... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L642-L686 | train | Iterates over the response data. |
mottosso/be | be/vendor/requests/models.py | Response.json | def json(self, **kwargs):
"""Returns the json-encoded content of a response, if any.
:param \*\*kwargs: Optional arguments that ``json.loads`` takes.
"""
if not self.encoding and len(self.content) > 3:
# No encoding set. JSON RFC 4627 section 3 states we should expect
... | python | def json(self, **kwargs):
"""Returns the json-encoded content of a response, if any.
:param \*\*kwargs: Optional arguments that ``json.loads`` takes.
"""
if not self.encoding and len(self.content) > 3:
# No encoding set. JSON RFC 4627 section 3 states we should expect
... | [
"def",
"json",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"if",
"not",
"self",
".",
"encoding",
"and",
"len",
"(",
"self",
".",
"content",
")",
">",
"3",
":",
"# No encoding set. JSON RFC 4627 section 3 states we should expect",
"# UTF-8, -16 or -32. Detect w... | Returns the json-encoded content of a response, if any.
:param \*\*kwargs: Optional arguments that ``json.loads`` takes. | [
"Returns",
"the",
"json",
"-",
"encoded",
"content",
"of",
"a",
"response",
"if",
"any",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L781-L802 | train | Returns the json - encoded content of a response if any. |
mottosso/be | be/vendor/requests/models.py | Response.raise_for_status | def raise_for_status(self):
"""Raises stored :class:`HTTPError`, if one occurred."""
http_error_msg = ''
if 400 <= self.status_code < 500:
http_error_msg = '%s Client Error: %s' % (self.status_code, self.reason)
elif 500 <= self.status_code < 600:
http_error_ms... | python | def raise_for_status(self):
"""Raises stored :class:`HTTPError`, if one occurred."""
http_error_msg = ''
if 400 <= self.status_code < 500:
http_error_msg = '%s Client Error: %s' % (self.status_code, self.reason)
elif 500 <= self.status_code < 600:
http_error_ms... | [
"def",
"raise_for_status",
"(",
"self",
")",
":",
"http_error_msg",
"=",
"''",
"if",
"400",
"<=",
"self",
".",
"status_code",
"<",
"500",
":",
"http_error_msg",
"=",
"'%s Client Error: %s'",
"%",
"(",
"self",
".",
"status_code",
",",
"self",
".",
"reason",
... | Raises stored :class:`HTTPError`, if one occurred. | [
"Raises",
"stored",
":",
"class",
":",
"HTTPError",
"if",
"one",
"occurred",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L822-L834 | train | Raises an exception if one occurred. |
mottosso/be | be/vendor/requests/packages/urllib3/poolmanager.py | PoolManager._new_pool | def _new_pool(self, scheme, host, port):
"""
Create a new :class:`ConnectionPool` based on host, port and scheme.
This method is used to actually create the connection pools handed out
by :meth:`connection_from_url` and companion methods. It is intended
to be overridden for cust... | python | def _new_pool(self, scheme, host, port):
"""
Create a new :class:`ConnectionPool` based on host, port and scheme.
This method is used to actually create the connection pools handed out
by :meth:`connection_from_url` and companion methods. It is intended
to be overridden for cust... | [
"def",
"_new_pool",
"(",
"self",
",",
"scheme",
",",
"host",
",",
"port",
")",
":",
"pool_cls",
"=",
"pool_classes_by_scheme",
"[",
"scheme",
"]",
"kwargs",
"=",
"self",
".",
"connection_pool_kw",
"if",
"scheme",
"==",
"'http'",
":",
"kwargs",
"=",
"self",... | Create a new :class:`ConnectionPool` based on host, port and scheme.
This method is used to actually create the connection pools handed out
by :meth:`connection_from_url` and companion methods. It is intended
to be overridden for customization. | [
"Create",
"a",
"new",
":",
"class",
":",
"ConnectionPool",
"based",
"on",
"host",
"port",
"and",
"scheme",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/poolmanager.py#L75-L90 | train | Create a new connection pool based on host port and scheme. |
mottosso/be | be/vendor/requests/packages/urllib3/poolmanager.py | PoolManager.connection_from_host | def connection_from_host(self, host, port=None, scheme='http'):
"""
Get a :class:`ConnectionPool` based on the host, port, and scheme.
If ``port`` isn't given, it will be derived from the ``scheme`` using
``urllib3.connectionpool.port_by_scheme``.
"""
if not host:
... | python | def connection_from_host(self, host, port=None, scheme='http'):
"""
Get a :class:`ConnectionPool` based on the host, port, and scheme.
If ``port`` isn't given, it will be derived from the ``scheme`` using
``urllib3.connectionpool.port_by_scheme``.
"""
if not host:
... | [
"def",
"connection_from_host",
"(",
"self",
",",
"host",
",",
"port",
"=",
"None",
",",
"scheme",
"=",
"'http'",
")",
":",
"if",
"not",
"host",
":",
"raise",
"LocationValueError",
"(",
"\"No host specified.\"",
")",
"scheme",
"=",
"scheme",
"or",
"'http'",
... | Get a :class:`ConnectionPool` based on the host, port, and scheme.
If ``port`` isn't given, it will be derived from the ``scheme`` using
``urllib3.connectionpool.port_by_scheme``. | [
"Get",
"a",
":",
"class",
":",
"ConnectionPool",
"based",
"on",
"the",
"host",
"port",
"and",
"scheme",
"."
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/poolmanager.py#L101-L127 | train | Get a ConnectionPool based on the given host and port and scheme. |
box/genty | genty/genty_repeat.py | genty_repeat | def genty_repeat(count):
"""
To use in conjunction with a TestClass wrapped with @genty.
Runs the wrapped test 'count' times:
@genty_repeat(count)
def test_some_function(self)
...
Can also wrap a test already decorated with @genty_dataset
@genty_repeat(3)
@g... | python | def genty_repeat(count):
"""
To use in conjunction with a TestClass wrapped with @genty.
Runs the wrapped test 'count' times:
@genty_repeat(count)
def test_some_function(self)
...
Can also wrap a test already decorated with @genty_dataset
@genty_repeat(3)
@g... | [
"def",
"genty_repeat",
"(",
"count",
")",
":",
"if",
"count",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"Really? Can't have {0} iterations. Please pick a value >= 0.\"",
".",
"format",
"(",
"count",
")",
")",
"def",
"wrap",
"(",
"test_method",
")",
":",
"test... | To use in conjunction with a TestClass wrapped with @genty.
Runs the wrapped test 'count' times:
@genty_repeat(count)
def test_some_function(self)
...
Can also wrap a test already decorated with @genty_dataset
@genty_repeat(3)
@genty_dataset(True, False)
def... | [
"To",
"use",
"in",
"conjunction",
"with",
"a",
"TestClass",
"wrapped",
"with",
"@genty",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_repeat.py#L6-L36 | train | Decorator to repeat count times. |
abingham/docopt-subcommands | docopt_subcommands/__init__.py | command | def command(name=None):
"""A decorator to register a subcommand with the global `Subcommands` instance.
"""
def decorator(f):
_commands.append((name, f))
return f
return decorator | python | def command(name=None):
"""A decorator to register a subcommand with the global `Subcommands` instance.
"""
def decorator(f):
_commands.append((name, f))
return f
return decorator | [
"def",
"command",
"(",
"name",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"_commands",
".",
"append",
"(",
"(",
"name",
",",
"f",
")",
")",
"return",
"f",
"return",
"decorator"
] | A decorator to register a subcommand with the global `Subcommands` instance. | [
"A",
"decorator",
"to",
"register",
"a",
"subcommand",
"with",
"the",
"global",
"Subcommands",
"instance",
"."
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/__init__.py#L8-L14 | train | A decorator to register a subcommand with the global _commands list. |
abingham/docopt-subcommands | docopt_subcommands/__init__.py | main | def main(program=None,
version=None,
doc_template=None,
commands=None,
argv=None,
exit_at_end=True):
"""Top-level driver for creating subcommand-based programs.
Args:
program: The name of your program.
version: The version string for your program.
... | python | def main(program=None,
version=None,
doc_template=None,
commands=None,
argv=None,
exit_at_end=True):
"""Top-level driver for creating subcommand-based programs.
Args:
program: The name of your program.
version: The version string for your program.
... | [
"def",
"main",
"(",
"program",
"=",
"None",
",",
"version",
"=",
"None",
",",
"doc_template",
"=",
"None",
",",
"commands",
"=",
"None",
",",
"argv",
"=",
"None",
",",
"exit_at_end",
"=",
"True",
")",
":",
"if",
"commands",
"is",
"None",
":",
"if",
... | Top-level driver for creating subcommand-based programs.
Args:
program: The name of your program.
version: The version string for your program.
doc_template: The top-level docstring template for your program. If
`None`, a standard default version is applied.
commands: A ... | [
"Top",
"-",
"level",
"driver",
"for",
"creating",
"subcommand",
"-",
"based",
"programs",
"."
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/__init__.py#L17-L69 | train | Main function for creating a new If instance. |
alecxe/scrapy-beautifulsoup | scrapy_beautifulsoup/middleware.py | BeautifulSoupMiddleware.process_response | def process_response(self, request, response, spider):
"""Overridden process_response would "pipe" response.body through BeautifulSoup."""
return response.replace(body=str(BeautifulSoup(response.body, self.parser))) | python | def process_response(self, request, response, spider):
"""Overridden process_response would "pipe" response.body through BeautifulSoup."""
return response.replace(body=str(BeautifulSoup(response.body, self.parser))) | [
"def",
"process_response",
"(",
"self",
",",
"request",
",",
"response",
",",
"spider",
")",
":",
"return",
"response",
".",
"replace",
"(",
"body",
"=",
"str",
"(",
"BeautifulSoup",
"(",
"response",
".",
"body",
",",
"self",
".",
"parser",
")",
")",
"... | Overridden process_response would "pipe" response.body through BeautifulSoup. | [
"Overridden",
"process_response",
"would",
"pipe",
"response",
".",
"body",
"through",
"BeautifulSoup",
"."
] | 733f50e83a5b60edc9325e4f14cd4ab2b3914555 | https://github.com/alecxe/scrapy-beautifulsoup/blob/733f50e83a5b60edc9325e4f14cd4ab2b3914555/scrapy_beautifulsoup/middleware.py#L14-L16 | train | Overridden process_response would pipe response. body through BeautifulSoup. |
box/genty | genty/genty.py | genty | def genty(target_cls):
"""
This decorator takes the information provided by @genty_dataset,
@genty_dataprovider, and @genty_repeat and generates the corresponding
test methods.
:param target_cls:
Test class whose test methods have been decorated.
:type target_cls:
`class`
""... | python | def genty(target_cls):
"""
This decorator takes the information provided by @genty_dataset,
@genty_dataprovider, and @genty_repeat and generates the corresponding
test methods.
:param target_cls:
Test class whose test methods have been decorated.
:type target_cls:
`class`
""... | [
"def",
"genty",
"(",
"target_cls",
")",
":",
"tests",
"=",
"_expand_tests",
"(",
"target_cls",
")",
"tests_with_datasets",
"=",
"_expand_datasets",
"(",
"tests",
")",
"tests_with_datasets_and_repeats",
"=",
"_expand_repeats",
"(",
"tests_with_datasets",
")",
"_add_new... | This decorator takes the information provided by @genty_dataset,
@genty_dataprovider, and @genty_repeat and generates the corresponding
test methods.
:param target_cls:
Test class whose test methods have been decorated.
:type target_cls:
`class` | [
"This",
"decorator",
"takes",
"the",
"information",
"provided",
"by",
"@genty_dataset",
"@genty_dataprovider",
"and",
"@genty_repeat",
"and",
"generates",
"the",
"corresponding",
"test",
"methods",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L21-L38 | train | This decorator creates a new base class that contains the test methods that are generated by the genty dataset and genty repeat methods. |
box/genty | genty/genty.py | _expand_datasets | def _expand_datasets(test_functions):
"""
Generator producing test_methods, with an optional dataset.
:param test_functions:
Iterator over tuples of test name and test unbound function.
:type test_functions:
`iterator` of `tuple` of (`unicode`, `function`)
:return:
Generator... | python | def _expand_datasets(test_functions):
"""
Generator producing test_methods, with an optional dataset.
:param test_functions:
Iterator over tuples of test name and test unbound function.
:type test_functions:
`iterator` of `tuple` of (`unicode`, `function`)
:return:
Generator... | [
"def",
"_expand_datasets",
"(",
"test_functions",
")",
":",
"for",
"name",
",",
"func",
"in",
"test_functions",
":",
"dataset_tuples",
"=",
"chain",
"(",
"[",
"(",
"None",
",",
"getattr",
"(",
"func",
",",
"'genty_datasets'",
",",
"{",
"}",
")",
")",
"]"... | Generator producing test_methods, with an optional dataset.
:param test_functions:
Iterator over tuples of test name and test unbound function.
:type test_functions:
`iterator` of `tuple` of (`unicode`, `function`)
:return:
Generator yielding a tuple of
- method_name : ... | [
"Generator",
"producing",
"test_methods",
"with",
"an",
"optional",
"dataset",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L62-L101 | train | Generates test_methods for the given test_functions. |
box/genty | genty/genty.py | _expand_repeats | def _expand_repeats(test_functions):
"""
Generator producing test_methods, with any repeat count unrolled.
:param test_functions:
Sequence of tuples of
- method_name : Name of the test method
- unbound function : Unbound function that will be the test method.
- dataset ... | python | def _expand_repeats(test_functions):
"""
Generator producing test_methods, with any repeat count unrolled.
:param test_functions:
Sequence of tuples of
- method_name : Name of the test method
- unbound function : Unbound function that will be the test method.
- dataset ... | [
"def",
"_expand_repeats",
"(",
"test_functions",
")",
":",
"for",
"name",
",",
"func",
",",
"dataset_name",
",",
"dataset",
",",
"dataprovider",
"in",
"test_functions",
":",
"repeat_count",
"=",
"getattr",
"(",
"func",
",",
"'genty_repeat_count'",
",",
"0",
")... | Generator producing test_methods, with any repeat count unrolled.
:param test_functions:
Sequence of tuples of
- method_name : Name of the test method
- unbound function : Unbound function that will be the test method.
- dataset name : String representation of the given dat... | [
"Generator",
"producing",
"test_methods",
"with",
"any",
"repeat",
"count",
"unrolled",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L104-L139 | train | Generates test_methods for the given test_functions. |
box/genty | genty/genty.py | _is_referenced_in_argv | def _is_referenced_in_argv(method_name):
"""
Various test runners allow one to run a specific test like so:
python -m unittest -v <test_module>.<test_name>
Return True is the given method name is so referenced.
:param method_name:
Base name of the method to add.
:type method_name:
... | python | def _is_referenced_in_argv(method_name):
"""
Various test runners allow one to run a specific test like so:
python -m unittest -v <test_module>.<test_name>
Return True is the given method name is so referenced.
:param method_name:
Base name of the method to add.
:type method_name:
... | [
"def",
"_is_referenced_in_argv",
"(",
"method_name",
")",
":",
"expr",
"=",
"'.*[:.]{0}$'",
".",
"format",
"(",
"method_name",
")",
"regex",
"=",
"re",
".",
"compile",
"(",
"expr",
")",
"return",
"any",
"(",
"regex",
".",
"match",
"(",
"arg",
")",
"for",... | Various test runners allow one to run a specific test like so:
python -m unittest -v <test_module>.<test_name>
Return True is the given method name is so referenced.
:param method_name:
Base name of the method to add.
:type method_name:
`unicode`
:return:
Is the given m... | [
"Various",
"test",
"runners",
"allow",
"one",
"to",
"run",
"a",
"specific",
"test",
"like",
"so",
":",
"python",
"-",
"m",
"unittest",
"-",
"v",
"<test_module",
">",
".",
"<test_name",
">"
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L193-L211 | train | Checks if the given method name is referenced by the command line. |
box/genty | genty/genty.py | _build_repeat_suffix | def _build_repeat_suffix(iteration, count):
"""
Return the suffix string to identify iteration X out of Y.
For example, with a count of 100, this will build strings like
"iteration_053" or "iteration_008".
:param iteration:
Current iteration.
:type iteration:
`int`
:param c... | python | def _build_repeat_suffix(iteration, count):
"""
Return the suffix string to identify iteration X out of Y.
For example, with a count of 100, this will build strings like
"iteration_053" or "iteration_008".
:param iteration:
Current iteration.
:type iteration:
`int`
:param c... | [
"def",
"_build_repeat_suffix",
"(",
"iteration",
",",
"count",
")",
":",
"format_width",
"=",
"int",
"(",
"math",
".",
"ceil",
"(",
"math",
".",
"log",
"(",
"count",
"+",
"1",
",",
"10",
")",
")",
")",
"new_suffix",
"=",
"'iteration_{0:0{width}d}'",
".",... | Return the suffix string to identify iteration X out of Y.
For example, with a count of 100, this will build strings like
"iteration_053" or "iteration_008".
:param iteration:
Current iteration.
:type iteration:
`int`
:param count:
Total number of iterations.
:type coun... | [
"Return",
"the",
"suffix",
"string",
"to",
"identify",
"iteration",
"X",
"out",
"of",
"Y",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L214-L239 | train | Build a repeat suffix for the current iteration. |
box/genty | genty/genty.py | _build_final_method_name | def _build_final_method_name(
method_name,
dataset_name,
dataprovider_name,
repeat_suffix,
):
"""
Return a nice human friendly name, that almost looks like code.
Example: a test called 'test_something' with a dataset of (5, 'hello')
Return: "test_something(5, 'hell... | python | def _build_final_method_name(
method_name,
dataset_name,
dataprovider_name,
repeat_suffix,
):
"""
Return a nice human friendly name, that almost looks like code.
Example: a test called 'test_something' with a dataset of (5, 'hello')
Return: "test_something(5, 'hell... | [
"def",
"_build_final_method_name",
"(",
"method_name",
",",
"dataset_name",
",",
"dataprovider_name",
",",
"repeat_suffix",
",",
")",
":",
"# For tests using a dataprovider, append \"_<dataprovider_name>\" to",
"# the test method name",
"suffix",
"=",
"''",
"if",
"dataprovider... | Return a nice human friendly name, that almost looks like code.
Example: a test called 'test_something' with a dataset of (5, 'hello')
Return: "test_something(5, 'hello')"
Example: a test called 'test_other_stuff' with dataset of (9) and repeats
Return: "test_other_stuff(9) iteration_<X>"
... | [
"Return",
"a",
"nice",
"human",
"friendly",
"name",
"that",
"almost",
"looks",
"like",
"code",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L270-L335 | train | Build the final test method name for the specified data set and dataset. |
box/genty | genty/genty.py | _build_dataset_method | def _build_dataset_method(method, dataset):
"""
Return a fabricated method that marshals the dataset into parameters
for given 'method'
:param method:
The underlying test method.
:type method:
`callable`
:param dataset:
Tuple or GentyArgs instance containing the args of t... | python | def _build_dataset_method(method, dataset):
"""
Return a fabricated method that marshals the dataset into parameters
for given 'method'
:param method:
The underlying test method.
:type method:
`callable`
:param dataset:
Tuple or GentyArgs instance containing the args of t... | [
"def",
"_build_dataset_method",
"(",
"method",
",",
"dataset",
")",
":",
"if",
"isinstance",
"(",
"dataset",
",",
"GentyArgs",
")",
":",
"test_method",
"=",
"lambda",
"my_self",
":",
"method",
"(",
"my_self",
",",
"*",
"dataset",
".",
"args",
",",
"*",
"... | Return a fabricated method that marshals the dataset into parameters
for given 'method'
:param method:
The underlying test method.
:type method:
`callable`
:param dataset:
Tuple or GentyArgs instance containing the args of the dataset.
:type dataset:
`tuple` or :class... | [
"Return",
"a",
"fabricated",
"method",
"that",
"marshals",
"the",
"dataset",
"into",
"parameters",
"for",
"given",
"method",
":",
"param",
"method",
":",
"The",
"underlying",
"test",
"method",
".",
":",
"type",
"method",
":",
"callable",
":",
"param",
"datas... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L338-L366 | train | Builds a test method that can be used to build the dataset for given method. |
box/genty | genty/genty.py | _build_dataprovider_method | def _build_dataprovider_method(method, dataset, dataprovider):
"""
Return a fabricated method that calls the dataprovider with the given
dataset, and marshals the return value from that into params to the
underlying test 'method'.
:param method:
The underlying test method.
:type method:
... | python | def _build_dataprovider_method(method, dataset, dataprovider):
"""
Return a fabricated method that calls the dataprovider with the given
dataset, and marshals the return value from that into params to the
underlying test 'method'.
:param method:
The underlying test method.
:type method:
... | [
"def",
"_build_dataprovider_method",
"(",
"method",
",",
"dataset",
",",
"dataprovider",
")",
":",
"if",
"isinstance",
"(",
"dataset",
",",
"GentyArgs",
")",
":",
"final_args",
"=",
"dataset",
".",
"args",
"final_kwargs",
"=",
"dataset",
".",
"kwargs",
"else",... | Return a fabricated method that calls the dataprovider with the given
dataset, and marshals the return value from that into params to the
underlying test 'method'.
:param method:
The underlying test method.
:type method:
`callable`
:param dataset:
Tuple or GentyArgs instance ... | [
"Return",
"a",
"fabricated",
"method",
"that",
"calls",
"the",
"dataprovider",
"with",
"the",
"given",
"dataset",
"and",
"marshals",
"the",
"return",
"value",
"from",
"that",
"into",
"params",
"to",
"the",
"underlying",
"test",
"method",
".",
":",
"param",
"... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L369-L416 | train | Build a test method that calls the dataprovider with the given dataset and returns the return value from that method. |
box/genty | genty/genty.py | _add_method_to_class | def _add_method_to_class(
target_cls,
method_name,
func,
dataset_name,
dataset,
dataprovider,
repeat_suffix,
):
"""
Add the described method to the given class.
:param target_cls:
Test class to which to add a method.
:type target_cls:
... | python | def _add_method_to_class(
target_cls,
method_name,
func,
dataset_name,
dataset,
dataprovider,
repeat_suffix,
):
"""
Add the described method to the given class.
:param target_cls:
Test class to which to add a method.
:type target_cls:
... | [
"def",
"_add_method_to_class",
"(",
"target_cls",
",",
"method_name",
",",
"func",
",",
"dataset_name",
",",
"dataset",
",",
"dataprovider",
",",
"repeat_suffix",
",",
")",
":",
"# pylint: disable=too-many-arguments",
"test_method_name_for_dataset",
"=",
"_build_final_met... | Add the described method to the given class.
:param target_cls:
Test class to which to add a method.
:type target_cls:
`class`
:param method_name:
Base name of the method to add.
:type method_name:
`unicode`
:param func:
The underlying test function to call.
... | [
"Add",
"the",
"described",
"method",
"to",
"the",
"given",
"class",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L450-L514 | train | Adds a method to the given class. |
bcbnz/python-rofi | rofi.py | Rofi.close | def close(self):
"""Close any open window.
Note that this only works with non-blocking methods.
"""
if self._process:
# Be nice first.
self._process.send_signal(signal.SIGINT)
# If it doesn't close itself promptly, be brutal.
# Python 3.... | python | def close(self):
"""Close any open window.
Note that this only works with non-blocking methods.
"""
if self._process:
# Be nice first.
self._process.send_signal(signal.SIGINT)
# If it doesn't close itself promptly, be brutal.
# Python 3.... | [
"def",
"close",
"(",
"self",
")",
":",
"if",
"self",
".",
"_process",
":",
"# Be nice first.",
"self",
".",
"_process",
".",
"send_signal",
"(",
"signal",
".",
"SIGINT",
")",
"# If it doesn't close itself promptly, be brutal.",
"# Python 3.2+ added the timeout option to... | Close any open window.
Note that this only works with non-blocking methods. | [
"Close",
"any",
"open",
"window",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L157-L190 | train | Close any open window. |
bcbnz/python-rofi | rofi.py | Rofi._run_blocking | def _run_blocking(self, args, input=None):
"""Internal API: run a blocking command with subprocess.
This closes any open non-blocking dialog before running the command.
Parameters
----------
args: Popen constructor arguments
Command to run.
input: string
... | python | def _run_blocking(self, args, input=None):
"""Internal API: run a blocking command with subprocess.
This closes any open non-blocking dialog before running the command.
Parameters
----------
args: Popen constructor arguments
Command to run.
input: string
... | [
"def",
"_run_blocking",
"(",
"self",
",",
"args",
",",
"input",
"=",
"None",
")",
":",
"# Close any existing dialog.",
"if",
"self",
".",
"_process",
":",
"self",
".",
"close",
"(",
")",
"# Make sure we grab stdout as text (not bytes).",
"kwargs",
"=",
"{",
"}",... | Internal API: run a blocking command with subprocess.
This closes any open non-blocking dialog before running the command.
Parameters
----------
args: Popen constructor arguments
Command to run.
input: string
Value to feed to the stdin of the process.
... | [
"Internal",
"API",
":",
"run",
"a",
"blocking",
"command",
"with",
"subprocess",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L193-L238 | train | Internal API to run a blocking command with subprocess. Popen |
bcbnz/python-rofi | rofi.py | Rofi._run_nonblocking | def _run_nonblocking(self, args, input=None):
"""Internal API: run a non-blocking command with subprocess.
This closes any open non-blocking dialog before running the command.
Parameters
----------
args: Popen constructor arguments
Command to run.
input: str... | python | def _run_nonblocking(self, args, input=None):
"""Internal API: run a non-blocking command with subprocess.
This closes any open non-blocking dialog before running the command.
Parameters
----------
args: Popen constructor arguments
Command to run.
input: str... | [
"def",
"_run_nonblocking",
"(",
"self",
",",
"args",
",",
"input",
"=",
"None",
")",
":",
"# Close any existing dialog.",
"if",
"self",
".",
"_process",
":",
"self",
".",
"close",
"(",
")",
"# Start the new one.",
"self",
".",
"_process",
"=",
"subprocess",
... | Internal API: run a non-blocking command with subprocess.
This closes any open non-blocking dialog before running the command.
Parameters
----------
args: Popen constructor arguments
Command to run.
input: string
Value to feed to the stdin of the process... | [
"Internal",
"API",
":",
"run",
"a",
"non",
"-",
"blocking",
"command",
"with",
"subprocess",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L241-L259 | train | Internal API to run a non - blocking command with subprocess. Popen |
bcbnz/python-rofi | rofi.py | Rofi.error | def error(self, message, rofi_args=None, **kwargs):
"""Show an error window.
This method blocks until the user presses a key.
Fullscreen mode is not supported for error windows, and if specified
will be ignored.
Parameters
----------
message: string
... | python | def error(self, message, rofi_args=None, **kwargs):
"""Show an error window.
This method blocks until the user presses a key.
Fullscreen mode is not supported for error windows, and if specified
will be ignored.
Parameters
----------
message: string
... | [
"def",
"error",
"(",
"self",
",",
"message",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# Generate arguments list.",
"args",
"=",
"[",
"'rofi'",
",",
"'-e'",
",",
"message",
"]",
"a... | Show an error window.
This method blocks until the user presses a key.
Fullscreen mode is not supported for error windows, and if specified
will be ignored.
Parameters
----------
message: string
Error message to show. | [
"Show",
"an",
"error",
"window",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L295-L316 | train | Show an error window. |
bcbnz/python-rofi | rofi.py | Rofi.status | def status(self, message, rofi_args=None, **kwargs):
"""Show a status message.
This method is non-blocking, and intended to give a status update to
the user while something is happening in the background.
To close the window, either call the close() method or use any of the
dis... | python | def status(self, message, rofi_args=None, **kwargs):
"""Show a status message.
This method is non-blocking, and intended to give a status update to
the user while something is happening in the background.
To close the window, either call the close() method or use any of the
dis... | [
"def",
"status",
"(",
"self",
",",
"message",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# Generate arguments list.",
"args",
"=",
"[",
"'rofi'",
",",
"'-e'",
",",
"message",
"]",
"... | Show a status message.
This method is non-blocking, and intended to give a status update to
the user while something is happening in the background.
To close the window, either call the close() method or use any of the
display methods to replace it with a different window.
Ful... | [
"Show",
"a",
"status",
"message",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L319-L344 | train | Show a status message. |
bcbnz/python-rofi | rofi.py | Rofi.select | def select(self, prompt, options, rofi_args=None, message="", select=None, **kwargs):
"""Show a list of options and return user selection.
This method blocks until the user makes their choice.
Parameters
----------
prompt: string
The prompt telling the user what the... | python | def select(self, prompt, options, rofi_args=None, message="", select=None, **kwargs):
"""Show a list of options and return user selection.
This method blocks until the user makes their choice.
Parameters
----------
prompt: string
The prompt telling the user what the... | [
"def",
"select",
"(",
"self",
",",
"prompt",
",",
"options",
",",
"rofi_args",
"=",
"None",
",",
"message",
"=",
"\"\"",
",",
"select",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# Replace newlines a... | Show a list of options and return user selection.
This method blocks until the user makes their choice.
Parameters
----------
prompt: string
The prompt telling the user what they are selecting.
options: list of strings
The options they can choose from. A... | [
"Show",
"a",
"list",
"of",
"options",
"and",
"return",
"user",
"selection",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L347-L462 | train | Show a list of options and return user selection. |
bcbnz/python-rofi | rofi.py | Rofi.generic_entry | def generic_entry(self, prompt, validator=None, message=None, rofi_args=None, **kwargs):
"""A generic entry box.
Parameters
----------
prompt: string
Text prompt for the entry.
validator: function, optional
A function to validate and convert the value ent... | python | def generic_entry(self, prompt, validator=None, message=None, rofi_args=None, **kwargs):
"""A generic entry box.
Parameters
----------
prompt: string
Text prompt for the entry.
validator: function, optional
A function to validate and convert the value ent... | [
"def",
"generic_entry",
"(",
"self",
",",
"prompt",
",",
"validator",
"=",
"None",
",",
"message",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"error",
"=",
"\"\"",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# ... | A generic entry box.
Parameters
----------
prompt: string
Text prompt for the entry.
validator: function, optional
A function to validate and convert the value entered by the user.
It should take one parameter, the string that the user entered, and
... | [
"A",
"generic",
"entry",
"box",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L465-L533 | train | A generic entry box. |
bcbnz/python-rofi | rofi.py | Rofi.text_entry | def text_entry(self, prompt, message=None, allow_blank=False, strip=True,
rofi_args=None, **kwargs):
"""Prompt the user to enter a piece of text.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Mes... | python | def text_entry(self, prompt, message=None, allow_blank=False, strip=True,
rofi_args=None, **kwargs):
"""Prompt the user to enter a piece of text.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Mes... | [
"def",
"text_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"allow_blank",
"=",
"False",
",",
"strip",
"=",
"True",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"text_validator",
"(",
"text",
")",
":... | Prompt the user to enter a piece of text.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
allow_blank: Boolean
Whether to allow blank entries.
strip... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"piece",
"of",
"text",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L536-L566 | train | Prompt the user to enter a piece of text. |
bcbnz/python-rofi | rofi.py | Rofi.integer_entry | def integer_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
"""Prompt the user to enter an integer.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the... | python | def integer_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
"""Prompt the user to enter an integer.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the... | [
"def",
"integer_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"min",
"=",
"None",
",",
"max",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Sanity check.",
"if",
"(",
"min",
"is",
"not",
"... | Prompt the user to enter an integer.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
min, max: integer, optional
Minimum and maximum values to allow. If Non... | [
"Prompt",
"the",
"user",
"to",
"enter",
"an",
"integer",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L569-L607 | train | Prompt the user to enter an integer value. |
bcbnz/python-rofi | rofi.py | Rofi.float_entry | def float_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
"""Prompt the user to enter a floating point number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to displa... | python | def float_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
"""Prompt the user to enter a floating point number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to displa... | [
"def",
"float_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"min",
"=",
"None",
",",
"max",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Sanity check.",
"if",
"(",
"min",
"is",
"not",
"No... | Prompt the user to enter a floating point number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
min, max: float, optional
Minimum and maximum values to al... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"floating",
"point",
"number",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L610-L648 | train | Prompt the user to enter a floating point number. |
bcbnz/python-rofi | rofi.py | Rofi.decimal_entry | def decimal_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
"""Prompt the user to enter a decimal number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display und... | python | def decimal_entry(self, prompt, message=None, min=None, max=None, rofi_args=None, **kwargs):
"""Prompt the user to enter a decimal number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display und... | [
"def",
"decimal_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"min",
"=",
"None",
",",
"max",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Sanity check.",
"if",
"(",
"min",
"is",
"not",
"... | Prompt the user to enter a decimal number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
min, max: Decimal, optional
Minimum and maximum values to allow. ... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"decimal",
"number",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L651-L689 | train | Prompt the user to enter a decimal number. |
bcbnz/python-rofi | rofi.py | Rofi.date_entry | def date_entry(self, prompt, message=None, formats=['%x', '%d/%m/%Y'],
show_example=False, rofi_args=None, **kwargs):
"""Prompt the user to enter a date.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
... | python | def date_entry(self, prompt, message=None, formats=['%x', '%d/%m/%Y'],
show_example=False, rofi_args=None, **kwargs):
"""Prompt the user to enter a date.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
... | [
"def",
"date_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"formats",
"=",
"[",
"'%x'",
",",
"'%d/%m/%Y'",
"]",
",",
"show_example",
"=",
"False",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"date_... | Prompt the user to enter a date.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
formats: list of strings, optional
The formats that the user can enter date... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"date",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L692-L737 | train | Prompt the user to enter a date. |
bcbnz/python-rofi | rofi.py | Rofi.time_entry | def time_entry(self, prompt, message=None, formats=['%X', '%H:%M', '%I:%M', '%H.%M',
'%I.%M'], show_example=False, rofi_args=None, **kwargs):
"""Prompt the user to enter a time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: stri... | python | def time_entry(self, prompt, message=None, formats=['%X', '%H:%M', '%I:%M', '%H.%M',
'%I.%M'], show_example=False, rofi_args=None, **kwargs):
"""Prompt the user to enter a time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: stri... | [
"def",
"time_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"formats",
"=",
"[",
"'%X'",
",",
"'%H:%M'",
",",
"'%I:%M'",
",",
"'%H.%M'",
",",
"'%I.%M'",
"]",
",",
"show_example",
"=",
"False",
",",
"rofi_args",
"=",
"None",
",",
... | Prompt the user to enter a time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
formats: list of strings, optional
The formats that the user can enter time... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"time",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L740-L785 | train | Prompt the user to enter a time. |
bcbnz/python-rofi | rofi.py | Rofi.datetime_entry | def datetime_entry(self, prompt, message=None, formats=['%x %X'], show_example=False,
rofi_args=None, **kwargs):
"""Prompt the user to enter a date and time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
... | python | def datetime_entry(self, prompt, message=None, formats=['%x %X'], show_example=False,
rofi_args=None, **kwargs):
"""Prompt the user to enter a date and time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
... | [
"def",
"datetime_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"formats",
"=",
"[",
"'%x %X'",
"]",
",",
"show_example",
"=",
"False",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"datetime_validator",
... | Prompt the user to enter a date and time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the entry line.
formats: list of strings, optional
The formats that the user can e... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"date",
"and",
"time",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L788-L833 | train | Prompt the user to enter a date and time. |
bcbnz/python-rofi | rofi.py | Rofi.exit_with_error | def exit_with_error(self, error, **kwargs):
"""Report an error and exit.
This raises a SystemExit exception to ask the interpreter to quit.
Parameters
----------
error: string
The error to report before quitting.
"""
self.error(error, **kwargs)
... | python | def exit_with_error(self, error, **kwargs):
"""Report an error and exit.
This raises a SystemExit exception to ask the interpreter to quit.
Parameters
----------
error: string
The error to report before quitting.
"""
self.error(error, **kwargs)
... | [
"def",
"exit_with_error",
"(",
"self",
",",
"error",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"error",
"(",
"error",
",",
"*",
"*",
"kwargs",
")",
"raise",
"SystemExit",
"(",
"error",
")"
] | Report an error and exit.
This raises a SystemExit exception to ask the interpreter to quit.
Parameters
----------
error: string
The error to report before quitting. | [
"Report",
"an",
"error",
"and",
"exit",
"."
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L836-L848 | train | Report an error and exit. |
box/genty | genty/private/__init__.py | format_kwarg | def format_kwarg(key, value):
"""
Return a string of form: "key=<value>"
If 'value' is a string, we want it quoted. The goal is to make
the string a named parameter in a method call.
"""
translator = repr if isinstance(value, six.string_types) else six.text_type
arg_value = translator(valu... | python | def format_kwarg(key, value):
"""
Return a string of form: "key=<value>"
If 'value' is a string, we want it quoted. The goal is to make
the string a named parameter in a method call.
"""
translator = repr if isinstance(value, six.string_types) else six.text_type
arg_value = translator(valu... | [
"def",
"format_kwarg",
"(",
"key",
",",
"value",
")",
":",
"translator",
"=",
"repr",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
"else",
"six",
".",
"text_type",
"arg_value",
"=",
"translator",
"(",
"value",
")",
"return",
"'... | Return a string of form: "key=<value>"
If 'value' is a string, we want it quoted. The goal is to make
the string a named parameter in a method call. | [
"Return",
"a",
"string",
"of",
"form",
":",
"key",
"=",
"<value",
">"
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/private/__init__.py#L7-L17 | train | Format a key = value pair in a
. |
box/genty | genty/private/__init__.py | format_arg | def format_arg(value):
"""
:param value:
Some value in a dataset.
:type value:
varies
:return:
unicode representation of that value
:rtype:
`unicode`
"""
translator = repr if isinstance(value, six.string_types) else six.text_type
return translator(value) | python | def format_arg(value):
"""
:param value:
Some value in a dataset.
:type value:
varies
:return:
unicode representation of that value
:rtype:
`unicode`
"""
translator = repr if isinstance(value, six.string_types) else six.text_type
return translator(value) | [
"def",
"format_arg",
"(",
"value",
")",
":",
"translator",
"=",
"repr",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
"else",
"six",
".",
"text_type",
"return",
"translator",
"(",
"value",
")"
] | :param value:
Some value in a dataset.
:type value:
varies
:return:
unicode representation of that value
:rtype:
`unicode` | [
":",
"param",
"value",
":",
"Some",
"value",
"in",
"a",
"dataset",
".",
":",
"type",
"value",
":",
"varies",
":",
"return",
":",
"unicode",
"representation",
"of",
"that",
"value",
":",
"rtype",
":",
"unicode"
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/private/__init__.py#L20-L32 | train | Formats the value in a dataset. |
box/genty | genty/private/__init__.py | encode_non_ascii_string | def encode_non_ascii_string(string):
"""
:param string:
The string to be encoded
:type string:
unicode or str
:return:
The encoded string
:rtype:
str
"""
encoded_string = string.encode('utf-8', 'replace')
if six.PY3:
encoded_string = encoded_string... | python | def encode_non_ascii_string(string):
"""
:param string:
The string to be encoded
:type string:
unicode or str
:return:
The encoded string
:rtype:
str
"""
encoded_string = string.encode('utf-8', 'replace')
if six.PY3:
encoded_string = encoded_string... | [
"def",
"encode_non_ascii_string",
"(",
"string",
")",
":",
"encoded_string",
"=",
"string",
".",
"encode",
"(",
"'utf-8'",
",",
"'replace'",
")",
"if",
"six",
".",
"PY3",
":",
"encoded_string",
"=",
"encoded_string",
".",
"decode",
"(",
")",
"return",
"encod... | :param string:
The string to be encoded
:type string:
unicode or str
:return:
The encoded string
:rtype:
str | [
":",
"param",
"string",
":",
"The",
"string",
"to",
"be",
"encoded",
":",
"type",
"string",
":",
"unicode",
"or",
"str",
":",
"return",
":",
"The",
"encoded",
"string",
":",
"rtype",
":",
"str"
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/private/__init__.py#L35-L50 | train | Encodes a non - ASCII string into a base64 - encoded version of the string. |
box/genty | genty/genty_dataset.py | genty_dataprovider | def genty_dataprovider(builder_function):
"""Decorator defining that this test gets parameters from the given
build_function.
:param builder_function:
A callable that returns parameters that will be passed to the method
decorated by this decorator.
If the builder_function returns a... | python | def genty_dataprovider(builder_function):
"""Decorator defining that this test gets parameters from the given
build_function.
:param builder_function:
A callable that returns parameters that will be passed to the method
decorated by this decorator.
If the builder_function returns a... | [
"def",
"genty_dataprovider",
"(",
"builder_function",
")",
":",
"datasets",
"=",
"getattr",
"(",
"builder_function",
",",
"'genty_datasets'",
",",
"{",
"None",
":",
"(",
")",
"}",
")",
"def",
"wrap",
"(",
"test_method",
")",
":",
"# Save the data providers in th... | Decorator defining that this test gets parameters from the given
build_function.
:param builder_function:
A callable that returns parameters that will be passed to the method
decorated by this decorator.
If the builder_function returns a tuple or list, then that will be
passed ... | [
"Decorator",
"defining",
"that",
"this",
"test",
"gets",
"parameters",
"from",
"the",
"given",
"build_function",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L15-L47 | train | Decorator that creates a test method that gets the parameters from the given build_function. |
box/genty | genty/genty_dataset.py | genty_dataset | def genty_dataset(*args, **kwargs):
"""Decorator defining data sets to provide to a test.
Inspired by http://sebastian-bergmann.de/archives/
702-Data-Providers-in-PHPUnit-3.2.html
The canonical way to call @genty_dataset, with each argument each
representing a data set to be injected in the test m... | python | def genty_dataset(*args, **kwargs):
"""Decorator defining data sets to provide to a test.
Inspired by http://sebastian-bergmann.de/archives/
702-Data-Providers-in-PHPUnit-3.2.html
The canonical way to call @genty_dataset, with each argument each
representing a data set to be injected in the test m... | [
"def",
"genty_dataset",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"datasets",
"=",
"_build_datasets",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"def",
"wrap",
"(",
"test_method",
")",
":",
"# Save the datasets in the test method. This data wil... | Decorator defining data sets to provide to a test.
Inspired by http://sebastian-bergmann.de/archives/
702-Data-Providers-in-PHPUnit-3.2.html
The canonical way to call @genty_dataset, with each argument each
representing a data set to be injected in the test method call:
@genty_dataset(
... | [
"Decorator",
"defining",
"data",
"sets",
"to",
"provide",
"to",
"a",
"test",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L50-L148 | train | Decorator for the genty_dataset method. |
box/genty | genty/genty_dataset.py | _build_datasets | def _build_datasets(*args, **kwargs):
"""Build the datasets into a dict, where the keys are the name of the
data set and the values are the data sets themselves.
:param args:
Tuple of unnamed data sets.
:type args:
`tuple` of varies
:param kwargs:
Dict of pre-named data sets... | python | def _build_datasets(*args, **kwargs):
"""Build the datasets into a dict, where the keys are the name of the
data set and the values are the data sets themselves.
:param args:
Tuple of unnamed data sets.
:type args:
`tuple` of varies
:param kwargs:
Dict of pre-named data sets... | [
"def",
"_build_datasets",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"datasets",
"=",
"OrderedDict",
"(",
")",
"_add_arg_datasets",
"(",
"datasets",
",",
"args",
")",
"_add_kwarg_datasets",
"(",
"datasets",
",",
"kwargs",
")",
"return",
"datasets"
... | Build the datasets into a dict, where the keys are the name of the
data set and the values are the data sets themselves.
:param args:
Tuple of unnamed data sets.
:type args:
`tuple` of varies
:param kwargs:
Dict of pre-named data sets.
:type kwargs:
`dict` of `unicod... | [
"Build",
"the",
"datasets",
"into",
"a",
"dict",
"where",
"the",
"keys",
"are",
"the",
"name",
"of",
"the",
"data",
"set",
"and",
"the",
"values",
"are",
"the",
"data",
"sets",
"themselves",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L151-L171 | train | Build the datasets into a dict where the keys are the name of the data set and the values are the data sets themselves. |
box/genty | genty/genty_dataset.py | _add_arg_datasets | def _add_arg_datasets(datasets, args):
"""Add data sets of the given args.
:param datasets:
The dict where to accumulate data sets.
:type datasets:
`dict`
:param args:
Tuple of unnamed data sets.
:type args:
`tuple` of varies
"""
for dataset in args:
... | python | def _add_arg_datasets(datasets, args):
"""Add data sets of the given args.
:param datasets:
The dict where to accumulate data sets.
:type datasets:
`dict`
:param args:
Tuple of unnamed data sets.
:type args:
`tuple` of varies
"""
for dataset in args:
... | [
"def",
"_add_arg_datasets",
"(",
"datasets",
",",
"args",
")",
":",
"for",
"dataset",
"in",
"args",
":",
"# turn a value into a 1-tuple.",
"if",
"not",
"isinstance",
"(",
"dataset",
",",
"(",
"tuple",
",",
"GentyArgs",
")",
")",
":",
"dataset",
"=",
"(",
"... | Add data sets of the given args.
:param datasets:
The dict where to accumulate data sets.
:type datasets:
`dict`
:param args:
Tuple of unnamed data sets.
:type args:
`tuple` of varies | [
"Add",
"data",
"sets",
"of",
"the",
"given",
"args",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L174-L198 | train | Add data sets of the given args to the given datasets. |
box/genty | genty/genty_dataset.py | _add_kwarg_datasets | def _add_kwarg_datasets(datasets, kwargs):
"""Add data sets of the given kwargs.
:param datasets:
The dict where to accumulate data sets.
:type datasets:
`dict`
:param kwargs:
Dict of pre-named data sets.
:type kwargs:
`dict` of `unicode` to varies
"""
for te... | python | def _add_kwarg_datasets(datasets, kwargs):
"""Add data sets of the given kwargs.
:param datasets:
The dict where to accumulate data sets.
:type datasets:
`dict`
:param kwargs:
Dict of pre-named data sets.
:type kwargs:
`dict` of `unicode` to varies
"""
for te... | [
"def",
"_add_kwarg_datasets",
"(",
"datasets",
",",
"kwargs",
")",
":",
"for",
"test_method_suffix",
",",
"dataset",
"in",
"six",
".",
"iteritems",
"(",
"kwargs",
")",
":",
"datasets",
"[",
"test_method_suffix",
"]",
"=",
"dataset"
] | Add data sets of the given kwargs.
:param datasets:
The dict where to accumulate data sets.
:type datasets:
`dict`
:param kwargs:
Dict of pre-named data sets.
:type kwargs:
`dict` of `unicode` to varies | [
"Add",
"data",
"sets",
"of",
"the",
"given",
"kwargs",
"."
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L201-L214 | train | Add data sets of the given kwargs to the given datasets. |
abingham/docopt-subcommands | docopt_subcommands/subcommands.py | dedent | def dedent(s):
"""Removes the hanging dedent from all the first line of a string."""
head, _, tail = s.partition('\n')
dedented_tail = textwrap.dedent(tail)
result = "{head}\n{tail}".format(
head=head,
tail=dedented_tail)
return result | python | def dedent(s):
"""Removes the hanging dedent from all the first line of a string."""
head, _, tail = s.partition('\n')
dedented_tail = textwrap.dedent(tail)
result = "{head}\n{tail}".format(
head=head,
tail=dedented_tail)
return result | [
"def",
"dedent",
"(",
"s",
")",
":",
"head",
",",
"_",
",",
"tail",
"=",
"s",
".",
"partition",
"(",
"'\\n'",
")",
"dedented_tail",
"=",
"textwrap",
".",
"dedent",
"(",
"tail",
")",
"result",
"=",
"\"{head}\\n{tail}\"",
".",
"format",
"(",
"head",
"=... | Removes the hanging dedent from all the first line of a string. | [
"Removes",
"the",
"hanging",
"dedent",
"from",
"all",
"the",
"first",
"line",
"of",
"a",
"string",
"."
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L20-L27 | train | Removes the hanging dedent from all the first line of a string. |
abingham/docopt-subcommands | docopt_subcommands/subcommands.py | Subcommands.top_level_doc | def top_level_doc(self):
"""The top-level documentation string for the program.
"""
return self._doc_template.format(
available_commands='\n '.join(sorted(self._commands)),
program=self.program) | python | def top_level_doc(self):
"""The top-level documentation string for the program.
"""
return self._doc_template.format(
available_commands='\n '.join(sorted(self._commands)),
program=self.program) | [
"def",
"top_level_doc",
"(",
"self",
")",
":",
"return",
"self",
".",
"_doc_template",
".",
"format",
"(",
"available_commands",
"=",
"'\\n '",
".",
"join",
"(",
"sorted",
"(",
"self",
".",
"_commands",
")",
")",
",",
"program",
"=",
"self",
".",
"progr... | The top-level documentation string for the program. | [
"The",
"top",
"-",
"level",
"documentation",
"string",
"for",
"the",
"program",
"."
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L83-L88 | train | The top - level documentation string for the program. |
abingham/docopt-subcommands | docopt_subcommands/subcommands.py | Subcommands.command | def command(self, name=None):
"""A decorator to add subcommands.
"""
def decorator(f):
self.add_command(f, name)
return f
return decorator | python | def command(self, name=None):
"""A decorator to add subcommands.
"""
def decorator(f):
self.add_command(f, name)
return f
return decorator | [
"def",
"command",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"self",
".",
"add_command",
"(",
"f",
",",
"name",
")",
"return",
"f",
"return",
"decorator"
] | A decorator to add subcommands. | [
"A",
"decorator",
"to",
"add",
"subcommands",
"."
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L90-L96 | train | A decorator to add subcommands. |
abingham/docopt-subcommands | docopt_subcommands/subcommands.py | Subcommands.add_command | def add_command(self, handler, name=None):
"""Add a subcommand `name` which invokes `handler`.
"""
if name is None:
name = docstring_to_subcommand(handler.__doc__)
# TODO: Prevent overwriting 'help'?
self._commands[name] = handler | python | def add_command(self, handler, name=None):
"""Add a subcommand `name` which invokes `handler`.
"""
if name is None:
name = docstring_to_subcommand(handler.__doc__)
# TODO: Prevent overwriting 'help'?
self._commands[name] = handler | [
"def",
"add_command",
"(",
"self",
",",
"handler",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"docstring_to_subcommand",
"(",
"handler",
".",
"__doc__",
")",
"# TODO: Prevent overwriting 'help'?",
"self",
".",
"_commands"... | Add a subcommand `name` which invokes `handler`. | [
"Add",
"a",
"subcommand",
"name",
"which",
"invokes",
"handler",
"."
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L98-L105 | train | Add a subcommand handler which invokes handler. |
elektito/finglish | finglish/f2p.py | variations | def variations(word):
"""Create variations of the word based on letter combinations like oo,
sh, etc."""
if len(word) == 1:
return [[word[0]]]
elif word == 'aa':
return [['A']]
elif word == 'ee':
return [['i']]
elif word == 'ei':
return [['ei']]
elif word in ['oo... | python | def variations(word):
"""Create variations of the word based on letter combinations like oo,
sh, etc."""
if len(word) == 1:
return [[word[0]]]
elif word == 'aa':
return [['A']]
elif word == 'ee':
return [['i']]
elif word == 'ei':
return [['ei']]
elif word in ['oo... | [
"def",
"variations",
"(",
"word",
")",
":",
"if",
"len",
"(",
"word",
")",
"==",
"1",
":",
"return",
"[",
"[",
"word",
"[",
"0",
"]",
"]",
"]",
"elif",
"word",
"==",
"'aa'",
":",
"return",
"[",
"[",
"'A'",
"]",
"]",
"elif",
"word",
"==",
"'ee... | Create variations of the word based on letter combinations like oo,
sh, etc. | [
"Create",
"variations",
"of",
"the",
"word",
"based",
"on",
"letter",
"combinations",
"like",
"oo",
"sh",
"etc",
"."
] | 3d6953d7ad385f860fac4b9110da4205326e4de5 | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L74-L129 | train | Create variations of the word based on letter combinations like oo ou etc. |
elektito/finglish | finglish/f2p.py | f2p_word | def f2p_word(word, max_word_size=15, cutoff=3):
"""Convert a single word from Finglish to Persian.
max_word_size: Maximum size of the words to consider. Words larger
than this will be kept unchanged.
cutoff: The cut-off point. For each word, there could be many
possibilities. By default 3 of these... | python | def f2p_word(word, max_word_size=15, cutoff=3):
"""Convert a single word from Finglish to Persian.
max_word_size: Maximum size of the words to consider. Words larger
than this will be kept unchanged.
cutoff: The cut-off point. For each word, there could be many
possibilities. By default 3 of these... | [
"def",
"f2p_word",
"(",
"word",
",",
"max_word_size",
"=",
"15",
",",
"cutoff",
"=",
"3",
")",
":",
"original_word",
"=",
"word",
"word",
"=",
"word",
".",
"lower",
"(",
")",
"c",
"=",
"dictionary",
".",
"get",
"(",
"word",
")",
"if",
"c",
":",
"... | Convert a single word from Finglish to Persian.
max_word_size: Maximum size of the words to consider. Words larger
than this will be kept unchanged.
cutoff: The cut-off point. For each word, there could be many
possibilities. By default 3 of these possibilities are considered
for each word. This n... | [
"Convert",
"a",
"single",
"word",
"from",
"Finglish",
"to",
"Persian",
"."
] | 3d6953d7ad385f860fac4b9110da4205326e4de5 | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L131-L164 | train | Convert a single word from Finglish to Persian. |
elektito/finglish | finglish/f2p.py | f2p_list | def f2p_list(phrase, max_word_size=15, cutoff=3):
"""Convert a phrase from Finglish to Persian.
phrase: The phrase to convert.
max_word_size: Maximum size of the words to consider. Words larger
than this will be kept unchanged.
cutoff: The cut-off point. For each word, there could be many
pos... | python | def f2p_list(phrase, max_word_size=15, cutoff=3):
"""Convert a phrase from Finglish to Persian.
phrase: The phrase to convert.
max_word_size: Maximum size of the words to consider. Words larger
than this will be kept unchanged.
cutoff: The cut-off point. For each word, there could be many
pos... | [
"def",
"f2p_list",
"(",
"phrase",
",",
"max_word_size",
"=",
"15",
",",
"cutoff",
"=",
"3",
")",
":",
"# split the phrase into words",
"results",
"=",
"[",
"w",
"for",
"w",
"in",
"sep_regex",
".",
"split",
"(",
"phrase",
")",
"if",
"w",
"]",
"# return an... | Convert a phrase from Finglish to Persian.
phrase: The phrase to convert.
max_word_size: Maximum size of the words to consider. Words larger
than this will be kept unchanged.
cutoff: The cut-off point. For each word, there could be many
possibilities. By default 3 of these possibilities are consi... | [
"Convert",
"a",
"phrase",
"from",
"Finglish",
"to",
"Persian",
"."
] | 3d6953d7ad385f860fac4b9110da4205326e4de5 | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L166-L194 | train | Convert a phrase from Finglish to Persian. |
elektito/finglish | finglish/f2p.py | f2p | def f2p(phrase, max_word_size=15, cutoff=3):
"""Convert a Finglish phrase to the most probable Persian phrase.
"""
results = f2p_list(phrase, max_word_size, cutoff)
return ' '.join(i[0][0] for i in results) | python | def f2p(phrase, max_word_size=15, cutoff=3):
"""Convert a Finglish phrase to the most probable Persian phrase.
"""
results = f2p_list(phrase, max_word_size, cutoff)
return ' '.join(i[0][0] for i in results) | [
"def",
"f2p",
"(",
"phrase",
",",
"max_word_size",
"=",
"15",
",",
"cutoff",
"=",
"3",
")",
":",
"results",
"=",
"f2p_list",
"(",
"phrase",
",",
"max_word_size",
",",
"cutoff",
")",
"return",
"' '",
".",
"join",
"(",
"i",
"[",
"0",
"]",
"[",
"0",
... | Convert a Finglish phrase to the most probable Persian phrase. | [
"Convert",
"a",
"Finglish",
"phrase",
"to",
"the",
"most",
"probable",
"Persian",
"phrase",
"."
] | 3d6953d7ad385f860fac4b9110da4205326e4de5 | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L196-L202 | train | Convert a Finglish phrase to the most probable Persian phrase. |
pytest-dev/apipkg | src/apipkg/__init__.py | distribution_version | def distribution_version(name):
"""try to get the version of the named distribution,
returs None on failure"""
from pkg_resources import get_distribution, DistributionNotFound
try:
dist = get_distribution(name)
except DistributionNotFound:
pass
else:
return dist.version | python | def distribution_version(name):
"""try to get the version of the named distribution,
returs None on failure"""
from pkg_resources import get_distribution, DistributionNotFound
try:
dist = get_distribution(name)
except DistributionNotFound:
pass
else:
return dist.version | [
"def",
"distribution_version",
"(",
"name",
")",
":",
"from",
"pkg_resources",
"import",
"get_distribution",
",",
"DistributionNotFound",
"try",
":",
"dist",
"=",
"get_distribution",
"(",
"name",
")",
"except",
"DistributionNotFound",
":",
"pass",
"else",
":",
"re... | try to get the version of the named distribution,
returs None on failure | [
"try",
"to",
"get",
"the",
"version",
"of",
"the",
"named",
"distribution",
"returs",
"None",
"on",
"failure"
] | e409195c52bab50e14745d0adf824b2a0390a50f | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L27-L36 | train | try to get the version of the named distribution returs None on failure |
pytest-dev/apipkg | src/apipkg/__init__.py | initpkg | def initpkg(pkgname, exportdefs, attr=None, eager=False):
""" initialize given package from the export definitions. """
attr = attr or {}
oldmod = sys.modules.get(pkgname)
d = {}
f = getattr(oldmod, '__file__', None)
if f:
f = _py_abspath(f)
d['__file__'] = f
if hasattr(oldmod, '... | python | def initpkg(pkgname, exportdefs, attr=None, eager=False):
""" initialize given package from the export definitions. """
attr = attr or {}
oldmod = sys.modules.get(pkgname)
d = {}
f = getattr(oldmod, '__file__', None)
if f:
f = _py_abspath(f)
d['__file__'] = f
if hasattr(oldmod, '... | [
"def",
"initpkg",
"(",
"pkgname",
",",
"exportdefs",
",",
"attr",
"=",
"None",
",",
"eager",
"=",
"False",
")",
":",
"attr",
"=",
"attr",
"or",
"{",
"}",
"oldmod",
"=",
"sys",
".",
"modules",
".",
"get",
"(",
"pkgname",
")",
"d",
"=",
"{",
"}",
... | initialize given package from the export definitions. | [
"initialize",
"given",
"package",
"from",
"the",
"export",
"definitions",
"."
] | e409195c52bab50e14745d0adf824b2a0390a50f | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L39-L67 | train | initialize given package from the export definitions. |
pytest-dev/apipkg | src/apipkg/__init__.py | importobj | def importobj(modpath, attrname):
"""imports a module, then resolves the attrname on it"""
module = __import__(modpath, None, None, ['__doc__'])
if not attrname:
return module
retval = module
names = attrname.split(".")
for x in names:
retval = getattr(retval, x)
return retv... | python | def importobj(modpath, attrname):
"""imports a module, then resolves the attrname on it"""
module = __import__(modpath, None, None, ['__doc__'])
if not attrname:
return module
retval = module
names = attrname.split(".")
for x in names:
retval = getattr(retval, x)
return retv... | [
"def",
"importobj",
"(",
"modpath",
",",
"attrname",
")",
":",
"module",
"=",
"__import__",
"(",
"modpath",
",",
"None",
",",
"None",
",",
"[",
"'__doc__'",
"]",
")",
"if",
"not",
"attrname",
":",
"return",
"module",
"retval",
"=",
"module",
"names",
"... | imports a module, then resolves the attrname on it | [
"imports",
"a",
"module",
"then",
"resolves",
"the",
"attrname",
"on",
"it"
] | e409195c52bab50e14745d0adf824b2a0390a50f | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L70-L80 | train | imports a module then resolves the attrname on it |
pytest-dev/apipkg | src/apipkg/__init__.py | ApiModule.__makeattr | def __makeattr(self, name):
"""lazily compute value for name or raise AttributeError if unknown."""
# print "makeattr", self.__name__, name
target = None
if '__onfirstaccess__' in self.__map__:
target = self.__map__.pop('__onfirstaccess__')
importobj(*target)()
... | python | def __makeattr(self, name):
"""lazily compute value for name or raise AttributeError if unknown."""
# print "makeattr", self.__name__, name
target = None
if '__onfirstaccess__' in self.__map__:
target = self.__map__.pop('__onfirstaccess__')
importobj(*target)()
... | [
"def",
"__makeattr",
"(",
"self",
",",
"name",
")",
":",
"# print \"makeattr\", self.__name__, name",
"target",
"=",
"None",
"if",
"'__onfirstaccess__'",
"in",
"self",
".",
"__map__",
":",
"target",
"=",
"self",
".",
"__map__",
".",
"pop",
"(",
"'__onfirstaccess... | lazily compute value for name or raise AttributeError if unknown. | [
"lazily",
"compute",
"value",
"for",
"name",
"or",
"raise",
"AttributeError",
"if",
"unknown",
"."
] | e409195c52bab50e14745d0adf824b2a0390a50f | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L137-L158 | train | lazily compute value for name or raise AttributeError |
kimmobrunfeldt/nap | nap/url.py | Url._request | def _request(self, http_method, relative_url='', **kwargs):
"""Does actual HTTP request using requests library."""
# It could be possible to call api.resource.get('/index')
# but it would be non-intuitive that the path would resolve
# to root of domain
relative_url = self._remove... | python | def _request(self, http_method, relative_url='', **kwargs):
"""Does actual HTTP request using requests library."""
# It could be possible to call api.resource.get('/index')
# but it would be non-intuitive that the path would resolve
# to root of domain
relative_url = self._remove... | [
"def",
"_request",
"(",
"self",
",",
"http_method",
",",
"relative_url",
"=",
"''",
",",
"*",
"*",
"kwargs",
")",
":",
"# It could be possible to call api.resource.get('/index')",
"# but it would be non-intuitive that the path would resolve",
"# to root of domain",
"relative_ur... | Does actual HTTP request using requests library. | [
"Does",
"actual",
"HTTP",
"request",
"using",
"requests",
"library",
"."
] | 3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd | https://github.com/kimmobrunfeldt/nap/blob/3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd/nap/url.py#L109-L132 | train | Does actual HTTP request using requests library. |
kimmobrunfeldt/nap | nap/url.py | Url._new_url | def _new_url(self, relative_url):
"""Create new Url which points to new url."""
return Url(
urljoin(self._base_url, relative_url),
**self._default_kwargs
) | python | def _new_url(self, relative_url):
"""Create new Url which points to new url."""
return Url(
urljoin(self._base_url, relative_url),
**self._default_kwargs
) | [
"def",
"_new_url",
"(",
"self",
",",
"relative_url",
")",
":",
"return",
"Url",
"(",
"urljoin",
"(",
"self",
".",
"_base_url",
",",
"relative_url",
")",
",",
"*",
"*",
"self",
".",
"_default_kwargs",
")"
] | Create new Url which points to new url. | [
"Create",
"new",
"Url",
"which",
"points",
"to",
"new",
"url",
"."
] | 3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd | https://github.com/kimmobrunfeldt/nap/blob/3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd/nap/url.py#L142-L148 | train | Create new Url which points to new url. |
ourway/auth | auth/CAS/authorization.py | Authorization.roles | def roles(self):
"""gets user groups"""
result = AuthGroup.objects(creator=self.client).only('role')
return json.loads(result.to_json()) | python | def roles(self):
"""gets user groups"""
result = AuthGroup.objects(creator=self.client).only('role')
return json.loads(result.to_json()) | [
"def",
"roles",
"(",
"self",
")",
":",
"result",
"=",
"AuthGroup",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
")",
".",
"only",
"(",
"'role'",
")",
"return",
"json",
".",
"loads",
"(",
"result",
".",
"to_json",
"(",
")",
")"
] | gets user groups | [
"gets",
"user",
"groups"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L25-L28 | train | gets user groups |
ourway/auth | auth/CAS/authorization.py | Authorization.get_permissions | def get_permissions(self, role):
"""gets permissions of role"""
target_role = AuthGroup.objects(role=role, creator=self.client).first()
if not target_role:
return '[]'
targets = AuthPermission.objects(groups=target_role, creator=self.client).only('name')
return json.l... | python | def get_permissions(self, role):
"""gets permissions of role"""
target_role = AuthGroup.objects(role=role, creator=self.client).first()
if not target_role:
return '[]'
targets = AuthPermission.objects(groups=target_role, creator=self.client).only('name')
return json.l... | [
"def",
"get_permissions",
"(",
"self",
",",
"role",
")",
":",
"target_role",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"if",
"not",
"target_role",
":",
"return",... | gets permissions of role | [
"gets",
"permissions",
"of",
"role"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L30-L36 | train | gets permissions of role |
ourway/auth | auth/CAS/authorization.py | Authorization.get_user_permissions | def get_user_permissions(self, user):
"""get permissions of a user"""
memberShipRecords = AuthMembership.objects(creator=self.client, user=user).only('groups')
results = []
for each in memberShipRecords:
for group in each.groups:
targetPermissionRecords = Auth... | python | def get_user_permissions(self, user):
"""get permissions of a user"""
memberShipRecords = AuthMembership.objects(creator=self.client, user=user).only('groups')
results = []
for each in memberShipRecords:
for group in each.groups:
targetPermissionRecords = Auth... | [
"def",
"get_user_permissions",
"(",
"self",
",",
"user",
")",
":",
"memberShipRecords",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"user",
"=",
"user",
")",
".",
"only",
"(",
"'groups'",
")",
"results",
"=",
"... | get permissions of a user | [
"get",
"permissions",
"of",
"a",
"user"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L39-L50 | train | get permissions of a user |
ourway/auth | auth/CAS/authorization.py | Authorization.get_user_roles | def get_user_roles(self, user):
"""get permissions of a user"""
memberShipRecords = AuthMembership.objects(creator=self.client, user=user).only('groups')
results = []
for each in memberShipRecords:
for group in each.groups:
results.append({'role':group.role})
... | python | def get_user_roles(self, user):
"""get permissions of a user"""
memberShipRecords = AuthMembership.objects(creator=self.client, user=user).only('groups')
results = []
for each in memberShipRecords:
for group in each.groups:
results.append({'role':group.role})
... | [
"def",
"get_user_roles",
"(",
"self",
",",
"user",
")",
":",
"memberShipRecords",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"user",
"=",
"user",
")",
".",
"only",
"(",
"'groups'",
")",
"results",
"=",
"[",
... | get permissions of a user | [
"get",
"permissions",
"of",
"a",
"user"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L52-L59 | train | get permissions of a user |
ourway/auth | auth/CAS/authorization.py | Authorization.get_role_members | def get_role_members(self, role):
"""get permissions of a user"""
targetRoleDb = AuthGroup.objects(creator=self.client, role=role)
members = AuthMembership.objects(groups__in=targetRoleDb).only('user')
return json.loads(members.to_json()) | python | def get_role_members(self, role):
"""get permissions of a user"""
targetRoleDb = AuthGroup.objects(creator=self.client, role=role)
members = AuthMembership.objects(groups__in=targetRoleDb).only('user')
return json.loads(members.to_json()) | [
"def",
"get_role_members",
"(",
"self",
",",
"role",
")",
":",
"targetRoleDb",
"=",
"AuthGroup",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"role",
"=",
"role",
")",
"members",
"=",
"AuthMembership",
".",
"objects",
"(",
"groups__in",... | get permissions of a user | [
"get",
"permissions",
"of",
"a",
"user"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L62-L66 | train | get permissions of a user |
ourway/auth | auth/CAS/authorization.py | Authorization.which_roles_can | def which_roles_can(self, name):
"""Which role can SendMail? """
targetPermissionRecords = AuthPermission.objects(creator=self.client, name=name).first()
return [{'role': group.role} for group in targetPermissionRecords.groups] | python | def which_roles_can(self, name):
"""Which role can SendMail? """
targetPermissionRecords = AuthPermission.objects(creator=self.client, name=name).first()
return [{'role': group.role} for group in targetPermissionRecords.groups] | [
"def",
"which_roles_can",
"(",
"self",
",",
"name",
")",
":",
"targetPermissionRecords",
"=",
"AuthPermission",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"name",
"=",
"name",
")",
".",
"first",
"(",
")",
"return",
"[",
"{",
"'role'... | Which role can SendMail? | [
"Which",
"role",
"can",
"SendMail?"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L68-L71 | train | Which roles can SendMail? |
ourway/auth | auth/CAS/authorization.py | Authorization.which_users_can | def which_users_can(self, name):
"""Which role can SendMail? """
_roles = self.which_roles_can(name)
result = [self.get_role_members(i.get('role')) for i in _roles]
return result | python | def which_users_can(self, name):
"""Which role can SendMail? """
_roles = self.which_roles_can(name)
result = [self.get_role_members(i.get('role')) for i in _roles]
return result | [
"def",
"which_users_can",
"(",
"self",
",",
"name",
")",
":",
"_roles",
"=",
"self",
".",
"which_roles_can",
"(",
"name",
")",
"result",
"=",
"[",
"self",
".",
"get_role_members",
"(",
"i",
".",
"get",
"(",
"'role'",
")",
")",
"for",
"i",
"in",
"_rol... | Which role can SendMail? | [
"Which",
"role",
"can",
"SendMail?"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L73-L77 | train | Which users can send mail? |
ourway/auth | auth/CAS/authorization.py | Authorization.get_role | def get_role(self, role):
"""Returns a role object
"""
role = AuthGroup.objects(role=role, creator=self.client).first()
return role | python | def get_role(self, role):
"""Returns a role object
"""
role = AuthGroup.objects(role=role, creator=self.client).first()
return role | [
"def",
"get_role",
"(",
"self",
",",
"role",
")",
":",
"role",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"return",
"role"
] | Returns a role object | [
"Returns",
"a",
"role",
"object"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L79-L83 | train | Returns a role object |
ourway/auth | auth/CAS/authorization.py | Authorization.add_role | def add_role(self, role, description=None):
""" Creates a new group """
new_group = AuthGroup(role=role, creator=self.client)
try:
new_group.save()
return True
except NotUniqueError:
return False | python | def add_role(self, role, description=None):
""" Creates a new group """
new_group = AuthGroup(role=role, creator=self.client)
try:
new_group.save()
return True
except NotUniqueError:
return False | [
"def",
"add_role",
"(",
"self",
",",
"role",
",",
"description",
"=",
"None",
")",
":",
"new_group",
"=",
"AuthGroup",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
"try",
":",
"new_group",
".",
"save",
"(",
")",
"return"... | Creates a new group | [
"Creates",
"a",
"new",
"group"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L85-L92 | train | Adds a role to the group |
ourway/auth | auth/CAS/authorization.py | Authorization.del_role | def del_role(self, role):
""" deletes a group """
target = AuthGroup.objects(role=role, creator=self.client).first()
if target:
target.delete()
return True
else:
return False | python | def del_role(self, role):
""" deletes a group """
target = AuthGroup.objects(role=role, creator=self.client).first()
if target:
target.delete()
return True
else:
return False | [
"def",
"del_role",
"(",
"self",
",",
"role",
")",
":",
"target",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"if",
"target",
":",
"target",
".",
"delete",
"(",... | deletes a group | [
"deletes",
"a",
"group"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L94-L101 | train | Deletes a group |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.