partition
stringclasses
3 values
func_name
stringlengths
1
134
docstring
stringlengths
1
46.9k
path
stringlengths
4
223
original_string
stringlengths
75
104k
code
stringlengths
75
104k
docstring_tokens
listlengths
1
1.97k
repo
stringlengths
7
55
language
stringclasses
1 value
url
stringlengths
87
315
code_tokens
listlengths
19
28.4k
sha
stringlengths
40
40
test
convert_to_theano_var
Convert neural vars to theano vars. :param obj: NeuralVariable or list or dict or tuple :return: theano var, test var, tensor found, neural var found
deepy/core/tensor_conversion.py
def convert_to_theano_var(obj): """ Convert neural vars to theano vars. :param obj: NeuralVariable or list or dict or tuple :return: theano var, test var, tensor found, neural var found """ from deepy.core.neural_var import NeuralVariable if type(obj) == tuple: return tuple(convert_t...
def convert_to_theano_var(obj): """ Convert neural vars to theano vars. :param obj: NeuralVariable or list or dict or tuple :return: theano var, test var, tensor found, neural var found """ from deepy.core.neural_var import NeuralVariable if type(obj) == tuple: return tuple(convert_t...
[ "Convert", "neural", "vars", "to", "theano", "vars", ".", ":", "param", "obj", ":", "NeuralVariable", "or", "list", "or", "dict", "or", "tuple", ":", "return", ":", "theano", "var", "test", "var", "tensor", "found", "neural", "var", "found" ]
zomux/deepy
python
https://github.com/zomux/deepy/blob/090fbad22a08a809b12951cd0d4984f5bd432698/deepy/core/tensor_conversion.py#L7-L64
[ "def", "convert_to_theano_var", "(", "obj", ")", ":", "from", "deepy", ".", "core", ".", "neural_var", "import", "NeuralVariable", "if", "type", "(", "obj", ")", "==", "tuple", ":", "return", "tuple", "(", "convert_to_theano_var", "(", "list", "(", "obj", ...
090fbad22a08a809b12951cd0d4984f5bd432698
test
convert_to_neural_var
Convert object and a test object into neural var. :param obj: tensor or list or dict or tuple :param test_obj: NeuralVar or list or dict or tuple :return:
deepy/core/tensor_conversion.py
def convert_to_neural_var(obj): """ Convert object and a test object into neural var. :param obj: tensor or list or dict or tuple :param test_obj: NeuralVar or list or dict or tuple :return: """ from theano.tensor.var import TensorVariable from deepy.core.neural_var import NeuralVariable...
def convert_to_neural_var(obj): """ Convert object and a test object into neural var. :param obj: tensor or list or dict or tuple :param test_obj: NeuralVar or list or dict or tuple :return: """ from theano.tensor.var import TensorVariable from deepy.core.neural_var import NeuralVariable...
[ "Convert", "object", "and", "a", "test", "object", "into", "neural", "var", ".", ":", "param", "obj", ":", "tensor", "or", "list", "or", "dict", "or", "tuple", ":", "param", "test_obj", ":", "NeuralVar", "or", "list", "or", "dict", "or", "tuple", ":", ...
zomux/deepy
python
https://github.com/zomux/deepy/blob/090fbad22a08a809b12951cd0d4984f5bd432698/deepy/core/tensor_conversion.py#L66-L95
[ "def", "convert_to_neural_var", "(", "obj", ")", ":", "from", "theano", ".", "tensor", ".", "var", "import", "TensorVariable", "from", "deepy", ".", "core", ".", "neural_var", "import", "NeuralVariable", "if", "type", "(", "obj", ")", "==", "list", ":", "r...
090fbad22a08a809b12951cd0d4984f5bd432698
test
neural_computation
An annotation to enable theano-based fucntions to be called with NeuralVar. :param original_func: :param prefer_tensor: a switch to return tensors when no inputs :return:
deepy/core/tensor_conversion.py
def neural_computation(original_func, prefer_tensor=False): """ An annotation to enable theano-based fucntions to be called with NeuralVar. :param original_func: :param prefer_tensor: a switch to return tensors when no inputs :return: """ def wrapper(*args, **kwargs): normal_args, t...
def neural_computation(original_func, prefer_tensor=False): """ An annotation to enable theano-based fucntions to be called with NeuralVar. :param original_func: :param prefer_tensor: a switch to return tensors when no inputs :return: """ def wrapper(*args, **kwargs): normal_args, t...
[ "An", "annotation", "to", "enable", "theano", "-", "based", "fucntions", "to", "be", "called", "with", "NeuralVar", ".", ":", "param", "original_func", ":", ":", "param", "prefer_tensor", ":", "a", "switch", "to", "return", "tensors", "when", "no", "inputs",...
zomux/deepy
python
https://github.com/zomux/deepy/blob/090fbad22a08a809b12951cd0d4984f5bd432698/deepy/core/tensor_conversion.py#L97-L129
[ "def", "neural_computation", "(", "original_func", ",", "prefer_tensor", "=", "False", ")", ":", "def", "wrapper", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "normal_args", ",", "tensor_found_in_args", ",", "neural_found_in_args", "=", "convert_to_thea...
090fbad22a08a809b12951cd0d4984f5bd432698
test
onehot_tensor
# batch x time
deepy/tensor/onehot.py
def onehot_tensor(i_matrix, vocab_size): """ # batch x time """ dim0, dim1 = i_matrix.shape i_vector = i_matrix.reshape((-1,)) hot_matrix = T.extra_ops.to_one_hot(i_vector, vocab_size).reshape((dim0, dim1, vocab_size)) return hot_matrix
def onehot_tensor(i_matrix, vocab_size): """ # batch x time """ dim0, dim1 = i_matrix.shape i_vector = i_matrix.reshape((-1,)) hot_matrix = T.extra_ops.to_one_hot(i_vector, vocab_size).reshape((dim0, dim1, vocab_size)) return hot_matrix
[ "#", "batch", "x", "time" ]
zomux/deepy
python
https://github.com/zomux/deepy/blob/090fbad22a08a809b12951cd0d4984f5bd432698/deepy/tensor/onehot.py#L9-L16
[ "def", "onehot_tensor", "(", "i_matrix", ",", "vocab_size", ")", ":", "dim0", ",", "dim1", "=", "i_matrix", ".", "shape", "i_vector", "=", "i_matrix", ".", "reshape", "(", "(", "-", "1", ",", ")", ")", "hot_matrix", "=", "T", ".", "extra_ops", ".", "...
090fbad22a08a809b12951cd0d4984f5bd432698
test
OAuth2.create_request_elements
Creates |oauth2| request elements.
authomatic/providers/oauth2.py
def create_request_elements( cls, request_type, credentials, url, method='GET', params=None, headers=None, body='', secret=None, redirect_uri='', scope='', csrf='', user_state='' ): """ Creates |oauth2| request elements. """ headers = headers or {...
def create_request_elements( cls, request_type, credentials, url, method='GET', params=None, headers=None, body='', secret=None, redirect_uri='', scope='', csrf='', user_state='' ): """ Creates |oauth2| request elements. """ headers = headers or {...
[ "Creates", "|oauth2|", "request", "elements", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth2.py#L115-L215
[ "def", "create_request_elements", "(", "cls", ",", "request_type", ",", "credentials", ",", "url", ",", "method", "=", "'GET'", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "body", "=", "''", ",", "secret", "=", "None", ",", "redirect_ur...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
OAuth2.decode_state
Decode state and return param. :param str state: state parameter passed through by provider :param str param: key to query from decoded state variable. Options include 'csrf' and 'user_state'. :returns: string value from decoded state
authomatic/providers/oauth2.py
def decode_state(cls, state, param='user_state'): """ Decode state and return param. :param str state: state parameter passed through by provider :param str param: key to query from decoded state variable. Options include 'csrf' and 'user_state'. ...
def decode_state(cls, state, param='user_state'): """ Decode state and return param. :param str state: state parameter passed through by provider :param str param: key to query from decoded state variable. Options include 'csrf' and 'user_state'. ...
[ "Decode", "state", "and", "return", "param", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth2.py#L262-L284
[ "def", "decode_state", "(", "cls", ",", "state", ",", "param", "=", "'user_state'", ")", ":", "if", "state", "and", "cls", ".", "supports_user_state", ":", "# urlsafe_b64 may include = which the browser quotes so must", "# unquote Cast to str to void b64decode translation err...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
OAuth2.refresh_credentials
Refreshes :class:`.Credentials` if it gives sense. :param credentials: :class:`.Credentials` to be refreshed. :returns: :class:`.Response`.
authomatic/providers/oauth2.py
def refresh_credentials(self, credentials): """ Refreshes :class:`.Credentials` if it gives sense. :param credentials: :class:`.Credentials` to be refreshed. :returns: :class:`.Response`. """ if not self._x_refresh_credentials_if(credentials): ...
def refresh_credentials(self, credentials): """ Refreshes :class:`.Credentials` if it gives sense. :param credentials: :class:`.Credentials` to be refreshed. :returns: :class:`.Response`. """ if not self._x_refresh_credentials_if(credentials): ...
[ "Refreshes", ":", "class", ":", ".", "Credentials", "if", "it", "gives", "sense", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth2.py#L286-L337
[ "def", "refresh_credentials", "(", "self", ",", "credentials", ")", ":", "if", "not", "self", ".", "_x_refresh_credentials_if", "(", "credentials", ")", ":", "return", "# We need consumer key and secret to make this kind of request.", "cfg", "=", "credentials", ".", "co...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Facebook._x_credentials_parser
We need to override this method to fix Facebooks naming deviation.
authomatic/providers/oauth2.py
def _x_credentials_parser(credentials, data): """ We need to override this method to fix Facebooks naming deviation. """ # Facebook returns "expires" instead of "expires_in". credentials.expire_in = data.get('expires') if data.get('token_type') == 'bearer': ...
def _x_credentials_parser(credentials, data): """ We need to override this method to fix Facebooks naming deviation. """ # Facebook returns "expires" instead of "expires_in". credentials.expire_in = data.get('expires') if data.get('token_type') == 'bearer': ...
[ "We", "need", "to", "override", "this", "method", "to", "fix", "Facebooks", "naming", "deviation", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth2.py#L976-L988
[ "def", "_x_credentials_parser", "(", "credentials", ",", "data", ")", ":", "# Facebook returns \"expires\" instead of \"expires_in\".", "credentials", ".", "expire_in", "=", "data", ".", "get", "(", "'expires'", ")", "if", "data", ".", "get", "(", "'token_type'", ")...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Google._x_request_elements_filter
Google doesn't accept client ID and secret to be at the same time in request parameters and in the basic authorization header in the access token request.
authomatic/providers/oauth2.py
def _x_request_elements_filter(cls, request_type, request_elements, credentials): """ Google doesn't accept client ID and secret to be at the same time in request parameters and in the basic authorization header in the access token request. """ ...
def _x_request_elements_filter(cls, request_type, request_elements, credentials): """ Google doesn't accept client ID and secret to be at the same time in request parameters and in the basic authorization header in the access token request. """ ...
[ "Google", "doesn", "t", "accept", "client", "ID", "and", "secret", "to", "be", "at", "the", "same", "time", "in", "request", "parameters", "and", "in", "the", "basic", "authorization", "header", "in", "the", "access", "token", "request", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth2.py#L1283-L1294
[ "def", "_x_request_elements_filter", "(", "cls", ",", "request_type", ",", "request_elements", ",", "credentials", ")", ":", "if", "request_type", "is", "cls", ".", "ACCESS_TOKEN_REQUEST_TYPE", ":", "params", "=", "request_elements", "[", "2", "]", "del", "params"...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
login
Login handler, must accept both GET and POST to be able to use OpenID.
examples/flask/werkzeug_adapter/main.py
def login(provider_name): """ Login handler, must accept both GET and POST to be able to use OpenID. """ # We need response object for the WerkzeugAdapter. response = make_response() # Log the user in, pass it the adapter and the provider name. result = authomatic.login( WerkzeugAd...
def login(provider_name): """ Login handler, must accept both GET and POST to be able to use OpenID. """ # We need response object for the WerkzeugAdapter. response = make_response() # Log the user in, pass it the adapter and the provider name. result = authomatic.login( WerkzeugAd...
[ "Login", "handler", "must", "accept", "both", "GET", "and", "POST", "to", "be", "able", "to", "use", "OpenID", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/examples/flask/werkzeug_adapter/main.py#L29-L54
[ "def", "login", "(", "provider_name", ")", ":", "# We need response object for the WerkzeugAdapter.", "response", "=", "make_response", "(", ")", "# Log the user in, pass it the adapter and the provider name.", "result", "=", "authomatic", ".", "login", "(", "WerkzeugAdapter", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
normalize_dict
Replaces all values that are single-item iterables with the value of its index 0. :param dict dict_: Dictionary to normalize. :returns: Normalized dictionary.
authomatic/core.py
def normalize_dict(dict_): """ Replaces all values that are single-item iterables with the value of its index 0. :param dict dict_: Dictionary to normalize. :returns: Normalized dictionary. """ return dict([(k, v[0] if not isinstance(v, str) and len(v) == 1 else v) ...
def normalize_dict(dict_): """ Replaces all values that are single-item iterables with the value of its index 0. :param dict dict_: Dictionary to normalize. :returns: Normalized dictionary. """ return dict([(k, v[0] if not isinstance(v, str) and len(v) == 1 else v) ...
[ "Replaces", "all", "values", "that", "are", "single", "-", "item", "iterables", "with", "the", "value", "of", "its", "index", "0", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L40-L54
[ "def", "normalize_dict", "(", "dict_", ")", ":", "return", "dict", "(", "[", "(", "k", ",", "v", "[", "0", "]", "if", "not", "isinstance", "(", "v", ",", "str", ")", "and", "len", "(", "v", ")", "==", "1", "else", "v", ")", "for", "k", ",", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
items_to_dict
Converts list of tuples to dictionary with duplicate keys converted to lists. :param list items: List of tuples. :returns: :class:`dict`
authomatic/core.py
def items_to_dict(items): """ Converts list of tuples to dictionary with duplicate keys converted to lists. :param list items: List of tuples. :returns: :class:`dict` """ res = collections.defaultdict(list) for k, v in items: res[k].append(v) return norm...
def items_to_dict(items): """ Converts list of tuples to dictionary with duplicate keys converted to lists. :param list items: List of tuples. :returns: :class:`dict` """ res = collections.defaultdict(list) for k, v in items: res[k].append(v) return norm...
[ "Converts", "list", "of", "tuples", "to", "dictionary", "with", "duplicate", "keys", "converted", "to", "lists", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L57-L75
[ "def", "items_to_dict", "(", "items", ")", ":", "res", "=", "collections", ".", "defaultdict", "(", "list", ")", "for", "k", ",", "v", "in", "items", ":", "res", "[", "k", "]", ".", "append", "(", "v", ")", "return", "normalize_dict", "(", "dict", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
json_qs_parser
Parses response body from JSON, XML or query string. :param body: string :returns: :class:`dict`, :class:`list` if input is JSON or query string, :class:`xml.etree.ElementTree.Element` if XML.
authomatic/core.py
def json_qs_parser(body): """ Parses response body from JSON, XML or query string. :param body: string :returns: :class:`dict`, :class:`list` if input is JSON or query string, :class:`xml.etree.ElementTree.Element` if XML. """ try: # Try JSON first. ret...
def json_qs_parser(body): """ Parses response body from JSON, XML or query string. :param body: string :returns: :class:`dict`, :class:`list` if input is JSON or query string, :class:`xml.etree.ElementTree.Element` if XML. """ try: # Try JSON first. ret...
[ "Parses", "response", "body", "from", "JSON", "XML", "or", "query", "string", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L143-L168
[ "def", "json_qs_parser", "(", "body", ")", ":", "try", ":", "# Try JSON first.", "return", "json", ".", "loads", "(", "body", ")", "except", "(", "OverflowError", ",", "TypeError", ",", "ValueError", ")", ":", "pass", "try", ":", "# Then XML.", "return", "...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
resolve_provider_class
Returns a provider class. :param class_name: :class:`string` or :class:`authomatic.providers.BaseProvider` subclass.
authomatic/core.py
def resolve_provider_class(class_): """ Returns a provider class. :param class_name: :class:`string` or :class:`authomatic.providers.BaseProvider` subclass. """ if isinstance(class_, str): # prepare path for authomatic.providers package path = '.'.join([__package__, 'providers...
def resolve_provider_class(class_): """ Returns a provider class. :param class_name: :class:`string` or :class:`authomatic.providers.BaseProvider` subclass. """ if isinstance(class_, str): # prepare path for authomatic.providers package path = '.'.join([__package__, 'providers...
[ "Returns", "a", "provider", "class", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L192-L209
[ "def", "resolve_provider_class", "(", "class_", ")", ":", "if", "isinstance", "(", "class_", ",", "str", ")", ":", "# prepare path for authomatic.providers package", "path", "=", "'.'", ".", "join", "(", "[", "__package__", ",", "'providers'", ",", "class_", "]"...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
id_to_name
Returns the provider :doc:`config` key based on it's ``id`` value. :param dict config: :doc:`config`. :param id: Value of the id parameter in the :ref:`config` to search for.
authomatic/core.py
def id_to_name(config, short_name): """ Returns the provider :doc:`config` key based on it's ``id`` value. :param dict config: :doc:`config`. :param id: Value of the id parameter in the :ref:`config` to search for. """ for k, v in list(config.items()): if v.get('id') =...
def id_to_name(config, short_name): """ Returns the provider :doc:`config` key based on it's ``id`` value. :param dict config: :doc:`config`. :param id: Value of the id parameter in the :ref:`config` to search for. """ for k, v in list(config.items()): if v.get('id') =...
[ "Returns", "the", "provider", ":", "doc", ":", "config", "key", "based", "on", "it", "s", "id", "value", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L212-L228
[ "def", "id_to_name", "(", "config", ",", "short_name", ")", ":", "for", "k", ",", "v", "in", "list", "(", "config", ".", "items", "(", ")", ")", ":", "if", "v", ".", "get", "(", "'id'", ")", "==", "short_name", ":", "return", "k", "raise", "Excep...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session.create_cookie
Creates the value for ``Set-Cookie`` HTTP header. :param bool delete: If ``True`` the cookie value will be ``deleted`` and the Expires value will be ``Thu, 01-Jan-1970 00:00:01 GMT``.
authomatic/core.py
def create_cookie(self, delete=None): """ Creates the value for ``Set-Cookie`` HTTP header. :param bool delete: If ``True`` the cookie value will be ``deleted`` and the Expires value will be ``Thu, 01-Jan-1970 00:00:01 GMT``. """ value = 'deleted' if del...
def create_cookie(self, delete=None): """ Creates the value for ``Set-Cookie`` HTTP header. :param bool delete: If ``True`` the cookie value will be ``deleted`` and the Expires value will be ``Thu, 01-Jan-1970 00:00:01 GMT``. """ value = 'deleted' if del...
[ "Creates", "the", "value", "for", "Set", "-", "Cookie", "HTTP", "header", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L364-L392
[ "def", "create_cookie", "(", "self", ",", "delete", "=", "None", ")", ":", "value", "=", "'deleted'", "if", "delete", "else", "self", ".", "_serialize", "(", "self", ".", "data", ")", "split_url", "=", "parse", ".", "urlsplit", "(", "self", ".", "adapt...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session.save
Adds the session cookie to headers.
authomatic/core.py
def save(self): """ Adds the session cookie to headers. """ if self.data: cookie = self.create_cookie() cookie_len = len(cookie) if cookie_len > 4093: raise SessionError('Cookie too long! The cookie size {0} ' ...
def save(self): """ Adds the session cookie to headers. """ if self.data: cookie = self.create_cookie() cookie_len = len(cookie) if cookie_len > 4093: raise SessionError('Cookie too long! The cookie size {0} ' ...
[ "Adds", "the", "session", "cookie", "to", "headers", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L394-L410
[ "def", "save", "(", "self", ")", ":", "if", "self", ".", "data", ":", "cookie", "=", "self", ".", "create_cookie", "(", ")", "cookie_len", "=", "len", "(", "cookie", ")", "if", "cookie_len", ">", "4093", ":", "raise", "SessionError", "(", "'Cookie too ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session._get_data
Extracts the session data from cookie.
authomatic/core.py
def _get_data(self): """ Extracts the session data from cookie. """ cookie = self.adapter.cookies.get(self.name) return self._deserialize(cookie) if cookie else {}
def _get_data(self): """ Extracts the session data from cookie. """ cookie = self.adapter.cookies.get(self.name) return self._deserialize(cookie) if cookie else {}
[ "Extracts", "the", "session", "data", "from", "cookie", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L415-L420
[ "def", "_get_data", "(", "self", ")", ":", "cookie", "=", "self", ".", "adapter", ".", "cookies", ".", "get", "(", "self", ".", "name", ")", "return", "self", ".", "_deserialize", "(", "cookie", ")", "if", "cookie", "else", "{", "}" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session.data
Gets session data lazily.
authomatic/core.py
def data(self): """ Gets session data lazily. """ if not self._data: self._data = self._get_data() # Always return a dict, even if deserialization returned nothing if self._data is None: self._data = {} return self._data
def data(self): """ Gets session data lazily. """ if not self._data: self._data = self._get_data() # Always return a dict, even if deserialization returned nothing if self._data is None: self._data = {} return self._data
[ "Gets", "session", "data", "lazily", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L423-L432
[ "def", "data", "(", "self", ")", ":", "if", "not", "self", ".", "_data", ":", "self", ".", "_data", "=", "self", ".", "_get_data", "(", ")", "# Always return a dict, even if deserialization returned nothing", "if", "self", ".", "_data", "is", "None", ":", "s...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session._signature
Creates signature for the session.
authomatic/core.py
def _signature(self, *parts): """ Creates signature for the session. """ signature = hmac.new(six.b(self.secret), digestmod=hashlib.sha1) signature.update(six.b('|'.join(parts))) return signature.hexdigest()
def _signature(self, *parts): """ Creates signature for the session. """ signature = hmac.new(six.b(self.secret), digestmod=hashlib.sha1) signature.update(six.b('|'.join(parts))) return signature.hexdigest()
[ "Creates", "signature", "for", "the", "session", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L434-L440
[ "def", "_signature", "(", "self", ",", "*", "parts", ")", ":", "signature", "=", "hmac", ".", "new", "(", "six", ".", "b", "(", "self", ".", "secret", ")", ",", "digestmod", "=", "hashlib", ".", "sha1", ")", "signature", ".", "update", "(", "six", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session._serialize
Converts the value to a signed string with timestamp. :param value: Object to be serialized. :returns: Serialized value.
authomatic/core.py
def _serialize(self, value): """ Converts the value to a signed string with timestamp. :param value: Object to be serialized. :returns: Serialized value. """ # data = copy.deepcopy(value) data = value # 1. Serialize ser...
def _serialize(self, value): """ Converts the value to a signed string with timestamp. :param value: Object to be serialized. :returns: Serialized value. """ # data = copy.deepcopy(value) data = value # 1. Serialize ser...
[ "Converts", "the", "value", "to", "a", "signed", "string", "with", "timestamp", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L442-L469
[ "def", "_serialize", "(", "self", ",", "value", ")", ":", "# data = copy.deepcopy(value)", "data", "=", "value", "# 1. Serialize", "serialized", "=", "pickle", ".", "dumps", "(", "data", ")", ".", "decode", "(", "'latin-1'", ")", "# 2. Encode", "# Percent encodi...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Session._deserialize
Deserializes and verifies the value created by :meth:`._serialize`. :param str value: The serialized value. :returns: Deserialized object.
authomatic/core.py
def _deserialize(self, value): """ Deserializes and verifies the value created by :meth:`._serialize`. :param str value: The serialized value. :returns: Deserialized object. """ # 3. Split encoded, timestamp, signature = value.split('|'...
def _deserialize(self, value): """ Deserializes and verifies the value created by :meth:`._serialize`. :param str value: The serialized value. :returns: Deserialized object. """ # 3. Split encoded, timestamp, signature = value.split('|'...
[ "Deserializes", "and", "verifies", "the", "value", "created", "by", ":", "meth", ":", ".", "_serialize", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L471-L500
[ "def", "_deserialize", "(", "self", ",", "value", ")", ":", "# 3. Split", "encoded", ",", "timestamp", ",", "signature", "=", "value", ".", "split", "(", "'|'", ")", "# Verify signature", "if", "not", "signature", "==", "self", ".", "_signature", "(", "sel...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
User.to_dict
Converts the :class:`.User` instance to a :class:`dict`. :returns: :class:`dict`
authomatic/core.py
def to_dict(self): """ Converts the :class:`.User` instance to a :class:`dict`. :returns: :class:`dict` """ # copy the dictionary d = copy.copy(self.__dict__) # Keep only the provider name to avoid circular reference d['provider'] = self.pr...
def to_dict(self): """ Converts the :class:`.User` instance to a :class:`dict`. :returns: :class:`dict` """ # copy the dictionary d = copy.copy(self.__dict__) # Keep only the provider name to avoid circular reference d['provider'] = self.pr...
[ "Converts", "the", ":", "class", ":", ".", "User", "instance", "to", "a", ":", "class", ":", "dict", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L608-L632
[ "def", "to_dict", "(", "self", ")", ":", "# copy the dictionary", "d", "=", "copy", ".", "copy", "(", "self", ".", "__dict__", ")", "# Keep only the provider name to avoid circular reference", "d", "[", "'provider'", "]", "=", "self", ".", "provider", ".", "name...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Credentials.expire_in
Computes :attr:`.expiration_time` when the value is set.
authomatic/core.py
def expire_in(self, value): """ Computes :attr:`.expiration_time` when the value is set. """ # pylint:disable=attribute-defined-outside-init if value: self._expiration_time = int(time.time()) + int(value) self._expire_in = value
def expire_in(self, value): """ Computes :attr:`.expiration_time` when the value is set. """ # pylint:disable=attribute-defined-outside-init if value: self._expiration_time = int(time.time()) + int(value) self._expire_in = value
[ "Computes", ":", "attr", ":", ".", "expiration_time", "when", "the", "value", "is", "set", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L727-L735
[ "def", "expire_in", "(", "self", ",", "value", ")", ":", "# pylint:disable=attribute-defined-outside-init", "if", "value", ":", "self", ".", "_expiration_time", "=", "int", "(", "time", ".", "time", "(", ")", ")", "+", "int", "(", "value", ")", "self", "."...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Credentials.valid
``True`` if credentials are valid, ``False`` if expired.
authomatic/core.py
def valid(self): """ ``True`` if credentials are valid, ``False`` if expired. """ if self.expiration_time: return self.expiration_time > int(time.time()) else: return True
def valid(self): """ ``True`` if credentials are valid, ``False`` if expired. """ if self.expiration_time: return self.expiration_time > int(time.time()) else: return True
[ "True", "if", "credentials", "are", "valid", "False", "if", "expired", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L761-L769
[ "def", "valid", "(", "self", ")", ":", "if", "self", ".", "expiration_time", ":", "return", "self", ".", "expiration_time", ">", "int", "(", "time", ".", "time", "(", ")", ")", "else", ":", "return", "True" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Credentials.expire_soon
Returns ``True`` if credentials expire sooner than specified. :param int seconds: Number of seconds. :returns: ``True`` if credentials expire sooner than specified, else ``False``.
authomatic/core.py
def expire_soon(self, seconds): """ Returns ``True`` if credentials expire sooner than specified. :param int seconds: Number of seconds. :returns: ``True`` if credentials expire sooner than specified, else ``False``. """ if self.exp...
def expire_soon(self, seconds): """ Returns ``True`` if credentials expire sooner than specified. :param int seconds: Number of seconds. :returns: ``True`` if credentials expire sooner than specified, else ``False``. """ if self.exp...
[ "Returns", "True", "if", "credentials", "expire", "sooner", "than", "specified", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L771-L787
[ "def", "expire_soon", "(", "self", ",", "seconds", ")", ":", "if", "self", ".", "expiration_time", ":", "return", "self", ".", "expiration_time", "<", "int", "(", "time", ".", "time", "(", ")", ")", "+", "int", "(", "seconds", ")", "else", ":", "retu...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Credentials.refresh
Refreshes the credentials only if the **provider** supports it and if it will expire in less than one day. It does nothing in other cases. .. note:: The credentials will be refreshed only if it gives sense i.e. only |oauth2|_ has the notion of credentials *refreshme...
authomatic/core.py
def refresh(self, force=False, soon=86400): """ Refreshes the credentials only if the **provider** supports it and if it will expire in less than one day. It does nothing in other cases. .. note:: The credentials will be refreshed only if it gives sense i.e. onl...
def refresh(self, force=False, soon=86400): """ Refreshes the credentials only if the **provider** supports it and if it will expire in less than one day. It does nothing in other cases. .. note:: The credentials will be refreshed only if it gives sense i.e. onl...
[ "Refreshes", "the", "credentials", "only", "if", "the", "**", "provider", "**", "supports", "it", "and", "if", "it", "will", "expire", "in", "less", "than", "one", "day", ".", "It", "does", "nothing", "in", "other", "cases", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L789-L818
[ "def", "refresh", "(", "self", ",", "force", "=", "False", ",", "soon", "=", "86400", ")", ":", "if", "hasattr", "(", "self", ".", "provider_class", ",", "'refresh_credentials'", ")", ":", "if", "force", "or", "self", ".", "expire_soon", "(", "soon", "...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Credentials.serialize
Converts the credentials to a percent encoded string to be stored for later use. :returns: :class:`string`
authomatic/core.py
def serialize(self): """ Converts the credentials to a percent encoded string to be stored for later use. :returns: :class:`string` """ if self.provider_id is None: raise ConfigError( 'To serialize credentials you need to specify...
def serialize(self): """ Converts the credentials to a percent encoded string to be stored for later use. :returns: :class:`string` """ if self.provider_id is None: raise ConfigError( 'To serialize credentials you need to specify...
[ "Converts", "the", "credentials", "to", "a", "percent", "encoded", "string", "to", "be", "stored", "for", "later", "use", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L847-L876
[ "def", "serialize", "(", "self", ")", ":", "if", "self", ".", "provider_id", "is", "None", ":", "raise", "ConfigError", "(", "'To serialize credentials you need to specify a '", "'unique integer under the \"id\" key in the config '", "'for each provider!'", ")", "# Get the pr...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Credentials.deserialize
A *class method* which reconstructs credentials created by :meth:`serialize`. You can also pass it a :class:`.Credentials` instance. :param dict config: The same :doc:`config` used in the :func:`.login` to get the credentials. :param str credentials: ...
authomatic/core.py
def deserialize(cls, config, credentials): """ A *class method* which reconstructs credentials created by :meth:`serialize`. You can also pass it a :class:`.Credentials` instance. :param dict config: The same :doc:`config` used in the :func:`.login` to get the ...
def deserialize(cls, config, credentials): """ A *class method* which reconstructs credentials created by :meth:`serialize`. You can also pass it a :class:`.Credentials` instance. :param dict config: The same :doc:`config` used in the :func:`.login` to get the ...
[ "A", "*", "class", "method", "*", "which", "reconstructs", "credentials", "created", "by", ":", "meth", ":", "serialize", ".", "You", "can", "also", "pass", "it", "a", ":", "class", ":", ".", "Credentials", "instance", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L879-L928
[ "def", "deserialize", "(", "cls", ",", "config", ",", "credentials", ")", ":", "# Accept both serialized and normal.", "if", "isinstance", "(", "credentials", ",", "Credentials", ")", ":", "return", "credentials", "decoded", "=", "parse", ".", "unquote", "(", "c...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
LoginResult.popup_js
Returns JavaScript that: #. Triggers the ``options.onLoginComplete(result, closer)`` handler set with the :ref:`authomatic.setup() <js_setup>` function of :ref:`javascript.js <js>`. #. Calls the JavasScript callback specified by :data:`callback_name` on the opener ...
authomatic/core.py
def popup_js(self, callback_name=None, indent=None, custom=None, stay_open=False): """ Returns JavaScript that: #. Triggers the ``options.onLoginComplete(result, closer)`` handler set with the :ref:`authomatic.setup() <js_setup>` function of :ref:`javas...
def popup_js(self, callback_name=None, indent=None, custom=None, stay_open=False): """ Returns JavaScript that: #. Triggers the ``options.onLoginComplete(result, closer)`` handler set with the :ref:`authomatic.setup() <js_setup>` function of :ref:`javas...
[ "Returns", "JavaScript", "that", ":" ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L943-L1004
[ "def", "popup_js", "(", "self", ",", "callback_name", "=", "None", ",", "indent", "=", "None", ",", "custom", "=", "None", ",", "stay_open", "=", "False", ")", ":", "custom_callback", "=", "\"\"\"\n try {{ window.opener.{cb}(result, closer); }} catch(e) {{}}\n ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
LoginResult.popup_html
Returns a HTML with JavaScript that: #. Triggers the ``options.onLoginComplete(result, closer)`` handler set with the :ref:`authomatic.setup() <js_setup>` function of :ref:`javascript.js <js>`. #. Calls the JavasScript callback specified by :data:`callback_name` on...
authomatic/core.py
def popup_html(self, callback_name=None, indent=None, title='Login | {0}', custom=None, stay_open=False): """ Returns a HTML with JavaScript that: #. Triggers the ``options.onLoginComplete(result, closer)`` handler set with the :ref:`authomatic.setup() <js_setup>...
def popup_html(self, callback_name=None, indent=None, title='Login | {0}', custom=None, stay_open=False): """ Returns a HTML with JavaScript that: #. Triggers the ``options.onLoginComplete(result, closer)`` handler set with the :ref:`authomatic.setup() <js_setup>...
[ "Returns", "a", "HTML", "with", "JavaScript", "that", ":" ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1006-L1058
[ "def", "popup_html", "(", "self", ",", "callback_name", "=", "None", ",", "indent", "=", "None", ",", "title", "=", "'Login | {0}'", ",", "custom", "=", "None", ",", "stay_open", "=", "False", ")", ":", "return", "\"\"\"\n <!DOCTYPE html>\n <html>\...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Response.is_binary_string
Return true if string is binary data.
authomatic/core.py
def is_binary_string(content): """ Return true if string is binary data. """ textchars = (bytearray([7, 8, 9, 10, 12, 13, 27]) + bytearray(range(0x20, 0x100))) return bool(content.translate(None, textchars))
def is_binary_string(content): """ Return true if string is binary data. """ textchars = (bytearray([7, 8, 9, 10, 12, 13, 27]) + bytearray(range(0x20, 0x100))) return bool(content.translate(None, textchars))
[ "Return", "true", "if", "string", "is", "binary", "data", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1142-L1149
[ "def", "is_binary_string", "(", "content", ")", ":", "textchars", "=", "(", "bytearray", "(", "[", "7", ",", "8", ",", "9", ",", "10", ",", "12", ",", "13", ",", "27", "]", ")", "+", "bytearray", "(", "range", "(", "0x20", ",", "0x100", ")", ")...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Response.content
The whole response content.
authomatic/core.py
def content(self): """ The whole response content. """ if not self._content: content = self.httplib_response.read() if self.is_binary_string(content): self._content = content else: self._content = content.decode('utf-8'...
def content(self): """ The whole response content. """ if not self._content: content = self.httplib_response.read() if self.is_binary_string(content): self._content = content else: self._content = content.decode('utf-8'...
[ "The", "whole", "response", "content", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1152-L1163
[ "def", "content", "(", "self", ")", ":", "if", "not", "self", ".", "_content", ":", "content", "=", "self", ".", "httplib_response", ".", "read", "(", ")", "if", "self", ".", "is_binary_string", "(", "content", ")", ":", "self", ".", "_content", "=", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Response.data
A :class:`dict` of data parsed from :attr:`.content`.
authomatic/core.py
def data(self): """ A :class:`dict` of data parsed from :attr:`.content`. """ if not self._data: self._data = self.content_parser(self.content) return self._data
def data(self): """ A :class:`dict` of data parsed from :attr:`.content`. """ if not self._data: self._data = self.content_parser(self.content) return self._data
[ "A", ":", "class", ":", "dict", "of", "data", "parsed", "from", ":", "attr", ":", ".", "content", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1166-L1173
[ "def", "data", "(", "self", ")", ":", "if", "not", "self", ".", "_data", ":", "self", ".", "_data", "=", "self", ".", "content_parser", "(", "self", ".", "content", ")", "return", "self", ".", "_data" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Authomatic.login
If :data:`provider_name` specified, launches the login procedure for corresponding :doc:`provider </reference/providers>` and returns :class:`.LoginResult`. If :data:`provider_name` is empty, acts like :meth:`.Authomatic.backend`. .. warning:: The method redirects ...
authomatic/core.py
def login(self, adapter, provider_name, callback=None, session=None, session_saver=None, **kwargs): """ If :data:`provider_name` specified, launches the login procedure for corresponding :doc:`provider </reference/providers>` and returns :class:`.LoginResult`. If :...
def login(self, adapter, provider_name, callback=None, session=None, session_saver=None, **kwargs): """ If :data:`provider_name` specified, launches the login procedure for corresponding :doc:`provider </reference/providers>` and returns :class:`.LoginResult`. If :...
[ "If", ":", "data", ":", "provider_name", "specified", "launches", "the", "login", "procedure", "for", "corresponding", ":", "doc", ":", "provider", "<", "/", "reference", "/", "providers", ">", "and", "returns", ":", "class", ":", ".", "LoginResult", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1336-L1416
[ "def", "login", "(", "self", ",", "adapter", ",", "provider_name", ",", "callback", "=", "None", ",", "session", "=", "None", ",", "session_saver", "=", "None", ",", "*", "*", "kwargs", ")", ":", "if", "provider_name", ":", "# retrieve required settings for ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Authomatic.access
Accesses **protected resource** on behalf of the **user**. :param credentials: The **user's** :class:`.Credentials` (serialized or normal). :param str url: The **protected resource** URL. :param str method: HTTP method of the request. :param dict h...
authomatic/core.py
def access(self, credentials, url, params=None, method='GET', headers=None, body='', max_redirects=5, content_parser=None): """ Accesses **protected resource** on behalf of the **user**. :param credentials: The **user's** :class:`.Credentials` (serialized or normal). ...
def access(self, credentials, url, params=None, method='GET', headers=None, body='', max_redirects=5, content_parser=None): """ Accesses **protected resource** on behalf of the **user**. :param credentials: The **user's** :class:`.Credentials` (serialized or normal). ...
[ "Accesses", "**", "protected", "resource", "**", "on", "behalf", "of", "the", "**", "user", "**", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1433-L1483
[ "def", "access", "(", "self", ",", "credentials", ",", "url", ",", "params", "=", "None", ",", "method", "=", "'GET'", ",", "headers", "=", "None", ",", "body", "=", "''", ",", "max_redirects", "=", "5", ",", "content_parser", "=", "None", ")", ":", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Authomatic.request_elements
Creates request elements for accessing **protected resource of a user**. Required arguments are :data:`credentials` and :data:`url`. You can pass :data:`credentials`, :data:`url`, :data:`method`, and :data:`params` as a JSON object. :param credentials: The **user's** credent...
authomatic/core.py
def request_elements( self, credentials=None, url=None, method='GET', params=None, headers=None, body='', json_input=None, return_json=False ): """ Creates request elements for accessing **protected resource of a user**. Required arguments are :data:`credentials` and ...
def request_elements( self, credentials=None, url=None, method='GET', params=None, headers=None, body='', json_input=None, return_json=False ): """ Creates request elements for accessing **protected resource of a user**. Required arguments are :data:`credentials` and ...
[ "Creates", "request", "elements", "for", "accessing", "**", "protected", "resource", "of", "a", "user", "**", ".", "Required", "arguments", "are", ":", "data", ":", "credentials", "and", ":", "data", ":", "url", ".", "You", "can", "pass", ":", "data", ":...
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1501-L1608
[ "def", "request_elements", "(", "self", ",", "credentials", "=", "None", ",", "url", "=", "None", ",", "method", "=", "'GET'", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "body", "=", "''", ",", "json_input", "=", "None", ",", "retu...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Authomatic.backend
Converts a *request handler* to a JSON backend which you can use with :ref:`authomatic.js <js>`. Just call it inside a *request handler* like this: :: class JSONHandler(webapp2.RequestHandler): def get(self): authomatic.backend(Webapp2Adapter(se...
authomatic/core.py
def backend(self, adapter): """ Converts a *request handler* to a JSON backend which you can use with :ref:`authomatic.js <js>`. Just call it inside a *request handler* like this: :: class JSONHandler(webapp2.RequestHandler): def get(self): ...
def backend(self, adapter): """ Converts a *request handler* to a JSON backend which you can use with :ref:`authomatic.js <js>`. Just call it inside a *request handler* like this: :: class JSONHandler(webapp2.RequestHandler): def get(self): ...
[ "Converts", "a", "*", "request", "handler", "*", "to", "a", "JSON", "backend", "which", "you", "can", "use", "with", ":", "ref", ":", "authomatic", ".", "js", "<js", ">", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/core.py#L1610-L1764
[ "def", "backend", "(", "self", ",", "adapter", ")", ":", "AUTHOMATIC_HEADER", "=", "'Authomatic-Response-To'", "# Collect request params", "request_type", "=", "adapter", ".", "params", ".", "get", "(", "'type'", ",", "'auto'", ")", "json_input", "=", "adapter", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
_normalize_params
Returns a normalized query string sorted first by key, then by value excluding the ``realm`` and ``oauth_signature`` parameters as specified here: http://oauth.net/core/1.0a/#rfc.section.9.1.1. :param params: :class:`dict` or :class:`list` of tuples.
authomatic/providers/oauth1.py
def _normalize_params(params): """ Returns a normalized query string sorted first by key, then by value excluding the ``realm`` and ``oauth_signature`` parameters as specified here: http://oauth.net/core/1.0a/#rfc.section.9.1.1. :param params: :class:`dict` or :class:`list` of tuples. ...
def _normalize_params(params): """ Returns a normalized query string sorted first by key, then by value excluding the ``realm`` and ``oauth_signature`` parameters as specified here: http://oauth.net/core/1.0a/#rfc.section.9.1.1. :param params: :class:`dict` or :class:`list` of tuples. ...
[ "Returns", "a", "normalized", "query", "string", "sorted", "first", "by", "key", "then", "by", "value", "excluding", "the", "realm", "and", "oauth_signature", "parameters", "as", "specified", "here", ":", "http", ":", "//", "oauth", ".", "net", "/", "core", ...
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth1.py#L61-L88
[ "def", "_normalize_params", "(", "params", ")", ":", "if", "isinstance", "(", "params", ",", "dict", ")", ":", "params", "=", "list", "(", "params", ".", "items", "(", ")", ")", "# remove \"realm\" and \"oauth_signature\"", "params", "=", "sorted", "(", "[",...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
_create_base_string
Returns base string for HMAC-SHA1 signature as specified in: http://oauth.net/core/1.0a/#rfc.section.9.1.3.
authomatic/providers/oauth1.py
def _create_base_string(method, base, params): """ Returns base string for HMAC-SHA1 signature as specified in: http://oauth.net/core/1.0a/#rfc.section.9.1.3. """ normalized_qs = _normalize_params(params) return _join_by_ampersand(method, base, normalized_qs)
def _create_base_string(method, base, params): """ Returns base string for HMAC-SHA1 signature as specified in: http://oauth.net/core/1.0a/#rfc.section.9.1.3. """ normalized_qs = _normalize_params(params) return _join_by_ampersand(method, base, normalized_qs)
[ "Returns", "base", "string", "for", "HMAC", "-", "SHA1", "signature", "as", "specified", "in", ":", "http", ":", "//", "oauth", ".", "net", "/", "core", "/", "1", ".", "0a", "/", "#rfc", ".", "section", ".", "9", ".", "1", ".", "3", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth1.py#L95-L102
[ "def", "_create_base_string", "(", "method", ",", "base", ",", "params", ")", ":", "normalized_qs", "=", "_normalize_params", "(", "params", ")", "return", "_join_by_ampersand", "(", "method", ",", "base", ",", "normalized_qs", ")" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
HMACSHA1SignatureGenerator.create_signature
Returns HMAC-SHA1 signature as specified at: http://oauth.net/core/1.0a/#rfc.section.9.2. :param str method: HTTP method of the request to be signed. :param str base: Base URL of the request without query string an fragment. :param dict params: Dict...
authomatic/providers/oauth1.py
def create_signature(cls, method, base, params, consumer_secret, token_secret=''): """ Returns HMAC-SHA1 signature as specified at: http://oauth.net/core/1.0a/#rfc.section.9.2. :param str method: HTTP method of the request to be signed. :par...
def create_signature(cls, method, base, params, consumer_secret, token_secret=''): """ Returns HMAC-SHA1 signature as specified at: http://oauth.net/core/1.0a/#rfc.section.9.2. :param str method: HTTP method of the request to be signed. :par...
[ "Returns", "HMAC", "-", "SHA1", "signature", "as", "specified", "at", ":", "http", ":", "//", "oauth", ".", "net", "/", "core", "/", "1", ".", "0a", "/", "#rfc", ".", "section", ".", "9", ".", "2", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth1.py#L179-L216
[ "def", "create_signature", "(", "cls", ",", "method", ",", "base", ",", "params", ",", "consumer_secret", ",", "token_secret", "=", "''", ")", ":", "base_string", "=", "_create_base_string", "(", "method", ",", "base", ",", "params", ")", "key", "=", "cls"...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
OAuth1.create_request_elements
Creates |oauth1| request elements.
authomatic/providers/oauth1.py
def create_request_elements( cls, request_type, credentials, url, params=None, headers=None, body='', method='GET', verifier='', callback='' ): """ Creates |oauth1| request elements. """ params = params or {} headers = headers or {} consumer_...
def create_request_elements( cls, request_type, credentials, url, params=None, headers=None, body='', method='GET', verifier='', callback='' ): """ Creates |oauth1| request elements. """ params = params or {} headers = headers or {} consumer_...
[ "Creates", "|oauth1|", "request", "elements", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth1.py#L299-L383
[ "def", "create_request_elements", "(", "cls", ",", "request_type", ",", "credentials", ",", "url", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "body", "=", "''", ",", "method", "=", "'GET'", ",", "verifier", "=", "''", ",", "callback", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Bitbucket._access_user_info
Email is available in separate method so second request is needed.
authomatic/providers/oauth1.py
def _access_user_info(self): """ Email is available in separate method so second request is needed. """ response = super(Bitbucket, self)._access_user_info() response.data.setdefault("email", None) email_response = self.access(self.user_email_url) if email_respo...
def _access_user_info(self): """ Email is available in separate method so second request is needed. """ response = super(Bitbucket, self)._access_user_info() response.data.setdefault("email", None) email_response = self.access(self.user_email_url) if email_respo...
[ "Email", "is", "available", "in", "separate", "method", "so", "second", "request", "is", "needed", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth1.py#L621-L635
[ "def", "_access_user_info", "(", "self", ")", ":", "response", "=", "super", "(", "Bitbucket", ",", "self", ")", ".", "_access_user_info", "(", ")", "response", ".", "data", ".", "setdefault", "(", "\"email\"", ",", "None", ")", "email_response", "=", "sel...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
Vimeo._access_user_info
Vimeo requires the user ID to access the user info endpoint, so we need to make two requests: one to get user ID and second to get user info.
authomatic/providers/oauth1.py
def _access_user_info(self): """ Vimeo requires the user ID to access the user info endpoint, so we need to make two requests: one to get user ID and second to get user info. """ response = super(Vimeo, self)._access_user_info() uid = response.data.get('oauth', {}).get('u...
def _access_user_info(self): """ Vimeo requires the user ID to access the user info endpoint, so we need to make two requests: one to get user ID and second to get user info. """ response = super(Vimeo, self)._access_user_info() uid = response.data.get('oauth', {}).get('u...
[ "Vimeo", "requires", "the", "user", "ID", "to", "access", "the", "user", "info", "endpoint", "so", "we", "need", "to", "make", "two", "requests", ":", "one", "to", "get", "user", "ID", "and", "second", "to", "get", "user", "info", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/oauth1.py#L1089-L1099
[ "def", "_access_user_info", "(", "self", ")", ":", "response", "=", "super", "(", "Vimeo", ",", "self", ")", ".", "_access_user_info", "(", ")", "uid", "=", "response", ".", "data", ".", "get", "(", "'oauth'", ",", "{", "}", ")", ".", "get", "(", "...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
FlaskAuthomatic.login
Decorator for Flask view functions.
authomatic/extras/flask.py
def login(self, *login_args, **login_kwargs): """ Decorator for Flask view functions. """ def decorator(f): @wraps(f) def decorated(*args, **kwargs): self.response = make_response() adapter = WerkzeugAdapter(request, self.response)...
def login(self, *login_args, **login_kwargs): """ Decorator for Flask view functions. """ def decorator(f): @wraps(f) def decorated(*args, **kwargs): self.response = make_response() adapter = WerkzeugAdapter(request, self.response)...
[ "Decorator", "for", "Flask", "view", "functions", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/extras/flask.py#L26-L44
[ "def", "login", "(", "self", ",", "*", "login_args", ",", "*", "*", "login_kwargs", ")", ":", "def", "decorator", "(", "f", ")", ":", "@", "wraps", "(", "f", ")", "def", "decorated", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "self", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
NDBConfig.get
Resembles the :meth:`dict.get` method. :returns: A configuration dictionary for specified provider.
authomatic/extras/gae/__init__.py
def get(cls, key, default=None): """ Resembles the :meth:`dict.get` method. :returns: A configuration dictionary for specified provider. """ # Query datastore. result = cls.query(cls.provider_name == key).get() if result: result_dict = ...
def get(cls, key, default=None): """ Resembles the :meth:`dict.get` method. :returns: A configuration dictionary for specified provider. """ # Query datastore. result = cls.query(cls.provider_name == key).get() if result: result_dict = ...
[ "Resembles", "the", ":", "meth", ":", "dict", ".", "get", "method", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/extras/gae/__init__.py#L128-L157
[ "def", "get", "(", "cls", ",", "key", ",", "default", "=", "None", ")", ":", "# Query datastore.", "result", "=", "cls", ".", "query", "(", "cls", ".", "provider_name", "==", "key", ")", ".", "get", "(", ")", "if", "result", ":", "result_dict", "=", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
NDBConfig.values
Resembles the :meth:`dict.values` method.
authomatic/extras/gae/__init__.py
def values(cls): """ Resembles the :meth:`dict.values` method. """ # get all items results = cls.query().fetch() # return list of dictionaries return [result.to_dict() for result in results]
def values(cls): """ Resembles the :meth:`dict.values` method. """ # get all items results = cls.query().fetch() # return list of dictionaries return [result.to_dict() for result in results]
[ "Resembles", "the", ":", "meth", ":", "dict", ".", "values", "method", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/extras/gae/__init__.py#L160-L168
[ "def", "values", "(", "cls", ")", ":", "# get all items", "results", "=", "cls", ".", "query", "(", ")", ".", "fetch", "(", ")", "# return list of dictionaries", "return", "[", "result", ".", "to_dict", "(", ")", "for", "result", "in", "results", "]" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
NDBConfig.initialize
Creates an **"Example"** entity of kind **"NDBConfig"** in the datastore if the model is empty and raises and error to inform you that you should populate the model with data. .. note:: The *Datastore Viewer* in the ``_ah/admin/`` won't let you add properties to a model...
authomatic/extras/gae/__init__.py
def initialize(cls): """ Creates an **"Example"** entity of kind **"NDBConfig"** in the datastore if the model is empty and raises and error to inform you that you should populate the model with data. .. note:: The *Datastore Viewer* in the ``_ah/admin/`` won't let ...
def initialize(cls): """ Creates an **"Example"** entity of kind **"NDBConfig"** in the datastore if the model is empty and raises and error to inform you that you should populate the model with data. .. note:: The *Datastore Viewer* in the ``_ah/admin/`` won't let ...
[ "Creates", "an", "**", "Example", "**", "entity", "of", "kind", "**", "NDBConfig", "**", "in", "the", "datastore", "if", "the", "model", "is", "empty", "and", "raises", "and", "error", "to", "inform", "you", "that", "you", "should", "populate", "the", "m...
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/extras/gae/__init__.py#L171-L213
[ "def", "initialize", "(", "cls", ")", ":", "if", "not", "len", "(", "cls", ".", "query", "(", ")", ".", "fetch", "(", ")", ")", ":", "example", "=", "cls", ".", "get_or_insert", "(", "'Example'", ")", "example", ".", "class_", "=", "'Provider class e...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
GAEOpenID.login
Launches the OpenID authentication procedure.
authomatic/providers/gaeopenid.py
def login(self): """ Launches the OpenID authentication procedure. """ if self.params.get(self.identifier_param): # ================================================================= # Phase 1 before redirect. # ========================================...
def login(self): """ Launches the OpenID authentication procedure. """ if self.params.get(self.identifier_param): # ================================================================= # Phase 1 before redirect. # ========================================...
[ "Launches", "the", "OpenID", "authentication", "procedure", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/gaeopenid.py#L50-L94
[ "def", "login", "(", "self", ")", ":", "if", "self", ".", "params", ".", "get", "(", "self", ".", "identifier_param", ")", ":", "# =================================================================", "# Phase 1 before redirect.", "# ============================================...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
_error_traceback_html
Generates error traceback HTML. :param tuple exc_info: Output of :func:`sys.exc_info` function. :param traceback: Output of :func:`traceback.format_exc` function.
authomatic/providers/__init__.py
def _error_traceback_html(exc_info, traceback_): """ Generates error traceback HTML. :param tuple exc_info: Output of :func:`sys.exc_info` function. :param traceback: Output of :func:`traceback.format_exc` function. """ html = """ <html> <head> <title>...
def _error_traceback_html(exc_info, traceback_): """ Generates error traceback HTML. :param tuple exc_info: Output of :func:`sys.exc_info` function. :param traceback: Output of :func:`traceback.format_exc` function. """ html = """ <html> <head> <title>...
[ "Generates", "error", "traceback", "HTML", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L49-L74
[ "def", "_error_traceback_html", "(", "exc_info", ",", "traceback_", ")", ":", "html", "=", "\"\"\"\n <html>\n <head>\n <title>ERROR: {error}</title>\n </head>\n <body style=\"font-family: sans-serif\">\n <h4>The Authomatic library encountered an erro...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
login_decorator
Decorate the :meth:`.BaseProvider.login` implementations with this decorator. Provides mechanism for error reporting and returning result which makes the :meth:`.BaseProvider.login` implementation cleaner.
authomatic/providers/__init__.py
def login_decorator(func): """ Decorate the :meth:`.BaseProvider.login` implementations with this decorator. Provides mechanism for error reporting and returning result which makes the :meth:`.BaseProvider.login` implementation cleaner. """ def wrap(provider, *args, **kwargs): err...
def login_decorator(func): """ Decorate the :meth:`.BaseProvider.login` implementations with this decorator. Provides mechanism for error reporting and returning result which makes the :meth:`.BaseProvider.login` implementation cleaner. """ def wrap(provider, *args, **kwargs): err...
[ "Decorate", "the", ":", "meth", ":", ".", "BaseProvider", ".", "login", "implementations", "with", "this", "decorator", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L77-L130
[ "def", "login_decorator", "(", "func", ")", ":", "def", "wrap", "(", "provider", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "error", "=", "None", "result", "=", "authomatic", ".", "core", ".", "LoginResult", "(", "provider", ")", "try", ":"...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider.to_dict
Converts the provider instance to a :class:`dict`. :returns: :class:`dict`
authomatic/providers/__init__.py
def to_dict(self): """ Converts the provider instance to a :class:`dict`. :returns: :class:`dict` """ return dict(name=self.name, id=getattr(self, 'id', None), type_id=self.type_id, type=self.get_type(), ...
def to_dict(self): """ Converts the provider instance to a :class:`dict`. :returns: :class:`dict` """ return dict(name=self.name, id=getattr(self, 'id', None), type_id=self.type_id, type=self.get_type(), ...
[ "Converts", "the", "provider", "instance", "to", "a", ":", "class", ":", "dict", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L217-L231
[ "def", "to_dict", "(", "self", ")", ":", "return", "dict", "(", "name", "=", "self", ".", "name", ",", "id", "=", "getattr", "(", "self", ",", "'id'", ",", "None", ")", ",", "type_id", "=", "self", ".", "type_id", ",", "type", "=", "self", ".", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._kwarg
Resolves keyword arguments from constructor or :doc:`config`. .. note:: The keyword arguments take this order of precedence: 1. Arguments passed to constructor through the :func:`authomatic.login`. 2. Provider specific arguments from :doc:`config`. ...
authomatic/providers/__init__.py
def _kwarg(self, kwargs, kwname, default=None): """ Resolves keyword arguments from constructor or :doc:`config`. .. note:: The keyword arguments take this order of precedence: 1. Arguments passed to constructor through the :func:`authomatic.login`. ...
def _kwarg(self, kwargs, kwname, default=None): """ Resolves keyword arguments from constructor or :doc:`config`. .. note:: The keyword arguments take this order of precedence: 1. Arguments passed to constructor through the :func:`authomatic.login`. ...
[ "Resolves", "keyword", "arguments", "from", "constructor", "or", ":", "doc", ":", "config", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L263-L287
[ "def", "_kwarg", "(", "self", ",", "kwargs", ",", "kwname", ",", "default", "=", "None", ")", ":", "return", "kwargs", ".", "get", "(", "kwname", ")", "or", "self", ".", "settings", ".", "config", ".", "get", "(", "self", ".", "name", ",", "{", "...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._session_key
Generates session key string. :param str key: e.g. ``"authomatic:facebook:key"``
authomatic/providers/__init__.py
def _session_key(self, key): """ Generates session key string. :param str key: e.g. ``"authomatic:facebook:key"`` """ return '{0}:{1}:{2}'.format(self.settings.prefix, self.name, key)
def _session_key(self, key): """ Generates session key string. :param str key: e.g. ``"authomatic:facebook:key"`` """ return '{0}:{1}:{2}'.format(self.settings.prefix, self.name, key)
[ "Generates", "session", "key", "string", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L289-L298
[ "def", "_session_key", "(", "self", ",", "key", ")", ":", "return", "'{0}:{1}:{2}'", ".", "format", "(", "self", ".", "settings", ".", "prefix", ",", "self", ".", "name", ",", "key", ")" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._session_set
Saves a value to session.
authomatic/providers/__init__.py
def _session_set(self, key, value): """ Saves a value to session. """ self.session[self._session_key(key)] = value
def _session_set(self, key, value): """ Saves a value to session. """ self.session[self._session_key(key)] = value
[ "Saves", "a", "value", "to", "session", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L300-L305
[ "def", "_session_set", "(", "self", ",", "key", ",", "value", ")", ":", "self", ".", "session", "[", "self", ".", "_session_key", "(", "key", ")", "]", "=", "value" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider.csrf_generator
Generates CSRF token. Inspired by this article: http://blog.ptsecurity.com/2012/10/random-number-security-in-python.html :returns: :class:`str` Random unguessable string.
authomatic/providers/__init__.py
def csrf_generator(secret): """ Generates CSRF token. Inspired by this article: http://blog.ptsecurity.com/2012/10/random-number-security-in-python.html :returns: :class:`str` Random unguessable string. """ # Create hash from random string plus sal...
def csrf_generator(secret): """ Generates CSRF token. Inspired by this article: http://blog.ptsecurity.com/2012/10/random-number-security-in-python.html :returns: :class:`str` Random unguessable string. """ # Create hash from random string plus sal...
[ "Generates", "CSRF", "token", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L315-L333
[ "def", "csrf_generator", "(", "secret", ")", ":", "# Create hash from random string plus salt.", "hashed", "=", "hashlib", ".", "md5", "(", "uuid", ".", "uuid4", "(", ")", ".", "bytes", "+", "six", ".", "b", "(", "secret", ")", ")", ".", "hexdigest", "(", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._log
Logs a message with pre-formatted prefix. :param int level: Logging level as specified in the `login module <http://docs.python.org/2/library/logging.html>`_ of Python standard library. :param str msg: The actual message.
authomatic/providers/__init__.py
def _log(cls, level, msg, **kwargs): """ Logs a message with pre-formatted prefix. :param int level: Logging level as specified in the `login module <http://docs.python.org/2/library/logging.html>`_ of Python standard library. :param str msg: ...
def _log(cls, level, msg, **kwargs): """ Logs a message with pre-formatted prefix. :param int level: Logging level as specified in the `login module <http://docs.python.org/2/library/logging.html>`_ of Python standard library. :param str msg: ...
[ "Logs", "a", "message", "with", "pre", "-", "formatted", "prefix", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L336-L353
[ "def", "_log", "(", "cls", ",", "level", ",", "msg", ",", "*", "*", "kwargs", ")", ":", "logger", "=", "getattr", "(", "cls", ",", "'_logger'", ",", "None", ")", "or", "authomatic", ".", "core", ".", "_logger", "logger", ".", "log", "(", "level", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._fetch
Fetches a URL. :param str url: The URL to fetch. :param str method: HTTP method of the request. :param dict params: Dictionary of request parameters. :param dict headers: HTTP headers of the request. :param str body: ...
authomatic/providers/__init__.py
def _fetch(self, url, method='GET', params=None, headers=None, body='', max_redirects=5, content_parser=None): """ Fetches a URL. :param str url: The URL to fetch. :param str method: HTTP method of the request. :param dict params: ...
def _fetch(self, url, method='GET', params=None, headers=None, body='', max_redirects=5, content_parser=None): """ Fetches a URL. :param str url: The URL to fetch. :param str method: HTTP method of the request. :param dict params: ...
[ "Fetches", "a", "URL", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L355-L464
[ "def", "_fetch", "(", "self", ",", "url", ",", "method", "=", "'GET'", ",", "params", "=", "None", ",", "headers", "=", "None", ",", "body", "=", "''", ",", "max_redirects", "=", "5", ",", "content_parser", "=", "None", ")", ":", "# 'magic' using _kwar...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._update_or_create_user
Updates or creates :attr:`.user`. :returns: :class:`.User`
authomatic/providers/__init__.py
def _update_or_create_user(self, data, credentials=None, content=None): """ Updates or creates :attr:`.user`. :returns: :class:`.User` """ if not self.user: self.user = authomatic.core.User(self, credentials=credentials) self.user.content = con...
def _update_or_create_user(self, data, credentials=None, content=None): """ Updates or creates :attr:`.user`. :returns: :class:`.User` """ if not self.user: self.user = authomatic.core.User(self, credentials=credentials) self.user.content = con...
[ "Updates", "or", "creates", ":", "attr", ":", ".", "user", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L466-L516
[ "def", "_update_or_create_user", "(", "self", ",", "data", ",", "credentials", "=", "None", ",", "content", "=", "None", ")", ":", "if", "not", "self", ".", "user", ":", "self", ".", "user", "=", "authomatic", ".", "core", ".", "User", "(", "self", "...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
BaseProvider._http_status_in_category
Checks whether a HTTP status code is in the category denoted by the hundreds digit.
authomatic/providers/__init__.py
def _http_status_in_category(status, category): """ Checks whether a HTTP status code is in the category denoted by the hundreds digit. """ assert category < 10, 'HTTP status category must be a one-digit int!' cat = category * 100 return status >= cat and status ...
def _http_status_in_category(status, category): """ Checks whether a HTTP status code is in the category denoted by the hundreds digit. """ assert category < 10, 'HTTP status category must be a one-digit int!' cat = category * 100 return status >= cat and status ...
[ "Checks", "whether", "a", "HTTP", "status", "code", "is", "in", "the", "category", "denoted", "by", "the", "hundreds", "digit", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L533-L541
[ "def", "_http_status_in_category", "(", "status", ",", "category", ")", ":", "assert", "category", "<", "10", ",", "'HTTP status category must be a one-digit int!'", "cat", "=", "category", "*", "100", "return", "status", ">=", "cat", "and", "status", "<", "cat", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider.type_id
A short string representing the provider implementation id used for serialization of :class:`.Credentials` and to identify the type of provider in JavaScript. The part before hyphen denotes the type of the provider, the part after hyphen denotes the class id e.g. ``oauth2.Facebo...
authomatic/providers/__init__.py
def type_id(self): """ A short string representing the provider implementation id used for serialization of :class:`.Credentials` and to identify the type of provider in JavaScript. The part before hyphen denotes the type of the provider, the part after hyphen denotes th...
def type_id(self): """ A short string representing the provider implementation id used for serialization of :class:`.Credentials` and to identify the type of provider in JavaScript. The part before hyphen denotes the type of the provider, the part after hyphen denotes th...
[ "A", "short", "string", "representing", "the", "provider", "implementation", "id", "used", "for", "serialization", "of", ":", "class", ":", ".", "Credentials", "and", "to", "identify", "the", "type", "of", "provider", "in", "JavaScript", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L754-L771
[ "def", "type_id", "(", "self", ")", ":", "cls", "=", "self", ".", "__class__", "mod", "=", "sys", ".", "modules", ".", "get", "(", "cls", ".", "__module__", ")", "return", "str", "(", "self", ".", "PROVIDER_TYPE_ID", ")", "+", "'-'", "+", "str", "(...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider.access
Fetches the **protected resource** of an authenticated **user**. :param credentials: The **user's** :class:`.Credentials` (serialized or normal). :param str url: The URL of the **protected resource**. :param str method: HTTP method of the request. ...
authomatic/providers/__init__.py
def access(self, url, params=None, method='GET', headers=None, body='', max_redirects=5, content_parser=None): """ Fetches the **protected resource** of an authenticated **user**. :param credentials: The **user's** :class:`.Credentials` (serialized or normal). ...
def access(self, url, params=None, method='GET', headers=None, body='', max_redirects=5, content_parser=None): """ Fetches the **protected resource** of an authenticated **user**. :param credentials: The **user's** :class:`.Credentials` (serialized or normal). ...
[ "Fetches", "the", "**", "protected", "resource", "**", "of", "an", "authenticated", "**", "user", "**", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L773-L832
[ "def", "access", "(", "self", ",", "url", ",", "params", "=", "None", ",", "method", "=", "'GET'", ",", "headers", "=", "None", ",", "body", "=", "''", ",", "max_redirects", "=", "5", ",", "content_parser", "=", "None", ")", ":", "if", "not", "self...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider.async_access
Same as :meth:`.access` but runs asynchronously in a separate thread. .. warning:: |async| :returns: :class:`.Future` instance representing the separate thread.
authomatic/providers/__init__.py
def async_access(self, *args, **kwargs): """ Same as :meth:`.access` but runs asynchronously in a separate thread. .. warning:: |async| :returns: :class:`.Future` instance representing the separate thread. """ return authomatic.core.Future(sel...
def async_access(self, *args, **kwargs): """ Same as :meth:`.access` but runs asynchronously in a separate thread. .. warning:: |async| :returns: :class:`.Future` instance representing the separate thread. """ return authomatic.core.Future(sel...
[ "Same", "as", ":", "meth", ":", ".", "access", "but", "runs", "asynchronously", "in", "a", "separate", "thread", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L834-L847
[ "def", "async_access", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return", "authomatic", ".", "core", ".", "Future", "(", "self", ".", "access", ",", "*", "args", ",", "*", "*", "kwargs", ")" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider.update_user
Updates the :attr:`.BaseProvider.user`. .. warning:: Fetches the :attr:`.user_info_url`! :returns: :class:`.UserInfoResponse`
authomatic/providers/__init__.py
def update_user(self): """ Updates the :attr:`.BaseProvider.user`. .. warning:: Fetches the :attr:`.user_info_url`! :returns: :class:`.UserInfoResponse` """ if self.user_info_url: response = self._access_user_info() self....
def update_user(self): """ Updates the :attr:`.BaseProvider.user`. .. warning:: Fetches the :attr:`.user_info_url`! :returns: :class:`.UserInfoResponse` """ if self.user_info_url: response = self._access_user_info() self....
[ "Updates", "the", ":", "attr", ":", ".", "BaseProvider", ".", "user", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L849-L865
[ "def", "update_user", "(", "self", ")", ":", "if", "self", ".", "user_info_url", ":", "response", "=", "self", ".", "_access_user_info", "(", ")", "self", ".", "user", "=", "self", ".", "_update_or_create_user", "(", "response", ".", "data", ",", "content"...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider._authorization_header
Creates authorization headers if the provider supports it. See: http://en.wikipedia.org/wiki/Basic_access_authentication. :param credentials: :class:`.Credentials` :returns: Headers as :class:`dict`.
authomatic/providers/__init__.py
def _authorization_header(cls, credentials): """ Creates authorization headers if the provider supports it. See: http://en.wikipedia.org/wiki/Basic_access_authentication. :param credentials: :class:`.Credentials` :returns: Headers as :class:`dict`. ...
def _authorization_header(cls, credentials): """ Creates authorization headers if the provider supports it. See: http://en.wikipedia.org/wiki/Basic_access_authentication. :param credentials: :class:`.Credentials` :returns: Headers as :class:`dict`. ...
[ "Creates", "authorization", "headers", "if", "the", "provider", "supports", "it", ".", "See", ":", "http", ":", "//", "en", ".", "wikipedia", ".", "org", "/", "wiki", "/", "Basic_access_authentication", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L872-L892
[ "def", "_authorization_header", "(", "cls", ",", "credentials", ")", ":", "if", "cls", ".", "_x_use_authorization_header", ":", "res", "=", "':'", ".", "join", "(", "(", "credentials", ".", "consumer_key", ",", "credentials", ".", "consumer_secret", ")", ")", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider._check_consumer
Validates the :attr:`.consumer`.
authomatic/providers/__init__.py
def _check_consumer(self): """ Validates the :attr:`.consumer`. """ # 'magic' using _kwarg method # pylint:disable=no-member if not self.consumer.key: raise ConfigError( 'Consumer key not specified for provider {0}!'.format( ...
def _check_consumer(self): """ Validates the :attr:`.consumer`. """ # 'magic' using _kwarg method # pylint:disable=no-member if not self.consumer.key: raise ConfigError( 'Consumer key not specified for provider {0}!'.format( ...
[ "Validates", "the", ":", "attr", ":", ".", "consumer", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L894-L909
[ "def", "_check_consumer", "(", "self", ")", ":", "# 'magic' using _kwarg method", "# pylint:disable=no-member", "if", "not", "self", ".", "consumer", ".", "key", ":", "raise", "ConfigError", "(", "'Consumer key not specified for provider {0}!'", ".", "format", "(", "sel...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider._split_url
Splits given url to url base and params converted to list of tuples.
authomatic/providers/__init__.py
def _split_url(url): """ Splits given url to url base and params converted to list of tuples. """ split = parse.urlsplit(url) base = parse.urlunsplit((split.scheme, split.netloc, split.path, 0, 0)) params = parse.parse_qsl(split.query, True) return base, params
def _split_url(url): """ Splits given url to url base and params converted to list of tuples. """ split = parse.urlsplit(url) base = parse.urlunsplit((split.scheme, split.netloc, split.path, 0, 0)) params = parse.parse_qsl(split.query, True) return base, params
[ "Splits", "given", "url", "to", "url", "base", "and", "params", "converted", "to", "list", "of", "tuples", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L912-L921
[ "def", "_split_url", "(", "url", ")", ":", "split", "=", "parse", ".", "urlsplit", "(", "url", ")", "base", "=", "parse", ".", "urlunsplit", "(", "(", "split", ".", "scheme", ",", "split", ".", "netloc", ",", "split", ".", "path", ",", "0", ",", ...
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
AuthorizationProvider._access_user_info
Accesses the :attr:`.user_info_url`. :returns: :class:`.UserInfoResponse`
authomatic/providers/__init__.py
def _access_user_info(self): """ Accesses the :attr:`.user_info_url`. :returns: :class:`.UserInfoResponse` """ url = self.user_info_url.format(**self.user.__dict__) return self.access(url)
def _access_user_info(self): """ Accesses the :attr:`.user_info_url`. :returns: :class:`.UserInfoResponse` """ url = self.user_info_url.format(**self.user.__dict__) return self.access(url)
[ "Accesses", "the", ":", "attr", ":", ".", "user_info_url", "." ]
authomatic/authomatic
python
https://github.com/authomatic/authomatic/blob/90a9ce60cc405ae8a2bf5c3713acd5d78579a04e/authomatic/providers/__init__.py#L968-L977
[ "def", "_access_user_info", "(", "self", ")", ":", "url", "=", "self", ".", "user_info_url", ".", "format", "(", "*", "*", "self", ".", "user", ".", "__dict__", ")", "return", "self", ".", "access", "(", "url", ")" ]
90a9ce60cc405ae8a2bf5c3713acd5d78579a04e
test
cross_origin
This function is the decorator which is used to wrap a Sanic route with. In the simplest case, simply use the default parameters to allow all origins in what is the most permissive configuration. If this method modifies state or performs authentication which may be brute-forced, you should add some degr...
sanic_cors/decorator.py
def cross_origin(app, *args, **kwargs): """ This function is the decorator which is used to wrap a Sanic route with. In the simplest case, simply use the default parameters to allow all origins in what is the most permissive configuration. If this method modifies state or performs authentication whi...
def cross_origin(app, *args, **kwargs): """ This function is the decorator which is used to wrap a Sanic route with. In the simplest case, simply use the default parameters to allow all origins in what is the most permissive configuration. If this method modifies state or performs authentication whi...
[ "This", "function", "is", "the", "decorator", "which", "is", "used", "to", "wrap", "a", "Sanic", "route", "with", ".", "In", "the", "simplest", "case", "simply", "use", "the", "default", "parameters", "to", "allow", "all", "origins", "in", "what", "is", ...
ashleysommer/sanic-cors
python
https://github.com/ashleysommer/sanic-cors/blob/f3d68def8cf859398b3c83e4109d815f1f038ea2/sanic_cors/decorator.py#L18-L120
[ "def", "cross_origin", "(", "app", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "_options", "=", "kwargs", "_real_decorator", "=", "cors", ".", "decorate", "(", "app", ",", "*", "args", ",", "run_middleware", "=", "False", ",", "with_context", ...
f3d68def8cf859398b3c83e4109d815f1f038ea2
test
set_cors_headers
Performs the actual evaluation of Sanic-CORS options and actually modifies the response object. This function is used both in the decorator and the after_request callback :param sanic.request.Request req:
sanic_cors/core.py
def set_cors_headers(req, resp, context, options): """ Performs the actual evaluation of Sanic-CORS options and actually modifies the response object. This function is used both in the decorator and the after_request callback :param sanic.request.Request req: """ try: request_c...
def set_cors_headers(req, resp, context, options): """ Performs the actual evaluation of Sanic-CORS options and actually modifies the response object. This function is used both in the decorator and the after_request callback :param sanic.request.Request req: """ try: request_c...
[ "Performs", "the", "actual", "evaluation", "of", "Sanic", "-", "CORS", "options", "and", "actually", "modifies", "the", "response", "object", "." ]
ashleysommer/sanic-cors
python
https://github.com/ashleysommer/sanic-cors/blob/f3d68def8cf859398b3c83e4109d815f1f038ea2/sanic_cors/core.py#L221-L265
[ "def", "set_cors_headers", "(", "req", ",", "resp", ",", "context", ",", "options", ")", ":", "try", ":", "request_context", "=", "context", ".", "request", "[", "id", "(", "req", ")", "]", "except", "AttributeError", ":", "LOG", ".", "debug", "(", "\"...
f3d68def8cf859398b3c83e4109d815f1f038ea2
test
get_app_kwarg_dict
Returns the dictionary of CORS specific app configurations.
sanic_cors/core.py
def get_app_kwarg_dict(appInstance): """Returns the dictionary of CORS specific app configurations.""" # In order to support blueprints which do not have a config attribute app_config = getattr(appInstance, 'config', {}) return dict( (k.lower().replace('cors_', ''), app_config.get(k)) fo...
def get_app_kwarg_dict(appInstance): """Returns the dictionary of CORS specific app configurations.""" # In order to support blueprints which do not have a config attribute app_config = getattr(appInstance, 'config', {}) return dict( (k.lower().replace('cors_', ''), app_config.get(k)) fo...
[ "Returns", "the", "dictionary", "of", "CORS", "specific", "app", "configurations", "." ]
ashleysommer/sanic-cors
python
https://github.com/ashleysommer/sanic-cors/blob/f3d68def8cf859398b3c83e4109d815f1f038ea2/sanic_cors/core.py#L318-L326
[ "def", "get_app_kwarg_dict", "(", "appInstance", ")", ":", "# In order to support blueprints which do not have a config attribute", "app_config", "=", "getattr", "(", "appInstance", ",", "'config'", ",", "{", "}", ")", "return", "dict", "(", "(", "k", ".", "lower", ...
f3d68def8cf859398b3c83e4109d815f1f038ea2
test
flexible_str
A more flexible str function which intelligently handles stringifying strings, lists and other iterables. The results are lexographically sorted to ensure generated responses are consistent when iterables such as Set are used.
sanic_cors/core.py
def flexible_str(obj): """ A more flexible str function which intelligently handles stringifying strings, lists and other iterables. The results are lexographically sorted to ensure generated responses are consistent when iterables such as Set are used. """ if obj is None: return Non...
def flexible_str(obj): """ A more flexible str function which intelligently handles stringifying strings, lists and other iterables. The results are lexographically sorted to ensure generated responses are consistent when iterables such as Set are used. """ if obj is None: return Non...
[ "A", "more", "flexible", "str", "function", "which", "intelligently", "handles", "stringifying", "strings", "lists", "and", "other", "iterables", ".", "The", "results", "are", "lexographically", "sorted", "to", "ensure", "generated", "responses", "are", "consistent"...
ashleysommer/sanic-cors
python
https://github.com/ashleysommer/sanic-cors/blob/f3d68def8cf859398b3c83e4109d815f1f038ea2/sanic_cors/core.py#L329-L342
[ "def", "flexible_str", "(", "obj", ")", ":", "if", "obj", "is", "None", ":", "return", "None", "elif", "(", "not", "isinstance", "(", "obj", ",", "str", ")", "and", "isinstance", "(", "obj", ",", "collections", ".", "abc", ".", "Iterable", ")", ")", ...
f3d68def8cf859398b3c83e4109d815f1f038ea2
test
ensure_iterable
Wraps scalars or string types as a list, or returns the iterable instance.
sanic_cors/core.py
def ensure_iterable(inst): """ Wraps scalars or string types as a list, or returns the iterable instance. """ if isinstance(inst, str): return [inst] elif not isinstance(inst, collections.abc.Iterable): return [inst] else: return inst
def ensure_iterable(inst): """ Wraps scalars or string types as a list, or returns the iterable instance. """ if isinstance(inst, str): return [inst] elif not isinstance(inst, collections.abc.Iterable): return [inst] else: return inst
[ "Wraps", "scalars", "or", "string", "types", "as", "a", "list", "or", "returns", "the", "iterable", "instance", "." ]
ashleysommer/sanic-cors
python
https://github.com/ashleysommer/sanic-cors/blob/f3d68def8cf859398b3c83e4109d815f1f038ea2/sanic_cors/core.py#L351-L360
[ "def", "ensure_iterable", "(", "inst", ")", ":", "if", "isinstance", "(", "inst", ",", "str", ")", ":", "return", "[", "inst", "]", "elif", "not", "isinstance", "(", "inst", ",", "collections", ".", "abc", ".", "Iterable", ")", ":", "return", "[", "i...
f3d68def8cf859398b3c83e4109d815f1f038ea2
test
isclose
Python 3.4 does not have math.isclose, so we need to steal it and add it here.
algorithms/util.py
def isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0): """ Python 3.4 does not have math.isclose, so we need to steal it and add it here. """ try: return math.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol) except AttributeError: # Running on older version of python, fall back to hand-rol...
def isclose(a, b, *, rel_tol=1e-09, abs_tol=0.0): """ Python 3.4 does not have math.isclose, so we need to steal it and add it here. """ try: return math.isclose(a, b, rel_tol=rel_tol, abs_tol=abs_tol) except AttributeError: # Running on older version of python, fall back to hand-rol...
[ "Python", "3", ".", "4", "does", "not", "have", "math", ".", "isclose", "so", "we", "need", "to", "steal", "it", "and", "add", "it", "here", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/util.py#L6-L23
[ "def", "isclose", "(", "a", ",", "b", ",", "*", ",", "rel_tol", "=", "1e-09", ",", "abs_tol", "=", "0.0", ")", ":", "try", ":", "return", "math", ".", "isclose", "(", "a", ",", "b", ",", "rel_tol", "=", "rel_tol", ",", "abs_tol", "=", "abs_tol", ...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
deprecated
Deprecator decorator.
audiosegment.py
def deprecated(func): """ Deprecator decorator. """ @functools.wraps(func) def new_func(*args, **kwargs): warnings.warn("Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, stacklevel=2) return func(*args, **kwargs) return new_func
def deprecated(func): """ Deprecator decorator. """ @functools.wraps(func) def new_func(*args, **kwargs): warnings.warn("Call to deprecated function {}.".format(func.__name__), category=DeprecationWarning, stacklevel=2) return func(*args, **kwargs) return new_func
[ "Deprecator", "decorator", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L47-L56
[ "def", "deprecated", "(", "func", ")", ":", "@", "functools", ".", "wraps", "(", "func", ")", "def", "new_func", "(", "*", "args", ",", "*", "*", "kwargs", ")", ":", "warnings", ".", "warn", "(", "\"Call to deprecated function {}.\"", ".", "format", "(",...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
deserialize
Attempts to deserialize a bytestring into an audiosegment. :param bstr: The bytestring serialized via an audiosegment's serialize() method. :returns: An AudioSegment object deserialized from `bstr`.
audiosegment.py
def deserialize(bstr): """ Attempts to deserialize a bytestring into an audiosegment. :param bstr: The bytestring serialized via an audiosegment's serialize() method. :returns: An AudioSegment object deserialized from `bstr`. """ d = pickle.loads(bstr) seg = pickle.loads(d['seg']) retur...
def deserialize(bstr): """ Attempts to deserialize a bytestring into an audiosegment. :param bstr: The bytestring serialized via an audiosegment's serialize() method. :returns: An AudioSegment object deserialized from `bstr`. """ d = pickle.loads(bstr) seg = pickle.loads(d['seg']) retur...
[ "Attempts", "to", "deserialize", "a", "bytestring", "into", "an", "audiosegment", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L1074-L1083
[ "def", "deserialize", "(", "bstr", ")", ":", "d", "=", "pickle", ".", "loads", "(", "bstr", ")", "seg", "=", "pickle", ".", "loads", "(", "d", "[", "'seg'", "]", ")", "return", "AudioSegment", "(", "seg", ",", "d", "[", "'name'", "]", ")" ]
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
from_file
Returns an AudioSegment object from the given file based on its file extension. If the extension is wrong, this will throw some sort of error. :param path: The path to the file, including the file extension. :returns: An AudioSegment instance from the file.
audiosegment.py
def from_file(path): """ Returns an AudioSegment object from the given file based on its file extension. If the extension is wrong, this will throw some sort of error. :param path: The path to the file, including the file extension. :returns: An AudioSegment instance from the file. """ _nam...
def from_file(path): """ Returns an AudioSegment object from the given file based on its file extension. If the extension is wrong, this will throw some sort of error. :param path: The path to the file, including the file extension. :returns: An AudioSegment instance from the file. """ _nam...
[ "Returns", "an", "AudioSegment", "object", "from", "the", "given", "file", "based", "on", "its", "file", "extension", ".", "If", "the", "extension", "is", "wrong", "this", "will", "throw", "some", "sort", "of", "error", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L1094-L1105
[ "def", "from_file", "(", "path", ")", ":", "_name", ",", "ext", "=", "os", ".", "path", ".", "splitext", "(", "path", ")", "ext", "=", "ext", ".", "lower", "(", ")", "[", "1", ":", "]", "seg", "=", "pydub", ".", "AudioSegment", ".", "from_file", ...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
from_numpy_array
Returns an AudioSegment created from the given numpy array. The numpy array must have shape = (num_samples, num_channels). :param nparr: The numpy array to create an AudioSegment from. :returns: An AudioSegment created from the given array.
audiosegment.py
def from_numpy_array(nparr, framerate): """ Returns an AudioSegment created from the given numpy array. The numpy array must have shape = (num_samples, num_channels). :param nparr: The numpy array to create an AudioSegment from. :returns: An AudioSegment created from the given array. """ #...
def from_numpy_array(nparr, framerate): """ Returns an AudioSegment created from the given numpy array. The numpy array must have shape = (num_samples, num_channels). :param nparr: The numpy array to create an AudioSegment from. :returns: An AudioSegment created from the given array. """ #...
[ "Returns", "an", "AudioSegment", "created", "from", "the", "given", "numpy", "array", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L1116-L1140
[ "def", "from_numpy_array", "(", "nparr", ",", "framerate", ")", ":", "# interleave the audio across all channels and collapse", "if", "nparr", ".", "dtype", ".", "itemsize", "not", "in", "(", "1", ",", "2", ",", "4", ")", ":", "raise", "ValueError", "(", "\"Nu...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
silent
Creates an AudioSegment object of the specified duration/frame_rate filled with digital silence. :param duration: The duration of the returned object in ms. :param frame_rate: The samples per second of the returned object. :returns: AudioSegment object filled with pure digital silence.
audiosegment.py
def silent(duration=1000, frame_rate=11025): """ Creates an AudioSegment object of the specified duration/frame_rate filled with digital silence. :param duration: The duration of the returned object in ms. :param frame_rate: The samples per second of the returned object. :returns: AudioSegment obje...
def silent(duration=1000, frame_rate=11025): """ Creates an AudioSegment object of the specified duration/frame_rate filled with digital silence. :param duration: The duration of the returned object in ms. :param frame_rate: The samples per second of the returned object. :returns: AudioSegment obje...
[ "Creates", "an", "AudioSegment", "object", "of", "the", "specified", "duration", "/", "frame_rate", "filled", "with", "digital", "silence", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L1142-L1151
[ "def", "silent", "(", "duration", "=", "1000", ",", "frame_rate", "=", "11025", ")", ":", "seg", "=", "pydub", ".", "AudioSegment", ".", "silent", "(", "duration", "=", "duration", ",", "frame_rate", "=", "frame_rate", ")", "return", "AudioSegment", "(", ...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.spl
Sound Pressure Level - defined as 20 * log10(p/p0), where p is the RMS of the sound wave in Pascals and p0 is 20 micro Pascals. Since we would need to know calibration information about the microphone used to record the sound in order to transform the PCM values of this audioseg...
audiosegment.py
def spl(self): """ Sound Pressure Level - defined as 20 * log10(p/p0), where p is the RMS of the sound wave in Pascals and p0 is 20 micro Pascals. Since we would need to know calibration information about the microphone used to record the sound in order to transform ...
def spl(self): """ Sound Pressure Level - defined as 20 * log10(p/p0), where p is the RMS of the sound wave in Pascals and p0 is 20 micro Pascals. Since we would need to know calibration information about the microphone used to record the sound in order to transform ...
[ "Sound", "Pressure", "Level", "-", "defined", "as", "20", "*", "log10", "(", "p", "/", "p0", ")", "where", "p", "is", "the", "RMS", "of", "the", "sound", "wave", "in", "Pascals", "and", "p0", "is", "20", "micro", "Pascals", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L130-L155
[ "def", "spl", "(", "self", ")", ":", "arr", "=", "self", ".", "to_numpy_array", "(", ")", "if", "len", "(", "arr", ")", "==", "0", ":", "return", "0.0", "else", ":", "rms", "=", "self", ".", "rms", "ratio", "=", "rms", "/", "P_REF_PCM", "return",...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.filter_bank
Returns a numpy array of shape (nfilters, nsamples), where each row of data is the result of bandpass filtering the audiosegment around a particular frequency. The frequencies are spaced from `lower_bound_hz` to `upper_bound_hz` and are returned with the np array. The particular spacing ...
audiosegment.py
def filter_bank(self, lower_bound_hz=50, upper_bound_hz=8E3, nfilters=128, mode='mel'): """ Returns a numpy array of shape (nfilters, nsamples), where each row of data is the result of bandpass filtering the audiosegment around a particular frequency. The frequencies are spaced f...
def filter_bank(self, lower_bound_hz=50, upper_bound_hz=8E3, nfilters=128, mode='mel'): """ Returns a numpy array of shape (nfilters, nsamples), where each row of data is the result of bandpass filtering the audiosegment around a particular frequency. The frequencies are spaced f...
[ "Returns", "a", "numpy", "array", "of", "shape", "(", "nfilters", "nsamples", ")", "where", "each", "row", "of", "data", "is", "the", "result", "of", "bandpass", "filtering", "the", "audiosegment", "around", "a", "particular", "frequency", ".", "The", "frequ...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L157-L225
[ "def", "filter_bank", "(", "self", ",", "lower_bound_hz", "=", "50", ",", "upper_bound_hz", "=", "8E3", ",", "nfilters", "=", "128", ",", "mode", "=", "'mel'", ")", ":", "# Logspace to get all the frequency channels we are after", "data", "=", "self", ".", "to_n...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.auditory_scene_analysis
Algorithm based on paper: Auditory Segmentation Based on Onset and Offset Analysis, by Hu and Wang, 2007. Returns a list of AudioSegments, each of which is all the sound during this AudioSegment's duration from a particular source. That is, if there are several overlapping sounds in this AudioS...
audiosegment.py
def auditory_scene_analysis(self, debug=False, debugplot=False): """ Algorithm based on paper: Auditory Segmentation Based on Onset and Offset Analysis, by Hu and Wang, 2007. Returns a list of AudioSegments, each of which is all the sound during this AudioSegment's duration from ...
def auditory_scene_analysis(self, debug=False, debugplot=False): """ Algorithm based on paper: Auditory Segmentation Based on Onset and Offset Analysis, by Hu and Wang, 2007. Returns a list of AudioSegments, each of which is all the sound during this AudioSegment's duration from ...
[ "Algorithm", "based", "on", "paper", ":", "Auditory", "Segmentation", "Based", "on", "Onset", "and", "Offset", "Analysis", "by", "Hu", "and", "Wang", "2007", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L227-L407
[ "def", "auditory_scene_analysis", "(", "self", ",", "debug", "=", "False", ",", "debugplot", "=", "False", ")", ":", "normalized", "=", "self", ".", "normalize_spl_by_average", "(", "db", "=", "60", ")", "def", "printd", "(", "*", "args", ",", "*", "*", ...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.detect_voice
Returns self as a list of tuples: [('v', voiced segment), ('u', unvoiced segment), (etc.)] The overall order of the AudioSegment is preserved. :param prob_detect_voice: The raw probability that any random 20ms window of the audio file contains voice. :...
audiosegment.py
def detect_voice(self, prob_detect_voice=0.5): """ Returns self as a list of tuples: [('v', voiced segment), ('u', unvoiced segment), (etc.)] The overall order of the AudioSegment is preserved. :param prob_detect_voice: The raw probability that any random 20ms window of the aud...
def detect_voice(self, prob_detect_voice=0.5): """ Returns self as a list of tuples: [('v', voiced segment), ('u', unvoiced segment), (etc.)] The overall order of the AudioSegment is preserved. :param prob_detect_voice: The raw probability that any random 20ms window of the aud...
[ "Returns", "self", "as", "a", "list", "of", "tuples", ":", "[", "(", "v", "voiced", "segment", ")", "(", "u", "unvoiced", "segment", ")", "(", "etc", ".", ")", "]" ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L409-L450
[ "def", "detect_voice", "(", "self", ",", "prob_detect_voice", "=", "0.5", ")", ":", "assert", "self", ".", "frame_rate", "in", "(", "48000", ",", "32000", ",", "16000", ",", "8000", ")", ",", "\"Try resampling to one of the allowed frame rates.\"", "assert", "se...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.dice
Cuts the AudioSegment into `seconds` segments (at most). So for example, if seconds=10, this will return a list of AudioSegments, in order, where each one is at most 10 seconds long. If `zero_pad` is True, the last item AudioSegment object will be zero padded to result in `seconds` seconds. ...
audiosegment.py
def dice(self, seconds, zero_pad=False): """ Cuts the AudioSegment into `seconds` segments (at most). So for example, if seconds=10, this will return a list of AudioSegments, in order, where each one is at most 10 seconds long. If `zero_pad` is True, the last item AudioSegment object wil...
def dice(self, seconds, zero_pad=False): """ Cuts the AudioSegment into `seconds` segments (at most). So for example, if seconds=10, this will return a list of AudioSegments, in order, where each one is at most 10 seconds long. If `zero_pad` is True, the last item AudioSegment object wil...
[ "Cuts", "the", "AudioSegment", "into", "seconds", "segments", "(", "at", "most", ")", ".", "So", "for", "example", "if", "seconds", "=", "10", "this", "will", "return", "a", "list", "of", "AudioSegments", "in", "order", "where", "each", "one", "is", "at"...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L452-L493
[ "def", "dice", "(", "self", ",", "seconds", ",", "zero_pad", "=", "False", ")", ":", "try", ":", "total_s", "=", "sum", "(", "seconds", ")", "if", "not", "(", "self", ".", "duration_seconds", "<=", "total_s", "+", "1", "and", "self", ".", "duration_s...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.detect_event
A list of tuples of the form [('n', AudioSegment), ('y', AudioSegment), etc.] is returned, where tuples of the form ('n', AudioSegment) are the segments of sound where the event was not detected, while ('y', AudioSegment) tuples were the segments of sound where the event was detected. .. code-b...
audiosegment.py
def detect_event(self, model, ms_per_input, transition_matrix, model_stats, event_length_s, start_as_yes=False, prob_raw_yes=0.5): """ A list of tuples of the form [('n', AudioSegment), ('y', AudioSegment), etc.] is returned, where tuples of the form ('n', AudioSegment) are ...
def detect_event(self, model, ms_per_input, transition_matrix, model_stats, event_length_s, start_as_yes=False, prob_raw_yes=0.5): """ A list of tuples of the form [('n', AudioSegment), ('y', AudioSegment), etc.] is returned, where tuples of the form ('n', AudioSegment) are ...
[ "A", "list", "of", "tuples", "of", "the", "form", "[", "(", "n", "AudioSegment", ")", "(", "y", "AudioSegment", ")", "etc", ".", "]", "is", "returned", "where", "tuples", "of", "the", "form", "(", "n", "AudioSegment", ")", "are", "the", "segments", "...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L495-L617
[ "def", "detect_event", "(", "self", ",", "model", ",", "ms_per_input", ",", "transition_matrix", ",", "model_stats", ",", "event_length_s", ",", "start_as_yes", "=", "False", ",", "prob_raw_yes", "=", "0.5", ")", ":", "if", "ms_per_input", "<", "0", "or", "m...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment._execute_sox_cmd
Executes a Sox command in a platform-independent manner. `cmd` must be a format string that includes {inputfile} and {outputfile}.
audiosegment.py
def _execute_sox_cmd(self, cmd, console_output=False): """ Executes a Sox command in a platform-independent manner. `cmd` must be a format string that includes {inputfile} and {outputfile}. """ on_windows = platform.system().lower() == "windows" # On Windows, a temporar...
def _execute_sox_cmd(self, cmd, console_output=False): """ Executes a Sox command in a platform-independent manner. `cmd` must be a format string that includes {inputfile} and {outputfile}. """ on_windows = platform.system().lower() == "windows" # On Windows, a temporar...
[ "Executes", "a", "Sox", "command", "in", "a", "platform", "-", "independent", "manner", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L619-L663
[ "def", "_execute_sox_cmd", "(", "self", ",", "cmd", ",", "console_output", "=", "False", ")", ":", "on_windows", "=", "platform", ".", "system", "(", ")", ".", "lower", "(", ")", "==", "\"windows\"", "# On Windows, a temporary file cannot be shared outside the proce...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.filter_silence
Returns a copy of this AudioSegment, but whose silence has been removed. .. note:: This method requires that you have the program 'sox' installed. .. warning:: This method uses the program 'sox' to perform the task. While this is very fast for a single function call, the IO may ad...
audiosegment.py
def filter_silence(self, duration_s=1, threshold_percentage=1, console_output=False): """ Returns a copy of this AudioSegment, but whose silence has been removed. .. note:: This method requires that you have the program 'sox' installed. .. warning:: This method uses the program 'sox' t...
def filter_silence(self, duration_s=1, threshold_percentage=1, console_output=False): """ Returns a copy of this AudioSegment, but whose silence has been removed. .. note:: This method requires that you have the program 'sox' installed. .. warning:: This method uses the program 'sox' t...
[ "Returns", "a", "copy", "of", "this", "AudioSegment", "but", "whose", "silence", "has", "been", "removed", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L665-L689
[ "def", "filter_silence", "(", "self", ",", "duration_s", "=", "1", ",", "threshold_percentage", "=", "1", ",", "console_output", "=", "False", ")", ":", "command", "=", "\"sox {inputfile} -t wav {outputfile} silence -l 1 0.1 \"", "+", "str", "(", "threshold_percentage...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.fft
Transforms the indicated slice of the AudioSegment into the frequency domain and returns the bins and the values. If neither `start_s` or `start_sample` is specified, the first sample of the slice will be the first sample of the AudioSegment. If neither `duration_s` or `num_samples` is...
audiosegment.py
def fft(self, start_s=None, duration_s=None, start_sample=None, num_samples=None, zero_pad=False): """ Transforms the indicated slice of the AudioSegment into the frequency domain and returns the bins and the values. If neither `start_s` or `start_sample` is specified, the first sample ...
def fft(self, start_s=None, duration_s=None, start_sample=None, num_samples=None, zero_pad=False): """ Transforms the indicated slice of the AudioSegment into the frequency domain and returns the bins and the values. If neither `start_s` or `start_sample` is specified, the first sample ...
[ "Transforms", "the", "indicated", "slice", "of", "the", "AudioSegment", "into", "the", "frequency", "domain", "and", "returns", "the", "bins", "and", "the", "values", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L691-L759
[ "def", "fft", "(", "self", ",", "start_s", "=", "None", ",", "duration_s", "=", "None", ",", "start_sample", "=", "None", ",", "num_samples", "=", "None", ",", "zero_pad", "=", "False", ")", ":", "if", "start_s", "is", "not", "None", "and", "start_samp...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.generate_frames
Yields self's data in chunks of frame_duration_ms. This function adapted from pywebrtc's example [https://github.com/wiseman/py-webrtcvad/blob/master/example.py]. :param frame_duration_ms: The length of each frame in ms. :param zero_pad: Whether or not to zero pad the end of the AudioSegment o...
audiosegment.py
def generate_frames(self, frame_duration_ms, zero_pad=True): """ Yields self's data in chunks of frame_duration_ms. This function adapted from pywebrtc's example [https://github.com/wiseman/py-webrtcvad/blob/master/example.py]. :param frame_duration_ms: The length of each frame in ms. ...
def generate_frames(self, frame_duration_ms, zero_pad=True): """ Yields self's data in chunks of frame_duration_ms. This function adapted from pywebrtc's example [https://github.com/wiseman/py-webrtcvad/blob/master/example.py]. :param frame_duration_ms: The length of each frame in ms. ...
[ "Yields", "self", "s", "data", "in", "chunks", "of", "frame_duration_ms", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L761-L789
[ "def", "generate_frames", "(", "self", ",", "frame_duration_ms", ",", "zero_pad", "=", "True", ")", ":", "Frame", "=", "collections", ".", "namedtuple", "(", "\"Frame\"", ",", "\"bytes timestamp duration\"", ")", "# (samples/sec) * (seconds in a frame) * (bytes/sample)", ...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.generate_frames_as_segments
Does the same thing as `generate_frames`, but yields tuples of (AudioSegment, timestamp) instead of Frames.
audiosegment.py
def generate_frames_as_segments(self, frame_duration_ms, zero_pad=True): """ Does the same thing as `generate_frames`, but yields tuples of (AudioSegment, timestamp) instead of Frames. """ for frame in self.generate_frames(frame_duration_ms, zero_pad=zero_pad): seg = AudioSeg...
def generate_frames_as_segments(self, frame_duration_ms, zero_pad=True): """ Does the same thing as `generate_frames`, but yields tuples of (AudioSegment, timestamp) instead of Frames. """ for frame in self.generate_frames(frame_duration_ms, zero_pad=zero_pad): seg = AudioSeg...
[ "Does", "the", "same", "thing", "as", "generate_frames", "but", "yields", "tuples", "of", "(", "AudioSegment", "timestamp", ")", "instead", "of", "Frames", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L791-L798
[ "def", "generate_frames_as_segments", "(", "self", ",", "frame_duration_ms", ",", "zero_pad", "=", "True", ")", ":", "for", "frame", "in", "self", ".", "generate_frames", "(", "frame_duration_ms", ",", "zero_pad", "=", "zero_pad", ")", ":", "seg", "=", "AudioS...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.human_audible
Returns an estimate of whether this AudioSegment is mostly human audible or not. This is done by taking an FFT of the segment and checking if the SPL of the segment falls below the function `f(x) = 40.11453 - 0.01683697x + 1.406211e-6x^2 - 2.371512e-11x^3`, where x is the most characteristic fre...
audiosegment.py
def human_audible(self): """ Returns an estimate of whether this AudioSegment is mostly human audible or not. This is done by taking an FFT of the segment and checking if the SPL of the segment falls below the function `f(x) = 40.11453 - 0.01683697x + 1.406211e-6x^2 - 2.371512e-11x^3`, ...
def human_audible(self): """ Returns an estimate of whether this AudioSegment is mostly human audible or not. This is done by taking an FFT of the segment and checking if the SPL of the segment falls below the function `f(x) = 40.11453 - 0.01683697x + 1.406211e-6x^2 - 2.371512e-11x^3`, ...
[ "Returns", "an", "estimate", "of", "whether", "this", "AudioSegment", "is", "mostly", "human", "audible", "or", "not", ".", "This", "is", "done", "by", "taking", "an", "FFT", "of", "the", "segment", "and", "checking", "if", "the", "SPL", "of", "the", "se...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L800-L827
[ "def", "human_audible", "(", "self", ")", ":", "hist_bins", ",", "hist_vals", "=", "self", ".", "fft", "(", ")", "hist_vals_real_normed", "=", "np", ".", "abs", "(", "hist_vals", ")", "/", "len", "(", "hist_vals", ")", "f_characteristic", "=", "hist_bins",...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.normalize_spl_by_average
Normalize the values in the AudioSegment so that its `spl` property gives `db`. .. note:: This method is currently broken - it returns an AudioSegment whose values are much smaller than reasonable, yet which yield an SPL value that equals the given `db`. Such an Audi...
audiosegment.py
def normalize_spl_by_average(self, db): """ Normalize the values in the AudioSegment so that its `spl` property gives `db`. .. note:: This method is currently broken - it returns an AudioSegment whose values are much smaller than reasonable, yet which yield an SPL valu...
def normalize_spl_by_average(self, db): """ Normalize the values in the AudioSegment so that its `spl` property gives `db`. .. note:: This method is currently broken - it returns an AudioSegment whose values are much smaller than reasonable, yet which yield an SPL valu...
[ "Normalize", "the", "values", "in", "the", "AudioSegment", "so", "that", "its", "spl", "property", "gives", "db", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L829-L876
[ "def", "normalize_spl_by_average", "(", "self", ",", "db", ")", ":", "arr", "=", "self", ".", "to_numpy_array", "(", ")", ".", "copy", "(", ")", "if", "len", "(", "arr", ")", "==", "0", ":", "raise", "ValueError", "(", "\"Cannot normalize the SPL of an emp...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.reduce
Reduces others into this one by concatenating all the others onto this one and returning the result. Does not modify self, instead, makes a copy and returns that. :param others: The other AudioSegment objects to append to this one. :returns: The concatenated result.
audiosegment.py
def reduce(self, others): """ Reduces others into this one by concatenating all the others onto this one and returning the result. Does not modify self, instead, makes a copy and returns that. :param others: The other AudioSegment objects to append to this one. :returns: The con...
def reduce(self, others): """ Reduces others into this one by concatenating all the others onto this one and returning the result. Does not modify self, instead, makes a copy and returns that. :param others: The other AudioSegment objects to append to this one. :returns: The con...
[ "Reduces", "others", "into", "this", "one", "by", "concatenating", "all", "the", "others", "onto", "this", "one", "and", "returning", "the", "result", ".", "Does", "not", "modify", "self", "instead", "makes", "a", "copy", "and", "returns", "that", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L878-L891
[ "def", "reduce", "(", "self", ",", "others", ")", ":", "ret", "=", "AudioSegment", "(", "self", ".", "seg", ",", "self", ".", "name", ")", "selfdata", "=", "[", "self", ".", "seg", ".", "_data", "]", "otherdata", "=", "[", "o", ".", "seg", ".", ...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.resample
Returns a new AudioSegment whose data is the same as this one, but which has been resampled to the specified characteristics. Any parameter left None will be unchanged. .. note:: This method requires that you have the program 'sox' installed. .. warning:: This method uses the program 'sox' to ...
audiosegment.py
def resample(self, sample_rate_Hz=None, sample_width=None, channels=None, console_output=False): """ Returns a new AudioSegment whose data is the same as this one, but which has been resampled to the specified characteristics. Any parameter left None will be unchanged. .. note:: This me...
def resample(self, sample_rate_Hz=None, sample_width=None, channels=None, console_output=False): """ Returns a new AudioSegment whose data is the same as this one, but which has been resampled to the specified characteristics. Any parameter left None will be unchanged. .. note:: This me...
[ "Returns", "a", "new", "AudioSegment", "whose", "data", "is", "the", "same", "as", "this", "one", "but", "which", "has", "been", "resampled", "to", "the", "specified", "characteristics", ".", "Any", "parameter", "left", "None", "will", "be", "unchanged", "."...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L893-L920
[ "def", "resample", "(", "self", ",", "sample_rate_Hz", "=", "None", ",", "sample_width", "=", "None", ",", "channels", "=", "None", ",", "console_output", "=", "False", ")", ":", "if", "sample_rate_Hz", "is", "None", ":", "sample_rate_Hz", "=", "self", "."...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.serialize
Serializes into a bytestring. :returns: An object of type Bytes.
audiosegment.py
def serialize(self): """ Serializes into a bytestring. :returns: An object of type Bytes. """ d = self.__getstate__() return pickle.dumps({ 'name': d['name'], 'seg': pickle.dumps(d['seg'], protocol=-1), }, protocol=-1)
def serialize(self): """ Serializes into a bytestring. :returns: An object of type Bytes. """ d = self.__getstate__() return pickle.dumps({ 'name': d['name'], 'seg': pickle.dumps(d['seg'], protocol=-1), }, protocol=-1)
[ "Serializes", "into", "a", "bytestring", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L938-L948
[ "def", "serialize", "(", "self", ")", ":", "d", "=", "self", ".", "__getstate__", "(", ")", "return", "pickle", ".", "dumps", "(", "{", "'name'", ":", "d", "[", "'name'", "]", ",", "'seg'", ":", "pickle", ".", "dumps", "(", "d", "[", "'seg'", "]"...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.spectrogram
Does a series of FFTs from `start_s` or `start_sample` for `duration_s` or `num_samples`. Effectively, transforms a slice of the AudioSegment into the frequency domain across different time bins. .. code-block:: python # Example for plotting a spectrogram using this function ...
audiosegment.py
def spectrogram(self, start_s=None, duration_s=None, start_sample=None, num_samples=None, window_length_s=None, window_length_samples=None, overlap=0.5, window=('tukey', 0.25)): """ Does a series of FFTs from `start_s` or `start_sample` for `duration_s` or `num_samples`. Effe...
def spectrogram(self, start_s=None, duration_s=None, start_sample=None, num_samples=None, window_length_s=None, window_length_samples=None, overlap=0.5, window=('tukey', 0.25)): """ Does a series of FFTs from `start_s` or `start_sample` for `duration_s` or `num_samples`. Effe...
[ "Does", "a", "series", "of", "FFTs", "from", "start_s", "or", "start_sample", "for", "duration_s", "or", "num_samples", ".", "Effectively", "transforms", "a", "slice", "of", "the", "AudioSegment", "into", "the", "frequency", "domain", "across", "different", "tim...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L950-L1042
[ "def", "spectrogram", "(", "self", ",", "start_s", "=", "None", ",", "duration_s", "=", "None", ",", "start_sample", "=", "None", ",", "num_samples", "=", "None", ",", "window_length_s", "=", "None", ",", "window_length_samples", "=", "None", ",", "overlap",...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.to_numpy_array
Convenience function for `np.array(self.get_array_of_samples())` while keeping the appropriate dtype.
audiosegment.py
def to_numpy_array(self): """ Convenience function for `np.array(self.get_array_of_samples())` while keeping the appropriate dtype. """ dtype_dict = { 1: np.int8, 2: np.int16, 4: np.int32 ...
def to_numpy_array(self): """ Convenience function for `np.array(self.get_array_of_samples())` while keeping the appropriate dtype. """ dtype_dict = { 1: np.int8, 2: np.int16, 4: np.int32 ...
[ "Convenience", "function", "for", "np", ".", "array", "(", "self", ".", "get_array_of_samples", "()", ")", "while", "keeping", "the", "appropriate", "dtype", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L1044-L1055
[ "def", "to_numpy_array", "(", "self", ")", ":", "dtype_dict", "=", "{", "1", ":", "np", ".", "int8", ",", "2", ":", "np", ".", "int16", ",", "4", ":", "np", ".", "int32", "}", "dtype", "=", "dtype_dict", "[", "self", ".", "sample_width", "]", "re...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
AudioSegment.zero_extend
Adds a number of zeros (digital silence) to the AudioSegment (returning a new one). :param duration_s: The number of seconds of zeros to add. If this is specified, `num_samples` must be None. :param num_samples: The number of zeros to add. If this is specified, `duration_s` must be None. :retur...
audiosegment.py
def zero_extend(self, duration_s=None, num_samples=None): """ Adds a number of zeros (digital silence) to the AudioSegment (returning a new one). :param duration_s: The number of seconds of zeros to add. If this is specified, `num_samples` must be None. :param num_samples: The number of...
def zero_extend(self, duration_s=None, num_samples=None): """ Adds a number of zeros (digital silence) to the AudioSegment (returning a new one). :param duration_s: The number of seconds of zeros to add. If this is specified, `num_samples` must be None. :param num_samples: The number of...
[ "Adds", "a", "number", "of", "zeros", "(", "digital", "silence", ")", "to", "the", "AudioSegment", "(", "returning", "a", "new", "one", ")", "." ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/audiosegment.py#L1057-L1072
[ "def", "zero_extend", "(", "self", ",", "duration_s", "=", "None", ",", "num_samples", "=", "None", ")", ":", "if", "duration_s", "is", "not", "None", "and", "num_samples", "is", "not", "None", ":", "raise", "ValueError", "(", "\"`duration_s` and `num_samples`...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
_compute_peaks_or_valleys_of_first_derivative
Takes a spectrogram and returns a 2D array of the form: 0 0 0 1 0 0 1 0 0 0 1 <-- Frequency 0 0 0 1 0 0 0 0 0 0 1 0 <-- Frequency 1 0 0 0 0 0 0 1 0 1 0 0 <-- Frequency 2 *** Time axis ******* Where a 1 means that the value in that time bin in the spectrogram corresponds to a peak/valley ...
algorithms/asa.py
def _compute_peaks_or_valleys_of_first_derivative(s, do_peaks=True): """ Takes a spectrogram and returns a 2D array of the form: 0 0 0 1 0 0 1 0 0 0 1 <-- Frequency 0 0 0 1 0 0 0 0 0 0 1 0 <-- Frequency 1 0 0 0 0 0 0 1 0 1 0 0 <-- Frequency 2 *** Time axis ******* Where a 1 means tha...
def _compute_peaks_or_valleys_of_first_derivative(s, do_peaks=True): """ Takes a spectrogram and returns a 2D array of the form: 0 0 0 1 0 0 1 0 0 0 1 <-- Frequency 0 0 0 1 0 0 0 0 0 0 1 0 <-- Frequency 1 0 0 0 0 0 0 1 0 1 0 0 <-- Frequency 2 *** Time axis ******* Where a 1 means tha...
[ "Takes", "a", "spectrogram", "and", "returns", "a", "2D", "array", "of", "the", "form", ":" ]
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L104-L143
[ "def", "_compute_peaks_or_valleys_of_first_derivative", "(", "s", ",", "do_peaks", "=", "True", ")", ":", "# Get the first derivative of each frequency in the time domain", "gradient", "=", "np", ".", "nan_to_num", "(", "np", ".", "apply_along_axis", "(", "np", ".", "gr...
1daefb8de626ddff3ff7016697c3ad31d262ecd6
test
_correlate_onsets_and_offsets
Takes an array of onsets and an array of offsets, of the shape [nfrequencies, nsamples], where each item in these arrays is either a 0 (not an on/offset) or a 1 (a possible on/offset). This function returns a new offsets array, where there is a one-to-one correlation between onsets and offsets, such that e...
algorithms/asa.py
def _correlate_onsets_and_offsets(onsets, offsets, gradients): """ Takes an array of onsets and an array of offsets, of the shape [nfrequencies, nsamples], where each item in these arrays is either a 0 (not an on/offset) or a 1 (a possible on/offset). This function returns a new offsets array, where th...
def _correlate_onsets_and_offsets(onsets, offsets, gradients): """ Takes an array of onsets and an array of offsets, of the shape [nfrequencies, nsamples], where each item in these arrays is either a 0 (not an on/offset) or a 1 (a possible on/offset). This function returns a new offsets array, where th...
[ "Takes", "an", "array", "of", "onsets", "and", "an", "array", "of", "offsets", "of", "the", "shape", "[", "nfrequencies", "nsamples", "]", "where", "each", "item", "in", "these", "arrays", "is", "either", "a", "0", "(", "not", "an", "on", "/", "offset"...
MaxStrange/AudioSegment
python
https://github.com/MaxStrange/AudioSegment/blob/1daefb8de626ddff3ff7016697c3ad31d262ecd6/algorithms/asa.py#L145-L195
[ "def", "_correlate_onsets_and_offsets", "(", "onsets", ",", "offsets", ",", "gradients", ")", ":", "# For each freq channel:", "for", "freq_index", ",", "(", "ons", ",", "offs", ")", "in", "enumerate", "(", "zip", "(", "onsets", "[", ":", ",", ":", "]", ",...
1daefb8de626ddff3ff7016697c3ad31d262ecd6