partition stringclasses 3
values | func_name stringlengths 1 134 | docstring stringlengths 1 46.9k | path stringlengths 4 223 | original_string stringlengths 75 104k | code stringlengths 75 104k | docstring_tokens listlengths 1 1.97k | repo stringlengths 7 55 | language stringclasses 1
value | url stringlengths 87 315 | code_tokens listlengths 19 28.4k | sha stringlengths 40 40 |
|---|---|---|---|---|---|---|---|---|---|---|---|
train | get_terminal_size | Returns the current size of the terminal as tuple in the form
``(width, height)`` in columns and rows. | be/vendor/click/termui.py | 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():
"""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... | [
"Returns",
"the",
"current",
"size",
"of",
"the",
"terminal",
"as",
"tuple",
"in",
"the",
"form",
"(",
"width",
"height",
")",
"in",
"columns",
"and",
"rows",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/termui.py#L148-L186 | [
"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",
",",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | style | 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... | be/vendor/click/termui.py | 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 preve... | [
"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",... | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/termui.py#L316-L382 | [
"def",
"style",
"(",
"text",
",",
"fg",
"=",
"None",
",",
"bg",
"=",
"None",
",",
"bold",
"=",
"None",
",",
"dim",
"=",
"None",
",",
"underline",
"=",
"None",
",",
"blink",
"=",
"None",
",",
"reverse",
"=",
"None",
",",
"reset",
"=",
"True",
")... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | secho | 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... | be/vendor/click/termui.py | 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):
"""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... | [
"This",
"function",
"combines",
":",
"func",
":",
"echo",
"and",
":",
"func",
":",
"style",
"into",
"one",
"call",
".",
"As",
"such",
"the",
"following",
"two",
"calls",
"are",
"the",
"same",
"::"
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/click/termui.py#L397-L409 | [
"def",
"secho",
"(",
"text",
",",
"file",
"=",
"None",
",",
"nl",
"=",
"True",
",",
"err",
"=",
"False",
",",
"color",
"=",
"None",
",",
"*",
"*",
"styles",
")",
":",
"return",
"echo",
"(",
"style",
"(",
"text",
",",
"*",
"*",
"styles",
")",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | merge_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` | be/vendor/requests/sessions.py | 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):
"""
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",
"... | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/sessions.py#L42-L72 | [
"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",... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | SessionRedirectMixin.resolve_redirects | Receives a Response. Returns a generator of Responses. | be/vendor/requests/sessions.py | 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):
"""Receives a Response. Returns a generator of Responses."""
i = 0
hist = [] # keep track of history
while resp.is_redirect:
prepared_request ... | [
"Receives",
"a",
"Response",
".",
"Returns",
"a",
"generator",
"of",
"Responses",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/sessions.py#L92-L201 | [
"def",
"resolve_redirects",
"(",
"self",
",",
"resp",
",",
"req",
",",
"stream",
"=",
"False",
",",
"timeout",
"=",
"None",
",",
"verify",
"=",
"True",
",",
"cert",
"=",
"None",
",",
"proxies",
"=",
"None",
")",
":",
"i",
"=",
"0",
"hist",
"=",
"... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | Session.send | Send a given PreparedRequest. | be/vendor/requests/sessions.py | 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):
"""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... | [
"Send",
"a",
"given",
"PreparedRequest",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/sessions.py#L538-L615 | [
"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",
"... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | HTTPResponse.stream | 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... | be/vendor/requests/packages/urllib3/response.py | 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):
"""
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... | [
"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",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/response.py#L256-L276 | [
"def",
"stream",
"(",
"self",
",",
"amt",
"=",
"2",
"**",
"16",
",",
"decode_content",
"=",
"None",
")",
":",
"while",
"not",
"is_fp_closed",
"(",
"self",
".",
"_fp",
")",
":",
"data",
"=",
"self",
".",
"read",
"(",
"amt",
"=",
"amt",
",",
"decod... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | PreparedRequest.prepare_method | Prepares the given HTTP method. | be/vendor/requests/models.py | 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):
"""Prepares the given HTTP method."""
self.method = method
if self.method is not None:
self.method = self.method.upper() | [
"Prepares",
"the",
"given",
"HTTP",
"method",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L328-L332 | [
"def",
"prepare_method",
"(",
"self",
",",
"method",
")",
":",
"self",
".",
"method",
"=",
"method",
"if",
"self",
".",
"method",
"is",
"not",
"None",
":",
"self",
".",
"method",
"=",
"self",
".",
"method",
".",
"upper",
"(",
")"
] | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | PreparedRequest.prepare_headers | Prepares the given HTTP headers. | be/vendor/requests/models.py | 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):
"""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() | [
"Prepares",
"the",
"given",
"HTTP",
"headers",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L406-L412 | [
"def",
"prepare_headers",
"(",
"self",
",",
"headers",
")",
":",
"if",
"headers",
":",
"self",
".",
"headers",
"=",
"CaseInsensitiveDict",
"(",
"(",
"to_native_string",
"(",
"name",
")",
",",
"value",
")",
"for",
"name",
",",
"value",
"in",
"headers",
".... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | Response.iter_content | 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 ... | be/vendor/requests/models.py | 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):
"""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... | [
"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",... | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L642-L686 | [
"def",
"iter_content",
"(",
"self",
",",
"chunk_size",
"=",
"1",
",",
"decode_unicode",
"=",
"False",
")",
":",
"def",
"generate",
"(",
")",
":",
"try",
":",
"# Special case for urllib3.",
"try",
":",
"for",
"chunk",
"in",
"self",
".",
"raw",
".",
"strea... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | Response.json | Returns the json-encoded content of a response, if any.
:param \*\*kwargs: Optional arguments that ``json.loads`` takes. | be/vendor/requests/models.py | 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):
"""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
... | [
"Returns",
"the",
"json",
"-",
"encoded",
"content",
"of",
"a",
"response",
"if",
"any",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L781-L802 | [
"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... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | Response.raise_for_status | Raises stored :class:`HTTPError`, if one occurred. | be/vendor/requests/models.py | 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):
"""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... | [
"Raises",
"stored",
":",
"class",
":",
"HTTPError",
"if",
"one",
"occurred",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/models.py#L822-L834 | [
"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",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | PoolManager._new_pool | 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. | be/vendor/requests/packages/urllib3/poolmanager.py | 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):
"""
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... | [
"Create",
"a",
"new",
":",
"class",
":",
"ConnectionPool",
"based",
"on",
"host",
"port",
"and",
"scheme",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/poolmanager.py#L75-L90 | [
"def",
"_new_pool",
"(",
"self",
",",
"scheme",
",",
"host",
",",
"port",
")",
":",
"pool_cls",
"=",
"pool_classes_by_scheme",
"[",
"scheme",
"]",
"kwargs",
"=",
"self",
".",
"connection_pool_kw",
"if",
"scheme",
"==",
"'http'",
":",
"kwargs",
"=",
"self",... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | PoolManager.connection_from_host | 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``. | be/vendor/requests/packages/urllib3/poolmanager.py | 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'):
"""
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:
... | [
"Get",
"a",
":",
"class",
":",
"ConnectionPool",
"based",
"on",
"the",
"host",
"port",
"and",
"scheme",
"."
] | mottosso/be | python | https://github.com/mottosso/be/blob/0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71/be/vendor/requests/packages/urllib3/poolmanager.py#L101-L127 | [
"def",
"connection_from_host",
"(",
"self",
",",
"host",
",",
"port",
"=",
"None",
",",
"scheme",
"=",
"'http'",
")",
":",
"if",
"not",
"host",
":",
"raise",
"LocationValueError",
"(",
"\"No host specified.\"",
")",
"scheme",
"=",
"scheme",
"or",
"'http'",
... | 0f3d4f3597c71223f616d78c6d9b2c8dffcd8a71 |
train | genty_repeat | 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... | genty/genty_repeat.py | 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):
"""
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... | [
"To",
"use",
"in",
"conjunction",
"with",
"a",
"TestClass",
"wrapped",
"with",
"@genty",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_repeat.py#L6-L36 | [
"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... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | command | A decorator to register a subcommand with the global `Subcommands` instance. | docopt_subcommands/__init__.py | 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):
"""A decorator to register a subcommand with the global `Subcommands` instance.
"""
def decorator(f):
_commands.append((name, f))
return f
return decorator | [
"A",
"decorator",
"to",
"register",
"a",
"subcommand",
"with",
"the",
"global",
"Subcommands",
"instance",
"."
] | abingham/docopt-subcommands | python | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/__init__.py#L8-L14 | [
"def",
"command",
"(",
"name",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"_commands",
".",
"append",
"(",
"(",
"name",
",",
"f",
")",
")",
"return",
"f",
"return",
"decorator"
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad |
train | main | 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 ... | docopt_subcommands/__init__.py | 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):
"""Top-level driver for creating subcommand-based programs.
Args:
program: The name of your program.
version: The version string for your program.
... | [
"Top",
"-",
"level",
"driver",
"for",
"creating",
"subcommand",
"-",
"based",
"programs",
"."
] | abingham/docopt-subcommands | python | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/__init__.py#L17-L69 | [
"def",
"main",
"(",
"program",
"=",
"None",
",",
"version",
"=",
"None",
",",
"doc_template",
"=",
"None",
",",
"commands",
"=",
"None",
",",
"argv",
"=",
"None",
",",
"exit_at_end",
"=",
"True",
")",
":",
"if",
"commands",
"is",
"None",
":",
"if",
... | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad |
train | BeautifulSoupMiddleware.process_response | Overridden process_response would "pipe" response.body through BeautifulSoup. | scrapy_beautifulsoup/middleware.py | 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):
"""Overridden process_response would "pipe" response.body through BeautifulSoup."""
return response.replace(body=str(BeautifulSoup(response.body, self.parser))) | [
"Overridden",
"process_response",
"would",
"pipe",
"response",
".",
"body",
"through",
"BeautifulSoup",
"."
] | alecxe/scrapy-beautifulsoup | python | https://github.com/alecxe/scrapy-beautifulsoup/blob/733f50e83a5b60edc9325e4f14cd4ab2b3914555/scrapy_beautifulsoup/middleware.py#L14-L16 | [
"def",
"process_response",
"(",
"self",
",",
"request",
",",
"response",
",",
"spider",
")",
":",
"return",
"response",
".",
"replace",
"(",
"body",
"=",
"str",
"(",
"BeautifulSoup",
"(",
"response",
".",
"body",
",",
"self",
".",
"parser",
")",
")",
"... | 733f50e83a5b60edc9325e4f14cd4ab2b3914555 |
train | genty | 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` | genty/genty.py | 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):
"""
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",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L21-L38 | [
"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... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _expand_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 : ... | genty/genty.py | 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):
"""
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... | [
"Generator",
"producing",
"test_methods",
"with",
"an",
"optional",
"dataset",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L62-L101 | [
"def",
"_expand_datasets",
"(",
"test_functions",
")",
":",
"for",
"name",
",",
"func",
"in",
"test_functions",
":",
"dataset_tuples",
"=",
"chain",
"(",
"[",
"(",
"None",
",",
"getattr",
"(",
"func",
",",
"'genty_datasets'",
",",
"{",
"}",
")",
")",
"]"... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _expand_repeats | 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... | genty/genty.py | 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):
"""
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 ... | [
"Generator",
"producing",
"test_methods",
"with",
"any",
"repeat",
"count",
"unrolled",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L104-L139 | [
"def",
"_expand_repeats",
"(",
"test_functions",
")",
":",
"for",
"name",
",",
"func",
",",
"dataset_name",
",",
"dataset",
",",
"dataprovider",
"in",
"test_functions",
":",
"repeat_count",
"=",
"getattr",
"(",
"func",
",",
"'genty_repeat_count'",
",",
"0",
")... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _is_referenced_in_argv | 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... | genty/genty.py | 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):
"""
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:
... | [
"Various",
"test",
"runners",
"allow",
"one",
"to",
"run",
"a",
"specific",
"test",
"like",
"so",
":",
"python",
"-",
"m",
"unittest",
"-",
"v",
"<test_module",
">",
".",
"<test_name",
">"
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L193-L211 | [
"def",
"_is_referenced_in_argv",
"(",
"method_name",
")",
":",
"expr",
"=",
"'.*[:.]{0}$'",
".",
"format",
"(",
"method_name",
")",
"regex",
"=",
"re",
".",
"compile",
"(",
"expr",
")",
"return",
"any",
"(",
"regex",
".",
"match",
"(",
"arg",
")",
"for",... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _build_repeat_suffix | 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... | genty/genty.py | 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):
"""
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... | [
"Return",
"the",
"suffix",
"string",
"to",
"identify",
"iteration",
"X",
"out",
"of",
"Y",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L214-L239 | [
"def",
"_build_repeat_suffix",
"(",
"iteration",
",",
"count",
")",
":",
"format_width",
"=",
"int",
"(",
"math",
".",
"ceil",
"(",
"math",
".",
"log",
"(",
"count",
"+",
"1",
",",
"10",
")",
")",
")",
"new_suffix",
"=",
"'iteration_{0:0{width}d}'",
".",... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _build_final_method_name | 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>"
... | genty/genty.py | 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,
):
"""
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... | [
"Return",
"a",
"nice",
"human",
"friendly",
"name",
"that",
"almost",
"looks",
"like",
"code",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L270-L335 | [
"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... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _build_dataset_method | 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... | genty/genty.py | 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):
"""
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... | [
"Return",
"a",
"fabricated",
"method",
"that",
"marshals",
"the",
"dataset",
"into",
"parameters",
"for",
"given",
"method",
":",
"param",
"method",
":",
"The",
"underlying",
"test",
"method",
".",
":",
"type",
"method",
":",
"callable",
":",
"param",
"datas... | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L338-L366 | [
"def",
"_build_dataset_method",
"(",
"method",
",",
"dataset",
")",
":",
"if",
"isinstance",
"(",
"dataset",
",",
"GentyArgs",
")",
":",
"test_method",
"=",
"lambda",
"my_self",
":",
"method",
"(",
"my_self",
",",
"*",
"dataset",
".",
"args",
",",
"*",
"... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _build_dataprovider_method | 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 ... | genty/genty.py | 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):
"""
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:
... | [
"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",
"... | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L369-L416 | [
"def",
"_build_dataprovider_method",
"(",
"method",
",",
"dataset",
",",
"dataprovider",
")",
":",
"if",
"isinstance",
"(",
"dataset",
",",
"GentyArgs",
")",
":",
"final_args",
"=",
"dataset",
".",
"args",
"final_kwargs",
"=",
"dataset",
".",
"kwargs",
"else",... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _add_method_to_class | 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.
... | genty/genty.py | 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,
):
"""
Add the described method to the given class.
:param target_cls:
Test class to which to add a method.
:type target_cls:
... | [
"Add",
"the",
"described",
"method",
"to",
"the",
"given",
"class",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty.py#L450-L514 | [
"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... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | Rofi.close | Close any open window.
Note that this only works with non-blocking methods. | rofi.py | 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):
"""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.... | [
"Close",
"any",
"open",
"window",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L157-L190 | [
"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... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi._run_blocking | 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.
... | rofi.py | 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):
"""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
... | [
"Internal",
"API",
":",
"run",
"a",
"blocking",
"command",
"with",
"subprocess",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L193-L238 | [
"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",
"=",
"{",
"}",... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi._run_nonblocking | 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... | rofi.py | 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):
"""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... | [
"Internal",
"API",
":",
"run",
"a",
"non",
"-",
"blocking",
"command",
"with",
"subprocess",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L241-L259 | [
"def",
"_run_nonblocking",
"(",
"self",
",",
"args",
",",
"input",
"=",
"None",
")",
":",
"# Close any existing dialog.",
"if",
"self",
".",
"_process",
":",
"self",
".",
"close",
"(",
")",
"# Start the new one.",
"self",
".",
"_process",
"=",
"subprocess",
... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.error | 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. | rofi.py | 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):
"""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
... | [
"Show",
"an",
"error",
"window",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L295-L316 | [
"def",
"error",
"(",
"self",
",",
"message",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# Generate arguments list.",
"args",
"=",
"[",
"'rofi'",
",",
"'-e'",
",",
"message",
"]",
"a... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.status | 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... | rofi.py | 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):
"""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... | [
"Show",
"a",
"status",
"message",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L319-L344 | [
"def",
"status",
"(",
"self",
",",
"message",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# Generate arguments list.",
"args",
"=",
"[",
"'rofi'",
",",
"'-e'",
",",
"message",
"]",
"... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.select | 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... | rofi.py | 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):
"""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... | [
"Show",
"a",
"list",
"of",
"options",
"and",
"return",
"user",
"selection",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L347-L462 | [
"def",
"select",
"(",
"self",
",",
"prompt",
",",
"options",
",",
"rofi_args",
"=",
"None",
",",
"message",
"=",
"\"\"",
",",
"select",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# Replace newlines a... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.generic_entry | 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
... | rofi.py | 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):
"""A generic entry box.
Parameters
----------
prompt: string
Text prompt for the entry.
validator: function, optional
A function to validate and convert the value ent... | [
"A",
"generic",
"entry",
"box",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L465-L533 | [
"def",
"generic_entry",
"(",
"self",
",",
"prompt",
",",
"validator",
"=",
"None",
",",
"message",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"error",
"=",
"\"\"",
"rofi_args",
"=",
"rofi_args",
"or",
"[",
"]",
"# ... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.text_entry | 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... | rofi.py | 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):
"""Prompt the user to enter a piece of text.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Mes... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"piece",
"of",
"text",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L536-L566 | [
"def",
"text_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"allow_blank",
"=",
"False",
",",
"strip",
"=",
"True",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"text_validator",
"(",
"text",
")",
":... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.integer_entry | 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... | rofi.py | 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):
"""Prompt the user to enter an integer.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display under the... | [
"Prompt",
"the",
"user",
"to",
"enter",
"an",
"integer",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L569-L607 | [
"def",
"integer_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"min",
"=",
"None",
",",
"max",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Sanity check.",
"if",
"(",
"min",
"is",
"not",
"... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.float_entry | 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... | rofi.py | 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):
"""Prompt the user to enter a floating point number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to displa... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"floating",
"point",
"number",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L610-L648 | [
"def",
"float_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"min",
"=",
"None",
",",
"max",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Sanity check.",
"if",
"(",
"min",
"is",
"not",
"No... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.decimal_entry | 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. ... | rofi.py | 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):
"""Prompt the user to enter a decimal number.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
Message to display und... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"decimal",
"number",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L651-L689 | [
"def",
"decimal_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"min",
"=",
"None",
",",
"max",
"=",
"None",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"# Sanity check.",
"if",
"(",
"min",
"is",
"not",
"... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.date_entry | 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... | rofi.py | 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):
"""Prompt the user to enter a date.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"date",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L692-L737 | [
"def",
"date_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"formats",
"=",
"[",
"'%x'",
",",
"'%d/%m/%Y'",
"]",
",",
"show_example",
"=",
"False",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"date_... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.time_entry | 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... | rofi.py | 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, **kwargs):
"""Prompt the user to enter a time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: stri... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"time",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L740-L785 | [
"def",
"time_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"formats",
"=",
"[",
"'%X'",
",",
"'%H:%M'",
",",
"'%I:%M'",
",",
"'%H.%M'",
",",
"'%I.%M'",
"]",
",",
"show_example",
"=",
"False",
",",
"rofi_args",
"=",
"None",
",",
... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.datetime_entry | 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... | rofi.py | 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):
"""Prompt the user to enter a date and time.
Parameters
----------
prompt: string
Prompt to display to the user.
message: string, optional
... | [
"Prompt",
"the",
"user",
"to",
"enter",
"a",
"date",
"and",
"time",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L788-L833 | [
"def",
"datetime_entry",
"(",
"self",
",",
"prompt",
",",
"message",
"=",
"None",
",",
"formats",
"=",
"[",
"'%x %X'",
"]",
",",
"show_example",
"=",
"False",
",",
"rofi_args",
"=",
"None",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"datetime_validator",
... | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | Rofi.exit_with_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. | rofi.py | 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):
"""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)
... | [
"Report",
"an",
"error",
"and",
"exit",
"."
] | bcbnz/python-rofi | python | https://github.com/bcbnz/python-rofi/blob/d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4/rofi.py#L836-L848 | [
"def",
"exit_with_error",
"(",
"self",
",",
"error",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
".",
"error",
"(",
"error",
",",
"*",
"*",
"kwargs",
")",
"raise",
"SystemExit",
"(",
"error",
")"
] | d20b3a2ba4ba1b294b002f25a8fb526c5115d0d4 |
train | format_kwarg | 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. | genty/private/__init__.py | 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):
"""
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... | [
"Return",
"a",
"string",
"of",
"form",
":",
"key",
"=",
"<value",
">"
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/private/__init__.py#L7-L17 | [
"def",
"format_kwarg",
"(",
"key",
",",
"value",
")",
":",
"translator",
"=",
"repr",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
"else",
"six",
".",
"text_type",
"arg_value",
"=",
"translator",
"(",
"value",
")",
"return",
"'... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | format_arg | :param value:
Some value in a dataset.
:type value:
varies
:return:
unicode representation of that value
:rtype:
`unicode` | genty/private/__init__.py | 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):
"""
: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) | [
":",
"param",
"value",
":",
"Some",
"value",
"in",
"a",
"dataset",
".",
":",
"type",
"value",
":",
"varies",
":",
"return",
":",
"unicode",
"representation",
"of",
"that",
"value",
":",
"rtype",
":",
"unicode"
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/private/__init__.py#L20-L32 | [
"def",
"format_arg",
"(",
"value",
")",
":",
"translator",
"=",
"repr",
"if",
"isinstance",
"(",
"value",
",",
"six",
".",
"string_types",
")",
"else",
"six",
".",
"text_type",
"return",
"translator",
"(",
"value",
")"
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | encode_non_ascii_string | :param string:
The string to be encoded
:type string:
unicode or str
:return:
The encoded string
:rtype:
str | genty/private/__init__.py | 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):
"""
: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... | [
":",
"param",
"string",
":",
"The",
"string",
"to",
"be",
"encoded",
":",
"type",
"string",
":",
"unicode",
"or",
"str",
":",
"return",
":",
"The",
"encoded",
"string",
":",
"rtype",
":",
"str"
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/private/__init__.py#L35-L50 | [
"def",
"encode_non_ascii_string",
"(",
"string",
")",
":",
"encoded_string",
"=",
"string",
".",
"encode",
"(",
"'utf-8'",
",",
"'replace'",
")",
"if",
"six",
".",
"PY3",
":",
"encoded_string",
"=",
"encoded_string",
".",
"decode",
"(",
")",
"return",
"encod... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | genty_dataprovider | 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 ... | genty/genty_dataset.py | 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):
"""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... | [
"Decorator",
"defining",
"that",
"this",
"test",
"gets",
"parameters",
"from",
"the",
"given",
"build_function",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L15-L47 | [
"def",
"genty_dataprovider",
"(",
"builder_function",
")",
":",
"datasets",
"=",
"getattr",
"(",
"builder_function",
",",
"'genty_datasets'",
",",
"{",
"None",
":",
"(",
")",
"}",
")",
"def",
"wrap",
"(",
"test_method",
")",
":",
"# Save the data providers in th... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | genty_dataset | 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(
... | genty/genty_dataset.py | 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):
"""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... | [
"Decorator",
"defining",
"data",
"sets",
"to",
"provide",
"to",
"a",
"test",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L50-L148 | [
"def",
"genty_dataset",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"datasets",
"=",
"_build_datasets",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
"def",
"wrap",
"(",
"test_method",
")",
":",
"# Save the datasets in the test method. This data wil... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _build_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... | genty/genty_dataset.py | 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):
"""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... | [
"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 | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L151-L171 | [
"def",
"_build_datasets",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"datasets",
"=",
"OrderedDict",
"(",
")",
"_add_arg_datasets",
"(",
"datasets",
",",
"args",
")",
"_add_kwarg_datasets",
"(",
"datasets",
",",
"kwargs",
")",
"return",
"datasets"
... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _add_arg_datasets | 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 | genty/genty_dataset.py | 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):
"""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:
... | [
"Add",
"data",
"sets",
"of",
"the",
"given",
"args",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L174-L198 | [
"def",
"_add_arg_datasets",
"(",
"datasets",
",",
"args",
")",
":",
"for",
"dataset",
"in",
"args",
":",
"# turn a value into a 1-tuple.",
"if",
"not",
"isinstance",
"(",
"dataset",
",",
"(",
"tuple",
",",
"GentyArgs",
")",
")",
":",
"dataset",
"=",
"(",
"... | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | _add_kwarg_datasets | 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 | genty/genty_dataset.py | 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):
"""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... | [
"Add",
"data",
"sets",
"of",
"the",
"given",
"kwargs",
"."
] | box/genty | python | https://github.com/box/genty/blob/85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081/genty/genty_dataset.py#L201-L214 | [
"def",
"_add_kwarg_datasets",
"(",
"datasets",
",",
"kwargs",
")",
":",
"for",
"test_method_suffix",
",",
"dataset",
"in",
"six",
".",
"iteritems",
"(",
"kwargs",
")",
":",
"datasets",
"[",
"test_method_suffix",
"]",
"=",
"dataset"
] | 85f7c960a2b67cf9e58e0d9e677e4a0bc4f05081 |
train | dedent | Removes the hanging dedent from all the first line of a string. | docopt_subcommands/subcommands.py | 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):
"""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 | [
"Removes",
"the",
"hanging",
"dedent",
"from",
"all",
"the",
"first",
"line",
"of",
"a",
"string",
"."
] | abingham/docopt-subcommands | python | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L20-L27 | [
"def",
"dedent",
"(",
"s",
")",
":",
"head",
",",
"_",
",",
"tail",
"=",
"s",
".",
"partition",
"(",
"'\\n'",
")",
"dedented_tail",
"=",
"textwrap",
".",
"dedent",
"(",
"tail",
")",
"result",
"=",
"\"{head}\\n{tail}\"",
".",
"format",
"(",
"head",
"=... | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad |
train | Subcommands.top_level_doc | The top-level documentation string for the program. | docopt_subcommands/subcommands.py | 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):
"""The top-level documentation string for the program.
"""
return self._doc_template.format(
available_commands='\n '.join(sorted(self._commands)),
program=self.program) | [
"The",
"top",
"-",
"level",
"documentation",
"string",
"for",
"the",
"program",
"."
] | abingham/docopt-subcommands | python | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L83-L88 | [
"def",
"top_level_doc",
"(",
"self",
")",
":",
"return",
"self",
".",
"_doc_template",
".",
"format",
"(",
"available_commands",
"=",
"'\\n '",
".",
"join",
"(",
"sorted",
"(",
"self",
".",
"_commands",
")",
")",
",",
"program",
"=",
"self",
".",
"progr... | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad |
train | Subcommands.command | A decorator to add subcommands. | docopt_subcommands/subcommands.py | 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):
"""A decorator to add subcommands.
"""
def decorator(f):
self.add_command(f, name)
return f
return decorator | [
"A",
"decorator",
"to",
"add",
"subcommands",
"."
] | abingham/docopt-subcommands | python | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L90-L96 | [
"def",
"command",
"(",
"self",
",",
"name",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"f",
")",
":",
"self",
".",
"add_command",
"(",
"f",
",",
"name",
")",
"return",
"f",
"return",
"decorator"
] | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad |
train | Subcommands.add_command | Add a subcommand `name` which invokes `handler`. | docopt_subcommands/subcommands.py | 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):
"""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 | [
"Add",
"a",
"subcommand",
"name",
"which",
"invokes",
"handler",
"."
] | abingham/docopt-subcommands | python | https://github.com/abingham/docopt-subcommands/blob/4b5cd75bb8eed01f9405345446ca58e9a29d67ad/docopt_subcommands/subcommands.py#L98-L105 | [
"def",
"add_command",
"(",
"self",
",",
"handler",
",",
"name",
"=",
"None",
")",
":",
"if",
"name",
"is",
"None",
":",
"name",
"=",
"docstring_to_subcommand",
"(",
"handler",
".",
"__doc__",
")",
"# TODO: Prevent overwriting 'help'?",
"self",
".",
"_commands"... | 4b5cd75bb8eed01f9405345446ca58e9a29d67ad |
train | variations | Create variations of the word based on letter combinations like oo,
sh, etc. | finglish/f2p.py | 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):
"""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... | [
"Create",
"variations",
"of",
"the",
"word",
"based",
"on",
"letter",
"combinations",
"like",
"oo",
"sh",
"etc",
"."
] | elektito/finglish | python | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L74-L129 | [
"def",
"variations",
"(",
"word",
")",
":",
"if",
"len",
"(",
"word",
")",
"==",
"1",
":",
"return",
"[",
"[",
"word",
"[",
"0",
"]",
"]",
"]",
"elif",
"word",
"==",
"'aa'",
":",
"return",
"[",
"[",
"'A'",
"]",
"]",
"elif",
"word",
"==",
"'ee... | 3d6953d7ad385f860fac4b9110da4205326e4de5 |
train | f2p_word | 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... | finglish/f2p.py | 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):
"""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... | [
"Convert",
"a",
"single",
"word",
"from",
"Finglish",
"to",
"Persian",
"."
] | elektito/finglish | python | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L131-L164 | [
"def",
"f2p_word",
"(",
"word",
",",
"max_word_size",
"=",
"15",
",",
"cutoff",
"=",
"3",
")",
":",
"original_word",
"=",
"word",
"word",
"=",
"word",
".",
"lower",
"(",
")",
"c",
"=",
"dictionary",
".",
"get",
"(",
"word",
")",
"if",
"c",
":",
"... | 3d6953d7ad385f860fac4b9110da4205326e4de5 |
train | f2p_list | 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... | finglish/f2p.py | 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):
"""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... | [
"Convert",
"a",
"phrase",
"from",
"Finglish",
"to",
"Persian",
"."
] | elektito/finglish | python | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L166-L194 | [
"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... | 3d6953d7ad385f860fac4b9110da4205326e4de5 |
train | f2p | Convert a Finglish phrase to the most probable Persian phrase. | finglish/f2p.py | 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):
"""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) | [
"Convert",
"a",
"Finglish",
"phrase",
"to",
"the",
"most",
"probable",
"Persian",
"phrase",
"."
] | elektito/finglish | python | https://github.com/elektito/finglish/blob/3d6953d7ad385f860fac4b9110da4205326e4de5/finglish/f2p.py#L196-L202 | [
"def",
"f2p",
"(",
"phrase",
",",
"max_word_size",
"=",
"15",
",",
"cutoff",
"=",
"3",
")",
":",
"results",
"=",
"f2p_list",
"(",
"phrase",
",",
"max_word_size",
",",
"cutoff",
")",
"return",
"' '",
".",
"join",
"(",
"i",
"[",
"0",
"]",
"[",
"0",
... | 3d6953d7ad385f860fac4b9110da4205326e4de5 |
train | distribution_version | try to get the version of the named distribution,
returs None on failure | src/apipkg/__init__.py | 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):
"""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 | [
"try",
"to",
"get",
"the",
"version",
"of",
"the",
"named",
"distribution",
"returs",
"None",
"on",
"failure"
] | pytest-dev/apipkg | python | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L27-L36 | [
"def",
"distribution_version",
"(",
"name",
")",
":",
"from",
"pkg_resources",
"import",
"get_distribution",
",",
"DistributionNotFound",
"try",
":",
"dist",
"=",
"get_distribution",
"(",
"name",
")",
"except",
"DistributionNotFound",
":",
"pass",
"else",
":",
"re... | e409195c52bab50e14745d0adf824b2a0390a50f |
train | initpkg | initialize given package from the export definitions. | src/apipkg/__init__.py | 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):
""" 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, '... | [
"initialize",
"given",
"package",
"from",
"the",
"export",
"definitions",
"."
] | pytest-dev/apipkg | python | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L39-L67 | [
"def",
"initpkg",
"(",
"pkgname",
",",
"exportdefs",
",",
"attr",
"=",
"None",
",",
"eager",
"=",
"False",
")",
":",
"attr",
"=",
"attr",
"or",
"{",
"}",
"oldmod",
"=",
"sys",
".",
"modules",
".",
"get",
"(",
"pkgname",
")",
"d",
"=",
"{",
"}",
... | e409195c52bab50e14745d0adf824b2a0390a50f |
train | importobj | imports a module, then resolves the attrname on it | src/apipkg/__init__.py | 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):
"""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... | [
"imports",
"a",
"module",
"then",
"resolves",
"the",
"attrname",
"on",
"it"
] | pytest-dev/apipkg | python | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L70-L80 | [
"def",
"importobj",
"(",
"modpath",
",",
"attrname",
")",
":",
"module",
"=",
"__import__",
"(",
"modpath",
",",
"None",
",",
"None",
",",
"[",
"'__doc__'",
"]",
")",
"if",
"not",
"attrname",
":",
"return",
"module",
"retval",
"=",
"module",
"names",
"... | e409195c52bab50e14745d0adf824b2a0390a50f |
train | ApiModule.__makeattr | lazily compute value for name or raise AttributeError if unknown. | src/apipkg/__init__.py | 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):
"""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)()
... | [
"lazily",
"compute",
"value",
"for",
"name",
"or",
"raise",
"AttributeError",
"if",
"unknown",
"."
] | pytest-dev/apipkg | python | https://github.com/pytest-dev/apipkg/blob/e409195c52bab50e14745d0adf824b2a0390a50f/src/apipkg/__init__.py#L137-L158 | [
"def",
"__makeattr",
"(",
"self",
",",
"name",
")",
":",
"# print \"makeattr\", self.__name__, name",
"target",
"=",
"None",
"if",
"'__onfirstaccess__'",
"in",
"self",
".",
"__map__",
":",
"target",
"=",
"self",
".",
"__map__",
".",
"pop",
"(",
"'__onfirstaccess... | e409195c52bab50e14745d0adf824b2a0390a50f |
train | Url._request | Does actual HTTP request using requests library. | nap/url.py | 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):
"""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... | [
"Does",
"actual",
"HTTP",
"request",
"using",
"requests",
"library",
"."
] | kimmobrunfeldt/nap | python | https://github.com/kimmobrunfeldt/nap/blob/3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd/nap/url.py#L109-L132 | [
"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... | 3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd |
train | Url._new_url | Create new Url which points to new url. | nap/url.py | 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):
"""Create new Url which points to new url."""
return Url(
urljoin(self._base_url, relative_url),
**self._default_kwargs
) | [
"Create",
"new",
"Url",
"which",
"points",
"to",
"new",
"url",
"."
] | kimmobrunfeldt/nap | python | https://github.com/kimmobrunfeldt/nap/blob/3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd/nap/url.py#L142-L148 | [
"def",
"_new_url",
"(",
"self",
",",
"relative_url",
")",
":",
"return",
"Url",
"(",
"urljoin",
"(",
"self",
".",
"_base_url",
",",
"relative_url",
")",
",",
"*",
"*",
"self",
".",
"_default_kwargs",
")"
] | 3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd |
train | Authorization.roles | gets user groups | auth/CAS/authorization.py | def roles(self):
"""gets user groups"""
result = AuthGroup.objects(creator=self.client).only('role')
return json.loads(result.to_json()) | def roles(self):
"""gets user groups"""
result = AuthGroup.objects(creator=self.client).only('role')
return json.loads(result.to_json()) | [
"gets",
"user",
"groups"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L25-L28 | [
"def",
"roles",
"(",
"self",
")",
":",
"result",
"=",
"AuthGroup",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
")",
".",
"only",
"(",
"'role'",
")",
"return",
"json",
".",
"loads",
"(",
"result",
".",
"to_json",
"(",
")",
")"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.get_permissions | gets permissions of role | auth/CAS/authorization.py | 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):
"""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... | [
"gets",
"permissions",
"of",
"role"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L30-L36 | [
"def",
"get_permissions",
"(",
"self",
",",
"role",
")",
":",
"target_role",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"if",
"not",
"target_role",
":",
"return",... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.get_user_permissions | get permissions of a user | auth/CAS/authorization.py | 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):
"""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... | [
"get",
"permissions",
"of",
"a",
"user"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L39-L50 | [
"def",
"get_user_permissions",
"(",
"self",
",",
"user",
")",
":",
"memberShipRecords",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"user",
"=",
"user",
")",
".",
"only",
"(",
"'groups'",
")",
"results",
"=",
"... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.get_user_roles | get permissions of a user | auth/CAS/authorization.py | 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):
"""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})
... | [
"get",
"permissions",
"of",
"a",
"user"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L52-L59 | [
"def",
"get_user_roles",
"(",
"self",
",",
"user",
")",
":",
"memberShipRecords",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"user",
"=",
"user",
")",
".",
"only",
"(",
"'groups'",
")",
"results",
"=",
"[",
... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.get_role_members | get permissions of a user | auth/CAS/authorization.py | 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):
"""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()) | [
"get",
"permissions",
"of",
"a",
"user"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L62-L66 | [
"def",
"get_role_members",
"(",
"self",
",",
"role",
")",
":",
"targetRoleDb",
"=",
"AuthGroup",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"role",
"=",
"role",
")",
"members",
"=",
"AuthMembership",
".",
"objects",
"(",
"groups__in",... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.which_roles_can | Which role can SendMail? | auth/CAS/authorization.py | 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):
"""Which role can SendMail? """
targetPermissionRecords = AuthPermission.objects(creator=self.client, name=name).first()
return [{'role': group.role} for group in targetPermissionRecords.groups] | [
"Which",
"role",
"can",
"SendMail?"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L68-L71 | [
"def",
"which_roles_can",
"(",
"self",
",",
"name",
")",
":",
"targetPermissionRecords",
"=",
"AuthPermission",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"name",
"=",
"name",
")",
".",
"first",
"(",
")",
"return",
"[",
"{",
"'role'... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.which_users_can | Which role can SendMail? | auth/CAS/authorization.py | 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):
"""Which role can SendMail? """
_roles = self.which_roles_can(name)
result = [self.get_role_members(i.get('role')) for i in _roles]
return result | [
"Which",
"role",
"can",
"SendMail?"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L73-L77 | [
"def",
"which_users_can",
"(",
"self",
",",
"name",
")",
":",
"_roles",
"=",
"self",
".",
"which_roles_can",
"(",
"name",
")",
"result",
"=",
"[",
"self",
".",
"get_role_members",
"(",
"i",
".",
"get",
"(",
"'role'",
")",
")",
"for",
"i",
"in",
"_rol... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.get_role | Returns a role object | auth/CAS/authorization.py | 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):
"""Returns a role object
"""
role = AuthGroup.objects(role=role, creator=self.client).first()
return role | [
"Returns",
"a",
"role",
"object"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L79-L83 | [
"def",
"get_role",
"(",
"self",
",",
"role",
")",
":",
"role",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"return",
"role"
] | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.add_role | Creates a new group | auth/CAS/authorization.py | 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):
""" Creates a new group """
new_group = AuthGroup(role=role, creator=self.client)
try:
new_group.save()
return True
except NotUniqueError:
return False | [
"Creates",
"a",
"new",
"group"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L85-L92 | [
"def",
"add_role",
"(",
"self",
",",
"role",
",",
"description",
"=",
"None",
")",
":",
"new_group",
"=",
"AuthGroup",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
"try",
":",
"new_group",
".",
"save",
"(",
")",
"return"... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.del_role | deletes a group | auth/CAS/authorization.py | 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):
""" deletes a group """
target = AuthGroup.objects(role=role, creator=self.client).first()
if target:
target.delete()
return True
else:
return False | [
"deletes",
"a",
"group"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L94-L101 | [
"def",
"del_role",
"(",
"self",
",",
"role",
")",
":",
"target",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"if",
"target",
":",
"target",
".",
"delete",
"(",... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.add_membership | make user a member of a group | auth/CAS/authorization.py | def add_membership(self, user, role):
""" make user a member of a group """
targetGroup = AuthGroup.objects(role=role, creator=self.client).first()
if not targetGroup:
return False
target = AuthMembership.objects(user=user, creator=self.client).first()
if not target:... | def add_membership(self, user, role):
""" make user a member of a group """
targetGroup = AuthGroup.objects(role=role, creator=self.client).first()
if not targetGroup:
return False
target = AuthMembership.objects(user=user, creator=self.client).first()
if not target:... | [
"make",
"user",
"a",
"member",
"of",
"a",
"group"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L103-L116 | [
"def",
"add_membership",
"(",
"self",
",",
"user",
",",
"role",
")",
":",
"targetGroup",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creator",
"=",
"self",
".",
"client",
")",
".",
"first",
"(",
")",
"if",
"not",
"targetGroup",
... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.del_membership | dismember user from a group | auth/CAS/authorization.py | def del_membership(self, user, role):
""" dismember user from a group """
if not self.has_membership(user, role):
return True
targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
if not targetRecord:
return True
for group in targe... | def del_membership(self, user, role):
""" dismember user from a group """
if not self.has_membership(user, role):
return True
targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
if not targetRecord:
return True
for group in targe... | [
"dismember",
"user",
"from",
"a",
"group"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L119-L130 | [
"def",
"del_membership",
"(",
"self",
",",
"user",
",",
"role",
")",
":",
"if",
"not",
"self",
".",
"has_membership",
"(",
"user",
",",
"role",
")",
":",
"return",
"True",
"targetRecord",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self"... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.has_membership | checks if user is member of a group | auth/CAS/authorization.py | def has_membership(self, user, role):
""" checks if user is member of a group"""
targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
if targetRecord:
return role in [i.role for i in targetRecord.groups]
return False | def has_membership(self, user, role):
""" checks if user is member of a group"""
targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
if targetRecord:
return role in [i.role for i in targetRecord.groups]
return False | [
"checks",
"if",
"user",
"is",
"member",
"of",
"a",
"group"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L132-L137 | [
"def",
"has_membership",
"(",
"self",
",",
"user",
",",
"role",
")",
":",
"targetRecord",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"user",
"=",
"user",
")",
".",
"first",
"(",
")",
"if",
"targetRecord",
":... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.add_permission | authorize a group for something | auth/CAS/authorization.py | def add_permission(self, role, name):
""" authorize a group for something """
if self.has_permission(role, name):
return True
targetGroup = AuthGroup.objects(role=role, creator=self.client).first()
if not targetGroup:
return False
# Create or update
... | def add_permission(self, role, name):
""" authorize a group for something """
if self.has_permission(role, name):
return True
targetGroup = AuthGroup.objects(role=role, creator=self.client).first()
if not targetGroup:
return False
# Create or update
... | [
"authorize",
"a",
"group",
"for",
"something"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L140-L151 | [
"def",
"add_permission",
"(",
"self",
",",
"role",
",",
"name",
")",
":",
"if",
"self",
".",
"has_permission",
"(",
"role",
",",
"name",
")",
":",
"return",
"True",
"targetGroup",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
"creato... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.del_permission | revoke authorization of a group | auth/CAS/authorization.py | def del_permission(self, role, name):
""" revoke authorization of a group """
if not self.has_permission(role, name):
return True
targetGroup = AuthGroup.objects(role=role, creator=self.client).first()
target = AuthPermission.objects(groups=targetGroup, name=name, creator=sel... | def del_permission(self, role, name):
""" revoke authorization of a group """
if not self.has_permission(role, name):
return True
targetGroup = AuthGroup.objects(role=role, creator=self.client).first()
target = AuthPermission.objects(groups=targetGroup, name=name, creator=sel... | [
"revoke",
"authorization",
"of",
"a",
"group"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L153-L162 | [
"def",
"del_permission",
"(",
"self",
",",
"role",
",",
"name",
")",
":",
"if",
"not",
"self",
".",
"has_permission",
"(",
"role",
",",
"name",
")",
":",
"return",
"True",
"targetGroup",
"=",
"AuthGroup",
".",
"objects",
"(",
"role",
"=",
"role",
",",
... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | Authorization.user_has_permission | verify user has permission | auth/CAS/authorization.py | def user_has_permission(self, user, name):
""" verify user has permission """
targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
if not targetRecord:
return False
for group in targetRecord.groups:
if self.has_permission(group.role, name)... | def user_has_permission(self, user, name):
""" verify user has permission """
targetRecord = AuthMembership.objects(creator=self.client, user=user).first()
if not targetRecord:
return False
for group in targetRecord.groups:
if self.has_permission(group.role, name)... | [
"verify",
"user",
"has",
"permission"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/authorization.py#L174-L182 | [
"def",
"user_has_permission",
"(",
"self",
",",
"user",
",",
"name",
")",
":",
"targetRecord",
"=",
"AuthMembership",
".",
"objects",
"(",
"creator",
"=",
"self",
".",
"client",
",",
"user",
"=",
"user",
")",
".",
"first",
"(",
")",
"if",
"not",
"targe... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | bump_version | patch: patch, minor, major | scripts/make-release.py | def bump_version(version, bump='patch'):
"""patch: patch, minor, major"""
try:
parts = map(int, version.split('.'))
except ValueError:
fail('Current version is not numeric')
if bump == 'patch':
parts[2] += 1
elif bump == 'minor':
parts[1] += 1
parts[2] = 0
... | def bump_version(version, bump='patch'):
"""patch: patch, minor, major"""
try:
parts = map(int, version.split('.'))
except ValueError:
fail('Current version is not numeric')
if bump == 'patch':
parts[2] += 1
elif bump == 'minor':
parts[1] += 1
parts[2] = 0
... | [
"patch",
":",
"patch",
"minor",
"major"
] | kimmobrunfeldt/nap | python | https://github.com/kimmobrunfeldt/nap/blob/3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd/scripts/make-release.py#L25-L42 | [
"def",
"bump_version",
"(",
"version",
",",
"bump",
"=",
"'patch'",
")",
":",
"try",
":",
"parts",
"=",
"map",
"(",
"int",
",",
"version",
".",
"split",
"(",
"'.'",
")",
")",
"except",
"ValueError",
":",
"fail",
"(",
"'Current version is not numeric'",
"... | 3ea7b41ef6b24b7e127bc87bb010d8a8bb18a4bd |
train | handler | Signal decorator to allow use of callback functions as class decorators. | auth/CAS/models/db.py | def handler(event):
"""Signal decorator to allow use of callback functions as class decorators."""
def decorator(fn):
def apply(cls):
event.connect(fn, sender=cls)
return cls
fn.apply = apply
return fn
return decorator | def handler(event):
"""Signal decorator to allow use of callback functions as class decorators."""
def decorator(fn):
def apply(cls):
event.connect(fn, sender=cls)
return cls
fn.apply = apply
return fn
return decorator | [
"Signal",
"decorator",
"to",
"allow",
"use",
"of",
"callback",
"functions",
"as",
"class",
"decorators",
"."
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/models/db.py#L47-L56 | [
"def",
"handler",
"(",
"event",
")",
":",
"def",
"decorator",
"(",
"fn",
")",
":",
"def",
"apply",
"(",
"cls",
")",
":",
"event",
".",
"connect",
"(",
"fn",
",",
"sender",
"=",
"cls",
")",
"return",
"cls",
"fn",
".",
"apply",
"=",
"apply",
"retur... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | stringify | dumps all valid jsons
This is the latest after hook | auth/CAS/REST/service.py | def stringify(req, resp):
"""
dumps all valid jsons
This is the latest after hook
"""
if isinstance(resp.body, dict):
try:
resp.body = json.dumps(resp.body)
except(nameError):
resp.status = falcon.HTTP_500 | def stringify(req, resp):
"""
dumps all valid jsons
This is the latest after hook
"""
if isinstance(resp.body, dict):
try:
resp.body = json.dumps(resp.body)
except(nameError):
resp.status = falcon.HTTP_500 | [
"dumps",
"all",
"valid",
"jsons",
"This",
"is",
"the",
"latest",
"after",
"hook"
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/REST/service.py#L71-L80 | [
"def",
"stringify",
"(",
"req",
",",
"resp",
")",
":",
"if",
"isinstance",
"(",
"resp",
".",
"body",
",",
"dict",
")",
":",
"try",
":",
"resp",
".",
"body",
"=",
"json",
".",
"dumps",
"(",
"resp",
".",
"body",
")",
"except",
"(",
"nameError",
")"... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | AuthComponent.process_response | Post-processing of the response (after routing).
Args:
req: Request object.
resp: Response object.
resource: Resource object to which the request was
routed. May be None if no route was found
for the request. | auth/CAS/REST/service.py | def process_response(self, req, resp, resource):
"""Post-processing of the response (after routing).
Args:
req: Request object.
resp: Response object.
resource: Resource object to which the request was
routed. May be None if no route was found
... | def process_response(self, req, resp, resource):
"""Post-processing of the response (after routing).
Args:
req: Request object.
resp: Response object.
resource: Resource object to which the request was
routed. May be None if no route was found
... | [
"Post",
"-",
"processing",
"of",
"the",
"response",
"(",
"after",
"routing",
")",
"."
] | ourway/auth | python | https://github.com/ourway/auth/blob/f0d9676854dcec494add4fa086a9b2a3e4d8cea5/auth/CAS/REST/service.py#L49-L63 | [
"def",
"process_response",
"(",
"self",
",",
"req",
",",
"resp",
",",
"resource",
")",
":",
"if",
"isinstance",
"(",
"resp",
".",
"body",
",",
"dict",
")",
":",
"try",
":",
"resp",
".",
"body",
"=",
"json",
".",
"dumps",
"(",
"resp",
".",
"body",
... | f0d9676854dcec494add4fa086a9b2a3e4d8cea5 |
train | run | Run the given command.
Parameters:
:param command: A string describing a command.
:param arguments: A list of strings describing arguments to the command. | django_shortcuts.py | def run(command=None, *arguments):
"""
Run the given command.
Parameters:
:param command: A string describing a command.
:param arguments: A list of strings describing arguments to the command.
"""
if command is None:
sys.exit('django-shortcuts: No argument was supplied, please spe... | def run(command=None, *arguments):
"""
Run the given command.
Parameters:
:param command: A string describing a command.
:param arguments: A list of strings describing arguments to the command.
"""
if command is None:
sys.exit('django-shortcuts: No argument was supplied, please spe... | [
"Run",
"the",
"given",
"command",
"."
] | jgorset/django-shortcuts | python | https://github.com/jgorset/django-shortcuts/blob/22117f797f22fd3db6b55f7db31e4cbe3fd9023d/django_shortcuts.py#L45-L76 | [
"def",
"run",
"(",
"command",
"=",
"None",
",",
"*",
"arguments",
")",
":",
"if",
"command",
"is",
"None",
":",
"sys",
".",
"exit",
"(",
"'django-shortcuts: No argument was supplied, please specify one.'",
")",
"if",
"command",
"in",
"ALIASES",
":",
"command",
... | 22117f797f22fd3db6b55f7db31e4cbe3fd9023d |
train | ParamListDef.instantiate | Create a ParamList instance for actual interpretation
:args: TODO
:returns: A ParamList object | pfp/functions.py | def instantiate(self, scope, args, interp):
"""Create a ParamList instance for actual interpretation
:args: TODO
:returns: A ParamList object
"""
param_instances = []
BYREF = "byref"
# TODO are default values for function parameters allowed in 010?
for... | def instantiate(self, scope, args, interp):
"""Create a ParamList instance for actual interpretation
:args: TODO
:returns: A ParamList object
"""
param_instances = []
BYREF = "byref"
# TODO are default values for function parameters allowed in 010?
for... | [
"Create",
"a",
"ParamList",
"instance",
"for",
"actual",
"interpretation"
] | d0c-s4vage/pfp | python | https://github.com/d0c-s4vage/pfp/blob/32f2d34fdec1c70019fa83c7006d5e3be0f92fcd/pfp/functions.py#L116-L160 | [
"def",
"instantiate",
"(",
"self",
",",
"scope",
",",
"args",
",",
"interp",
")",
":",
"param_instances",
"=",
"[",
"]",
"BYREF",
"=",
"\"byref\"",
"# TODO are default values for function parameters allowed in 010?",
"for",
"param_name",
",",
"param_cls",
"in",
"sel... | 32f2d34fdec1c70019fa83c7006d5e3be0f92fcd |
train | get_experiments | get_experiments will return loaded json for all valid experiments from an experiment folder
:param base: full path to the base folder with experiments inside
:param load: if True, returns a list of loaded config.json objects. If False (default) returns the paths to the experiments | expfactory/experiment.py | def get_experiments(base, load=False):
''' get_experiments will return loaded json for all valid experiments from an experiment folder
:param base: full path to the base folder with experiments inside
:param load: if True, returns a list of loaded config.json objects. If False (default) returns the paths to... | def get_experiments(base, load=False):
''' get_experiments will return loaded json for all valid experiments from an experiment folder
:param base: full path to the base folder with experiments inside
:param load: if True, returns a list of loaded config.json objects. If False (default) returns the paths to... | [
"get_experiments",
"will",
"return",
"loaded",
"json",
"for",
"all",
"valid",
"experiments",
"from",
"an",
"experiment",
"folder",
":",
"param",
"base",
":",
"full",
"path",
"to",
"the",
"base",
"folder",
"with",
"experiments",
"inside",
":",
"param",
"load",
... | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L54-L67 | [
"def",
"get_experiments",
"(",
"base",
",",
"load",
"=",
"False",
")",
":",
"experiments",
"=",
"find_directories",
"(",
"base",
")",
"valid_experiments",
"=",
"[",
"e",
"for",
"e",
"in",
"experiments",
"if",
"validate",
"(",
"e",
",",
"cleanup",
"=",
"F... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | load_experiments | load_experiments
a wrapper for load_experiment to read multiple experiments
:param experiment_folders: a list of experiment folders to load, full paths | expfactory/experiment.py | def load_experiments(folders):
'''load_experiments
a wrapper for load_experiment to read multiple experiments
:param experiment_folders: a list of experiment folders to load, full paths
'''
experiments = []
if isinstance(folders,str):
folders = [experiment_folders]
for folder in fold... | def load_experiments(folders):
'''load_experiments
a wrapper for load_experiment to read multiple experiments
:param experiment_folders: a list of experiment folders to load, full paths
'''
experiments = []
if isinstance(folders,str):
folders = [experiment_folders]
for folder in fold... | [
"load_experiments",
"a",
"wrapper",
"for",
"load_experiment",
"to",
"read",
"multiple",
"experiments",
":",
"param",
"experiment_folders",
":",
"a",
"list",
"of",
"experiment",
"folders",
"to",
"load",
"full",
"paths"
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L70-L81 | [
"def",
"load_experiments",
"(",
"folders",
")",
":",
"experiments",
"=",
"[",
"]",
"if",
"isinstance",
"(",
"folders",
",",
"str",
")",
":",
"folders",
"=",
"[",
"experiment_folders",
"]",
"for",
"folder",
"in",
"folders",
":",
"exp",
"=",
"load_experiment... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | load_experiment | load_experiment:
reads in the config.json for a folder, returns None if not found.
:param folder: full path to experiment folder
:param return_path: if True, don't load the config.json, but return it | expfactory/experiment.py | def load_experiment(folder, return_path=False):
'''load_experiment:
reads in the config.json for a folder, returns None if not found.
:param folder: full path to experiment folder
:param return_path: if True, don't load the config.json, but return it
'''
fullpath = os.path.abspath(folder)
co... | def load_experiment(folder, return_path=False):
'''load_experiment:
reads in the config.json for a folder, returns None if not found.
:param folder: full path to experiment folder
:param return_path: if True, don't load the config.json, but return it
'''
fullpath = os.path.abspath(folder)
co... | [
"load_experiment",
":",
"reads",
"in",
"the",
"config",
".",
"json",
"for",
"a",
"folder",
"returns",
"None",
"if",
"not",
"found",
".",
":",
"param",
"folder",
":",
"full",
"path",
"to",
"experiment",
"folder",
":",
"param",
"return_path",
":",
"if",
"T... | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L84-L97 | [
"def",
"load_experiment",
"(",
"folder",
",",
"return_path",
"=",
"False",
")",
":",
"fullpath",
"=",
"os",
".",
"path",
".",
"abspath",
"(",
"folder",
")",
"config",
"=",
"\"%s/config.json\"",
"%",
"(",
"fullpath",
")",
"if",
"not",
"os",
".",
"path",
... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | get_selection | we compare the basename (the exp_id) of the selection and available,
regardless of parent directories | expfactory/experiment.py | def get_selection(available, selection, base='/scif/apps'):
'''we compare the basename (the exp_id) of the selection and available,
regardless of parent directories'''
if isinstance(selection, str):
selection = selection.split(',')
available = [os.path.basename(x) for x in available]
s... | def get_selection(available, selection, base='/scif/apps'):
'''we compare the basename (the exp_id) of the selection and available,
regardless of parent directories'''
if isinstance(selection, str):
selection = selection.split(',')
available = [os.path.basename(x) for x in available]
s... | [
"we",
"compare",
"the",
"basename",
"(",
"the",
"exp_id",
")",
"of",
"the",
"selection",
"and",
"available",
"regardless",
"of",
"parent",
"directories"
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L100-L113 | [
"def",
"get_selection",
"(",
"available",
",",
"selection",
",",
"base",
"=",
"'/scif/apps'",
")",
":",
"if",
"isinstance",
"(",
"selection",
",",
"str",
")",
":",
"selection",
"=",
"selection",
".",
"split",
"(",
"','",
")",
"available",
"=",
"[",
"os",... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | make_lookup | make_lookup returns dict object to quickly look up query experiment on exp_id
:param experiment_list: a list of query (dict objects)
:param key_field: the key in the dictionary to base the lookup key (str)
:returns lookup: dict (json) with key as "key_field" from query_list | expfactory/experiment.py | def make_lookup(experiment_list, key='exp_id'):
'''make_lookup returns dict object to quickly look up query experiment on exp_id
:param experiment_list: a list of query (dict objects)
:param key_field: the key in the dictionary to base the lookup key (str)
:returns lookup: dict (json) with key as "key_f... | def make_lookup(experiment_list, key='exp_id'):
'''make_lookup returns dict object to quickly look up query experiment on exp_id
:param experiment_list: a list of query (dict objects)
:param key_field: the key in the dictionary to base the lookup key (str)
:returns lookup: dict (json) with key as "key_f... | [
"make_lookup",
"returns",
"dict",
"object",
"to",
"quickly",
"look",
"up",
"query",
"experiment",
"on",
"exp_id",
":",
"param",
"experiment_list",
":",
"a",
"list",
"of",
"query",
"(",
"dict",
"objects",
")",
":",
"param",
"key_field",
":",
"the",
"key",
"... | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L116-L128 | [
"def",
"make_lookup",
"(",
"experiment_list",
",",
"key",
"=",
"'exp_id'",
")",
":",
"lookup",
"=",
"dict",
"(",
")",
"for",
"single_experiment",
"in",
"experiment_list",
":",
"if",
"isinstance",
"(",
"single_experiment",
",",
"str",
")",
":",
"single_experime... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | validate | validate
:param folder: full path to experiment folder with config.json. If path begins
with https, we assume to be starting from a repository. | expfactory/experiment.py | def validate(folder=None, cleanup=False):
'''validate
:param folder: full path to experiment folder with config.json. If path begins
with https, we assume to be starting from a repository.
'''
from expfactory.validator import ExperimentValidator
cli = ExperimentValidator()
ret... | def validate(folder=None, cleanup=False):
'''validate
:param folder: full path to experiment folder with config.json. If path begins
with https, we assume to be starting from a repository.
'''
from expfactory.validator import ExperimentValidator
cli = ExperimentValidator()
ret... | [
"validate",
":",
"param",
"folder",
":",
"full",
"path",
"to",
"experiment",
"folder",
"with",
"config",
".",
"json",
".",
"If",
"path",
"begins",
"with",
"https",
"we",
"assume",
"to",
"be",
"starting",
"from",
"a",
"repository",
"."
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L131-L138 | [
"def",
"validate",
"(",
"folder",
"=",
"None",
",",
"cleanup",
"=",
"False",
")",
":",
"from",
"expfactory",
".",
"validator",
"import",
"ExperimentValidator",
"cli",
"=",
"ExperimentValidator",
"(",
")",
"return",
"cli",
".",
"validate",
"(",
"folder",
",",... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | get_library | return the raw library, without parsing | expfactory/experiment.py | def get_library(lookup=True, key='exp_id'):
''' return the raw library, without parsing'''
library = None
response = requests.get(EXPFACTORY_LIBRARY)
if response.status_code == 200:
library = response.json()
if lookup is True:
return make_lookup(library,key=key)
return li... | def get_library(lookup=True, key='exp_id'):
''' return the raw library, without parsing'''
library = None
response = requests.get(EXPFACTORY_LIBRARY)
if response.status_code == 200:
library = response.json()
if lookup is True:
return make_lookup(library,key=key)
return li... | [
"return",
"the",
"raw",
"library",
"without",
"parsing"
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/experiment.py#L147-L155 | [
"def",
"get_library",
"(",
"lookup",
"=",
"True",
",",
"key",
"=",
"'exp_id'",
")",
":",
"library",
"=",
"None",
"response",
"=",
"requests",
".",
"get",
"(",
"EXPFACTORY_LIBRARY",
")",
"if",
"response",
".",
"status_code",
"==",
"200",
":",
"library",
"... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | int3 | Define the ``Int3()`` function in the interpreter. Calling
``Int3()`` will drop the user into an interactive debugger. | pfp/native/dbg.py | def int3(params, ctxt, scope, stream, coord, interp):
"""Define the ``Int3()`` function in the interpreter. Calling
``Int3()`` will drop the user into an interactive debugger.
"""
if interp._no_debug:
return
if interp._int3:
interp.debugger = PfpDbg(interp)
interp.debugger.c... | def int3(params, ctxt, scope, stream, coord, interp):
"""Define the ``Int3()`` function in the interpreter. Calling
``Int3()`` will drop the user into an interactive debugger.
"""
if interp._no_debug:
return
if interp._int3:
interp.debugger = PfpDbg(interp)
interp.debugger.c... | [
"Define",
"the",
"Int3",
"()",
"function",
"in",
"the",
"interpreter",
".",
"Calling",
"Int3",
"()",
"will",
"drop",
"the",
"user",
"into",
"an",
"interactive",
"debugger",
"."
] | d0c-s4vage/pfp | python | https://github.com/d0c-s4vage/pfp/blob/32f2d34fdec1c70019fa83c7006d5e3be0f92fcd/pfp/native/dbg.py#L9-L18 | [
"def",
"int3",
"(",
"params",
",",
"ctxt",
",",
"scope",
",",
"stream",
",",
"coord",
",",
"interp",
")",
":",
"if",
"interp",
".",
"_no_debug",
":",
"return",
"if",
"interp",
".",
"_int3",
":",
"interp",
".",
"debugger",
"=",
"PfpDbg",
"(",
"interp"... | 32f2d34fdec1c70019fa83c7006d5e3be0f92fcd |
train | EFServer.initdb | initdb will check for writability of the data folder, meaning
that it is bound to the local machine. If the folder isn't bound,
expfactory runs in demo mode (not saving data) | expfactory/server.py | def initdb(self):
'''initdb will check for writability of the data folder, meaning
that it is bound to the local machine. If the folder isn't bound,
expfactory runs in demo mode (not saving data)
'''
self.database = EXPFACTORY_DATABASE
bot.info("DATABASE: %s" %self... | def initdb(self):
'''initdb will check for writability of the data folder, meaning
that it is bound to the local machine. If the folder isn't bound,
expfactory runs in demo mode (not saving data)
'''
self.database = EXPFACTORY_DATABASE
bot.info("DATABASE: %s" %self... | [
"initdb",
"will",
"check",
"for",
"writability",
"of",
"the",
"data",
"folder",
"meaning",
"that",
"it",
"is",
"bound",
"to",
"the",
"local",
"machine",
".",
"If",
"the",
"folder",
"isn",
"t",
"bound",
"expfactory",
"runs",
"in",
"demo",
"mode",
"(",
"no... | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/server.py#L56-L74 | [
"def",
"initdb",
"(",
"self",
")",
":",
"self",
".",
"database",
"=",
"EXPFACTORY_DATABASE",
"bot",
".",
"info",
"(",
"\"DATABASE: %s\"",
"%",
"self",
".",
"database",
")",
"# Supported database options",
"valid",
"=",
"(",
"'sqlite'",
",",
"'postgres'",
",",
... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | EFServer.setup | obtain database and filesystem preferences from defaults,
and compare with selection in container. | expfactory/server.py | def setup(self):
''' obtain database and filesystem preferences from defaults,
and compare with selection in container.
'''
self.selection = EXPFACTORY_EXPERIMENTS
self.ordered = len(EXPFACTORY_EXPERIMENTS) > 0
self.data_base = EXPFACTORY_DATA
self.study_id =... | def setup(self):
''' obtain database and filesystem preferences from defaults,
and compare with selection in container.
'''
self.selection = EXPFACTORY_EXPERIMENTS
self.ordered = len(EXPFACTORY_EXPERIMENTS) > 0
self.data_base = EXPFACTORY_DATA
self.study_id =... | [
"obtain",
"database",
"and",
"filesystem",
"preferences",
"from",
"defaults",
"and",
"compare",
"with",
"selection",
"in",
"container",
"."
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/server.py#L77-L103 | [
"def",
"setup",
"(",
"self",
")",
":",
"self",
".",
"selection",
"=",
"EXPFACTORY_EXPERIMENTS",
"self",
".",
"ordered",
"=",
"len",
"(",
"EXPFACTORY_EXPERIMENTS",
")",
">",
"0",
"self",
".",
"data_base",
"=",
"EXPFACTORY_DATA",
"self",
".",
"study_id",
"=",
... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | EFServer.get_next | return the name of the next experiment, depending on the user's
choice to randomize. We don't remove any experiments here, that is
done on finish, in the case the user doesn't submit data (and
thus finish). A return of None means the user has completed the
battery of experime... | expfactory/server.py | def get_next(self, session):
'''return the name of the next experiment, depending on the user's
choice to randomize. We don't remove any experiments here, that is
done on finish, in the case the user doesn't submit data (and
thus finish). A return of None means the user has comp... | def get_next(self, session):
'''return the name of the next experiment, depending on the user's
choice to randomize. We don't remove any experiments here, that is
done on finish, in the case the user doesn't submit data (and
thus finish). A return of None means the user has comp... | [
"return",
"the",
"name",
"of",
"the",
"next",
"experiment",
"depending",
"on",
"the",
"user",
"s",
"choice",
"to",
"randomize",
".",
"We",
"don",
"t",
"remove",
"any",
"experiments",
"here",
"that",
"is",
"done",
"on",
"finish",
"in",
"the",
"case",
"the... | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/server.py#L105-L120 | [
"def",
"get_next",
"(",
"self",
",",
"session",
")",
":",
"next",
"=",
"None",
"experiments",
"=",
"session",
".",
"get",
"(",
"'experiments'",
",",
"[",
"]",
")",
"if",
"len",
"(",
"experiments",
")",
">",
"0",
":",
"if",
"app",
".",
"randomize",
... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | EFServer.finish_experiment | remove an experiment from the list after completion. | expfactory/server.py | def finish_experiment(self, session, exp_id):
'''remove an experiment from the list after completion.
'''
self.logger.debug('Finishing %s' %exp_id)
experiments = session.get('experiments', [])
experiments = [x for x in experiments if x != exp_id]
session['experiments'] = ... | def finish_experiment(self, session, exp_id):
'''remove an experiment from the list after completion.
'''
self.logger.debug('Finishing %s' %exp_id)
experiments = session.get('experiments', [])
experiments = [x for x in experiments if x != exp_id]
session['experiments'] = ... | [
"remove",
"an",
"experiment",
"from",
"the",
"list",
"after",
"completion",
"."
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/server.py#L123-L130 | [
"def",
"finish_experiment",
"(",
"self",
",",
"session",
",",
"exp_id",
")",
":",
"self",
".",
"logger",
".",
"debug",
"(",
"'Finishing %s'",
"%",
"exp_id",
")",
"experiments",
"=",
"session",
".",
"get",
"(",
"'experiments'",
",",
"[",
"]",
")",
"experi... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | find_subdirectories | Return directories (and sub) starting from a base | expfactory/utils.py | def find_subdirectories(basepath):
'''
Return directories (and sub) starting from a base
'''
directories = []
for root, dirnames, filenames in os.walk(basepath):
new_directories = [d for d in dirnames if d not in directories]
directories = directories + new_directories
return dir... | def find_subdirectories(basepath):
'''
Return directories (and sub) starting from a base
'''
directories = []
for root, dirnames, filenames in os.walk(basepath):
new_directories = [d for d in dirnames if d not in directories]
directories = directories + new_directories
return dir... | [
"Return",
"directories",
"(",
"and",
"sub",
")",
"starting",
"from",
"a",
"base"
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/utils.py#L66-L74 | [
"def",
"find_subdirectories",
"(",
"basepath",
")",
":",
"directories",
"=",
"[",
"]",
"for",
"root",
",",
"dirnames",
",",
"filenames",
"in",
"os",
".",
"walk",
"(",
"basepath",
")",
":",
"new_directories",
"=",
"[",
"d",
"for",
"d",
"in",
"dirnames",
... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
train | find_directories | Return directories at one level specified by user
(not recursive) | expfactory/utils.py | def find_directories(root,fullpath=True):
'''
Return directories at one level specified by user
(not recursive)
'''
directories = []
for item in os.listdir(root):
# Don't include hidden directories
if not re.match("^[.]",item):
if os.path.isdir(os.path.join(root, item... | def find_directories(root,fullpath=True):
'''
Return directories at one level specified by user
(not recursive)
'''
directories = []
for item in os.listdir(root):
# Don't include hidden directories
if not re.match("^[.]",item):
if os.path.isdir(os.path.join(root, item... | [
"Return",
"directories",
"at",
"one",
"level",
"specified",
"by",
"user",
"(",
"not",
"recursive",
")"
] | expfactory/expfactory | python | https://github.com/expfactory/expfactory/blob/27ce6cc93e17231df8a8024f18e631336afd3501/expfactory/utils.py#L77-L91 | [
"def",
"find_directories",
"(",
"root",
",",
"fullpath",
"=",
"True",
")",
":",
"directories",
"=",
"[",
"]",
"for",
"item",
"in",
"os",
".",
"listdir",
"(",
"root",
")",
":",
"# Don't include hidden directories",
"if",
"not",
"re",
".",
"match",
"(",
"\... | 27ce6cc93e17231df8a8024f18e631336afd3501 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.