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 | Jobs.get_jobs | List jobs belonging to a specific user. | sauceclient.py | def get_jobs(self, full=None, limit=None, skip=None, start=None, end=None,
output_format=None):
"""List jobs belonging to a specific user."""
method = 'GET'
endpoint = '/rest/v1/{}/jobs'.format(self.client.sauce_username)
data = {}
if full is not None:
... | def get_jobs(self, full=None, limit=None, skip=None, start=None, end=None,
output_format=None):
"""List jobs belonging to a specific user."""
method = 'GET'
endpoint = '/rest/v1/{}/jobs'.format(self.client.sauce_username)
data = {}
if full is not None:
... | [
"List",
"jobs",
"belonging",
"to",
"a",
"specific",
"user",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L403-L423 | [
"def",
"get_jobs",
"(",
"self",
",",
"full",
"=",
"None",
",",
"limit",
"=",
"None",
",",
"skip",
"=",
"None",
",",
"start",
"=",
"None",
",",
"end",
"=",
"None",
",",
"output_format",
"=",
"None",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Jobs.update_job | Edit an existing job. | sauceclient.py | def update_job(self, job_id, build=None, custom_data=None,
name=None, passed=None, public=None, tags=None):
"""Edit an existing job."""
method = 'PUT'
endpoint = '/rest/v1/{}/jobs/{}'.format(self.client.sauce_username,
job_id)
... | def update_job(self, job_id, build=None, custom_data=None,
name=None, passed=None, public=None, tags=None):
"""Edit an existing job."""
method = 'PUT'
endpoint = '/rest/v1/{}/jobs/{}'.format(self.client.sauce_username,
job_id)
... | [
"Edit",
"an",
"existing",
"job",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L432-L452 | [
"def",
"update_job",
"(",
"self",
",",
"job_id",
",",
"build",
"=",
"None",
",",
"custom_data",
"=",
"None",
",",
"name",
"=",
"None",
",",
"passed",
"=",
"None",
",",
"public",
"=",
"None",
",",
"tags",
"=",
"None",
")",
":",
"method",
"=",
"'PUT'... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Jobs.stop_job | Terminates a running job. | sauceclient.py | def stop_job(self, job_id):
"""Terminates a running job."""
method = 'PUT'
endpoint = '/rest/v1/{}/jobs/{}/stop'.format(
self.client.sauce_username, job_id)
return self.client.request(method, endpoint) | def stop_job(self, job_id):
"""Terminates a running job."""
method = 'PUT'
endpoint = '/rest/v1/{}/jobs/{}/stop'.format(
self.client.sauce_username, job_id)
return self.client.request(method, endpoint) | [
"Terminates",
"a",
"running",
"job",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L461-L466 | [
"def",
"stop_job",
"(",
"self",
",",
"job_id",
")",
":",
"method",
"=",
"'PUT'",
"endpoint",
"=",
"'/rest/v1/{}/jobs/{}/stop'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"job_id",
")",
"return",
"self",
".",
"client",
".",
"req... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Jobs.get_job_asset_url | Get details about the static assets collected for a specific job. | sauceclient.py | def get_job_asset_url(self, job_id, filename):
"""Get details about the static assets collected for a specific job."""
return 'https://saucelabs.com/rest/v1/{}/jobs/{}/assets/{}'.format(
self.client.sauce_username, job_id, filename) | def get_job_asset_url(self, job_id, filename):
"""Get details about the static assets collected for a specific job."""
return 'https://saucelabs.com/rest/v1/{}/jobs/{}/assets/{}'.format(
self.client.sauce_username, job_id, filename) | [
"Get",
"details",
"about",
"the",
"static",
"assets",
"collected",
"for",
"a",
"specific",
"job",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L475-L478 | [
"def",
"get_job_asset_url",
"(",
"self",
",",
"job_id",
",",
"filename",
")",
":",
"return",
"'https://saucelabs.com/rest/v1/{}/jobs/{}/assets/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"job_id",
",",
"filename",
")"
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Jobs.get_auth_token | Get an auth token to access protected job resources.
https://wiki.saucelabs.com/display/DOCS/Building+Links+to+Test+Results | sauceclient.py | def get_auth_token(self, job_id, date_range=None):
"""Get an auth token to access protected job resources.
https://wiki.saucelabs.com/display/DOCS/Building+Links+to+Test+Results
"""
key = '{}:{}'.format(self.client.sauce_username,
self.client.sauce_access_ke... | def get_auth_token(self, job_id, date_range=None):
"""Get an auth token to access protected job resources.
https://wiki.saucelabs.com/display/DOCS/Building+Links+to+Test+Results
"""
key = '{}:{}'.format(self.client.sauce_username,
self.client.sauce_access_ke... | [
"Get",
"an",
"auth",
"token",
"to",
"access",
"protected",
"job",
"resources",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L487-L497 | [
"def",
"get_auth_token",
"(",
"self",
",",
"job_id",
",",
"date_range",
"=",
"None",
")",
":",
"key",
"=",
"'{}:{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"self",
".",
"client",
".",
"sauce_access_key",
")",
"if",
"date_... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Storage.upload_file | Uploads a file to the temporary sauce storage. | sauceclient.py | def upload_file(self, filepath, overwrite=True):
"""Uploads a file to the temporary sauce storage."""
method = 'POST'
filename = os.path.split(filepath)[1]
endpoint = '/rest/v1/storage/{}/{}?overwrite={}'.format(
self.client.sauce_username, filename, "true" if overwrite else ... | def upload_file(self, filepath, overwrite=True):
"""Uploads a file to the temporary sauce storage."""
method = 'POST'
filename = os.path.split(filepath)[1]
endpoint = '/rest/v1/storage/{}/{}?overwrite={}'.format(
self.client.sauce_username, filename, "true" if overwrite else ... | [
"Uploads",
"a",
"file",
"to",
"the",
"temporary",
"sauce",
"storage",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L509-L518 | [
"def",
"upload_file",
"(",
"self",
",",
"filepath",
",",
"overwrite",
"=",
"True",
")",
":",
"method",
"=",
"'POST'",
"filename",
"=",
"os",
".",
"path",
".",
"split",
"(",
"filepath",
")",
"[",
"1",
"]",
"endpoint",
"=",
"'/rest/v1/storage/{}/{}?overwrite... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Storage.get_stored_files | Check which files are in your temporary storage. | sauceclient.py | def get_stored_files(self):
"""Check which files are in your temporary storage."""
method = 'GET'
endpoint = '/rest/v1/storage/{}'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | def get_stored_files(self):
"""Check which files are in your temporary storage."""
method = 'GET'
endpoint = '/rest/v1/storage/{}'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | [
"Check",
"which",
"files",
"are",
"in",
"your",
"temporary",
"storage",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L520-L524 | [
"def",
"get_stored_files",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/storage/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",",
... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Tunnels.get_tunnels | Retrieves all running tunnels for a specific user. | sauceclient.py | def get_tunnels(self):
"""Retrieves all running tunnels for a specific user."""
method = 'GET'
endpoint = '/rest/v1/{}/tunnels'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | def get_tunnels(self):
"""Retrieves all running tunnels for a specific user."""
method = 'GET'
endpoint = '/rest/v1/{}/tunnels'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | [
"Retrieves",
"all",
"running",
"tunnels",
"for",
"a",
"specific",
"user",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L536-L540 | [
"def",
"get_tunnels",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/{}/tunnels'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",",
"endp... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | Tunnels.get_tunnel | Get information for a tunnel given its ID. | sauceclient.py | def get_tunnel(self, tunnel_id):
"""Get information for a tunnel given its ID."""
method = 'GET'
endpoint = '/rest/v1/{}/tunnels/{}'.format(
self.client.sauce_username, tunnel_id)
return self.client.request(method, endpoint) | def get_tunnel(self, tunnel_id):
"""Get information for a tunnel given its ID."""
method = 'GET'
endpoint = '/rest/v1/{}/tunnels/{}'.format(
self.client.sauce_username, tunnel_id)
return self.client.request(method, endpoint) | [
"Get",
"information",
"for",
"a",
"tunnel",
"given",
"its",
"ID",
"."
] | cgoldberg/sauceclient | python | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L542-L547 | [
"def",
"get_tunnel",
"(",
"self",
",",
"tunnel_id",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/{}/tunnels/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"tunnel_id",
")",
"return",
"self",
".",
"client",
".",
... | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 |
train | apply | Apply a patch.
The patch's :attr:`~Patch.obj` attribute is injected into the patch's
:attr:`~Patch.destination` under the patch's :attr:`~Patch.name`.
This is a wrapper around calling
``setattr(patch.destination, patch.name, patch.obj)``.
Parameters
----------
patch : gorilla.Patch
... | gorilla.py | def apply(patch):
"""Apply a patch.
The patch's :attr:`~Patch.obj` attribute is injected into the patch's
:attr:`~Patch.destination` under the patch's :attr:`~Patch.name`.
This is a wrapper around calling
``setattr(patch.destination, patch.name, patch.obj)``.
Parameters
----------
pat... | def apply(patch):
"""Apply a patch.
The patch's :attr:`~Patch.obj` attribute is injected into the patch's
:attr:`~Patch.destination` under the patch's :attr:`~Patch.name`.
This is a wrapper around calling
``setattr(patch.destination, patch.name, patch.obj)``.
Parameters
----------
pat... | [
"Apply",
"a",
"patch",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L231-L283 | [
"def",
"apply",
"(",
"patch",
")",
":",
"settings",
"=",
"Settings",
"(",
")",
"if",
"patch",
".",
"settings",
"is",
"None",
"else",
"patch",
".",
"settings",
"# When a hit occurs due to an attribute at the destination already existing",
"# with the patch's name, the exis... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | patch | Decorator to create a patch.
The object being decorated becomes the :attr:`~Patch.obj` attribute of the
patch.
Parameters
----------
destination : object
Patch destination.
name : str
Name of the attribute at the destination.
settings : gorilla.Settings
Settings.
... | gorilla.py | def patch(destination, name=None, settings=None):
"""Decorator to create a patch.
The object being decorated becomes the :attr:`~Patch.obj` attribute of the
patch.
Parameters
----------
destination : object
Patch destination.
name : str
Name of the attribute at the destinat... | def patch(destination, name=None, settings=None):
"""Decorator to create a patch.
The object being decorated becomes the :attr:`~Patch.obj` attribute of the
patch.
Parameters
----------
destination : object
Patch destination.
name : str
Name of the attribute at the destinat... | [
"Decorator",
"to",
"create",
"a",
"patch",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L286-L319 | [
"def",
"patch",
"(",
"destination",
",",
"name",
"=",
"None",
",",
"settings",
"=",
"None",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"base",
"=",
"_get_base",
"(",
"wrapped",
")",
"name_",
"=",
"base",
".",
"__name__",
"if",
"name",
"i... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | patches | Decorator to create a patch for each member of a module or a class.
Parameters
----------
destination : object
Patch destination.
settings : gorilla.Settings
Settings.
traverse_bases : bool
If the object is a class, the base classes are also traversed.
filter : function
... | gorilla.py | def patches(destination, settings=None, traverse_bases=True,
filter=default_filter, recursive=True, use_decorators=True):
"""Decorator to create a patch for each member of a module or a class.
Parameters
----------
destination : object
Patch destination.
settings : gorilla.Setti... | def patches(destination, settings=None, traverse_bases=True,
filter=default_filter, recursive=True, use_decorators=True):
"""Decorator to create a patch for each member of a module or a class.
Parameters
----------
destination : object
Patch destination.
settings : gorilla.Setti... | [
"Decorator",
"to",
"create",
"a",
"patch",
"for",
"each",
"member",
"of",
"a",
"module",
"or",
"a",
"class",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L322-L372 | [
"def",
"patches",
"(",
"destination",
",",
"settings",
"=",
"None",
",",
"traverse_bases",
"=",
"True",
",",
"filter",
"=",
"default_filter",
",",
"recursive",
"=",
"True",
",",
"use_decorators",
"=",
"True",
")",
":",
"def",
"decorator",
"(",
"wrapped",
"... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | destination | Modifier decorator to update a patch's destination.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
value : object
Patch destination.
... | gorilla.py | def destination(value):
"""Modifier decorator to update a patch's destination.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
value : object
... | def destination(value):
"""Modifier decorator to update a patch's destination.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
value : object
... | [
"Modifier",
"decorator",
"to",
"update",
"a",
"patch",
"s",
"destination",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L375-L397 | [
"def",
"destination",
"(",
"value",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"data",
"=",
"get_decorator_data",
"(",
"_get_base",
"(",
"wrapped",
")",
",",
"set_default",
"=",
"True",
")",
"data",
".",
"override",
"[",
"'destination'",
"]",
... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | settings | Modifier decorator to update a patch's settings.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
kwargs
Settings to update. See :class:`Set... | gorilla.py | def settings(**kwargs):
"""Modifier decorator to update a patch's settings.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
kwargs
Sett... | def settings(**kwargs):
"""Modifier decorator to update a patch's settings.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
kwargs
Sett... | [
"Modifier",
"decorator",
"to",
"update",
"a",
"patch",
"s",
"settings",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L425-L447 | [
"def",
"settings",
"(",
"*",
"*",
"kwargs",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"data",
"=",
"get_decorator_data",
"(",
"_get_base",
"(",
"wrapped",
")",
",",
"set_default",
"=",
"True",
")",
"data",
".",
"override",
".",
"setdefault"... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | filter | Modifier decorator to force the inclusion or exclusion of an attribute.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
value : bool
``True... | gorilla.py | def filter(value):
"""Modifier decorator to force the inclusion or exclusion of an attribute.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
v... | def filter(value):
"""Modifier decorator to force the inclusion or exclusion of an attribute.
This only modifies the behaviour of the :func:`create_patches` function
and the :func:`patches` decorator, given that their parameter
``use_decorators`` is set to ``True``.
Parameters
----------
v... | [
"Modifier",
"decorator",
"to",
"force",
"the",
"inclusion",
"or",
"exclusion",
"of",
"an",
"attribute",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L450-L474 | [
"def",
"filter",
"(",
"value",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"data",
"=",
"get_decorator_data",
"(",
"_get_base",
"(",
"wrapped",
")",
",",
"set_default",
"=",
"True",
")",
"data",
".",
"filter",
"=",
"value",
"return",
"wrapped... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | create_patches | Create a patch for each member of a module or a class.
Parameters
----------
destination : object
Patch destination.
root : object
Root object, either a module or a class.
settings : gorilla.Settings
Settings.
traverse_bases : bool
If the object is a class, the b... | gorilla.py | def create_patches(destination, root, settings=None, traverse_bases=True,
filter=default_filter, recursive=True, use_decorators=True):
"""Create a patch for each member of a module or a class.
Parameters
----------
destination : object
Patch destination.
root : object
... | def create_patches(destination, root, settings=None, traverse_bases=True,
filter=default_filter, recursive=True, use_decorators=True):
"""Create a patch for each member of a module or a class.
Parameters
----------
destination : object
Patch destination.
root : object
... | [
"Create",
"a",
"patch",
"for",
"each",
"member",
"of",
"a",
"module",
"or",
"a",
"class",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L477-L559 | [
"def",
"create_patches",
"(",
"destination",
",",
"root",
",",
"settings",
"=",
"None",
",",
"traverse_bases",
"=",
"True",
",",
"filter",
"=",
"default_filter",
",",
"recursive",
"=",
"True",
",",
"use_decorators",
"=",
"True",
")",
":",
"if",
"filter",
"... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | find_patches | Find all the patches created through decorators.
Parameters
----------
modules : list of module
Modules and/or packages to search the patches in.
recursive : bool
``True`` to search recursively in subpackages.
Returns
-------
list of gorilla.Patch
Patches found.
... | gorilla.py | def find_patches(modules, recursive=True):
"""Find all the patches created through decorators.
Parameters
----------
modules : list of module
Modules and/or packages to search the patches in.
recursive : bool
``True`` to search recursively in subpackages.
Returns
-------
... | def find_patches(modules, recursive=True):
"""Find all the patches created through decorators.
Parameters
----------
modules : list of module
Modules and/or packages to search the patches in.
recursive : bool
``True`` to search recursively in subpackages.
Returns
-------
... | [
"Find",
"all",
"the",
"patches",
"created",
"through",
"decorators",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L562-L600 | [
"def",
"find_patches",
"(",
"modules",
",",
"recursive",
"=",
"True",
")",
":",
"out",
"=",
"[",
"]",
"modules",
"=",
"(",
"module",
"for",
"package",
"in",
"modules",
"for",
"module",
"in",
"_module_iterator",
"(",
"package",
",",
"recursive",
"=",
"rec... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | get_attribute | Retrieve an attribute while bypassing the descriptor protocol.
As per the built-in |getattr()|_ function, if the input object is a class
then its base classes might also be searched until the attribute is found.
Parameters
----------
obj : object
Object to search the attribute in.
name... | gorilla.py | def get_attribute(obj, name):
"""Retrieve an attribute while bypassing the descriptor protocol.
As per the built-in |getattr()|_ function, if the input object is a class
then its base classes might also be searched until the attribute is found.
Parameters
----------
obj : object
Object... | def get_attribute(obj, name):
"""Retrieve an attribute while bypassing the descriptor protocol.
As per the built-in |getattr()|_ function, if the input object is a class
then its base classes might also be searched until the attribute is found.
Parameters
----------
obj : object
Object... | [
"Retrieve",
"an",
"attribute",
"while",
"bypassing",
"the",
"descriptor",
"protocol",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L603-L638 | [
"def",
"get_attribute",
"(",
"obj",
",",
"name",
")",
":",
"objs",
"=",
"inspect",
".",
"getmro",
"(",
"obj",
")",
"if",
"isinstance",
"(",
"obj",
",",
"_CLASS_TYPES",
")",
"else",
"[",
"obj",
"]",
"for",
"obj_",
"in",
"objs",
":",
"try",
":",
"ret... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | get_decorator_data | Retrieve any decorator data from an object.
Parameters
----------
obj : object
Object.
set_default : bool
If no data is found, a default one is set on the object and returned,
otherwise ``None`` is returned.
Returns
-------
gorilla.DecoratorData
The decorato... | gorilla.py | def get_decorator_data(obj, set_default=False):
"""Retrieve any decorator data from an object.
Parameters
----------
obj : object
Object.
set_default : bool
If no data is found, a default one is set on the object and returned,
otherwise ``None`` is returned.
Returns
... | def get_decorator_data(obj, set_default=False):
"""Retrieve any decorator data from an object.
Parameters
----------
obj : object
Object.
set_default : bool
If no data is found, a default one is set on the object and returned,
otherwise ``None`` is returned.
Returns
... | [
"Retrieve",
"any",
"decorator",
"data",
"from",
"an",
"object",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L668-L697 | [
"def",
"get_decorator_data",
"(",
"obj",
",",
"set_default",
"=",
"False",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"_CLASS_TYPES",
")",
":",
"datas",
"=",
"getattr",
"(",
"obj",
",",
"_DECORATOR_DATA",
",",
"{",
"}",
")",
"data",
"=",
"datas",
"... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | _get_base | Unwrap decorators to retrieve the base object. | gorilla.py | def _get_base(obj):
"""Unwrap decorators to retrieve the base object."""
if hasattr(obj, '__func__'):
obj = obj.__func__
elif isinstance(obj, property):
obj = obj.fget
elif isinstance(obj, (classmethod, staticmethod)):
# Fallback for Python < 2.7 back when no `__func__` attribute... | def _get_base(obj):
"""Unwrap decorators to retrieve the base object."""
if hasattr(obj, '__func__'):
obj = obj.__func__
elif isinstance(obj, property):
obj = obj.fget
elif isinstance(obj, (classmethod, staticmethod)):
# Fallback for Python < 2.7 back when no `__func__` attribute... | [
"Unwrap",
"decorators",
"to",
"retrieve",
"the",
"base",
"object",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L700-L713 | [
"def",
"_get_base",
"(",
"obj",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'__func__'",
")",
":",
"obj",
"=",
"obj",
".",
"__func__",
"elif",
"isinstance",
"(",
"obj",
",",
"property",
")",
":",
"obj",
"=",
"obj",
".",
"fget",
"elif",
"isinstance",... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | _get_members | Retrieve the member attributes of a module or a class.
The descriptor protocol is bypassed. | gorilla.py | def _get_members(obj, traverse_bases=True, filter=default_filter,
recursive=True):
"""Retrieve the member attributes of a module or a class.
The descriptor protocol is bypassed."""
if filter is None:
filter = _true
out = []
stack = collections.deque((obj,))
while stack... | def _get_members(obj, traverse_bases=True, filter=default_filter,
recursive=True):
"""Retrieve the member attributes of a module or a class.
The descriptor protocol is bypassed."""
if filter is None:
filter = _true
out = []
stack = collections.deque((obj,))
while stack... | [
"Retrieve",
"the",
"member",
"attributes",
"of",
"a",
"module",
"or",
"a",
"class",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L716-L750 | [
"def",
"_get_members",
"(",
"obj",
",",
"traverse_bases",
"=",
"True",
",",
"filter",
"=",
"default_filter",
",",
"recursive",
"=",
"True",
")",
":",
"if",
"filter",
"is",
"None",
":",
"filter",
"=",
"_true",
"out",
"=",
"[",
"]",
"stack",
"=",
"collec... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | _module_iterator | Iterate over modules. | gorilla.py | def _module_iterator(root, recursive=True):
"""Iterate over modules."""
yield root
stack = collections.deque((root,))
while stack:
package = stack.popleft()
# The '__path__' attribute of a package might return a list of paths if
# the package is referenced as a namespace.
... | def _module_iterator(root, recursive=True):
"""Iterate over modules."""
yield root
stack = collections.deque((root,))
while stack:
package = stack.popleft()
# The '__path__' attribute of a package might return a list of paths if
# the package is referenced as a namespace.
... | [
"Iterate",
"over",
"modules",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L753-L778 | [
"def",
"_module_iterator",
"(",
"root",
",",
"recursive",
"=",
"True",
")",
":",
"yield",
"root",
"stack",
"=",
"collections",
".",
"deque",
"(",
"(",
"root",
",",
")",
")",
"while",
"stack",
":",
"package",
"=",
"stack",
".",
"popleft",
"(",
")",
"#... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | Patch._update | Update some attributes.
If a 'settings' attribute is passed as a dict, then it updates the
content of the settings, if any, instead of completely overwriting it. | gorilla.py | def _update(self, **kwargs):
"""Update some attributes.
If a 'settings' attribute is passed as a dict, then it updates the
content of the settings, if any, instead of completely overwriting it.
"""
for key, value in _iteritems(kwargs):
if key == 'settings':
... | def _update(self, **kwargs):
"""Update some attributes.
If a 'settings' attribute is passed as a dict, then it updates the
content of the settings, if any, instead of completely overwriting it.
"""
for key, value in _iteritems(kwargs):
if key == 'settings':
... | [
"Update",
"some",
"attributes",
"."
] | christophercrouzet/gorilla | python | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L212-L228 | [
"def",
"_update",
"(",
"self",
",",
"*",
"*",
"kwargs",
")",
":",
"for",
"key",
",",
"value",
"in",
"_iteritems",
"(",
"kwargs",
")",
":",
"if",
"key",
"==",
"'settings'",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"if",
"self",
... | 10c68d04be28524f2cd7be22eddca77678e12860 |
train | TpmApi.request | To make a request to the API. | tpm.py | def request(self, path, action, data=''):
"""To make a request to the API."""
# Check if the path includes URL or not.
head = self.base_url
if path.startswith(head):
path = path[len(head):]
path = quote_plus(path, safe='/')
if not path.startswith(self.api)... | def request(self, path, action, data=''):
"""To make a request to the API."""
# Check if the path includes URL or not.
head = self.base_url
if path.startswith(head):
path = path[len(head):]
path = quote_plus(path, safe='/')
if not path.startswith(self.api)... | [
"To",
"make",
"a",
"request",
"to",
"the",
"API",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L126-L207 | [
"def",
"request",
"(",
"self",
",",
"path",
",",
"action",
",",
"data",
"=",
"''",
")",
":",
"# Check if the path includes URL or not.",
"head",
"=",
"self",
".",
"base_url",
"if",
"path",
".",
"startswith",
"(",
"head",
")",
":",
"path",
"=",
"path",
"[... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.get_collection | To get pagewise data. | tpm.py | def get_collection(self, path):
"""To get pagewise data."""
while True:
items = self.get(path)
req = self.req
for item in items:
yield item
if req.links and req.links['next'] and\
req.links['next']['rel'] == 'next':
... | def get_collection(self, path):
"""To get pagewise data."""
while True:
items = self.get(path)
req = self.req
for item in items:
yield item
if req.links and req.links['next'] and\
req.links['next']['rel'] == 'next':
... | [
"To",
"get",
"pagewise",
"data",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L225-L236 | [
"def",
"get_collection",
"(",
"self",
",",
"path",
")",
":",
"while",
"True",
":",
"items",
"=",
"self",
".",
"get",
"(",
"path",
")",
"req",
"=",
"self",
".",
"req",
"for",
"item",
"in",
"items",
":",
"yield",
"item",
"if",
"req",
".",
"links",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.collection | To return all items generated by get collection. | tpm.py | def collection(self, path):
"""To return all items generated by get collection."""
data = []
for item in self.get_collection(path):
data.append(item)
return data | def collection(self, path):
"""To return all items generated by get collection."""
data = []
for item in self.get_collection(path):
data.append(item)
return data | [
"To",
"return",
"all",
"items",
"generated",
"by",
"get",
"collection",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L238-L243 | [
"def",
"collection",
"(",
"self",
",",
"path",
")",
":",
"data",
"=",
"[",
"]",
"for",
"item",
"in",
"self",
".",
"get_collection",
"(",
"path",
")",
":",
"data",
".",
"append",
"(",
"item",
")",
"return",
"data"
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.list_projects_search | List projects with searchstring. | tpm.py | def list_projects_search(self, searchstring):
"""List projects with searchstring."""
log.debug('List all projects with: %s' % searchstring)
return self.collection('projects/search/%s.json' %
quote_plus(searchstring)) | def list_projects_search(self, searchstring):
"""List projects with searchstring."""
log.debug('List all projects with: %s' % searchstring)
return self.collection('projects/search/%s.json' %
quote_plus(searchstring)) | [
"List",
"projects",
"with",
"searchstring",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L263-L267 | [
"def",
"list_projects_search",
"(",
"self",
",",
"searchstring",
")",
":",
"log",
".",
"debug",
"(",
"'List all projects with: %s'",
"%",
"searchstring",
")",
"return",
"self",
".",
"collection",
"(",
"'projects/search/%s.json'",
"%",
"quote_plus",
"(",
"searchstrin... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.create_project | Create a project. | tpm.py | def create_project(self, data):
"""Create a project."""
# http://teampasswordmanager.com/docs/api-projects/#create_project
log.info('Create project: %s' % data)
NewID = self.post('projects.json', data).get('id')
log.info('Project has been created with ID %s' % NewID)
retu... | def create_project(self, data):
"""Create a project."""
# http://teampasswordmanager.com/docs/api-projects/#create_project
log.info('Create project: %s' % data)
NewID = self.post('projects.json', data).get('id')
log.info('Project has been created with ID %s' % NewID)
retu... | [
"Create",
"a",
"project",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L287-L293 | [
"def",
"create_project",
"(",
"self",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#create_project",
"log",
".",
"info",
"(",
"'Create project: %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'projects.json'",
",",
"dat... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_project | Update a project. | tpm.py | def update_project(self, ID, data):
"""Update a project."""
# http://teampasswordmanager.com/docs/api-projects/#update_project
log.info('Update project %s with %s' % (ID, data))
self.put('projects/%s.json' % ID, data) | def update_project(self, ID, data):
"""Update a project."""
# http://teampasswordmanager.com/docs/api-projects/#update_project
log.info('Update project %s with %s' % (ID, data))
self.put('projects/%s.json' % ID, data) | [
"Update",
"a",
"project",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L295-L299 | [
"def",
"update_project",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#update_project",
"log",
".",
"info",
"(",
"'Update project %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"(",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.change_parent_of_project | Change parent of project. | tpm.py | def change_parent_of_project(self, ID, NewParrentID):
"""Change parent of project."""
# http://teampasswordmanager.com/docs/api-projects/#change_parent
log.info('Change parrent for project %s to %s' % (ID, NewParrentID))
data = {'parent_id': NewParrentID}
self.put('projects/%s/ch... | def change_parent_of_project(self, ID, NewParrentID):
"""Change parent of project."""
# http://teampasswordmanager.com/docs/api-projects/#change_parent
log.info('Change parrent for project %s to %s' % (ID, NewParrentID))
data = {'parent_id': NewParrentID}
self.put('projects/%s/ch... | [
"Change",
"parent",
"of",
"project",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L301-L306 | [
"def",
"change_parent_of_project",
"(",
"self",
",",
"ID",
",",
"NewParrentID",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#change_parent",
"log",
".",
"info",
"(",
"'Change parrent for project %s to %s'",
"%",
"(",
"ID",
",",
"NewParrentID",
")",
")",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_security_of_project | Update security of project. | tpm.py | def update_security_of_project(self, ID, data):
"""Update security of project."""
# http://teampasswordmanager.com/docs/api-projects/#update_project_security
log.info('Update project %s security %s' % (ID, data))
self.put('projects/%s/security.json' % ID, data) | def update_security_of_project(self, ID, data):
"""Update security of project."""
# http://teampasswordmanager.com/docs/api-projects/#update_project_security
log.info('Update project %s security %s' % (ID, data))
self.put('projects/%s/security.json' % ID, data) | [
"Update",
"security",
"of",
"project",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L308-L312 | [
"def",
"update_security_of_project",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#update_project_security",
"log",
".",
"info",
"(",
"'Update project %s security %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.list_passwords_search | List passwords with searchstring. | tpm.py | def list_passwords_search(self, searchstring):
"""List passwords with searchstring."""
log.debug('List all passwords with: %s' % searchstring)
return self.collection('passwords/search/%s.json' %
quote_plus(searchstring)) | def list_passwords_search(self, searchstring):
"""List passwords with searchstring."""
log.debug('List all passwords with: %s' % searchstring)
return self.collection('passwords/search/%s.json' %
quote_plus(searchstring)) | [
"List",
"passwords",
"with",
"searchstring",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L348-L352 | [
"def",
"list_passwords_search",
"(",
"self",
",",
"searchstring",
")",
":",
"log",
".",
"debug",
"(",
"'List all passwords with: %s'",
"%",
"searchstring",
")",
"return",
"self",
".",
"collection",
"(",
"'passwords/search/%s.json'",
"%",
"quote_plus",
"(",
"searchst... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.create_password | Create a password. | tpm.py | def create_password(self, data):
"""Create a password."""
# http://teampasswordmanager.com/docs/api-passwords/#create_password
log.info('Create new password %s' % data)
NewID = self.post('passwords.json', data).get('id')
log.info('Password has been created with ID %s' % NewID)
... | def create_password(self, data):
"""Create a password."""
# http://teampasswordmanager.com/docs/api-passwords/#create_password
log.info('Create new password %s' % data)
NewID = self.post('passwords.json', data).get('id')
log.info('Password has been created with ID %s' % NewID)
... | [
"Create",
"a",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L366-L372 | [
"def",
"create_password",
"(",
"self",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#create_password",
"log",
".",
"info",
"(",
"'Create new password %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'passwords.json'",
","... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_password | Update a password. | tpm.py | def update_password(self, ID, data):
"""Update a password."""
# http://teampasswordmanager.com/docs/api-passwords/#update_password
log.info('Update Password %s with %s' % (ID, data))
self.put('passwords/%s.json' % ID, data) | def update_password(self, ID, data):
"""Update a password."""
# http://teampasswordmanager.com/docs/api-passwords/#update_password
log.info('Update Password %s with %s' % (ID, data))
self.put('passwords/%s.json' % ID, data) | [
"Update",
"a",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L374-L378 | [
"def",
"update_password",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#update_password",
"log",
".",
"info",
"(",
"'Update Password %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"("... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_security_of_password | Update security of a password. | tpm.py | def update_security_of_password(self, ID, data):
"""Update security of a password."""
# http://teampasswordmanager.com/docs/api-passwords/#update_security_password
log.info('Update security of password %s with %s' % (ID, data))
self.put('passwords/%s/security.json' % ID, data) | def update_security_of_password(self, ID, data):
"""Update security of a password."""
# http://teampasswordmanager.com/docs/api-passwords/#update_security_password
log.info('Update security of password %s with %s' % (ID, data))
self.put('passwords/%s/security.json' % ID, data) | [
"Update",
"security",
"of",
"a",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L380-L384 | [
"def",
"update_security_of_password",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#update_security_password",
"log",
".",
"info",
"(",
"'Update security of password %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")"... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_custom_fields_of_password | Update custom fields definitions of a password. | tpm.py | def update_custom_fields_of_password(self, ID, data):
"""Update custom fields definitions of a password."""
# http://teampasswordmanager.com/docs/api-passwords/#update_cf_password
log.info('Update custom fields of password %s with %s' % (ID, data))
self.put('passwords/%s/custom_fields.js... | def update_custom_fields_of_password(self, ID, data):
"""Update custom fields definitions of a password."""
# http://teampasswordmanager.com/docs/api-passwords/#update_cf_password
log.info('Update custom fields of password %s with %s' % (ID, data))
self.put('passwords/%s/custom_fields.js... | [
"Update",
"custom",
"fields",
"definitions",
"of",
"a",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L386-L390 | [
"def",
"update_custom_fields_of_password",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#update_cf_password",
"log",
".",
"info",
"(",
"'Update custom fields of password %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.unlock_password | Unlock a password. | tpm.py | def unlock_password(self, ID, reason):
"""Unlock a password."""
# http://teampasswordmanager.com/docs/api-passwords/#unlock_password
log.info('Unlock password %s, Reason: %s' % (ID, reason))
self.unlock_reason = reason
self.put('passwords/%s/unlock.json' % ID) | def unlock_password(self, ID, reason):
"""Unlock a password."""
# http://teampasswordmanager.com/docs/api-passwords/#unlock_password
log.info('Unlock password %s, Reason: %s' % (ID, reason))
self.unlock_reason = reason
self.put('passwords/%s/unlock.json' % ID) | [
"Unlock",
"a",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L404-L409 | [
"def",
"unlock_password",
"(",
"self",
",",
"ID",
",",
"reason",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#unlock_password",
"log",
".",
"info",
"(",
"'Unlock password %s, Reason: %s'",
"%",
"(",
"ID",
",",
"reason",
")",
")",
"self",
".",
"unl... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.list_mypasswords_search | List my passwords with searchstring. | tpm.py | def list_mypasswords_search(self, searchstring):
"""List my passwords with searchstring."""
# http://teampasswordmanager.com/docs/api-my-passwords/#list_passwords
log.debug('List MyPasswords with %s' % searchstring)
return self.collection('my_passwords/search/%s.json' %
... | def list_mypasswords_search(self, searchstring):
"""List my passwords with searchstring."""
# http://teampasswordmanager.com/docs/api-my-passwords/#list_passwords
log.debug('List MyPasswords with %s' % searchstring)
return self.collection('my_passwords/search/%s.json' %
... | [
"List",
"my",
"passwords",
"with",
"searchstring",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L417-L422 | [
"def",
"list_mypasswords_search",
"(",
"self",
",",
"searchstring",
")",
":",
"# http://teampasswordmanager.com/docs/api-my-passwords/#list_passwords",
"log",
".",
"debug",
"(",
"'List MyPasswords with %s'",
"%",
"searchstring",
")",
"return",
"self",
".",
"collection",
"("... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.create_mypassword | Create my password. | tpm.py | def create_mypassword(self, data):
"""Create my password."""
# http://teampasswordmanager.com/docs/api-my-passwords/#create_password
log.info('Create MyPassword with %s' % data)
NewID = self.post('my_passwords.json', data).get('id')
log.info('MyPassword has been created with %s' ... | def create_mypassword(self, data):
"""Create my password."""
# http://teampasswordmanager.com/docs/api-my-passwords/#create_password
log.info('Create MyPassword with %s' % data)
NewID = self.post('my_passwords.json', data).get('id')
log.info('MyPassword has been created with %s' ... | [
"Create",
"my",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L430-L436 | [
"def",
"create_mypassword",
"(",
"self",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-my-passwords/#create_password",
"log",
".",
"info",
"(",
"'Create MyPassword with %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'my_passwords.js... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_mypassword | Update my password. | tpm.py | def update_mypassword(self, ID, data):
"""Update my password."""
# http://teampasswordmanager.com/docs/api-my-passwords/#update_password
log.info('Update MyPassword %s with %s' % (ID, data))
self.put('my_passwords/%s.json' % ID, data) | def update_mypassword(self, ID, data):
"""Update my password."""
# http://teampasswordmanager.com/docs/api-my-passwords/#update_password
log.info('Update MyPassword %s with %s' % (ID, data))
self.put('my_passwords/%s.json' % ID, data) | [
"Update",
"my",
"password",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L438-L442 | [
"def",
"update_mypassword",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-my-passwords/#update_password",
"log",
".",
"info",
"(",
"'Update MyPassword %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put"... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.create_user | Create a User. | tpm.py | def create_user(self, data):
"""Create a User."""
# http://teampasswordmanager.com/docs/api-users/#create_user
log.info('Create user with %s' % data)
NewID = self.post('users.json', data).get('id')
log.info('User has been created with ID %s' % NewID)
return NewID | def create_user(self, data):
"""Create a User."""
# http://teampasswordmanager.com/docs/api-users/#create_user
log.info('Create user with %s' % data)
NewID = self.post('users.json', data).get('id')
log.info('User has been created with ID %s' % NewID)
return NewID | [
"Create",
"a",
"User",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L496-L502 | [
"def",
"create_user",
"(",
"self",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#create_user",
"log",
".",
"info",
"(",
"'Create user with %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'users.json'",
",",
"data",
")",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_user | Update a User. | tpm.py | def update_user(self, ID, data):
"""Update a User."""
# http://teampasswordmanager.com/docs/api-users/#update_user
log.info('Update user %s with %s' % (ID, data))
self.put('users/%s.json' % ID, data) | def update_user(self, ID, data):
"""Update a User."""
# http://teampasswordmanager.com/docs/api-users/#update_user
log.info('Update user %s with %s' % (ID, data))
self.put('users/%s.json' % ID, data) | [
"Update",
"a",
"User",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L504-L508 | [
"def",
"update_user",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#update_user",
"log",
".",
"info",
"(",
"'Update user %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"(",
"'users/%s.j... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.change_user_password | Change password of a User. | tpm.py | def change_user_password(self, ID, data):
"""Change password of a User."""
# http://teampasswordmanager.com/docs/api-users/#change_password
log.info('Change user %s password' % ID)
self.put('users/%s/change_password.json' % ID, data) | def change_user_password(self, ID, data):
"""Change password of a User."""
# http://teampasswordmanager.com/docs/api-users/#change_password
log.info('Change user %s password' % ID)
self.put('users/%s/change_password.json' % ID, data) | [
"Change",
"password",
"of",
"a",
"User",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L510-L514 | [
"def",
"change_user_password",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#change_password",
"log",
".",
"info",
"(",
"'Change user %s password'",
"%",
"ID",
")",
"self",
".",
"put",
"(",
"'users/%s/change_password.js... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.convert_user_to_ldap | Convert a normal user to a LDAP user. | tpm.py | def convert_user_to_ldap(self, ID, DN):
"""Convert a normal user to a LDAP user."""
# http://teampasswordmanager.com/docs/api-users/#convert_to_ldap
data = {'login_dn': DN}
log.info('Convert User %s to LDAP DN %s' % (ID, DN))
self.put('users/%s/convert_to_ldap.json' % ID, data) | def convert_user_to_ldap(self, ID, DN):
"""Convert a normal user to a LDAP user."""
# http://teampasswordmanager.com/docs/api-users/#convert_to_ldap
data = {'login_dn': DN}
log.info('Convert User %s to LDAP DN %s' % (ID, DN))
self.put('users/%s/convert_to_ldap.json' % ID, data) | [
"Convert",
"a",
"normal",
"user",
"to",
"a",
"LDAP",
"user",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L528-L533 | [
"def",
"convert_user_to_ldap",
"(",
"self",
",",
"ID",
",",
"DN",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#convert_to_ldap",
"data",
"=",
"{",
"'login_dn'",
":",
"DN",
"}",
"log",
".",
"info",
"(",
"'Convert User %s to LDAP DN %s'",
"%",
"(",
"ID"... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.create_group | Create a Group. | tpm.py | def create_group(self, data):
"""Create a Group."""
# http://teampasswordmanager.com/docs/api-groups/#create_group
log.info('Create group with %s' % data)
NewID = self.post('groups.json', data).get('id')
log.info('Group has been created with ID %s' % NewID)
return NewID | def create_group(self, data):
"""Create a Group."""
# http://teampasswordmanager.com/docs/api-groups/#create_group
log.info('Create group with %s' % data)
NewID = self.post('groups.json', data).get('id')
log.info('Group has been created with ID %s' % NewID)
return NewID | [
"Create",
"a",
"Group",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L558-L564 | [
"def",
"create_group",
"(",
"self",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#create_group",
"log",
".",
"info",
"(",
"'Create group with %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'groups.json'",
",",
"data",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.update_group | Update a Group. | tpm.py | def update_group(self, ID, data):
"""Update a Group."""
# http://teampasswordmanager.com/docs/api-groups/#update_group
log.info('Update group %s with %s' % (ID, data))
self.put('groups/%s.json' % ID, data) | def update_group(self, ID, data):
"""Update a Group."""
# http://teampasswordmanager.com/docs/api-groups/#update_group
log.info('Update group %s with %s' % (ID, data))
self.put('groups/%s.json' % ID, data) | [
"Update",
"a",
"Group",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L566-L570 | [
"def",
"update_group",
"(",
"self",
",",
"ID",
",",
"data",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#update_group",
"log",
".",
"info",
"(",
"'Update group %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"(",
"'groups... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.add_user_to_group | Add a user to a group. | tpm.py | def add_user_to_group(self, GroupID, UserID):
"""Add a user to a group."""
# http://teampasswordmanager.com/docs/api-groups/#add_user
log.info('Add User %s to Group %s' % (UserID, GroupID))
self.put('groups/%s/add_user/%s.json' % (GroupID, UserID)) | def add_user_to_group(self, GroupID, UserID):
"""Add a user to a group."""
# http://teampasswordmanager.com/docs/api-groups/#add_user
log.info('Add User %s to Group %s' % (UserID, GroupID))
self.put('groups/%s/add_user/%s.json' % (GroupID, UserID)) | [
"Add",
"a",
"user",
"to",
"a",
"group",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L572-L576 | [
"def",
"add_user_to_group",
"(",
"self",
",",
"GroupID",
",",
"UserID",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#add_user",
"log",
".",
"info",
"(",
"'Add User %s to Group %s'",
"%",
"(",
"UserID",
",",
"GroupID",
")",
")",
"self",
".",
"put",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.delete_user_from_group | Delete a user from a group. | tpm.py | def delete_user_from_group(self, GroupID, UserID):
"""Delete a user from a group."""
# http://teampasswordmanager.com/docs/api-groups/#del_user
log.info('Delete user %s from group %s' % (UserID, GroupID))
self.put('groups/%s/delete_user/%s.json' % (GroupID, UserID)) | def delete_user_from_group(self, GroupID, UserID):
"""Delete a user from a group."""
# http://teampasswordmanager.com/docs/api-groups/#del_user
log.info('Delete user %s from group %s' % (UserID, GroupID))
self.put('groups/%s/delete_user/%s.json' % (GroupID, UserID)) | [
"Delete",
"a",
"user",
"from",
"a",
"group",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L578-L582 | [
"def",
"delete_user_from_group",
"(",
"self",
",",
"GroupID",
",",
"UserID",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#del_user",
"log",
".",
"info",
"(",
"'Delete user %s from group %s'",
"%",
"(",
"UserID",
",",
"GroupID",
")",
")",
"self",
".",
... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | TpmApi.up_to_date | Check if Team Password Manager is up to date. | tpm.py | def up_to_date(self):
"""Check if Team Password Manager is up to date."""
VersionInfo = self.get_latest_version()
CurrentVersion = VersionInfo.get('version')
LatestVersion = VersionInfo.get('latest_version')
if CurrentVersion == LatestVersion:
log.info('TeamPasswordM... | def up_to_date(self):
"""Check if Team Password Manager is up to date."""
VersionInfo = self.get_latest_version()
CurrentVersion = VersionInfo.get('version')
LatestVersion = VersionInfo.get('latest_version')
if CurrentVersion == LatestVersion:
log.info('TeamPasswordM... | [
"Check",
"if",
"Team",
"Password",
"Manager",
"is",
"up",
"to",
"date",
"."
] | peshay/tpm | python | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L608-L620 | [
"def",
"up_to_date",
"(",
"self",
")",
":",
"VersionInfo",
"=",
"self",
".",
"get_latest_version",
"(",
")",
"CurrentVersion",
"=",
"VersionInfo",
".",
"get",
"(",
"'version'",
")",
"LatestVersion",
"=",
"VersionInfo",
".",
"get",
"(",
"'latest_version'",
")",... | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc |
train | convert_exception | Decorator: Catch exception ``from_exception`` and instead raise ``to_exception(*to_args, **to_kw)``.
Useful when modules you're using in a method throw their own errors that you want to
convert to your own exceptions that you handle higher in the stack.
Example: ::
class FooError(Exception):
... | unstdlib/standard/exception_.py | def convert_exception(from_exception, to_exception, *to_args, **to_kw):
"""
Decorator: Catch exception ``from_exception`` and instead raise ``to_exception(*to_args, **to_kw)``.
Useful when modules you're using in a method throw their own errors that you want to
convert to your own exceptions that you h... | def convert_exception(from_exception, to_exception, *to_args, **to_kw):
"""
Decorator: Catch exception ``from_exception`` and instead raise ``to_exception(*to_args, **to_kw)``.
Useful when modules you're using in a method throw their own errors that you want to
convert to your own exceptions that you h... | [
"Decorator",
":",
"Catch",
"exception",
"from_exception",
"and",
"instead",
"raise",
"to_exception",
"(",
"*",
"to_args",
"**",
"to_kw",
")",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/exception_.py#L9-L51 | [
"def",
"convert_exception",
"(",
"from_exception",
",",
"to_exception",
",",
"*",
"to_args",
",",
"*",
"*",
"to_kw",
")",
":",
"def",
"wrapper",
"(",
"fn",
")",
":",
"def",
"fn_new",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"try",
":",
"ret... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | iterate_date_values | Convert (date, value) sorted lists into contiguous value-per-day data sets. Great for sparklines.
Example::
[(datetime.date(2011, 1, 1), 1), (datetime.date(2011, 1, 4), 2)] -> [1, 0, 0, 2] | unstdlib/standard/datetime_.py | def iterate_date_values(d, start_date=None, stop_date=None, default=0):
"""
Convert (date, value) sorted lists into contiguous value-per-day data sets. Great for sparklines.
Example::
[(datetime.date(2011, 1, 1), 1), (datetime.date(2011, 1, 4), 2)] -> [1, 0, 0, 2]
"""
dataiter = iter(d)
... | def iterate_date_values(d, start_date=None, stop_date=None, default=0):
"""
Convert (date, value) sorted lists into contiguous value-per-day data sets. Great for sparklines.
Example::
[(datetime.date(2011, 1, 1), 1), (datetime.date(2011, 1, 4), 2)] -> [1, 0, 0, 2]
"""
dataiter = iter(d)
... | [
"Convert",
"(",
"date",
"value",
")",
"sorted",
"lists",
"into",
"contiguous",
"value",
"-",
"per",
"-",
"day",
"data",
"sets",
".",
"Great",
"for",
"sparklines",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L16-L43 | [
"def",
"iterate_date_values",
"(",
"d",
",",
"start_date",
"=",
"None",
",",
"stop_date",
"=",
"None",
",",
"default",
"=",
"0",
")",
":",
"dataiter",
"=",
"iter",
"(",
"d",
")",
"cur_day",
",",
"cur_val",
"=",
"next",
"(",
"dataiter",
")",
"start_date... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | truncate_datetime | Given a datetime ``t`` and a ``resolution``, flatten the precision beyond the given resolution.
``resolution`` can be one of: year, month, day, hour, minute, second, microsecond
Example::
>>> t = datetime.datetime(2000, 1, 2, 3, 4, 5, 6000) # Or, 2000-01-02 03:04:05.006000
>>> truncate_datet... | unstdlib/standard/datetime_.py | def truncate_datetime(t, resolution):
"""
Given a datetime ``t`` and a ``resolution``, flatten the precision beyond the given resolution.
``resolution`` can be one of: year, month, day, hour, minute, second, microsecond
Example::
>>> t = datetime.datetime(2000, 1, 2, 3, 4, 5, 6000) # Or, 2000... | def truncate_datetime(t, resolution):
"""
Given a datetime ``t`` and a ``resolution``, flatten the precision beyond the given resolution.
``resolution`` can be one of: year, month, day, hour, minute, second, microsecond
Example::
>>> t = datetime.datetime(2000, 1, 2, 3, 4, 5, 6000) # Or, 2000... | [
"Given",
"a",
"datetime",
"t",
"and",
"a",
"resolution",
"flatten",
"the",
"precision",
"beyond",
"the",
"given",
"resolution",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L53-L85 | [
"def",
"truncate_datetime",
"(",
"t",
",",
"resolution",
")",
":",
"resolutions",
"=",
"[",
"'year'",
",",
"'month'",
",",
"'day'",
",",
"'hour'",
",",
"'minute'",
",",
"'second'",
",",
"'microsecond'",
"]",
"if",
"resolution",
"not",
"in",
"resolutions",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | to_timezone | Return an aware datetime which is ``dt`` converted to ``timezone``.
If ``dt`` is naive, it is assumed to be UTC.
For example, if ``dt`` is "06:00 UTC+0000" and ``timezone`` is "EDT-0400",
then the result will be "02:00 EDT-0400".
This method follows the guidelines in http://pytz.sourceforge.net/ | unstdlib/standard/datetime_.py | def to_timezone(dt, timezone):
"""
Return an aware datetime which is ``dt`` converted to ``timezone``.
If ``dt`` is naive, it is assumed to be UTC.
For example, if ``dt`` is "06:00 UTC+0000" and ``timezone`` is "EDT-0400",
then the result will be "02:00 EDT-0400".
This method follows the guid... | def to_timezone(dt, timezone):
"""
Return an aware datetime which is ``dt`` converted to ``timezone``.
If ``dt`` is naive, it is assumed to be UTC.
For example, if ``dt`` is "06:00 UTC+0000" and ``timezone`` is "EDT-0400",
then the result will be "02:00 EDT-0400".
This method follows the guid... | [
"Return",
"an",
"aware",
"datetime",
"which",
"is",
"dt",
"converted",
"to",
"timezone",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L87-L100 | [
"def",
"to_timezone",
"(",
"dt",
",",
"timezone",
")",
":",
"if",
"dt",
".",
"tzinfo",
"is",
"None",
":",
"dt",
"=",
"dt",
".",
"replace",
"(",
"tzinfo",
"=",
"_UTC",
")",
"return",
"timezone",
".",
"normalize",
"(",
"dt",
".",
"astimezone",
"(",
"... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | now | Return a naive datetime object for the given ``timezone``. A ``timezone``
is any pytz- like or datetime.tzinfo-like timezone object. If no timezone
is given, then UTC is assumed.
This method is best used with pytz installed::
pip install pytz | unstdlib/standard/datetime_.py | def now(timezone=None):
"""
Return a naive datetime object for the given ``timezone``. A ``timezone``
is any pytz- like or datetime.tzinfo-like timezone object. If no timezone
is given, then UTC is assumed.
This method is best used with pytz installed::
pip install pytz
"""
d = dat... | def now(timezone=None):
"""
Return a naive datetime object for the given ``timezone``. A ``timezone``
is any pytz- like or datetime.tzinfo-like timezone object. If no timezone
is given, then UTC is assumed.
This method is best used with pytz installed::
pip install pytz
"""
d = dat... | [
"Return",
"a",
"naive",
"datetime",
"object",
"for",
"the",
"given",
"timezone",
".",
"A",
"timezone",
"is",
"any",
"pytz",
"-",
"like",
"or",
"datetime",
".",
"tzinfo",
"-",
"like",
"timezone",
"object",
".",
"If",
"no",
"timezone",
"is",
"given",
"then... | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L102-L116 | [
"def",
"now",
"(",
"timezone",
"=",
"None",
")",
":",
"d",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"if",
"not",
"timezone",
":",
"return",
"d",
"return",
"to_timezone",
"(",
"d",
",",
"timezone",
")",
".",
"replace",
"(",
"tzinfo",... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | enumerate_query_by_limit | Enumerate over SQLAlchemy query object ``q`` and yield individual results
fetched in batches of size ``limit`` using SQL LIMIT and OFFSET. | unstdlib/sqlalchemy.py | def enumerate_query_by_limit(q, limit=1000):
"""
Enumerate over SQLAlchemy query object ``q`` and yield individual results
fetched in batches of size ``limit`` using SQL LIMIT and OFFSET.
"""
for offset in count(0, limit):
r = q.offset(offset).limit(limit).all()
for row in r:
... | def enumerate_query_by_limit(q, limit=1000):
"""
Enumerate over SQLAlchemy query object ``q`` and yield individual results
fetched in batches of size ``limit`` using SQL LIMIT and OFFSET.
"""
for offset in count(0, limit):
r = q.offset(offset).limit(limit).all()
for row in r:
... | [
"Enumerate",
"over",
"SQLAlchemy",
"query",
"object",
"q",
"and",
"yield",
"individual",
"results",
"fetched",
"in",
"batches",
"of",
"size",
"limit",
"using",
"SQL",
"LIMIT",
"and",
"OFFSET",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/sqlalchemy.py#L7-L19 | [
"def",
"enumerate_query_by_limit",
"(",
"q",
",",
"limit",
"=",
"1000",
")",
":",
"for",
"offset",
"in",
"count",
"(",
"0",
",",
"limit",
")",
":",
"r",
"=",
"q",
".",
"offset",
"(",
"offset",
")",
".",
"limit",
"(",
"limit",
")",
".",
"all",
"("... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | validate_many | Validate a dictionary of data against the provided schema.
Returns a list of values positioned in the same order as given in ``schema``, each
value is validated with the corresponding validator. Raises formencode.Invalid if
validation failed.
Similar to get_many but using formencode validation.
:... | unstdlib/formencode.py | def validate_many(d, schema):
"""Validate a dictionary of data against the provided schema.
Returns a list of values positioned in the same order as given in ``schema``, each
value is validated with the corresponding validator. Raises formencode.Invalid if
validation failed.
Similar to get_many bu... | def validate_many(d, schema):
"""Validate a dictionary of data against the provided schema.
Returns a list of values positioned in the same order as given in ``schema``, each
value is validated with the corresponding validator. Raises formencode.Invalid if
validation failed.
Similar to get_many bu... | [
"Validate",
"a",
"dictionary",
"of",
"data",
"against",
"the",
"provided",
"schema",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/formencode.py#L12-L35 | [
"def",
"validate_many",
"(",
"d",
",",
"schema",
")",
":",
"return",
"[",
"validator",
".",
"to_python",
"(",
"d",
".",
"get",
"(",
"key",
")",
",",
"state",
"=",
"key",
")",
"for",
"key",
",",
"validator",
"in",
"schema",
"]"
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | assert_hashable | Verify that each argument is hashable.
Passes silently if successful. Raises descriptive TypeError otherwise.
Example::
>>> assert_hashable(1, 'foo', bar='baz')
>>> assert_hashable(1, [], baz='baz')
Traceback (most recent call last):
...
TypeError: Argument in positi... | unstdlib/standard/functools_.py | def assert_hashable(*args, **kw):
""" Verify that each argument is hashable.
Passes silently if successful. Raises descriptive TypeError otherwise.
Example::
>>> assert_hashable(1, 'foo', bar='baz')
>>> assert_hashable(1, [], baz='baz')
Traceback (most recent call last):
... | def assert_hashable(*args, **kw):
""" Verify that each argument is hashable.
Passes silently if successful. Raises descriptive TypeError otherwise.
Example::
>>> assert_hashable(1, 'foo', bar='baz')
>>> assert_hashable(1, [], baz='baz')
Traceback (most recent call last):
... | [
"Verify",
"that",
"each",
"argument",
"is",
"hashable",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L13-L39 | [
"def",
"assert_hashable",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"try",
":",
"for",
"i",
",",
"arg",
"in",
"enumerate",
"(",
"args",
")",
":",
"hash",
"(",
"arg",
")",
"except",
"TypeError",
":",
"raise",
"TypeError",
"(",
"'Argument in pos... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | memoized | Memoize a function into an optionally-specificed cache container.
If the `cache` container is not specified, then the instance container is
accessible from the wrapped function's `memoize_cache` property.
Example::
>>> @memoized
... def foo(bar):
... print("Not cached.")
... | unstdlib/standard/functools_.py | def memoized(fn=None, cache=None):
""" Memoize a function into an optionally-specificed cache container.
If the `cache` container is not specified, then the instance container is
accessible from the wrapped function's `memoize_cache` property.
Example::
>>> @memoized
... def foo(bar):... | def memoized(fn=None, cache=None):
""" Memoize a function into an optionally-specificed cache container.
If the `cache` container is not specified, then the instance container is
accessible from the wrapped function's `memoize_cache` property.
Example::
>>> @memoized
... def foo(bar):... | [
"Memoize",
"a",
"function",
"into",
"an",
"optionally",
"-",
"specificed",
"cache",
"container",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L59-L110 | [
"def",
"memoized",
"(",
"fn",
"=",
"None",
",",
"cache",
"=",
"None",
")",
":",
"if",
"fn",
":",
"# This is a hack to support both @memoize and @memoize(...)",
"return",
"memoized",
"(",
"cache",
"=",
"cache",
")",
"(",
"fn",
")",
"if",
"cache",
"is",
"None"... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | memoized_method | Memoize a class's method.
Arguments are similar to to `memoized`, except that the cache container is
specified with `cache_factory`: a function called with no arguments to
create the caching container for the instance.
Note that, unlike `memoized`, the result cache will be stored on the
instance, ... | unstdlib/standard/functools_.py | def memoized_method(method=None, cache_factory=None):
""" Memoize a class's method.
Arguments are similar to to `memoized`, except that the cache container is
specified with `cache_factory`: a function called with no arguments to
create the caching container for the instance.
Note that, unlike `me... | def memoized_method(method=None, cache_factory=None):
""" Memoize a class's method.
Arguments are similar to to `memoized`, except that the cache container is
specified with `cache_factory`: a function called with no arguments to
create the caching container for the instance.
Note that, unlike `me... | [
"Memoize",
"a",
"class",
"s",
"method",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L129-L199 | [
"def",
"memoized_method",
"(",
"method",
"=",
"None",
",",
"cache_factory",
"=",
"None",
")",
":",
"if",
"method",
"is",
"None",
":",
"return",
"lambda",
"f",
":",
"memoized_method",
"(",
"f",
",",
"cache_factory",
"=",
"cache_factory",
")",
"cache_factory",... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | deprecated | Throw a warning when a function/method will be soon deprecated
Supports passing a ``message`` and an ``exception`` class
(uses ``PendingDeprecationWarning`` by default). This is useful if you
want to alternatively pass a ``DeprecationWarning`` exception for already
deprecated functions/methods.
Ex... | unstdlib/standard/functools_.py | def deprecated(message, exception=PendingDeprecationWarning):
"""Throw a warning when a function/method will be soon deprecated
Supports passing a ``message`` and an ``exception`` class
(uses ``PendingDeprecationWarning`` by default). This is useful if you
want to alternatively pass a ``DeprecationWarn... | def deprecated(message, exception=PendingDeprecationWarning):
"""Throw a warning when a function/method will be soon deprecated
Supports passing a ``message`` and an ``exception`` class
(uses ``PendingDeprecationWarning`` by default). This is useful if you
want to alternatively pass a ``DeprecationWarn... | [
"Throw",
"a",
"warning",
"when",
"a",
"function",
"/",
"method",
"will",
"be",
"soon",
"deprecated"
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L202-L233 | [
"def",
"deprecated",
"(",
"message",
",",
"exception",
"=",
"PendingDeprecationWarning",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"warnin... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | groupby_count | Aggregate iterator values into buckets based on how frequently the
values appear.
Example::
>>> list(groupby_count([1, 1, 1, 2, 3]))
[(1, 3), (2, 1), (3, 1)] | unstdlib/standard/list_.py | def groupby_count(i, key=None, force_keys=None):
""" Aggregate iterator values into buckets based on how frequently the
values appear.
Example::
>>> list(groupby_count([1, 1, 1, 2, 3]))
[(1, 3), (2, 1), (3, 1)]
"""
counter = defaultdict(lambda: 0)
if not key:
key = lamb... | def groupby_count(i, key=None, force_keys=None):
""" Aggregate iterator values into buckets based on how frequently the
values appear.
Example::
>>> list(groupby_count([1, 1, 1, 2, 3]))
[(1, 3), (2, 1), (3, 1)]
"""
counter = defaultdict(lambda: 0)
if not key:
key = lamb... | [
"Aggregate",
"iterator",
"values",
"into",
"buckets",
"based",
"on",
"how",
"frequently",
"the",
"values",
"appear",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L16-L36 | [
"def",
"groupby_count",
"(",
"i",
",",
"key",
"=",
"None",
",",
"force_keys",
"=",
"None",
")",
":",
"counter",
"=",
"defaultdict",
"(",
"lambda",
":",
"0",
")",
"if",
"not",
"key",
":",
"key",
"=",
"lambda",
"o",
":",
"o",
"for",
"k",
"in",
"i",... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | is_iterable | Return whether ``maybe_iter`` is an iterable, unless it's an instance of one
of the base class, or tuple of base classes, given in ``unless``.
Example::
>>> is_iterable('foo')
False
>>> is_iterable(['foo'])
True
>>> is_iterable(['foo'], unless=list)
False
... | unstdlib/standard/list_.py | def is_iterable(maybe_iter, unless=(string_types, dict)):
""" Return whether ``maybe_iter`` is an iterable, unless it's an instance of one
of the base class, or tuple of base classes, given in ``unless``.
Example::
>>> is_iterable('foo')
False
>>> is_iterable(['foo'])
True
... | def is_iterable(maybe_iter, unless=(string_types, dict)):
""" Return whether ``maybe_iter`` is an iterable, unless it's an instance of one
of the base class, or tuple of base classes, given in ``unless``.
Example::
>>> is_iterable('foo')
False
>>> is_iterable(['foo'])
True
... | [
"Return",
"whether",
"maybe_iter",
"is",
"an",
"iterable",
"unless",
"it",
"s",
"an",
"instance",
"of",
"one",
"of",
"the",
"base",
"class",
"or",
"tuple",
"of",
"base",
"classes",
"given",
"in",
"unless",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L39-L58 | [
"def",
"is_iterable",
"(",
"maybe_iter",
",",
"unless",
"=",
"(",
"string_types",
",",
"dict",
")",
")",
":",
"try",
":",
"iter",
"(",
"maybe_iter",
")",
"except",
"TypeError",
":",
"return",
"False",
"return",
"not",
"isinstance",
"(",
"maybe_iter",
",",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | iterate | Always return an iterable.
Returns ``maybe_iter`` if it is an iterable, otherwise it returns a single
element iterable containing ``maybe_iter``. By default, strings and dicts
are treated as non-iterable. This can be overridden by passing in a type
or tuple of types for ``unless``.
:param maybe_it... | unstdlib/standard/list_.py | def iterate(maybe_iter, unless=(string_types, dict)):
""" Always return an iterable.
Returns ``maybe_iter`` if it is an iterable, otherwise it returns a single
element iterable containing ``maybe_iter``. By default, strings and dicts
are treated as non-iterable. This can be overridden by passing in a t... | def iterate(maybe_iter, unless=(string_types, dict)):
""" Always return an iterable.
Returns ``maybe_iter`` if it is an iterable, otherwise it returns a single
element iterable containing ``maybe_iter``. By default, strings and dicts
are treated as non-iterable. This can be overridden by passing in a t... | [
"Always",
"return",
"an",
"iterable",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L61-L89 | [
"def",
"iterate",
"(",
"maybe_iter",
",",
"unless",
"=",
"(",
"string_types",
",",
"dict",
")",
")",
":",
"if",
"is_iterable",
"(",
"maybe_iter",
",",
"unless",
"=",
"unless",
")",
":",
"return",
"maybe_iter",
"return",
"[",
"maybe_iter",
"]"
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | iterate_items | Return a consistent (key, value) iterable on dict-like objects,
including lists of tuple pairs.
Example:
>>> list(iterate_items({'a': 1}))
[('a', 1)]
>>> list(iterate_items([('a', 1), ('b', 2)]))
[('a', 1), ('b', 2)] | unstdlib/standard/list_.py | def iterate_items(dictish):
""" Return a consistent (key, value) iterable on dict-like objects,
including lists of tuple pairs.
Example:
>>> list(iterate_items({'a': 1}))
[('a', 1)]
>>> list(iterate_items([('a', 1), ('b', 2)]))
[('a', 1), ('b', 2)]
"""
if hasattr(di... | def iterate_items(dictish):
""" Return a consistent (key, value) iterable on dict-like objects,
including lists of tuple pairs.
Example:
>>> list(iterate_items({'a': 1}))
[('a', 1)]
>>> list(iterate_items([('a', 1), ('b', 2)]))
[('a', 1), ('b', 2)]
"""
if hasattr(di... | [
"Return",
"a",
"consistent",
"(",
"key",
"value",
")",
"iterable",
"on",
"dict",
"-",
"like",
"objects",
"including",
"lists",
"of",
"tuple",
"pairs",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L92-L107 | [
"def",
"iterate_items",
"(",
"dictish",
")",
":",
"if",
"hasattr",
"(",
"dictish",
",",
"'iteritems'",
")",
":",
"return",
"dictish",
".",
"iteritems",
"(",
")",
"if",
"hasattr",
"(",
"dictish",
",",
"'items'",
")",
":",
"return",
"dictish",
".",
"items"... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | iterate_chunks | Iterate over an iterator ``i`` in ``size`` chunks, yield chunks.
Similar to pagination.
Example::
>>> list(iterate_chunks([1, 2, 3, 4], size=2))
[[1, 2], [3, 4]] | unstdlib/standard/list_.py | def iterate_chunks(i, size=10):
"""
Iterate over an iterator ``i`` in ``size`` chunks, yield chunks.
Similar to pagination.
Example::
>>> list(iterate_chunks([1, 2, 3, 4], size=2))
[[1, 2], [3, 4]]
"""
accumulator = []
for n, i in enumerate(i):
accumulator.append(i... | def iterate_chunks(i, size=10):
"""
Iterate over an iterator ``i`` in ``size`` chunks, yield chunks.
Similar to pagination.
Example::
>>> list(iterate_chunks([1, 2, 3, 4], size=2))
[[1, 2], [3, 4]]
"""
accumulator = []
for n, i in enumerate(i):
accumulator.append(i... | [
"Iterate",
"over",
"an",
"iterator",
"i",
"in",
"size",
"chunks",
"yield",
"chunks",
".",
"Similar",
"to",
"pagination",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L110-L129 | [
"def",
"iterate_chunks",
"(",
"i",
",",
"size",
"=",
"10",
")",
":",
"accumulator",
"=",
"[",
"]",
"for",
"n",
",",
"i",
"in",
"enumerate",
"(",
"i",
")",
":",
"accumulator",
".",
"append",
"(",
"i",
")",
"if",
"(",
"n",
"+",
"1",
")",
"%",
"... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | listify | A decorator which wraps a function's return value in ``list(...)``.
Useful when an algorithm can be expressed more cleanly as a generator but
the function should return an list.
Example::
>>> @listify
... def get_lengths(iterable):
... for i in iterable:
... yi... | unstdlib/standard/list_.py | def listify(fn=None, wrapper=list):
"""
A decorator which wraps a function's return value in ``list(...)``.
Useful when an algorithm can be expressed more cleanly as a generator but
the function should return an list.
Example::
>>> @listify
... def get_lengths(iterable):
.... | def listify(fn=None, wrapper=list):
"""
A decorator which wraps a function's return value in ``list(...)``.
Useful when an algorithm can be expressed more cleanly as a generator but
the function should return an list.
Example::
>>> @listify
... def get_lengths(iterable):
.... | [
"A",
"decorator",
"which",
"wraps",
"a",
"function",
"s",
"return",
"value",
"in",
"list",
"(",
"...",
")",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L149-L179 | [
"def",
"listify",
"(",
"fn",
"=",
"None",
",",
"wrapper",
"=",
"list",
")",
":",
"def",
"listify_return",
"(",
"fn",
")",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"listify_helper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"return",
"wrap... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | is_subclass | Similar to the ``issubclass`` builtin, but does not raise a ``TypeError``
if either ``o`` or ``bases`` is not an instance of ``type``.
Example::
>>> is_subclass(IOError, Exception)
True
>>> is_subclass(Exception, None)
False
>>> is_subclass(None, Exception)
Fals... | unstdlib/standard/type_.py | def is_subclass(o, bases):
"""
Similar to the ``issubclass`` builtin, but does not raise a ``TypeError``
if either ``o`` or ``bases`` is not an instance of ``type``.
Example::
>>> is_subclass(IOError, Exception)
True
>>> is_subclass(Exception, None)
False
>>> is... | def is_subclass(o, bases):
"""
Similar to the ``issubclass`` builtin, but does not raise a ``TypeError``
if either ``o`` or ``bases`` is not an instance of ``type``.
Example::
>>> is_subclass(IOError, Exception)
True
>>> is_subclass(Exception, None)
False
>>> is... | [
"Similar",
"to",
"the",
"issubclass",
"builtin",
"but",
"does",
"not",
"raise",
"a",
"TypeError",
"if",
"either",
"o",
"or",
"bases",
"is",
"not",
"an",
"instance",
"of",
"type",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/type_.py#L6-L35 | [
"def",
"is_subclass",
"(",
"o",
",",
"bases",
")",
":",
"try",
":",
"return",
"_issubclass",
"(",
"o",
",",
"bases",
")",
"except",
"TypeError",
":",
"pass",
"if",
"not",
"isinstance",
"(",
"o",
",",
"type",
")",
":",
"return",
"False",
"if",
"not",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | get_many | Returns a predictable number of elements out of ``d`` in a list for auto-expanding.
Keys in ``required`` will raise KeyError if not found in ``d``.
Keys in ``optional`` will return None if not found in ``d``.
Keys in ``one_of`` will raise KeyError if none exist, otherwise return the first in ``d``.
Ex... | unstdlib/standard/dict_.py | def get_many(d, required=[], optional=[], one_of=[]):
"""
Returns a predictable number of elements out of ``d`` in a list for auto-expanding.
Keys in ``required`` will raise KeyError if not found in ``d``.
Keys in ``optional`` will return None if not found in ``d``.
Keys in ``one_of`` will raise Ke... | def get_many(d, required=[], optional=[], one_of=[]):
"""
Returns a predictable number of elements out of ``d`` in a list for auto-expanding.
Keys in ``required`` will raise KeyError if not found in ``d``.
Keys in ``optional`` will return None if not found in ``d``.
Keys in ``one_of`` will raise Ke... | [
"Returns",
"a",
"predictable",
"number",
"of",
"elements",
"out",
"of",
"d",
"in",
"a",
"list",
"for",
"auto",
"-",
"expanding",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/dict_.py#L6-L30 | [
"def",
"get_many",
"(",
"d",
",",
"required",
"=",
"[",
"]",
",",
"optional",
"=",
"[",
"]",
",",
"one_of",
"=",
"[",
"]",
")",
":",
"d",
"=",
"d",
"or",
"{",
"}",
"r",
"=",
"[",
"d",
"[",
"k",
"]",
"for",
"k",
"in",
"required",
"]",
"r",... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | random_string | Return a random string of given length and alphabet.
Default alphabet is url-friendly (base62). | unstdlib/standard/string_.py | def random_string(length=6, alphabet=string.ascii_letters+string.digits):
"""
Return a random string of given length and alphabet.
Default alphabet is url-friendly (base62).
"""
return ''.join([random.choice(alphabet) for i in xrange(length)]) | def random_string(length=6, alphabet=string.ascii_letters+string.digits):
"""
Return a random string of given length and alphabet.
Default alphabet is url-friendly (base62).
"""
return ''.join([random.choice(alphabet) for i in xrange(length)]) | [
"Return",
"a",
"random",
"string",
"of",
"given",
"length",
"and",
"alphabet",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L44-L50 | [
"def",
"random_string",
"(",
"length",
"=",
"6",
",",
"alphabet",
"=",
"string",
".",
"ascii_letters",
"+",
"string",
".",
"digits",
")",
":",
"return",
"''",
".",
"join",
"(",
"[",
"random",
".",
"choice",
"(",
"alphabet",
")",
"for",
"i",
"in",
"xr... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | number_to_string | Given an non-negative integer ``n``, convert it to a string composed of
the given ``alphabet`` mapping, where the position of each element in
``alphabet`` is its radix value.
Examples::
>>> number_to_string(12345678, '01')
'101111000110000101001110'
>>> number_to_string(12345678, ... | unstdlib/standard/string_.py | def number_to_string(n, alphabet):
"""
Given an non-negative integer ``n``, convert it to a string composed of
the given ``alphabet`` mapping, where the position of each element in
``alphabet`` is its radix value.
Examples::
>>> number_to_string(12345678, '01')
'1011110001100001010... | def number_to_string(n, alphabet):
"""
Given an non-negative integer ``n``, convert it to a string composed of
the given ``alphabet`` mapping, where the position of each element in
``alphabet`` is its radix value.
Examples::
>>> number_to_string(12345678, '01')
'1011110001100001010... | [
"Given",
"an",
"non",
"-",
"negative",
"integer",
"n",
"convert",
"it",
"to",
"a",
"string",
"composed",
"of",
"the",
"given",
"alphabet",
"mapping",
"where",
"the",
"position",
"of",
"each",
"element",
"in",
"alphabet",
"is",
"its",
"radix",
"value",
"."
... | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L53-L83 | [
"def",
"number_to_string",
"(",
"n",
",",
"alphabet",
")",
":",
"result",
"=",
"''",
"base",
"=",
"len",
"(",
"alphabet",
")",
"current",
"=",
"int",
"(",
"n",
")",
"if",
"current",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"invalid n (must be non-neg... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | string_to_number | Given a string ``s``, convert it to an integer composed of the given
``alphabet`` mapping, where the position of each element in ``alphabet`` is
its radix value.
Examples::
>>> string_to_number('101111000110000101001110', '01')
12345678
>>> string_to_number('babbbbaaabbaaaababaabb... | unstdlib/standard/string_.py | def string_to_number(s, alphabet):
"""
Given a string ``s``, convert it to an integer composed of the given
``alphabet`` mapping, where the position of each element in ``alphabet`` is
its radix value.
Examples::
>>> string_to_number('101111000110000101001110', '01')
12345678
... | def string_to_number(s, alphabet):
"""
Given a string ``s``, convert it to an integer composed of the given
``alphabet`` mapping, where the position of each element in ``alphabet`` is
its radix value.
Examples::
>>> string_to_number('101111000110000101001110', '01')
12345678
... | [
"Given",
"a",
"string",
"s",
"convert",
"it",
"to",
"an",
"integer",
"composed",
"of",
"the",
"given",
"alphabet",
"mapping",
"where",
"the",
"position",
"of",
"each",
"element",
"in",
"alphabet",
"is",
"its",
"radix",
"value",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L86-L112 | [
"def",
"string_to_number",
"(",
"s",
",",
"alphabet",
")",
":",
"base",
"=",
"len",
"(",
"alphabet",
")",
"inverse_alphabet",
"=",
"dict",
"(",
"zip",
"(",
"alphabet",
",",
"xrange",
"(",
"0",
",",
"base",
")",
")",
")",
"n",
"=",
"0",
"exp",
"=",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | bytes_to_number | Convert a string to an integer.
:param b:
String or bytearray to convert.
:param endian:
Byte order to convert into ('big' or 'little' endian-ness, default
'big')
Assumes bytes are 8 bits.
This is a special-case version of string_to_number with a full base-256
ASCII alpha... | unstdlib/standard/string_.py | def bytes_to_number(b, endian='big'):
"""
Convert a string to an integer.
:param b:
String or bytearray to convert.
:param endian:
Byte order to convert into ('big' or 'little' endian-ness, default
'big')
Assumes bytes are 8 bits.
This is a special-case version of str... | def bytes_to_number(b, endian='big'):
"""
Convert a string to an integer.
:param b:
String or bytearray to convert.
:param endian:
Byte order to convert into ('big' or 'little' endian-ness, default
'big')
Assumes bytes are 8 bits.
This is a special-case version of str... | [
"Convert",
"a",
"string",
"to",
"an",
"integer",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L115-L149 | [
"def",
"bytes_to_number",
"(",
"b",
",",
"endian",
"=",
"'big'",
")",
":",
"if",
"endian",
"==",
"'big'",
":",
"b",
"=",
"reversed",
"(",
"b",
")",
"n",
"=",
"0",
"for",
"i",
",",
"ch",
"in",
"enumerate",
"(",
"bytearray",
"(",
"b",
")",
")",
"... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | number_to_bytes | Convert an integer to a corresponding string of bytes..
:param n:
Integer to convert.
:param endian:
Byte order to convert into ('big' or 'little' endian-ness, default
'big')
Assumes bytes are 8 bits.
This is a special-case version of number_to_string with a full base-256
... | unstdlib/standard/string_.py | def number_to_bytes(n, endian='big'):
"""
Convert an integer to a corresponding string of bytes..
:param n:
Integer to convert.
:param endian:
Byte order to convert into ('big' or 'little' endian-ness, default
'big')
Assumes bytes are 8 bits.
This is a special-case ve... | def number_to_bytes(n, endian='big'):
"""
Convert an integer to a corresponding string of bytes..
:param n:
Integer to convert.
:param endian:
Byte order to convert into ('big' or 'little' endian-ness, default
'big')
Assumes bytes are 8 bits.
This is a special-case ve... | [
"Convert",
"an",
"integer",
"to",
"a",
"corresponding",
"string",
"of",
"bytes",
".."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L152-L193 | [
"def",
"number_to_bytes",
"(",
"n",
",",
"endian",
"=",
"'big'",
")",
":",
"res",
"=",
"[",
"]",
"while",
"n",
":",
"n",
",",
"ch",
"=",
"divmod",
"(",
"n",
",",
"256",
")",
"if",
"PY3",
":",
"res",
".",
"append",
"(",
"ch",
")",
"else",
":",... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | to_str | r"""
Returns a ``str`` of ``obj``, encoding using ``encoding`` if necessary. For
example::
>>> some_str = b"\xff"
>>> some_unicode = u"\u1234"
>>> some_exception = Exception(u'Error: ' + some_unicode)
>>> r(to_str(some_str))
b'\xff'
>>> r(to_str(some_unicode))
... | unstdlib/standard/string_.py | def to_str(obj, encoding='utf-8', **encode_args):
r"""
Returns a ``str`` of ``obj``, encoding using ``encoding`` if necessary. For
example::
>>> some_str = b"\xff"
>>> some_unicode = u"\u1234"
>>> some_exception = Exception(u'Error: ' + some_unicode)
>>> r(to_str(some_str))
... | def to_str(obj, encoding='utf-8', **encode_args):
r"""
Returns a ``str`` of ``obj``, encoding using ``encoding`` if necessary. For
example::
>>> some_str = b"\xff"
>>> some_unicode = u"\u1234"
>>> some_exception = Exception(u'Error: ' + some_unicode)
>>> r(to_str(some_str))
... | [
"r",
"Returns",
"a",
"str",
"of",
"obj",
"encoding",
"using",
"encoding",
"if",
"necessary",
".",
"For",
"example",
"::"
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L196-L227 | [
"def",
"to_str",
"(",
"obj",
",",
"encoding",
"=",
"'utf-8'",
",",
"*",
"*",
"encode_args",
")",
":",
"# Note: On py3, ``b'x'.__str__()`` returns ``\"b'x'\"``, so we need to do the",
"# explicit check first.",
"if",
"isinstance",
"(",
"obj",
",",
"binary_type",
")",
":"... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | to_unicode | r"""
Returns a ``unicode`` of ``obj``, decoding using ``encoding`` if necessary.
If decoding fails, the ``fallback`` encoding (default ``latin1``) is used.
Examples::
>>> r(to_unicode(b'\xe1\x88\xb4'))
u'\u1234'
>>> r(to_unicode(b'\xff'))
u'\xff'
>>> r(to_unicode(u'... | unstdlib/standard/string_.py | def to_unicode(obj, encoding='utf-8', fallback='latin1', **decode_args):
r"""
Returns a ``unicode`` of ``obj``, decoding using ``encoding`` if necessary.
If decoding fails, the ``fallback`` encoding (default ``latin1``) is used.
Examples::
>>> r(to_unicode(b'\xe1\x88\xb4'))
u'\u1234'
... | def to_unicode(obj, encoding='utf-8', fallback='latin1', **decode_args):
r"""
Returns a ``unicode`` of ``obj``, decoding using ``encoding`` if necessary.
If decoding fails, the ``fallback`` encoding (default ``latin1``) is used.
Examples::
>>> r(to_unicode(b'\xe1\x88\xb4'))
u'\u1234'
... | [
"r",
"Returns",
"a",
"unicode",
"of",
"obj",
"decoding",
"using",
"encoding",
"if",
"necessary",
".",
"If",
"decoding",
"fails",
"the",
"fallback",
"encoding",
"(",
"default",
"latin1",
")",
"is",
"used",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L230-L264 | [
"def",
"to_unicode",
"(",
"obj",
",",
"encoding",
"=",
"'utf-8'",
",",
"fallback",
"=",
"'latin1'",
",",
"*",
"*",
"decode_args",
")",
":",
"# Note: on py3, the `bytes` type defines an unhelpful \"__str__\" function,",
"# so we need to do this check (see comments in ``to_str``)... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | to_float | Return input converted into a float. If failed, then return ``default``.
Note that, by default, ``allow_nan=False``, so ``to_float`` will not return
``nan``, ``inf``, or ``-inf``.
Examples::
>>> to_float('1.5')
1.5
>>> to_float(1)
1.0
>>> to_float('')
0.0
... | unstdlib/standard/string_.py | def to_float(s, default=0.0, allow_nan=False):
"""
Return input converted into a float. If failed, then return ``default``.
Note that, by default, ``allow_nan=False``, so ``to_float`` will not return
``nan``, ``inf``, or ``-inf``.
Examples::
>>> to_float('1.5')
1.5
>>> to_... | def to_float(s, default=0.0, allow_nan=False):
"""
Return input converted into a float. If failed, then return ``default``.
Note that, by default, ``allow_nan=False``, so ``to_float`` will not return
``nan``, ``inf``, or ``-inf``.
Examples::
>>> to_float('1.5')
1.5
>>> to_... | [
"Return",
"input",
"converted",
"into",
"a",
"float",
".",
"If",
"failed",
"then",
"return",
"default",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L294-L329 | [
"def",
"to_float",
"(",
"s",
",",
"default",
"=",
"0.0",
",",
"allow_nan",
"=",
"False",
")",
":",
"try",
":",
"f",
"=",
"float",
"(",
"s",
")",
"except",
"(",
"TypeError",
",",
"ValueError",
")",
":",
"return",
"default",
"if",
"not",
"allow_nan",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | format_int | Return `singular.format(n)` if n is 1, or `plural.format(n)` otherwise. If
plural is not specified, then it is assumed to be same as singular but
suffixed with an 's'.
:param n:
Integer which determines pluralness.
:param singular:
String with a format() placeholder for n. (Default: `u... | unstdlib/standard/string_.py | def format_int(n, singular=_Default, plural=_Default):
"""
Return `singular.format(n)` if n is 1, or `plural.format(n)` otherwise. If
plural is not specified, then it is assumed to be same as singular but
suffixed with an 's'.
:param n:
Integer which determines pluralness.
:param singu... | def format_int(n, singular=_Default, plural=_Default):
"""
Return `singular.format(n)` if n is 1, or `plural.format(n)` otherwise. If
plural is not specified, then it is assumed to be same as singular but
suffixed with an 's'.
:param n:
Integer which determines pluralness.
:param singu... | [
"Return",
"singular",
".",
"format",
"(",
"n",
")",
"if",
"n",
"is",
"1",
"or",
"plural",
".",
"format",
"(",
"n",
")",
"otherwise",
".",
"If",
"plural",
"is",
"not",
"specified",
"then",
"it",
"is",
"assumed",
"to",
"be",
"same",
"as",
"singular",
... | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L332-L375 | [
"def",
"format_int",
"(",
"n",
",",
"singular",
"=",
"_Default",
",",
"plural",
"=",
"_Default",
")",
":",
"n",
"=",
"int",
"(",
"n",
")",
"if",
"singular",
"in",
"(",
"None",
",",
"_Default",
")",
":",
"if",
"plural",
"is",
"_Default",
":",
"plura... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | dollars_to_cents | Given a string or integer representing dollars, return an integer of
equivalent cents, in an input-resilient way.
This works by stripping any non-numeric characters before attempting to
cast the value.
Examples::
>>> dollars_to_cents('$1')
100
>>> dollars_to_cents('1')
... | unstdlib/standard/string_.py | def dollars_to_cents(s, allow_negative=False):
"""
Given a string or integer representing dollars, return an integer of
equivalent cents, in an input-resilient way.
This works by stripping any non-numeric characters before attempting to
cast the value.
Examples::
>>> dollars_to_ce... | def dollars_to_cents(s, allow_negative=False):
"""
Given a string or integer representing dollars, return an integer of
equivalent cents, in an input-resilient way.
This works by stripping any non-numeric characters before attempting to
cast the value.
Examples::
>>> dollars_to_ce... | [
"Given",
"a",
"string",
"or",
"integer",
"representing",
"dollars",
"return",
"an",
"integer",
"of",
"equivalent",
"cents",
"in",
"an",
"input",
"-",
"resilient",
"way",
".",
"This",
"works",
"by",
"stripping",
"any",
"non",
"-",
"numeric",
"characters",
"be... | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L381-L415 | [
"def",
"dollars_to_cents",
"(",
"s",
",",
"allow_negative",
"=",
"False",
")",
":",
"# TODO: Implement cents_to_dollars",
"if",
"not",
"s",
":",
"return",
"if",
"isinstance",
"(",
"s",
",",
"string_types",
")",
":",
"s",
"=",
"''",
".",
"join",
"(",
"RE_NU... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | slugify | Normalize `s` into ASCII and replace non-word characters with `delimiter`. | unstdlib/standard/string_.py | def slugify(s, delimiter='-'):
"""
Normalize `s` into ASCII and replace non-word characters with `delimiter`.
"""
s = unicodedata.normalize('NFKD', to_unicode(s)).encode('ascii', 'ignore').decode('ascii')
return RE_SLUG.sub(delimiter, s).strip(delimiter).lower() | def slugify(s, delimiter='-'):
"""
Normalize `s` into ASCII and replace non-word characters with `delimiter`.
"""
s = unicodedata.normalize('NFKD', to_unicode(s)).encode('ascii', 'ignore').decode('ascii')
return RE_SLUG.sub(delimiter, s).strip(delimiter).lower() | [
"Normalize",
"s",
"into",
"ASCII",
"and",
"replace",
"non",
"-",
"word",
"characters",
"with",
"delimiter",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L420-L425 | [
"def",
"slugify",
"(",
"s",
",",
"delimiter",
"=",
"'-'",
")",
":",
"s",
"=",
"unicodedata",
".",
"normalize",
"(",
"'NFKD'",
",",
"to_unicode",
"(",
"s",
")",
")",
".",
"encode",
"(",
"'ascii'",
",",
"'ignore'",
")",
".",
"decode",
"(",
"'ascii'",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | get_cache_buster | Return a string that can be used as a parameter for cache-busting URLs
for this asset.
:param src_path:
Filesystem path to the file we're generating a cache-busting value for.
:param method:
Method for cache-busting. Supported values: importtime, mtime, md5
The default is 'importti... | unstdlib/html.py | def get_cache_buster(src_path, method='importtime'):
""" Return a string that can be used as a parameter for cache-busting URLs
for this asset.
:param src_path:
Filesystem path to the file we're generating a cache-busting value for.
:param method:
Method for cache-busting. Supported va... | def get_cache_buster(src_path, method='importtime'):
""" Return a string that can be used as a parameter for cache-busting URLs
for this asset.
:param src_path:
Filesystem path to the file we're generating a cache-busting value for.
:param method:
Method for cache-busting. Supported va... | [
"Return",
"a",
"string",
"that",
"can",
"be",
"used",
"as",
"a",
"parameter",
"for",
"cache",
"-",
"busting",
"URLs",
"for",
"this",
"asset",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/html.py#L46-L75 | [
"def",
"get_cache_buster",
"(",
"src_path",
",",
"method",
"=",
"'importtime'",
")",
":",
"try",
":",
"fn",
"=",
"_BUST_METHODS",
"[",
"method",
"]",
"except",
"KeyError",
":",
"raise",
"KeyError",
"(",
"'Unsupported busting method value: %s'",
"%",
"method",
")... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | _generate_dom_attrs | Yield compiled DOM attribute key-value strings.
If the value is `True`, then it is treated as no-value. If `None`, then it
is skipped. | unstdlib/html.py | def _generate_dom_attrs(attrs, allow_no_value=True):
""" Yield compiled DOM attribute key-value strings.
If the value is `True`, then it is treated as no-value. If `None`, then it
is skipped.
"""
for attr in iterate_items(attrs):
if isinstance(attr, basestring):
attr = (attr, Tr... | def _generate_dom_attrs(attrs, allow_no_value=True):
""" Yield compiled DOM attribute key-value strings.
If the value is `True`, then it is treated as no-value. If `None`, then it
is skipped.
"""
for attr in iterate_items(attrs):
if isinstance(attr, basestring):
attr = (attr, Tr... | [
"Yield",
"compiled",
"DOM",
"attribute",
"key",
"-",
"value",
"strings",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/html.py#L78-L95 | [
"def",
"_generate_dom_attrs",
"(",
"attrs",
",",
"allow_no_value",
"=",
"True",
")",
":",
"for",
"attr",
"in",
"iterate_items",
"(",
"attrs",
")",
":",
"if",
"isinstance",
"(",
"attr",
",",
"basestring",
")",
":",
"attr",
"=",
"(",
"attr",
",",
"True",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | tag | Helper for programmatically building HTML tags.
Note that this barely does any escaping, and will happily spit out
dangerous user input if used as such.
:param tagname:
Tag name of the DOM element we want to return.
:param content:
Optional content of the DOM element. If `None`, then ... | unstdlib/html.py | def tag(tagname, content='', attrs=None):
""" Helper for programmatically building HTML tags.
Note that this barely does any escaping, and will happily spit out
dangerous user input if used as such.
:param tagname:
Tag name of the DOM element we want to return.
:param content:
Opt... | def tag(tagname, content='', attrs=None):
""" Helper for programmatically building HTML tags.
Note that this barely does any escaping, and will happily spit out
dangerous user input if used as such.
:param tagname:
Tag name of the DOM element we want to return.
:param content:
Opt... | [
"Helper",
"for",
"programmatically",
"building",
"HTML",
"tags",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/html.py#L107-L146 | [
"def",
"tag",
"(",
"tagname",
",",
"content",
"=",
"''",
",",
"attrs",
"=",
"None",
")",
":",
"attrs_str",
"=",
"attrs",
"and",
"' '",
".",
"join",
"(",
"_generate_dom_attrs",
"(",
"attrs",
")",
")",
"open_tag",
"=",
"tagname",
"if",
"attrs_str",
":",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | javascript_link | Helper for programmatically building HTML JavaScript source include
links, with optional cache busting.
:param src_url:
Goes into the `src` attribute of the `<script src="...">` tag.
:param src_path:
Optional filesystem path to the source file, used when `cache_bust` is
enabled.
... | unstdlib/html.py | def javascript_link(src_url, src_path=None, cache_bust=None, content='', extra_attrs=None):
""" Helper for programmatically building HTML JavaScript source include
links, with optional cache busting.
:param src_url:
Goes into the `src` attribute of the `<script src="...">` tag.
:param src_path... | def javascript_link(src_url, src_path=None, cache_bust=None, content='', extra_attrs=None):
""" Helper for programmatically building HTML JavaScript source include
links, with optional cache busting.
:param src_url:
Goes into the `src` attribute of the `<script src="...">` tag.
:param src_path... | [
"Helper",
"for",
"programmatically",
"building",
"HTML",
"JavaScript",
"source",
"include",
"links",
"with",
"optional",
"cache",
"busting",
"."
] | shazow/unstdlib.py | python | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/html.py#L164-L202 | [
"def",
"javascript_link",
"(",
"src_url",
",",
"src_path",
"=",
"None",
",",
"cache_bust",
"=",
"None",
",",
"content",
"=",
"''",
",",
"extra_attrs",
"=",
"None",
")",
":",
"if",
"cache_bust",
":",
"append_suffix",
"=",
"get_cache_buster",
"(",
"src_path",
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 |
train | package_meta | Read __init__.py for global package metadata.
Do this without importing the package. | setup.py | def package_meta():
"""Read __init__.py for global package metadata.
Do this without importing the package.
"""
_version_re = re.compile(r'__version__\s+=\s+(.*)')
_url_re = re.compile(r'__url__\s+=\s+(.*)')
_license_re = re.compile(r'__license__\s+=\s+(.*)')
with open('lambda_uploader/__in... | def package_meta():
"""Read __init__.py for global package metadata.
Do this without importing the package.
"""
_version_re = re.compile(r'__version__\s+=\s+(.*)')
_url_re = re.compile(r'__url__\s+=\s+(.*)')
_license_re = re.compile(r'__license__\s+=\s+(.*)')
with open('lambda_uploader/__in... | [
"Read",
"__init__",
".",
"py",
"for",
"global",
"package",
"metadata",
".",
"Do",
"this",
"without",
"importing",
"the",
"package",
"."
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/setup.py#L37-L57 | [
"def",
"package_meta",
"(",
")",
":",
"_version_re",
"=",
"re",
".",
"compile",
"(",
"r'__version__\\s+=\\s+(.*)'",
")",
"_url_re",
"=",
"re",
".",
"compile",
"(",
"r'__url__\\s+=\\s+(.*)'",
")",
"_license_re",
"=",
"re",
".",
"compile",
"(",
"r'__license__\\s+=... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | create_subscriptions | Adds supported subscriptions | lambda_uploader/subscribers.py | def create_subscriptions(config, profile_name):
''' Adds supported subscriptions '''
if 'kinesis' in config.subscription.keys():
data = config.subscription['kinesis']
function_name = config.name
stream_name = data['stream']
batch_size = data['batch_size']
starting_positio... | def create_subscriptions(config, profile_name):
''' Adds supported subscriptions '''
if 'kinesis' in config.subscription.keys():
data = config.subscription['kinesis']
function_name = config.name
stream_name = data['stream']
batch_size = data['batch_size']
starting_positio... | [
"Adds",
"supported",
"subscriptions"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/subscribers.py#L77-L93 | [
"def",
"create_subscriptions",
"(",
"config",
",",
"profile_name",
")",
":",
"if",
"'kinesis'",
"in",
"config",
".",
"subscription",
".",
"keys",
"(",
")",
":",
"data",
"=",
"config",
".",
"subscription",
"[",
"'kinesis'",
"]",
"function_name",
"=",
"config"... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | KinesisSubscriber.subscribe | Subscribes the lambda to the Kinesis stream | lambda_uploader/subscribers.py | def subscribe(self):
''' Subscribes the lambda to the Kinesis stream '''
try:
LOG.debug('Creating Kinesis subscription')
if self.starting_position_ts:
self._lambda_client \
.create_event_source_mapping(
EventSourceArn=se... | def subscribe(self):
''' Subscribes the lambda to the Kinesis stream '''
try:
LOG.debug('Creating Kinesis subscription')
if self.starting_position_ts:
self._lambda_client \
.create_event_source_mapping(
EventSourceArn=se... | [
"Subscribes",
"the",
"lambda",
"to",
"the",
"Kinesis",
"stream"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/subscribers.py#L37-L74 | [
"def",
"subscribe",
"(",
"self",
")",
":",
"try",
":",
"LOG",
".",
"debug",
"(",
"'Creating Kinesis subscription'",
")",
"if",
"self",
".",
"starting_position_ts",
":",
"self",
".",
"_lambda_client",
".",
"create_event_source_mapping",
"(",
"EventSourceArn",
"=",
... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | PackageUploader._format_vpc_config | Returns {} if the VPC config is set to None by Config,
returns the formatted config otherwise | lambda_uploader/uploader.py | def _format_vpc_config(self):
'''
Returns {} if the VPC config is set to None by Config,
returns the formatted config otherwise
'''
if self._config.raw['vpc']:
return {
'SubnetIds': self._config.raw['vpc']['subnets'],
'SecurityGroupIds'... | def _format_vpc_config(self):
'''
Returns {} if the VPC config is set to None by Config,
returns the formatted config otherwise
'''
if self._config.raw['vpc']:
return {
'SubnetIds': self._config.raw['vpc']['subnets'],
'SecurityGroupIds'... | [
"Returns",
"{}",
"if",
"the",
"VPC",
"config",
"is",
"set",
"to",
"None",
"by",
"Config",
"returns",
"the",
"formatted",
"config",
"otherwise"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/uploader.py#L203-L217 | [
"def",
"_format_vpc_config",
"(",
"self",
")",
":",
"if",
"self",
".",
"_config",
".",
"raw",
"[",
"'vpc'",
"]",
":",
"return",
"{",
"'SubnetIds'",
":",
"self",
".",
"_config",
".",
"raw",
"[",
"'vpc'",
"]",
"[",
"'subnets'",
"]",
",",
"'SecurityGroupI... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | PackageUploader._upload_s3 | Uploads the lambda package to s3 | lambda_uploader/uploader.py | def _upload_s3(self, zip_file):
'''
Uploads the lambda package to s3
'''
s3_client = self._aws_session.client('s3')
transfer = boto3.s3.transfer.S3Transfer(s3_client)
transfer.upload_file(zip_file, self._config.s3_bucket,
self._config.s3_packa... | def _upload_s3(self, zip_file):
'''
Uploads the lambda package to s3
'''
s3_client = self._aws_session.client('s3')
transfer = boto3.s3.transfer.S3Transfer(s3_client)
transfer.upload_file(zip_file, self._config.s3_bucket,
self._config.s3_packa... | [
"Uploads",
"the",
"lambda",
"package",
"to",
"s3"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/uploader.py#L219-L226 | [
"def",
"_upload_s3",
"(",
"self",
",",
"zip_file",
")",
":",
"s3_client",
"=",
"self",
".",
"_aws_session",
".",
"client",
"(",
"'s3'",
")",
"transfer",
"=",
"boto3",
".",
"s3",
".",
"transfer",
".",
"S3Transfer",
"(",
"s3_client",
")",
"transfer",
".",
... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | main | lambda-uploader command line interface. | lambda_uploader/shell.py | def main(arv=None):
"""lambda-uploader command line interface."""
# Check for Python 2.7 or later
if sys.version_info[0] < 3 and not sys.version_info[1] == 7:
raise RuntimeError('lambda-uploader requires Python 2.7 or later')
import argparse
parser = argparse.ArgumentParser(
de... | def main(arv=None):
"""lambda-uploader command line interface."""
# Check for Python 2.7 or later
if sys.version_info[0] < 3 and not sys.version_info[1] == 7:
raise RuntimeError('lambda-uploader requires Python 2.7 or later')
import argparse
parser = argparse.ArgumentParser(
de... | [
"lambda",
"-",
"uploader",
"command",
"line",
"interface",
"."
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/shell.py#L117-L203 | [
"def",
"main",
"(",
"arv",
"=",
"None",
")",
":",
"# Check for Python 2.7 or later",
"if",
"sys",
".",
"version_info",
"[",
"0",
"]",
"<",
"3",
"and",
"not",
"sys",
".",
"version_info",
"[",
"1",
"]",
"==",
"7",
":",
"raise",
"RuntimeError",
"(",
"'lam... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | build_package | Builds the zip file and creates the package with it | lambda_uploader/package.py | def build_package(path, requires, virtualenv=None, ignore=None,
extra_files=None, zipfile_name=ZIPFILE_NAME,
pyexec=None):
'''Builds the zip file and creates the package with it'''
pkg = Package(path, zipfile_name, pyexec)
if extra_files:
for fil in extra_files:
... | def build_package(path, requires, virtualenv=None, ignore=None,
extra_files=None, zipfile_name=ZIPFILE_NAME,
pyexec=None):
'''Builds the zip file and creates the package with it'''
pkg = Package(path, zipfile_name, pyexec)
if extra_files:
for fil in extra_files:
... | [
"Builds",
"the",
"zip",
"file",
"and",
"creates",
"the",
"package",
"with",
"it"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L39-L53 | [
"def",
"build_package",
"(",
"path",
",",
"requires",
",",
"virtualenv",
"=",
"None",
",",
"ignore",
"=",
"None",
",",
"extra_files",
"=",
"None",
",",
"zipfile_name",
"=",
"ZIPFILE_NAME",
",",
"pyexec",
"=",
"None",
")",
":",
"pkg",
"=",
"Package",
"(",... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.build | Calls all necessary methods to build the Lambda Package | lambda_uploader/package.py | def build(self, ignore=None):
'''Calls all necessary methods to build the Lambda Package'''
self._prepare_workspace()
self.install_dependencies()
self.package(ignore) | def build(self, ignore=None):
'''Calls all necessary methods to build the Lambda Package'''
self._prepare_workspace()
self.install_dependencies()
self.package(ignore) | [
"Calls",
"all",
"necessary",
"methods",
"to",
"build",
"the",
"Lambda",
"Package"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L76-L80 | [
"def",
"build",
"(",
"self",
",",
"ignore",
"=",
"None",
")",
":",
"self",
".",
"_prepare_workspace",
"(",
")",
"self",
".",
"install_dependencies",
"(",
")",
"self",
".",
"package",
"(",
"ignore",
")"
] | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.clean_workspace | Clean up the temporary workspace if one exists | lambda_uploader/package.py | def clean_workspace(self):
'''Clean up the temporary workspace if one exists'''
if os.path.isdir(self._temp_workspace):
shutil.rmtree(self._temp_workspace) | def clean_workspace(self):
'''Clean up the temporary workspace if one exists'''
if os.path.isdir(self._temp_workspace):
shutil.rmtree(self._temp_workspace) | [
"Clean",
"up",
"the",
"temporary",
"workspace",
"if",
"one",
"exists"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L82-L85 | [
"def",
"clean_workspace",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"isdir",
"(",
"self",
".",
"_temp_workspace",
")",
":",
"shutil",
".",
"rmtree",
"(",
"self",
".",
"_temp_workspace",
")"
] | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.clean_zipfile | remove existing zipfile | lambda_uploader/package.py | def clean_zipfile(self):
'''remove existing zipfile'''
if os.path.isfile(self.zip_file):
os.remove(self.zip_file) | def clean_zipfile(self):
'''remove existing zipfile'''
if os.path.isfile(self.zip_file):
os.remove(self.zip_file) | [
"remove",
"existing",
"zipfile"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L87-L90 | [
"def",
"clean_zipfile",
"(",
"self",
")",
":",
"if",
"os",
".",
"path",
".",
"isfile",
"(",
"self",
".",
"zip_file",
")",
":",
"os",
".",
"remove",
"(",
"self",
".",
"zip_file",
")"
] | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.requirements | Sets the requirements for the package.
It will take either a valid path to a requirements file or
a list of requirements. | lambda_uploader/package.py | def requirements(self, requires):
'''
Sets the requirements for the package.
It will take either a valid path to a requirements file or
a list of requirements.
'''
if requires:
if isinstance(requires, basestring) and \
os.path.isfile(os.path.ab... | def requirements(self, requires):
'''
Sets the requirements for the package.
It will take either a valid path to a requirements file or
a list of requirements.
'''
if requires:
if isinstance(requires, basestring) and \
os.path.isfile(os.path.ab... | [
"Sets",
"the",
"requirements",
"for",
"the",
"package",
"."
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L92-L112 | [
"def",
"requirements",
"(",
"self",
",",
"requires",
")",
":",
"if",
"requires",
":",
"if",
"isinstance",
"(",
"requires",
",",
"basestring",
")",
"and",
"os",
".",
"path",
".",
"isfile",
"(",
"os",
".",
"path",
".",
"abspath",
"(",
"requires",
")",
... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.virtualenv | Sets the virtual environment for the lambda package
If this is not set then package_dependencies will create a new one.
Takes a path to a virtualenv or a boolean if the virtualenv creation
should be skipped. | lambda_uploader/package.py | def virtualenv(self, virtualenv):
'''
Sets the virtual environment for the lambda package
If this is not set then package_dependencies will create a new one.
Takes a path to a virtualenv or a boolean if the virtualenv creation
should be skipped.
'''
# If a boole... | def virtualenv(self, virtualenv):
'''
Sets the virtual environment for the lambda package
If this is not set then package_dependencies will create a new one.
Takes a path to a virtualenv or a boolean if the virtualenv creation
should be skipped.
'''
# If a boole... | [
"Sets",
"the",
"virtual",
"environment",
"for",
"the",
"lambda",
"package"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L114-L133 | [
"def",
"virtualenv",
"(",
"self",
",",
"virtualenv",
")",
":",
"# If a boolean is passed then set the internal _skip_virtualenv flag",
"if",
"isinstance",
"(",
"virtualenv",
",",
"bool",
")",
":",
"self",
".",
"_skip_virtualenv",
"=",
"virtualenv",
"else",
":",
"self"... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.install_dependencies | Creates a virtualenv and installs requirements | lambda_uploader/package.py | def install_dependencies(self):
''' Creates a virtualenv and installs requirements '''
# If virtualenv is set to skip then do nothing
if self._skip_virtualenv:
LOG.info('Skip Virtualenv set ... nothing to do')
return
has_reqs = _isfile(self._requirements_file) or... | def install_dependencies(self):
''' Creates a virtualenv and installs requirements '''
# If virtualenv is set to skip then do nothing
if self._skip_virtualenv:
LOG.info('Skip Virtualenv set ... nothing to do')
return
has_reqs = _isfile(self._requirements_file) or... | [
"Creates",
"a",
"virtualenv",
"and",
"installs",
"requirements"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L141-L157 | [
"def",
"install_dependencies",
"(",
"self",
")",
":",
"# If virtualenv is set to skip then do nothing",
"if",
"self",
".",
"_skip_virtualenv",
":",
"LOG",
".",
"info",
"(",
"'Skip Virtualenv set ... nothing to do'",
")",
"return",
"has_reqs",
"=",
"_isfile",
"(",
"self"... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package._build_new_virtualenv | Build a new virtualenvironment if self._virtualenv is set to None | lambda_uploader/package.py | def _build_new_virtualenv(self):
'''Build a new virtualenvironment if self._virtualenv is set to None'''
if self._virtualenv is None:
# virtualenv was "None" which means "do default"
self._pkg_venv = os.path.join(self._temp_workspace, 'venv')
self._venv_pip = 'bin/pip... | def _build_new_virtualenv(self):
'''Build a new virtualenvironment if self._virtualenv is set to None'''
if self._virtualenv is None:
# virtualenv was "None" which means "do default"
self._pkg_venv = os.path.join(self._temp_workspace, 'venv')
self._venv_pip = 'bin/pip... | [
"Build",
"a",
"new",
"virtualenvironment",
"if",
"self",
".",
"_virtualenv",
"is",
"set",
"to",
"None"
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L168-L189 | [
"def",
"_build_new_virtualenv",
"(",
"self",
")",
":",
"if",
"self",
".",
"_virtualenv",
"is",
"None",
":",
"# virtualenv was \"None\" which means \"do default\"",
"self",
".",
"_pkg_venv",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_temp_workspace",
... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package._install_requirements | Create a new virtualenvironment and install requirements
if there are any. | lambda_uploader/package.py | def _install_requirements(self):
'''
Create a new virtualenvironment and install requirements
if there are any.
'''
if not hasattr(self, '_pkg_venv'):
err = 'Must call build_new_virtualenv before install_requirements'
raise Exception(err)
cmd = No... | def _install_requirements(self):
'''
Create a new virtualenvironment and install requirements
if there are any.
'''
if not hasattr(self, '_pkg_venv'):
err = 'Must call build_new_virtualenv before install_requirements'
raise Exception(err)
cmd = No... | [
"Create",
"a",
"new",
"virtualenvironment",
"and",
"install",
"requirements",
"if",
"there",
"are",
"any",
"."
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L207-L237 | [
"def",
"_install_requirements",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"'_pkg_venv'",
")",
":",
"err",
"=",
"'Must call build_new_virtualenv before install_requirements'",
"raise",
"Exception",
"(",
"err",
")",
"cmd",
"=",
"None",
"if",
... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | Package.package | Create a zip file of the lambda script and its dependencies.
:param list ignore: a list of regular expression strings to match paths
of files in the source of the lambda script against and ignore
those files when creating the zip file. The paths to be matched are
local to th... | lambda_uploader/package.py | def package(self, ignore=None):
"""
Create a zip file of the lambda script and its dependencies.
:param list ignore: a list of regular expression strings to match paths
of files in the source of the lambda script against and ignore
those files when creating the zip file.... | def package(self, ignore=None):
"""
Create a zip file of the lambda script and its dependencies.
:param list ignore: a list of regular expression strings to match paths
of files in the source of the lambda script against and ignore
those files when creating the zip file.... | [
"Create",
"a",
"zip",
"file",
"of",
"the",
"lambda",
"script",
"and",
"its",
"dependencies",
"."
] | rackerlabs/lambda-uploader | python | https://github.com/rackerlabs/lambda-uploader/blob/a5036e60d45d1a4fdc07df071f5b6e3b113388d4/lambda_uploader/package.py#L239-L294 | [
"def",
"package",
"(",
"self",
",",
"ignore",
"=",
"None",
")",
":",
"ignore",
"=",
"ignore",
"or",
"[",
"]",
"package",
"=",
"os",
".",
"path",
".",
"join",
"(",
"self",
".",
"_temp_workspace",
",",
"'lambda_package'",
")",
"# Copy site packages into pack... | a5036e60d45d1a4fdc07df071f5b6e3b113388d4 |
train | encode_properties | Performs encoding of url parameters from dictionary to a string. It does
not escape backslash because it is not needed.
See: http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-SetItemProperties | artifactory.py | def encode_properties(parameters):
"""
Performs encoding of url parameters from dictionary to a string. It does
not escape backslash because it is not needed.
See: http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-SetItemProperties
"""
result = []
for para... | def encode_properties(parameters):
"""
Performs encoding of url parameters from dictionary to a string. It does
not escape backslash because it is not needed.
See: http://www.jfrog.com/confluence/display/RTF/Artifactory+REST+API#ArtifactoryRESTAPI-SetItemProperties
"""
result = []
for para... | [
"Performs",
"encoding",
"of",
"url",
"parameters",
"from",
"dictionary",
"to",
"a",
"string",
".",
"It",
"does",
"not",
"escape",
"backslash",
"because",
"it",
"is",
"not",
"needed",
"."
] | Parallels/artifactory | python | https://github.com/Parallels/artifactory/blob/09ddcc4ae15095eec2347d39774c3f8aca6c4654/artifactory.py#L271-L288 | [
"def",
"encode_properties",
"(",
"parameters",
")",
":",
"result",
"=",
"[",
"]",
"for",
"param",
"in",
"iter",
"(",
"sorted",
"(",
"parameters",
")",
")",
":",
"if",
"isinstance",
"(",
"parameters",
"[",
"param",
"]",
",",
"(",
"list",
",",
"tuple",
... | 09ddcc4ae15095eec2347d39774c3f8aca6c4654 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.