repo stringlengths 7 55 | path stringlengths 4 223 | func_name stringlengths 1 134 | original_string stringlengths 75 104k | language stringclasses 1
value | code stringlengths 75 104k | code_tokens listlengths 19 28.4k | docstring stringlengths 1 46.9k | docstring_tokens listlengths 1 1.97k | sha stringlengths 40 40 | url stringlengths 87 315 | partition stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI._save_token_on_disk | def _save_token_on_disk(self):
"""Helper function that saves the token on disk"""
token = self._token.copy()
# Client secret is needed for token refreshing and isn't returned
# as a pared of OAuth token by default
token.update(client_secret=self._client_secret)
with cod... | python | def _save_token_on_disk(self):
"""Helper function that saves the token on disk"""
token = self._token.copy()
# Client secret is needed for token refreshing and isn't returned
# as a pared of OAuth token by default
token.update(client_secret=self._client_secret)
with cod... | [
"def",
"_save_token_on_disk",
"(",
"self",
")",
":",
"token",
"=",
"self",
".",
"_token",
".",
"copy",
"(",
")",
"# Client secret is needed for token refreshing and isn't returned",
"# as a pared of OAuth token by default",
"token",
".",
"update",
"(",
"client_secret",
"=... | Helper function that saves the token on disk | [
"Helper",
"function",
"that",
"saves",
"the",
"token",
"on",
"disk"
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L119-L133 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI._get_oauth_token | def _get_oauth_token(self):
"""
Get Monzo access token via OAuth2 `authorization code` grant type.
Official docs:
https://monzo.com/docs/#acquire-an-access-token
:returns: OAuth 2 access token
:rtype: dict
"""
url = urljoin(self.api_url, '/oauth2/tok... | python | def _get_oauth_token(self):
"""
Get Monzo access token via OAuth2 `authorization code` grant type.
Official docs:
https://monzo.com/docs/#acquire-an-access-token
:returns: OAuth 2 access token
:rtype: dict
"""
url = urljoin(self.api_url, '/oauth2/tok... | [
"def",
"_get_oauth_token",
"(",
"self",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"api_url",
",",
"'/oauth2/token'",
")",
"oauth",
"=",
"OAuth2Session",
"(",
"client_id",
"=",
"self",
".",
"_client_id",
",",
"redirect_uri",
"=",
"config",
".",
"RE... | Get Monzo access token via OAuth2 `authorization code` grant type.
Official docs:
https://monzo.com/docs/#acquire-an-access-token
:returns: OAuth 2 access token
:rtype: dict | [
"Get",
"Monzo",
"access",
"token",
"via",
"OAuth2",
"authorization",
"code",
"grant",
"type",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L135-L158 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI._refresh_oath_token | def _refresh_oath_token(self):
"""
Refresh Monzo OAuth 2 token.
Official docs:
https://monzo.com/docs/#refreshing-access
:raises UnableToRefreshTokenException: when token couldn't be refreshed
"""
url = urljoin(self.api_url, '/oauth2/token')
data = {... | python | def _refresh_oath_token(self):
"""
Refresh Monzo OAuth 2 token.
Official docs:
https://monzo.com/docs/#refreshing-access
:raises UnableToRefreshTokenException: when token couldn't be refreshed
"""
url = urljoin(self.api_url, '/oauth2/token')
data = {... | [
"def",
"_refresh_oath_token",
"(",
"self",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"api_url",
",",
"'/oauth2/token'",
")",
"data",
"=",
"{",
"'grant_type'",
":",
"'refresh_token'",
",",
"'client_id'",
":",
"self",
".",
"_client_id",
",",
"'client_... | Refresh Monzo OAuth 2 token.
Official docs:
https://monzo.com/docs/#refreshing-access
:raises UnableToRefreshTokenException: when token couldn't be refreshed | [
"Refresh",
"Monzo",
"OAuth",
"2",
"token",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L160-L187 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI._get_response | def _get_response(self, method, endpoint, params=None):
"""
Helper method to handle HTTP requests and catch API errors
:param method: valid HTTP method
:type method: str
:param endpoint: API endpoint
:type endpoint: str
:param params: extra parameters passed with... | python | def _get_response(self, method, endpoint, params=None):
"""
Helper method to handle HTTP requests and catch API errors
:param method: valid HTTP method
:type method: str
:param endpoint: API endpoint
:type endpoint: str
:param params: extra parameters passed with... | [
"def",
"_get_response",
"(",
"self",
",",
"method",
",",
"endpoint",
",",
"params",
"=",
"None",
")",
":",
"url",
"=",
"urljoin",
"(",
"self",
".",
"api_url",
",",
"endpoint",
")",
"try",
":",
"response",
"=",
"getattr",
"(",
"self",
".",
"_session",
... | Helper method to handle HTTP requests and catch API errors
:param method: valid HTTP method
:type method: str
:param endpoint: API endpoint
:type endpoint: str
:param params: extra parameters passed with the request
:type params: dict
:returns: API response
... | [
"Helper",
"method",
"to",
"handle",
"HTTP",
"requests",
"and",
"catch",
"API",
"errors"
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L189-L229 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI.whoami | def whoami(self):
"""
Get information about the access token.
Official docs:
https://monzo.com/docs/#authenticating-requests
:returns: access token details
:rtype: dict
"""
endpoint = '/ping/whoami'
response = self._get_response(
... | python | def whoami(self):
"""
Get information about the access token.
Official docs:
https://monzo.com/docs/#authenticating-requests
:returns: access token details
:rtype: dict
"""
endpoint = '/ping/whoami'
response = self._get_response(
... | [
"def",
"whoami",
"(",
"self",
")",
":",
"endpoint",
"=",
"'/ping/whoami'",
"response",
"=",
"self",
".",
"_get_response",
"(",
"method",
"=",
"'get'",
",",
"endpoint",
"=",
"endpoint",
",",
")",
"return",
"response",
".",
"json",
"(",
")"
] | Get information about the access token.
Official docs:
https://monzo.com/docs/#authenticating-requests
:returns: access token details
:rtype: dict | [
"Get",
"information",
"about",
"the",
"access",
"token",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L231-L246 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI.accounts | def accounts(self, refresh=False):
"""
Returns a list of accounts owned by the currently authorised user.
It's often used when deciding whether to require explicit account ID
or use the only available one, so we cache the response by default.
Official docs:
https://m... | python | def accounts(self, refresh=False):
"""
Returns a list of accounts owned by the currently authorised user.
It's often used when deciding whether to require explicit account ID
or use the only available one, so we cache the response by default.
Official docs:
https://m... | [
"def",
"accounts",
"(",
"self",
",",
"refresh",
"=",
"False",
")",
":",
"if",
"not",
"refresh",
"and",
"self",
".",
"_cached_accounts",
":",
"return",
"self",
".",
"_cached_accounts",
"endpoint",
"=",
"'/accounts'",
"response",
"=",
"self",
".",
"_get_respon... | Returns a list of accounts owned by the currently authorised user.
It's often used when deciding whether to require explicit account ID
or use the only available one, so we cache the response by default.
Official docs:
https://monzo.com/docs/#list-accounts
:param refresh: d... | [
"Returns",
"a",
"list",
"of",
"accounts",
"owned",
"by",
"the",
"currently",
"authorised",
"user",
".",
"It",
"s",
"often",
"used",
"when",
"deciding",
"whether",
"to",
"require",
"explicit",
"account",
"ID",
"or",
"use",
"the",
"only",
"available",
"one",
... | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L248-L274 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI.balance | def balance(self, account_id=None):
"""
Returns balance information for a specific account.
Official docs:
https://monzo.com/docs/#read-balance
:param account_id: Monzo account ID
:type account_id: str
:raises: ValueError
:returns: Monzo balance inst... | python | def balance(self, account_id=None):
"""
Returns balance information for a specific account.
Official docs:
https://monzo.com/docs/#read-balance
:param account_id: Monzo account ID
:type account_id: str
:raises: ValueError
:returns: Monzo balance inst... | [
"def",
"balance",
"(",
"self",
",",
"account_id",
"=",
"None",
")",
":",
"if",
"not",
"account_id",
":",
"if",
"len",
"(",
"self",
".",
"accounts",
"(",
")",
")",
"==",
"1",
":",
"account_id",
"=",
"self",
".",
"accounts",
"(",
")",
"[",
"0",
"]"... | Returns balance information for a specific account.
Official docs:
https://monzo.com/docs/#read-balance
:param account_id: Monzo account ID
:type account_id: str
:raises: ValueError
:returns: Monzo balance instance
:rtype: MonzoBalance | [
"Returns",
"balance",
"information",
"for",
"a",
"specific",
"account",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L276-L303 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI.pots | def pots(self, refresh=False):
"""
Returns a list of pots owned by the currently authorised user.
Official docs:
https://monzo.com/docs/#pots
:param refresh: decides if the pots information should be refreshed.
:type refresh: bool
:returns: list of Monzo pot... | python | def pots(self, refresh=False):
"""
Returns a list of pots owned by the currently authorised user.
Official docs:
https://monzo.com/docs/#pots
:param refresh: decides if the pots information should be refreshed.
:type refresh: bool
:returns: list of Monzo pot... | [
"def",
"pots",
"(",
"self",
",",
"refresh",
"=",
"False",
")",
":",
"if",
"not",
"refresh",
"and",
"self",
".",
"_cached_pots",
":",
"return",
"self",
".",
"_cached_pots",
"endpoint",
"=",
"'/pots/listV1'",
"response",
"=",
"self",
".",
"_get_response",
"(... | Returns a list of pots owned by the currently authorised user.
Official docs:
https://monzo.com/docs/#pots
:param refresh: decides if the pots information should be refreshed.
:type refresh: bool
:returns: list of Monzo pots
:rtype: list of MonzoPot | [
"Returns",
"a",
"list",
"of",
"pots",
"owned",
"by",
"the",
"currently",
"authorised",
"user",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L305-L329 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI.transactions | def transactions(self, account_id=None, reverse=True, limit=None):
"""
Returns a list of transactions on the user's account.
Official docs:
https://monzo.com/docs/#list-transactions
:param account_id: Monzo account ID
:type account_id: str
:param reverse: wh... | python | def transactions(self, account_id=None, reverse=True, limit=None):
"""
Returns a list of transactions on the user's account.
Official docs:
https://monzo.com/docs/#list-transactions
:param account_id: Monzo account ID
:type account_id: str
:param reverse: wh... | [
"def",
"transactions",
"(",
"self",
",",
"account_id",
"=",
"None",
",",
"reverse",
"=",
"True",
",",
"limit",
"=",
"None",
")",
":",
"if",
"not",
"account_id",
":",
"if",
"len",
"(",
"self",
".",
"accounts",
"(",
")",
")",
"==",
"1",
":",
"account... | Returns a list of transactions on the user's account.
Official docs:
https://monzo.com/docs/#list-transactions
:param account_id: Monzo account ID
:type account_id: str
:param reverse: whether transactions should be in in descending order
:type reverse: bool
... | [
"Returns",
"a",
"list",
"of",
"transactions",
"on",
"the",
"user",
"s",
"account",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L331-L372 | train |
pawelad/pymonzo | src/pymonzo/monzo_api.py | MonzoAPI.transaction | def transaction(self, transaction_id, expand_merchant=False):
"""
Returns an individual transaction, fetched by its id.
Official docs:
https://monzo.com/docs/#retrieve-transaction
:param transaction_id: Monzo transaction ID
:type transaction_id: str
:param e... | python | def transaction(self, transaction_id, expand_merchant=False):
"""
Returns an individual transaction, fetched by its id.
Official docs:
https://monzo.com/docs/#retrieve-transaction
:param transaction_id: Monzo transaction ID
:type transaction_id: str
:param e... | [
"def",
"transaction",
"(",
"self",
",",
"transaction_id",
",",
"expand_merchant",
"=",
"False",
")",
":",
"endpoint",
"=",
"'/transactions/{}'",
".",
"format",
"(",
"transaction_id",
")",
"data",
"=",
"dict",
"(",
")",
"if",
"expand_merchant",
":",
"data",
"... | Returns an individual transaction, fetched by its id.
Official docs:
https://monzo.com/docs/#retrieve-transaction
:param transaction_id: Monzo transaction ID
:type transaction_id: str
:param expand_merchant: whether merchant data should be included
:type expand_merc... | [
"Returns",
"an",
"individual",
"transaction",
"fetched",
"by",
"its",
"id",
"."
] | b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9 | https://github.com/pawelad/pymonzo/blob/b5c8d4f46dcb3a2f475797a8b8ef1c15f6493fb9/src/pymonzo/monzo_api.py#L374-L398 | train |
cluther/snmposter | snmposter/scripts.py | launcher | def launcher():
"""Launch it."""
parser = OptionParser()
parser.add_option(
'-f',
'--file',
dest='filename',
default='agents.csv',
help='snmposter configuration file'
)
options, args = parser.parse_args()
factory = SNMPosterFactory()
snmpd_status = s... | python | def launcher():
"""Launch it."""
parser = OptionParser()
parser.add_option(
'-f',
'--file',
dest='filename',
default='agents.csv',
help='snmposter configuration file'
)
options, args = parser.parse_args()
factory = SNMPosterFactory()
snmpd_status = s... | [
"def",
"launcher",
"(",
")",
":",
"parser",
"=",
"OptionParser",
"(",
")",
"parser",
".",
"add_option",
"(",
"'-f'",
",",
"'--file'",
",",
"dest",
"=",
"'filename'",
",",
"default",
"=",
"'agents.csv'",
",",
"help",
"=",
"'snmposter configuration file'",
")"... | Launch it. | [
"Launch",
"it",
"."
] | 3d9fb122368893cc71374442da6d49cde19aac75 | https://github.com/cluther/snmposter/blob/3d9fb122368893cc71374442da6d49cde19aac75/snmposter/scripts.py#L22-L52 | train |
cgoldberg/sauceclient | sauceclient.py | SauceClient.get_auth_string | def get_auth_string(self):
"""Create auth string from credentials."""
auth_info = '{}:{}'.format(self.sauce_username, self.sauce_access_key)
return base64.b64encode(auth_info.encode('utf-8')).decode('utf-8') | python | def get_auth_string(self):
"""Create auth string from credentials."""
auth_info = '{}:{}'.format(self.sauce_username, self.sauce_access_key)
return base64.b64encode(auth_info.encode('utf-8')).decode('utf-8') | [
"def",
"get_auth_string",
"(",
"self",
")",
":",
"auth_info",
"=",
"'{}:{}'",
".",
"format",
"(",
"self",
".",
"sauce_username",
",",
"self",
".",
"sauce_access_key",
")",
"return",
"base64",
".",
"b64encode",
"(",
"auth_info",
".",
"encode",
"(",
"'utf-8'",... | Create auth string from credentials. | [
"Create",
"auth",
"string",
"from",
"credentials",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L59-L62 | train |
cgoldberg/sauceclient | sauceclient.py | SauceClient.make_auth_headers | def make_auth_headers(self, content_type):
"""Add authorization header."""
headers = self.make_headers(content_type)
headers['Authorization'] = 'Basic {}'.format(self.get_auth_string())
return headers | python | def make_auth_headers(self, content_type):
"""Add authorization header."""
headers = self.make_headers(content_type)
headers['Authorization'] = 'Basic {}'.format(self.get_auth_string())
return headers | [
"def",
"make_auth_headers",
"(",
"self",
",",
"content_type",
")",
":",
"headers",
"=",
"self",
".",
"make_headers",
"(",
"content_type",
")",
"headers",
"[",
"'Authorization'",
"]",
"=",
"'Basic {}'",
".",
"format",
"(",
"self",
".",
"get_auth_string",
"(",
... | Add authorization header. | [
"Add",
"authorization",
"header",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L70-L74 | train |
cgoldberg/sauceclient | sauceclient.py | SauceClient.request | def request(self, method, url, body=None, content_type='application/json'):
"""Send http request."""
headers = self.make_auth_headers(content_type)
connection = http_client.HTTPSConnection(self.apibase)
connection.request(method, url, body, headers=headers)
response = connection.... | python | def request(self, method, url, body=None, content_type='application/json'):
"""Send http request."""
headers = self.make_auth_headers(content_type)
connection = http_client.HTTPSConnection(self.apibase)
connection.request(method, url, body, headers=headers)
response = connection.... | [
"def",
"request",
"(",
"self",
",",
"method",
",",
"url",
",",
"body",
"=",
"None",
",",
"content_type",
"=",
"'application/json'",
")",
":",
"headers",
"=",
"self",
".",
"make_auth_headers",
"(",
"content_type",
")",
"connection",
"=",
"http_client",
".",
... | Send http request. | [
"Send",
"http",
"request",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L76-L87 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_user | def get_user(self):
"""Access basic account information."""
method = 'GET'
endpoint = '/rest/v1/users/{}'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | python | def get_user(self):
"""Access basic account information."""
method = 'GET'
endpoint = '/rest/v1/users/{}'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"get_user",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/users/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",",
"endpoint"... | Access basic account information. | [
"Access",
"basic",
"account",
"information",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L100-L104 | train |
cgoldberg/sauceclient | sauceclient.py | Account.create_user | def create_user(self, username, password, name, email):
"""Create a sub account."""
method = 'POST'
endpoint = '/rest/v1/users/{}'.format(self.client.sauce_username)
body = json.dumps({'username': username, 'password': password,
'name': name, 'email': email, })... | python | def create_user(self, username, password, name, email):
"""Create a sub account."""
method = 'POST'
endpoint = '/rest/v1/users/{}'.format(self.client.sauce_username)
body = json.dumps({'username': username, 'password': password,
'name': name, 'email': email, })... | [
"def",
"create_user",
"(",
"self",
",",
"username",
",",
"password",
",",
"name",
",",
"email",
")",
":",
"method",
"=",
"'POST'",
"endpoint",
"=",
"'/rest/v1/users/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"body",
"=",
... | Create a sub account. | [
"Create",
"a",
"sub",
"account",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L106-L112 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_concurrency | def get_concurrency(self):
"""Check account concurrency limits."""
method = 'GET'
endpoint = '/rest/v1.1/users/{}/concurrency'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | python | def get_concurrency(self):
"""Check account concurrency limits."""
method = 'GET'
endpoint = '/rest/v1.1/users/{}/concurrency'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"get_concurrency",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1.1/users/{}/concurrency'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method"... | Check account concurrency limits. | [
"Check",
"account",
"concurrency",
"limits",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L114-L119 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_subaccounts | def get_subaccounts(self):
"""Get a list of sub accounts associated with a parent account."""
method = 'GET'
endpoint = '/rest/v1/users/{}/list-subaccounts'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | python | def get_subaccounts(self):
"""Get a list of sub accounts associated with a parent account."""
method = 'GET'
endpoint = '/rest/v1/users/{}/list-subaccounts'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"get_subaccounts",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/users/{}/list-subaccounts'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"meth... | Get a list of sub accounts associated with a parent account. | [
"Get",
"a",
"list",
"of",
"sub",
"accounts",
"associated",
"with",
"a",
"parent",
"account",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L121-L126 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_siblings | def get_siblings(self):
"""Get a list of sibling accounts associated with provided account."""
method = 'GET'
endpoint = '/rest/v1.1/users/{}/siblings'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | python | def get_siblings(self):
"""Get a list of sibling accounts associated with provided account."""
method = 'GET'
endpoint = '/rest/v1.1/users/{}/siblings'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"get_siblings",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1.1/users/{}/siblings'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",... | Get a list of sibling accounts associated with provided account. | [
"Get",
"a",
"list",
"of",
"sibling",
"accounts",
"associated",
"with",
"provided",
"account",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L128-L133 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_subaccount_info | def get_subaccount_info(self):
"""Get information about a sub account."""
method = 'GET'
endpoint = '/rest/v1/users/{}/subaccounts'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | python | def get_subaccount_info(self):
"""Get information about a sub account."""
method = 'GET'
endpoint = '/rest/v1/users/{}/subaccounts'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"get_subaccount_info",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/users/{}/subaccounts'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"metho... | Get information about a sub account. | [
"Get",
"information",
"about",
"a",
"sub",
"account",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L135-L140 | train |
cgoldberg/sauceclient | sauceclient.py | Account.change_access_key | def change_access_key(self):
"""Change access key of your account."""
method = 'POST'
endpoint = '/rest/v1/users/{}/accesskey/change'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | python | def change_access_key(self):
"""Change access key of your account."""
method = 'POST'
endpoint = '/rest/v1/users/{}/accesskey/change'.format(
self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"change_access_key",
"(",
"self",
")",
":",
"method",
"=",
"'POST'",
"endpoint",
"=",
"'/rest/v1/users/{}/accesskey/change'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"m... | Change access key of your account. | [
"Change",
"access",
"key",
"of",
"your",
"account",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L142-L147 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_activity | def get_activity(self):
"""Check account concurrency limits."""
method = 'GET'
endpoint = '/rest/v1/{}/activity'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | python | def get_activity(self):
"""Check account concurrency limits."""
method = 'GET'
endpoint = '/rest/v1/{}/activity'.format(self.client.sauce_username)
return self.client.request(method, endpoint) | [
"def",
"get_activity",
"(",
"self",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/{}/activity'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",",
"en... | Check account concurrency limits. | [
"Check",
"account",
"concurrency",
"limits",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L149-L153 | train |
cgoldberg/sauceclient | sauceclient.py | Account.get_usage | def get_usage(self, start=None, end=None):
"""Access historical account usage data."""
method = 'GET'
endpoint = '/rest/v1/users/{}/usage'.format(self.client.sauce_username)
data = {}
if start:
data['start'] = start
if end:
data['end'] = end
... | python | def get_usage(self, start=None, end=None):
"""Access historical account usage data."""
method = 'GET'
endpoint = '/rest/v1/users/{}/usage'.format(self.client.sauce_username)
data = {}
if start:
data['start'] = start
if end:
data['end'] = end
... | [
"def",
"get_usage",
"(",
"self",
",",
"start",
"=",
"None",
",",
"end",
"=",
"None",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/users/{}/usage'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"data",
"=",
"{",
... | Access historical account usage data. | [
"Access",
"historical",
"account",
"usage",
"data",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L155-L166 | train |
cgoldberg/sauceclient | sauceclient.py | Information.get_platforms | def get_platforms(self, automation_api='all'):
"""Get a list of objects describing all the OS and browser platforms
currently supported on Sauce Labs."""
method = 'GET'
endpoint = '/rest/v1/info/platforms/{}'.format(automation_api)
return self.client.request(method, endpoint) | python | def get_platforms(self, automation_api='all'):
"""Get a list of objects describing all the OS and browser platforms
currently supported on Sauce Labs."""
method = 'GET'
endpoint = '/rest/v1/info/platforms/{}'.format(automation_api)
return self.client.request(method, endpoint) | [
"def",
"get_platforms",
"(",
"self",
",",
"automation_api",
"=",
"'all'",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/info/platforms/{}'",
".",
"format",
"(",
"automation_api",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"metho... | Get a list of objects describing all the OS and browser platforms
currently supported on Sauce Labs. | [
"Get",
"a",
"list",
"of",
"objects",
"describing",
"all",
"the",
"OS",
"and",
"browser",
"platforms",
"currently",
"supported",
"on",
"Sauce",
"Labs",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L351-L356 | train |
cgoldberg/sauceclient | sauceclient.py | Jobs.get_jobs | 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:
... | python | 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",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",... | List jobs belonging to a specific user. | [
"List",
"jobs",
"belonging",
"to",
"a",
"specific",
"user",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L403-L423 | train |
cgoldberg/sauceclient | sauceclient.py | Jobs.update_job | 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)
... | python | 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",
")",
":",
"method",
"=",
"'PUT'... | Edit an existing job. | [
"Edit",
"an",
"existing",
"job",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L432-L452 | train |
cgoldberg/sauceclient | sauceclient.py | Jobs.stop_job | 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) | python | 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",
")",
":",
"method",
"=",
"'PUT'",
"endpoint",
"=",
"'/rest/v1/{}/jobs/{}/stop'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"job_id",
")",
"return",
"self",
".",
"client",
".",
"req... | Terminates a running job. | [
"Terminates",
"a",
"running",
"job",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L461-L466 | train |
cgoldberg/sauceclient | sauceclient.py | Jobs.get_job_asset_url | 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) | python | 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",
")",
":",
"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. | [
"Get",
"details",
"about",
"the",
"static",
"assets",
"collected",
"for",
"a",
"specific",
"job",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L475-L478 | train |
cgoldberg/sauceclient | sauceclient.py | Jobs.get_auth_token | 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... | python | 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",
")",
":",
"key",
"=",
"'{}:{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"self",
".",
"client",
".",
"sauce_access_key",
")",
"if",
"date_... | Get an auth token to access protected job resources.
https://wiki.saucelabs.com/display/DOCS/Building+Links+to+Test+Results | [
"Get",
"an",
"auth",
"token",
"to",
"access",
"protected",
"job",
"resources",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L487-L497 | train |
cgoldberg/sauceclient | sauceclient.py | Storage.upload_file | 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 ... | python | 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",
")",
":",
"method",
"=",
"'POST'",
"filename",
"=",
"os",
".",
"path",
".",
"split",
"(",
"filepath",
")",
"[",
"1",
"]",
"endpoint",
"=",
"'/rest/v1/storage/{}/{}?overwrite... | Uploads a file to the temporary sauce storage. | [
"Uploads",
"a",
"file",
"to",
"the",
"temporary",
"sauce",
"storage",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L509-L518 | train |
cgoldberg/sauceclient | sauceclient.py | Storage.get_stored_files | 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) | python | 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",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/storage/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",",
... | Check which files are in your temporary storage. | [
"Check",
"which",
"files",
"are",
"in",
"your",
"temporary",
"storage",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L520-L524 | train |
cgoldberg/sauceclient | sauceclient.py | Tunnels.get_tunnels | 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) | python | 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",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/{}/tunnels'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
")",
"return",
"self",
".",
"client",
".",
"request",
"(",
"method",
",",
"endp... | Retrieves all running tunnels for a specific user. | [
"Retrieves",
"all",
"running",
"tunnels",
"for",
"a",
"specific",
"user",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L536-L540 | train |
cgoldberg/sauceclient | sauceclient.py | Tunnels.get_tunnel | 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) | python | 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",
")",
":",
"method",
"=",
"'GET'",
"endpoint",
"=",
"'/rest/v1/{}/tunnels/{}'",
".",
"format",
"(",
"self",
".",
"client",
".",
"sauce_username",
",",
"tunnel_id",
")",
"return",
"self",
".",
"client",
".",
... | Get information for a tunnel given its ID. | [
"Get",
"information",
"for",
"a",
"tunnel",
"given",
"its",
"ID",
"."
] | aa27b7da8eb2e483adc2754c694fe5082e1fa8f7 | https://github.com/cgoldberg/sauceclient/blob/aa27b7da8eb2e483adc2754c694fe5082e1fa8f7/sauceclient.py#L542-L547 | train |
christophercrouzet/gorilla | gorilla.py | apply | 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... | python | 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",
")",
":",
"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... | 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
... | [
"Apply",
"a",
"patch",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L231-L283 | train |
christophercrouzet/gorilla | gorilla.py | patch | 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... | python | 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",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"base",
"=",
"_get_base",
"(",
"wrapped",
")",
"name_",
"=",
"base",
".",
"__name__",
"if",
"name",
"i... | 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.
... | [
"Decorator",
"to",
"create",
"a",
"patch",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L286-L319 | train |
christophercrouzet/gorilla | gorilla.py | patches | 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... | python | 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",
")",
":",
"def",
"decorator",
"(",
"wrapped",
"... | 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
... | [
"Decorator",
"to",
"create",
"a",
"patch",
"for",
"each",
"member",
"of",
"a",
"module",
"or",
"a",
"class",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L322-L372 | train |
christophercrouzet/gorilla | gorilla.py | destination | 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
... | python | 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",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"data",
"=",
"get_decorator_data",
"(",
"_get_base",
"(",
"wrapped",
")",
",",
"set_default",
"=",
"True",
")",
"data",
".",
"override",
"[",
"'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.
... | [
"Modifier",
"decorator",
"to",
"update",
"a",
"patch",
"s",
"destination",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L375-L397 | train |
christophercrouzet/gorilla | gorilla.py | settings | 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... | python | 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",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"data",
"=",
"get_decorator_data",
"(",
"_get_base",
"(",
"wrapped",
")",
",",
"set_default",
"=",
"True",
")",
"data",
".",
"override",
".",
"setdefault"... | 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... | [
"Modifier",
"decorator",
"to",
"update",
"a",
"patch",
"s",
"settings",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L425-L447 | train |
christophercrouzet/gorilla | gorilla.py | filter | 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... | python | 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",
")",
":",
"def",
"decorator",
"(",
"wrapped",
")",
":",
"data",
"=",
"get_decorator_data",
"(",
"_get_base",
"(",
"wrapped",
")",
",",
"set_default",
"=",
"True",
")",
"data",
".",
"filter",
"=",
"value",
"return",
"wrapped... | 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... | [
"Modifier",
"decorator",
"to",
"force",
"the",
"inclusion",
"or",
"exclusion",
"of",
"an",
"attribute",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L450-L474 | train |
christophercrouzet/gorilla | gorilla.py | create_patches | 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
... | python | 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",
")",
":",
"if",
"filter",
"... | 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... | [
"Create",
"a",
"patch",
"for",
"each",
"member",
"of",
"a",
"module",
"or",
"a",
"class",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L477-L559 | train |
christophercrouzet/gorilla | gorilla.py | find_patches | 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
-------
... | python | 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",
")",
":",
"out",
"=",
"[",
"]",
"modules",
"=",
"(",
"module",
"for",
"package",
"in",
"modules",
"for",
"module",
"in",
"_module_iterator",
"(",
"package",
",",
"recursive",
"=",
"rec... | 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.
... | [
"Find",
"all",
"the",
"patches",
"created",
"through",
"decorators",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L562-L600 | train |
christophercrouzet/gorilla | gorilla.py | get_attribute | 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... | python | 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",
")",
":",
"objs",
"=",
"inspect",
".",
"getmro",
"(",
"obj",
")",
"if",
"isinstance",
"(",
"obj",
",",
"_CLASS_TYPES",
")",
"else",
"[",
"obj",
"]",
"for",
"obj_",
"in",
"objs",
":",
"try",
":",
"ret... | 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... | [
"Retrieve",
"an",
"attribute",
"while",
"bypassing",
"the",
"descriptor",
"protocol",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L603-L638 | train |
christophercrouzet/gorilla | gorilla.py | get_decorator_data | 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
... | python | 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",
")",
":",
"if",
"isinstance",
"(",
"obj",
",",
"_CLASS_TYPES",
")",
":",
"datas",
"=",
"getattr",
"(",
"obj",
",",
"_DECORATOR_DATA",
",",
"{",
"}",
")",
"data",
"=",
"datas",
"... | 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... | [
"Retrieve",
"any",
"decorator",
"data",
"from",
"an",
"object",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L668-L697 | train |
christophercrouzet/gorilla | gorilla.py | _get_base | 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... | python | 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",
")",
":",
"if",
"hasattr",
"(",
"obj",
",",
"'__func__'",
")",
":",
"obj",
"=",
"obj",
".",
"__func__",
"elif",
"isinstance",
"(",
"obj",
",",
"property",
")",
":",
"obj",
"=",
"obj",
".",
"fget",
"elif",
"isinstance",... | Unwrap decorators to retrieve the base object. | [
"Unwrap",
"decorators",
"to",
"retrieve",
"the",
"base",
"object",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L700-L713 | train |
christophercrouzet/gorilla | gorilla.py | _get_members | 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... | python | 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",
")",
":",
"if",
"filter",
"is",
"None",
":",
"filter",
"=",
"_true",
"out",
"=",
"[",
"]",
"stack",
"=",
"collec... | Retrieve the member attributes of a module or a class.
The descriptor protocol is bypassed. | [
"Retrieve",
"the",
"member",
"attributes",
"of",
"a",
"module",
"or",
"a",
"class",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L716-L750 | train |
christophercrouzet/gorilla | gorilla.py | _module_iterator | 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.
... | python | 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",
")",
":",
"yield",
"root",
"stack",
"=",
"collections",
".",
"deque",
"(",
"(",
"root",
",",
")",
")",
"while",
"stack",
":",
"package",
"=",
"stack",
".",
"popleft",
"(",
")",
"#... | Iterate over modules. | [
"Iterate",
"over",
"modules",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L753-L778 | train |
christophercrouzet/gorilla | gorilla.py | Patch._update | 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':
... | python | 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",
")",
":",
"for",
"key",
",",
"value",
"in",
"_iteritems",
"(",
"kwargs",
")",
":",
"if",
"key",
"==",
"'settings'",
":",
"if",
"isinstance",
"(",
"value",
",",
"dict",
")",
":",
"if",
"self",
... | 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. | [
"Update",
"some",
"attributes",
"."
] | 10c68d04be28524f2cd7be22eddca77678e12860 | https://github.com/christophercrouzet/gorilla/blob/10c68d04be28524f2cd7be22eddca77678e12860/gorilla.py#L212-L228 | train |
peshay/tpm | tpm.py | TpmApi.request | 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)... | python | 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",
"=",
"''",
")",
":",
"# Check if the path includes URL or not.",
"head",
"=",
"self",
".",
"base_url",
"if",
"path",
".",
"startswith",
"(",
"head",
")",
":",
"path",
"=",
"path",
"[... | To make a request to the API. | [
"To",
"make",
"a",
"request",
"to",
"the",
"API",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L126-L207 | train |
peshay/tpm | tpm.py | TpmApi.get_collection | 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':
... | python | 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",
")",
":",
"while",
"True",
":",
"items",
"=",
"self",
".",
"get",
"(",
"path",
")",
"req",
"=",
"self",
".",
"req",
"for",
"item",
"in",
"items",
":",
"yield",
"item",
"if",
"req",
".",
"links",
... | To get pagewise data. | [
"To",
"get",
"pagewise",
"data",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L225-L236 | train |
peshay/tpm | tpm.py | TpmApi.collection | 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 | python | 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",
")",
":",
"data",
"=",
"[",
"]",
"for",
"item",
"in",
"self",
".",
"get_collection",
"(",
"path",
")",
":",
"data",
".",
"append",
"(",
"item",
")",
"return",
"data"
] | To return all items generated by get collection. | [
"To",
"return",
"all",
"items",
"generated",
"by",
"get",
"collection",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L238-L243 | train |
peshay/tpm | tpm.py | TpmApi.list_projects_search | 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)) | python | 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",
")",
":",
"log",
".",
"debug",
"(",
"'List all projects with: %s'",
"%",
"searchstring",
")",
"return",
"self",
".",
"collection",
"(",
"'projects/search/%s.json'",
"%",
"quote_plus",
"(",
"searchstrin... | List projects with searchstring. | [
"List",
"projects",
"with",
"searchstring",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L263-L267 | train |
peshay/tpm | tpm.py | TpmApi.create_project | 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... | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#create_project",
"log",
".",
"info",
"(",
"'Create project: %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'projects.json'",
",",
"dat... | Create a project. | [
"Create",
"a",
"project",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L287-L293 | train |
peshay/tpm | tpm.py | TpmApi.update_project | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#update_project",
"log",
".",
"info",
"(",
"'Update project %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"(",
... | Update a project. | [
"Update",
"a",
"project",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L295-L299 | train |
peshay/tpm | tpm.py | TpmApi.change_parent_of_project | 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... | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#change_parent",
"log",
".",
"info",
"(",
"'Change parrent for project %s to %s'",
"%",
"(",
"ID",
",",
"NewParrentID",
")",
")",
... | Change parent of project. | [
"Change",
"parent",
"of",
"project",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L301-L306 | train |
peshay/tpm | tpm.py | TpmApi.update_security_of_project | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-projects/#update_project_security",
"log",
".",
"info",
"(",
"'Update project %s security %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
... | Update security of project. | [
"Update",
"security",
"of",
"project",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L308-L312 | train |
peshay/tpm | tpm.py | TpmApi.list_passwords_search | 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)) | python | 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",
")",
":",
"log",
".",
"debug",
"(",
"'List all passwords with: %s'",
"%",
"searchstring",
")",
"return",
"self",
".",
"collection",
"(",
"'passwords/search/%s.json'",
"%",
"quote_plus",
"(",
"searchst... | List passwords with searchstring. | [
"List",
"passwords",
"with",
"searchstring",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L348-L352 | train |
peshay/tpm | tpm.py | TpmApi.create_password | 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)
... | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#create_password",
"log",
".",
"info",
"(",
"'Create new password %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'passwords.json'",
","... | Create a password. | [
"Create",
"a",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L366-L372 | train |
peshay/tpm | tpm.py | TpmApi.update_password | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#update_password",
"log",
".",
"info",
"(",
"'Update Password %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"("... | Update a password. | [
"Update",
"a",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L374-L378 | train |
peshay/tpm | tpm.py | TpmApi.update_security_of_password | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#update_security_password",
"log",
".",
"info",
"(",
"'Update security of password %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")"... | Update security of a password. | [
"Update",
"security",
"of",
"a",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L380-L384 | train |
peshay/tpm | tpm.py | TpmApi.update_custom_fields_of_password | 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... | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#update_cf_password",
"log",
".",
"info",
"(",
"'Update custom fields of password %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
... | Update custom fields definitions of a password. | [
"Update",
"custom",
"fields",
"definitions",
"of",
"a",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L386-L390 | train |
peshay/tpm | tpm.py | TpmApi.unlock_password | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-passwords/#unlock_password",
"log",
".",
"info",
"(",
"'Unlock password %s, Reason: %s'",
"%",
"(",
"ID",
",",
"reason",
")",
")",
"self",
".",
"unl... | Unlock a password. | [
"Unlock",
"a",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L404-L409 | train |
peshay/tpm | tpm.py | TpmApi.list_mypasswords_search | 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' %
... | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-my-passwords/#list_passwords",
"log",
".",
"debug",
"(",
"'List MyPasswords with %s'",
"%",
"searchstring",
")",
"return",
"self",
".",
"collection",
"("... | List my passwords with searchstring. | [
"List",
"my",
"passwords",
"with",
"searchstring",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L417-L422 | train |
peshay/tpm | tpm.py | TpmApi.create_mypassword | 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' ... | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-my-passwords/#create_password",
"log",
".",
"info",
"(",
"'Create MyPassword with %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'my_passwords.js... | Create my password. | [
"Create",
"my",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L430-L436 | train |
peshay/tpm | tpm.py | TpmApi.update_mypassword | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-my-passwords/#update_password",
"log",
".",
"info",
"(",
"'Update MyPassword %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put"... | Update my password. | [
"Update",
"my",
"password",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L438-L442 | train |
peshay/tpm | tpm.py | TpmApi.create_user | 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 | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#create_user",
"log",
".",
"info",
"(",
"'Create user with %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'users.json'",
",",
"data",
")",
... | Create a User. | [
"Create",
"a",
"User",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L496-L502 | train |
peshay/tpm | tpm.py | TpmApi.update_user | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#update_user",
"log",
".",
"info",
"(",
"'Update user %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"(",
"'users/%s.j... | Update a User. | [
"Update",
"a",
"User",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L504-L508 | train |
peshay/tpm | tpm.py | TpmApi.change_user_password | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#change_password",
"log",
".",
"info",
"(",
"'Change user %s password'",
"%",
"ID",
")",
"self",
".",
"put",
"(",
"'users/%s/change_password.js... | Change password of a User. | [
"Change",
"password",
"of",
"a",
"User",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L510-L514 | train |
peshay/tpm | tpm.py | TpmApi.convert_user_to_ldap | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-users/#convert_to_ldap",
"data",
"=",
"{",
"'login_dn'",
":",
"DN",
"}",
"log",
".",
"info",
"(",
"'Convert User %s to LDAP DN %s'",
"%",
"(",
"ID"... | Convert a normal user to a LDAP user. | [
"Convert",
"a",
"normal",
"user",
"to",
"a",
"LDAP",
"user",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L528-L533 | train |
peshay/tpm | tpm.py | TpmApi.create_group | 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 | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#create_group",
"log",
".",
"info",
"(",
"'Create group with %s'",
"%",
"data",
")",
"NewID",
"=",
"self",
".",
"post",
"(",
"'groups.json'",
",",
"data",
... | Create a Group. | [
"Create",
"a",
"Group",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L558-L564 | train |
peshay/tpm | tpm.py | TpmApi.update_group | 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) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#update_group",
"log",
".",
"info",
"(",
"'Update group %s with %s'",
"%",
"(",
"ID",
",",
"data",
")",
")",
"self",
".",
"put",
"(",
"'groups... | Update a Group. | [
"Update",
"a",
"Group",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L566-L570 | train |
peshay/tpm | tpm.py | TpmApi.add_user_to_group | 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)) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#add_user",
"log",
".",
"info",
"(",
"'Add User %s to Group %s'",
"%",
"(",
"UserID",
",",
"GroupID",
")",
")",
"self",
".",
"put",
... | Add a user to a group. | [
"Add",
"a",
"user",
"to",
"a",
"group",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L572-L576 | train |
peshay/tpm | tpm.py | TpmApi.delete_user_from_group | 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)) | python | 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",
")",
":",
"# http://teampasswordmanager.com/docs/api-groups/#del_user",
"log",
".",
"info",
"(",
"'Delete user %s from group %s'",
"%",
"(",
"UserID",
",",
"GroupID",
")",
")",
"self",
".",
... | Delete a user from a group. | [
"Delete",
"a",
"user",
"from",
"a",
"group",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L578-L582 | train |
peshay/tpm | tpm.py | TpmApi.up_to_date | 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... | python | 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",
")",
":",
"VersionInfo",
"=",
"self",
".",
"get_latest_version",
"(",
")",
"CurrentVersion",
"=",
"VersionInfo",
".",
"get",
"(",
"'version'",
")",
"LatestVersion",
"=",
"VersionInfo",
".",
"get",
"(",
"'latest_version'",
")",... | Check if Team Password Manager is up to date. | [
"Check",
"if",
"Team",
"Password",
"Manager",
"is",
"up",
"to",
"date",
"."
] | 8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc | https://github.com/peshay/tpm/blob/8e64a4d8b89d54bdd2c92d965463a7508aa3d0bc/tpm.py#L608-L620 | train |
shazow/unstdlib.py | unstdlib/standard/exception_.py | convert_exception | 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... | python | 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",
")",
":",
"def",
"wrapper",
"(",
"fn",
")",
":",
"def",
"fn_new",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"try",
":",
"ret... | 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):
... | [
"Decorator",
":",
"Catch",
"exception",
"from_exception",
"and",
"instead",
"raise",
"to_exception",
"(",
"*",
"to_args",
"**",
"to_kw",
")",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/exception_.py#L9-L51 | train |
shazow/unstdlib.py | unstdlib/standard/datetime_.py | iterate_date_values | 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)
... | python | 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",
")",
":",
"dataiter",
"=",
"iter",
"(",
"d",
")",
"cur_day",
",",
"cur_val",
"=",
"next",
"(",
"dataiter",
")",
"start_date... | 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] | [
"Convert",
"(",
"date",
"value",
")",
"sorted",
"lists",
"into",
"contiguous",
"value",
"-",
"per",
"-",
"day",
"data",
"sets",
".",
"Great",
"for",
"sparklines",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L16-L43 | train |
shazow/unstdlib.py | unstdlib/standard/datetime_.py | truncate_datetime | 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... | python | 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",
")",
":",
"resolutions",
"=",
"[",
"'year'",
",",
"'month'",
",",
"'day'",
",",
"'hour'",
",",
"'minute'",
",",
"'second'",
",",
"'microsecond'",
"]",
"if",
"resolution",
"not",
"in",
"resolutions",
... | 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... | [
"Given",
"a",
"datetime",
"t",
"and",
"a",
"resolution",
"flatten",
"the",
"precision",
"beyond",
"the",
"given",
"resolution",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L53-L85 | train |
shazow/unstdlib.py | unstdlib/standard/datetime_.py | to_timezone | 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... | python | 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",
")",
":",
"if",
"dt",
".",
"tzinfo",
"is",
"None",
":",
"dt",
"=",
"dt",
".",
"replace",
"(",
"tzinfo",
"=",
"_UTC",
")",
"return",
"timezone",
".",
"normalize",
"(",
"dt",
".",
"astimezone",
"(",
"... | 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/ | [
"Return",
"an",
"aware",
"datetime",
"which",
"is",
"dt",
"converted",
"to",
"timezone",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L87-L100 | train |
shazow/unstdlib.py | unstdlib/standard/datetime_.py | now | 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... | python | 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",
")",
":",
"d",
"=",
"datetime",
".",
"datetime",
".",
"utcnow",
"(",
")",
"if",
"not",
"timezone",
":",
"return",
"d",
"return",
"to_timezone",
"(",
"d",
",",
"timezone",
")",
".",
"replace",
"(",
"tzinfo",... | 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 | [
"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... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/datetime_.py#L102-L116 | train |
shazow/unstdlib.py | unstdlib/sqlalchemy.py | enumerate_query_by_limit | 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:
... | python | 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",
")",
":",
"for",
"offset",
"in",
"count",
"(",
"0",
",",
"limit",
")",
":",
"r",
"=",
"q",
".",
"offset",
"(",
"offset",
")",
".",
"limit",
"(",
"limit",
")",
".",
"all",
"("... | Enumerate over SQLAlchemy query object ``q`` and yield individual results
fetched in batches of size ``limit`` using SQL LIMIT and OFFSET. | [
"Enumerate",
"over",
"SQLAlchemy",
"query",
"object",
"q",
"and",
"yield",
"individual",
"results",
"fetched",
"in",
"batches",
"of",
"size",
"limit",
"using",
"SQL",
"LIMIT",
"and",
"OFFSET",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/sqlalchemy.py#L7-L19 | train |
shazow/unstdlib.py | unstdlib/formencode.py | validate_many | 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... | python | 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",
")",
":",
"return",
"[",
"validator",
".",
"to_python",
"(",
"d",
".",
"get",
"(",
"key",
")",
",",
"state",
"=",
"key",
")",
"for",
"key",
",",
"validator",
"in",
"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 but using formencode validation.
:... | [
"Validate",
"a",
"dictionary",
"of",
"data",
"against",
"the",
"provided",
"schema",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/formencode.py#L12-L35 | train |
shazow/unstdlib.py | unstdlib/standard/functools_.py | assert_hashable | 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):
... | python | 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",
")",
":",
"try",
":",
"for",
"i",
",",
"arg",
"in",
"enumerate",
"(",
"args",
")",
":",
"hash",
"(",
"arg",
")",
"except",
"TypeError",
":",
"raise",
"TypeError",
"(",
"'Argument in pos... | 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... | [
"Verify",
"that",
"each",
"argument",
"is",
"hashable",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L13-L39 | train |
shazow/unstdlib.py | unstdlib/standard/functools_.py | memoized | 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):... | python | 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",
")",
":",
"if",
"fn",
":",
"# This is a hack to support both @memoize and @memoize(...)",
"return",
"memoized",
"(",
"cache",
"=",
"cache",
")",
"(",
"fn",
")",
"if",
"cache",
"is",
"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):
... print("Not cached.")
... | [
"Memoize",
"a",
"function",
"into",
"an",
"optionally",
"-",
"specificed",
"cache",
"container",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L59-L110 | train |
shazow/unstdlib.py | unstdlib/standard/functools_.py | memoized_method | 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... | python | 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",
")",
":",
"if",
"method",
"is",
"None",
":",
"return",
"lambda",
"f",
":",
"memoized_method",
"(",
"f",
",",
"cache_factory",
"=",
"cache_factory",
")",
"cache_factory",... | 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, ... | [
"Memoize",
"a",
"class",
"s",
"method",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L129-L199 | train |
shazow/unstdlib.py | unstdlib/standard/functools_.py | deprecated | 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... | python | 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",
")",
":",
"def",
"decorator",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapper",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"warnin... | 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... | [
"Throw",
"a",
"warning",
"when",
"a",
"function",
"/",
"method",
"will",
"be",
"soon",
"deprecated"
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/functools_.py#L202-L233 | train |
shazow/unstdlib.py | unstdlib/standard/list_.py | groupby_count | 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... | python | 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",
")",
":",
"counter",
"=",
"defaultdict",
"(",
"lambda",
":",
"0",
")",
"if",
"not",
"key",
":",
"key",
"=",
"lambda",
"o",
":",
"o",
"for",
"k",
"in",
"i",... | 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)] | [
"Aggregate",
"iterator",
"values",
"into",
"buckets",
"based",
"on",
"how",
"frequently",
"the",
"values",
"appear",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L16-L36 | train |
shazow/unstdlib.py | unstdlib/standard/list_.py | is_iterable | 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
... | python | 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",
")",
")",
":",
"try",
":",
"iter",
"(",
"maybe_iter",
")",
"except",
"TypeError",
":",
"return",
"False",
"return",
"not",
"isinstance",
"(",
"maybe_iter",
",",
... | 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
... | [
"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",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L39-L58 | train |
shazow/unstdlib.py | unstdlib/standard/list_.py | iterate | 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... | python | 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",
")",
")",
":",
"if",
"is_iterable",
"(",
"maybe_iter",
",",
"unless",
"=",
"unless",
")",
":",
"return",
"maybe_iter",
"return",
"[",
"maybe_iter",
"]"
] | 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... | [
"Always",
"return",
"an",
"iterable",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L61-L89 | train |
shazow/unstdlib.py | unstdlib/standard/list_.py | iterate_items | 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... | python | 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",
")",
":",
"if",
"hasattr",
"(",
"dictish",
",",
"'iteritems'",
")",
":",
"return",
"dictish",
".",
"iteritems",
"(",
")",
"if",
"hasattr",
"(",
"dictish",
",",
"'items'",
")",
":",
"return",
"dictish",
".",
"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)] | [
"Return",
"a",
"consistent",
"(",
"key",
"value",
")",
"iterable",
"on",
"dict",
"-",
"like",
"objects",
"including",
"lists",
"of",
"tuple",
"pairs",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L92-L107 | train |
shazow/unstdlib.py | unstdlib/standard/list_.py | iterate_chunks | 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... | python | 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",
")",
":",
"accumulator",
"=",
"[",
"]",
"for",
"n",
",",
"i",
"in",
"enumerate",
"(",
"i",
")",
":",
"accumulator",
".",
"append",
"(",
"i",
")",
"if",
"(",
"n",
"+",
"1",
")",
"%",
"... | 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]] | [
"Iterate",
"over",
"an",
"iterator",
"i",
"in",
"size",
"chunks",
"yield",
"chunks",
".",
"Similar",
"to",
"pagination",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L110-L129 | train |
shazow/unstdlib.py | unstdlib/standard/list_.py | listify | 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):
.... | python | 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",
")",
":",
"def",
"listify_return",
"(",
"fn",
")",
":",
"@",
"wraps",
"(",
"fn",
")",
"def",
"listify_helper",
"(",
"*",
"args",
",",
"*",
"*",
"kw",
")",
":",
"return",
"wrap... | 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... | [
"A",
"decorator",
"which",
"wraps",
"a",
"function",
"s",
"return",
"value",
"in",
"list",
"(",
"...",
")",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/list_.py#L149-L179 | train |
shazow/unstdlib.py | unstdlib/standard/type_.py | is_subclass | 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... | python | 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",
")",
":",
"try",
":",
"return",
"_issubclass",
"(",
"o",
",",
"bases",
")",
"except",
"TypeError",
":",
"pass",
"if",
"not",
"isinstance",
"(",
"o",
",",
"type",
")",
":",
"return",
"False",
"if",
"not",
... | 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... | [
"Similar",
"to",
"the",
"issubclass",
"builtin",
"but",
"does",
"not",
"raise",
"a",
"TypeError",
"if",
"either",
"o",
"or",
"bases",
"is",
"not",
"an",
"instance",
"of",
"type",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/type_.py#L6-L35 | train |
shazow/unstdlib.py | unstdlib/standard/dict_.py | get_many | 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... | python | 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",
"=",
"[",
"]",
")",
":",
"d",
"=",
"d",
"or",
"{",
"}",
"r",
"=",
"[",
"d",
"[",
"k",
"]",
"for",
"k",
"in",
"required",
"]",
"r",... | 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... | [
"Returns",
"a",
"predictable",
"number",
"of",
"elements",
"out",
"of",
"d",
"in",
"a",
"list",
"for",
"auto",
"-",
"expanding",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/dict_.py#L6-L30 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | random_string | 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)]) | python | 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",
"''",
".",
"join",
"(",
"[",
"random",
".",
"choice",
"(",
"alphabet",
")",
"for",
"i",
"in",
"xr... | Return a random string of given length and alphabet.
Default alphabet is url-friendly (base62). | [
"Return",
"a",
"random",
"string",
"of",
"given",
"length",
"and",
"alphabet",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L44-L50 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | number_to_string | 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... | python | 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",
")",
":",
"result",
"=",
"''",
"base",
"=",
"len",
"(",
"alphabet",
")",
"current",
"=",
"int",
"(",
"n",
")",
"if",
"current",
"<",
"0",
":",
"raise",
"ValueError",
"(",
"\"invalid n (must be non-neg... | 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, ... | [
"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",
"."
... | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L53-L83 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | string_to_number | 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
... | python | 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",
")",
":",
"base",
"=",
"len",
"(",
"alphabet",
")",
"inverse_alphabet",
"=",
"dict",
"(",
"zip",
"(",
"alphabet",
",",
"xrange",
"(",
"0",
",",
"base",
")",
")",
")",
"n",
"=",
"0",
"exp",
"=",
... | 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... | [
"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",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L86-L112 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | bytes_to_number | 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... | python | 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'",
")",
":",
"if",
"endian",
"==",
"'big'",
":",
"b",
"=",
"reversed",
"(",
"b",
")",
"n",
"=",
"0",
"for",
"i",
",",
"ch",
"in",
"enumerate",
"(",
"bytearray",
"(",
"b",
")",
")",
"... | 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... | [
"Convert",
"a",
"string",
"to",
"an",
"integer",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L115-L149 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | number_to_bytes | 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... | python | 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'",
")",
":",
"res",
"=",
"[",
"]",
"while",
"n",
":",
"n",
",",
"ch",
"=",
"divmod",
"(",
"n",
",",
"256",
")",
"if",
"PY3",
":",
"res",
".",
"append",
"(",
"ch",
")",
"else",
":",... | 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
... | [
"Convert",
"an",
"integer",
"to",
"a",
"corresponding",
"string",
"of",
"bytes",
".."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L152-L193 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | to_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))
... | python | 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",
")",
":",
"# Note: On py3, ``b'x'.__str__()`` returns ``\"b'x'\"``, so we need to do the",
"# explicit check first.",
"if",
"isinstance",
"(",
"obj",
",",
"binary_type",
")",
":"... | 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))
... | [
"r",
"Returns",
"a",
"str",
"of",
"obj",
"encoding",
"using",
"encoding",
"if",
"necessary",
".",
"For",
"example",
"::"
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L196-L227 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | to_unicode | 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'
... | python | 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",
")",
":",
"# Note: on py3, the `bytes` type defines an unhelpful \"__str__\" function,",
"# so we need to do this check (see comments in ``to_str``)... | 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'... | [
"r",
"Returns",
"a",
"unicode",
"of",
"obj",
"decoding",
"using",
"encoding",
"if",
"necessary",
".",
"If",
"decoding",
"fails",
"the",
"fallback",
"encoding",
"(",
"default",
"latin1",
")",
"is",
"used",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L230-L264 | train |
shazow/unstdlib.py | unstdlib/standard/string_.py | to_float | 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_... | python | 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",
")",
":",
"try",
":",
"f",
"=",
"float",
"(",
"s",
")",
"except",
"(",
"TypeError",
",",
"ValueError",
")",
":",
"return",
"default",
"if",
"not",
"allow_nan",
... | 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
... | [
"Return",
"input",
"converted",
"into",
"a",
"float",
".",
"If",
"failed",
"then",
"return",
"default",
"."
] | e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83 | https://github.com/shazow/unstdlib.py/blob/e0632fe165cfbfdb5a7e4bc7b412c9d6f2ebad83/unstdlib/standard/string_.py#L294-L329 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.