id
int32
0
252k
repo
stringlengths
7
55
path
stringlengths
4
127
func_name
stringlengths
1
88
original_string
stringlengths
75
19.8k
language
stringclasses
1 value
code
stringlengths
51
19.8k
code_tokens
list
docstring
stringlengths
3
17.3k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
87
242
8,000
bmihelac/django-cruds
cruds/urls.py
crud_for_app
def crud_for_app(app_label, urlprefix=None): """ Returns list of ``url`` items to CRUD an app. """ if urlprefix is None: urlprefix = app_label + '/' app = apps.get_app_config(app_label) urls = [] for model in app.get_models(): urls += crud_for_model(model, urlprefix) return urls
python
def crud_for_app(app_label, urlprefix=None): if urlprefix is None: urlprefix = app_label + '/' app = apps.get_app_config(app_label) urls = [] for model in app.get_models(): urls += crud_for_model(model, urlprefix) return urls
[ "def", "crud_for_app", "(", "app_label", ",", "urlprefix", "=", "None", ")", ":", "if", "urlprefix", "is", "None", ":", "urlprefix", "=", "app_label", "+", "'/'", "app", "=", "apps", ".", "get_app_config", "(", "app_label", ")", "urls", "=", "[", "]", ...
Returns list of ``url`` items to CRUD an app.
[ "Returns", "list", "of", "url", "items", "to", "CRUD", "an", "app", "." ]
7828aac3eb2b4c02e5f3843c4cbff654d57cf1e7
https://github.com/bmihelac/django-cruds/blob/7828aac3eb2b4c02e5f3843c4cbff654d57cf1e7/cruds/urls.py#L112-L122
8,001
bmihelac/django-cruds
cruds/views.py
CRUDMixin.get_context_data
def get_context_data(self, **kwargs): """ Adds available urls and names. """ context = super(CRUDMixin, self).get_context_data(**kwargs) context.update({ 'model_verbose_name': self.model._meta.verbose_name, 'model_verbose_name_plural': self.model._meta.verbose_name_plural, }) context['fields'] = utils.get_fields(self.model) if hasattr(self, 'object') and self.object: for action in utils.INSTANCE_ACTIONS: try: url = reverse( utils.crud_url_name(self.model, action), kwargs={'pk': self.object.pk}) except NoReverseMatch: # pragma: no cover url = None context['url_%s' % action] = url for action in utils.LIST_ACTIONS: try: url = reverse(utils.crud_url_name(self.model, action)) except NoReverseMatch: # pragma: no cover url = None context['url_%s' % action] = url return context
python
def get_context_data(self, **kwargs): context = super(CRUDMixin, self).get_context_data(**kwargs) context.update({ 'model_verbose_name': self.model._meta.verbose_name, 'model_verbose_name_plural': self.model._meta.verbose_name_plural, }) context['fields'] = utils.get_fields(self.model) if hasattr(self, 'object') and self.object: for action in utils.INSTANCE_ACTIONS: try: url = reverse( utils.crud_url_name(self.model, action), kwargs={'pk': self.object.pk}) except NoReverseMatch: # pragma: no cover url = None context['url_%s' % action] = url for action in utils.LIST_ACTIONS: try: url = reverse(utils.crud_url_name(self.model, action)) except NoReverseMatch: # pragma: no cover url = None context['url_%s' % action] = url return context
[ "def", "get_context_data", "(", "self", ",", "*", "*", "kwargs", ")", ":", "context", "=", "super", "(", "CRUDMixin", ",", "self", ")", ".", "get_context_data", "(", "*", "*", "kwargs", ")", "context", ".", "update", "(", "{", "'model_verbose_name'", ":"...
Adds available urls and names.
[ "Adds", "available", "urls", "and", "names", "." ]
7828aac3eb2b4c02e5f3843c4cbff654d57cf1e7
https://github.com/bmihelac/django-cruds/blob/7828aac3eb2b4c02e5f3843c4cbff654d57cf1e7/cruds/views.py#L23-L52
8,002
bmihelac/django-cruds
cruds/views.py
CRUDMixin.get_template_names
def get_template_names(self): """ Adds crud_template_name to default template names. """ names = super(CRUDMixin, self).get_template_names() if self.crud_template_name: names.append(self.crud_template_name) return names
python
def get_template_names(self): names = super(CRUDMixin, self).get_template_names() if self.crud_template_name: names.append(self.crud_template_name) return names
[ "def", "get_template_names", "(", "self", ")", ":", "names", "=", "super", "(", "CRUDMixin", ",", "self", ")", ".", "get_template_names", "(", ")", "if", "self", ".", "crud_template_name", ":", "names", ".", "append", "(", "self", ".", "crud_template_name", ...
Adds crud_template_name to default template names.
[ "Adds", "crud_template_name", "to", "default", "template", "names", "." ]
7828aac3eb2b4c02e5f3843c4cbff654d57cf1e7
https://github.com/bmihelac/django-cruds/blob/7828aac3eb2b4c02e5f3843c4cbff654d57cf1e7/cruds/views.py#L54-L61
8,003
croscon/fleaker
setup.py
install
def install(): """Install Fleaker. In a function so we can protect this file so it's only run when we explicitly invoke it and not, say, when py.test collects all Python modules. """ _version_re = re.compile(r"__version__\s+=\s+(.*)") # pylint: disable=invalid-name with open('./fleaker/__init__.py', 'rb') as file_: version = ast.literal_eval(_version_re.search( # pylint: disable=invalid-name file_.read().decode('utf-8')).group(1)) download_url = ('https://github.com/croscon/fleaker/archive/' 'v{}.tar.gz'.format(version)) setup( name='fleaker', version=version, download_url=download_url, description='Tools and extensions to make Flask development easier.', url='https://github.com/croscon/fleaker', author='Croscon Consulting', author_email='open.source@croscon.com', license='BSD', packages=[ 'fleaker', 'fleaker.marshmallow', 'fleaker.marshmallow.fields', 'fleaker.peewee', 'fleaker.peewee.fields', 'fleaker.peewee.mixins', 'fleaker.peewee.mixins.time', ], zip_safe=False, long_description=__doc__, include_package_data=True, platforms='any', install_requires=[ 'Flask', 'Flask-Classful', 'Flask-Login', 'Flask-Marshmallow', 'arrow', 'bcrypt', 'blinker', 'marshmallow', 'marshmallow-jsonschema', 'peewee', 'pendulum', 'phonenumbers', 'simplejson', ], classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Environment :: Web Environment', 'Framework :: Flask', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', # @TODO: Pick specific Python versions; out of the gate flask does 2.6, # 2.7, 3.3, 3.4, and 3.5 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development :: Libraries :: Application Frameworks', 'Topic :: Software Development :: Libraries :: Python Modules', ], keywords=['flask', 'web development', 'flask extension'] )
python
def install(): _version_re = re.compile(r"__version__\s+=\s+(.*)") # pylint: disable=invalid-name with open('./fleaker/__init__.py', 'rb') as file_: version = ast.literal_eval(_version_re.search( # pylint: disable=invalid-name file_.read().decode('utf-8')).group(1)) download_url = ('https://github.com/croscon/fleaker/archive/' 'v{}.tar.gz'.format(version)) setup( name='fleaker', version=version, download_url=download_url, description='Tools and extensions to make Flask development easier.', url='https://github.com/croscon/fleaker', author='Croscon Consulting', author_email='open.source@croscon.com', license='BSD', packages=[ 'fleaker', 'fleaker.marshmallow', 'fleaker.marshmallow.fields', 'fleaker.peewee', 'fleaker.peewee.fields', 'fleaker.peewee.mixins', 'fleaker.peewee.mixins.time', ], zip_safe=False, long_description=__doc__, include_package_data=True, platforms='any', install_requires=[ 'Flask', 'Flask-Classful', 'Flask-Login', 'Flask-Marshmallow', 'arrow', 'bcrypt', 'blinker', 'marshmallow', 'marshmallow-jsonschema', 'peewee', 'pendulum', 'phonenumbers', 'simplejson', ], classifiers=[ 'Development Status :: 2 - Pre-Alpha', 'Environment :: Web Environment', 'Framework :: Flask', 'Intended Audience :: Developers', 'License :: OSI Approved :: BSD License', 'Operating System :: OS Independent', 'Programming Language :: Python', # @TODO: Pick specific Python versions; out of the gate flask does 2.6, # 2.7, 3.3, 3.4, and 3.5 'Programming Language :: Python :: 2', 'Programming Language :: Python :: 3', 'Topic :: Internet :: WWW/HTTP :: Dynamic Content', 'Topic :: Software Development :: Libraries :: Application Frameworks', 'Topic :: Software Development :: Libraries :: Python Modules', ], keywords=['flask', 'web development', 'flask extension'] )
[ "def", "install", "(", ")", ":", "_version_re", "=", "re", ".", "compile", "(", "r\"__version__\\s+=\\s+(.*)\"", ")", "# pylint: disable=invalid-name", "with", "open", "(", "'./fleaker/__init__.py'", ",", "'rb'", ")", "as", "file_", ":", "version", "=", "ast", "...
Install Fleaker. In a function so we can protect this file so it's only run when we explicitly invoke it and not, say, when py.test collects all Python modules.
[ "Install", "Fleaker", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/setup.py#L50-L120
8,004
croscon/fleaker
fleaker/peewee/fields/json.py
JSONField.python_value
def python_value(self, value): """Return the JSON in the database as a ``dict``. Returns: dict: The field run through json.loads """ value = super(JSONField, self).python_value(value) if value is not None: return flask.json.loads(value, **self._load_kwargs)
python
def python_value(self, value): value = super(JSONField, self).python_value(value) if value is not None: return flask.json.loads(value, **self._load_kwargs)
[ "def", "python_value", "(", "self", ",", "value", ")", ":", "value", "=", "super", "(", "JSONField", ",", "self", ")", ".", "python_value", "(", "value", ")", "if", "value", "is", "not", "None", ":", "return", "flask", ".", "json", ".", "loads", "(",...
Return the JSON in the database as a ``dict``. Returns: dict: The field run through json.loads
[ "Return", "the", "JSON", "in", "the", "database", "as", "a", "dict", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/fields/json.py#L101-L110
8,005
croscon/fleaker
fleaker/peewee/fields/json.py
JSONField.db_value
def db_value(self, value): """Store the value in the database. If the value is a dict like object, it is converted to a string before storing. """ # Everything is encoded being before being surfaced value = flask.json.dumps(value) return super(JSONField, self).db_value(value)
python
def db_value(self, value): # Everything is encoded being before being surfaced value = flask.json.dumps(value) return super(JSONField, self).db_value(value)
[ "def", "db_value", "(", "self", ",", "value", ")", ":", "# Everything is encoded being before being surfaced", "value", "=", "flask", ".", "json", ".", "dumps", "(", "value", ")", "return", "super", "(", "JSONField", ",", "self", ")", ".", "db_value", "(", "...
Store the value in the database. If the value is a dict like object, it is converted to a string before storing.
[ "Store", "the", "value", "in", "the", "database", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/fields/json.py#L112-L121
8,006
croscon/fleaker
fleaker/peewee/mixins/search.py
SearchMixin.search
def search(cls, term, fields=()): """Generic SQL search function that uses SQL ``LIKE`` to search the database for matching records. The records are sorted by their relavancey to the search term. The query searches and sorts on the folling criteria, in order, where the target string is ``exactly``: 1. Straight equality (``x = 'exactly'``) 2. Right hand ``LIKE`` (``x LIKE 'exact%'``) 3. Substring ``LIKE`` (``x LIKE %act%``) Args: term (str): The search term to apply to the query. Keyword Args: fields (list|tuple|None): An optional list of fields to apply the search to. If not provided, the class variable ``Meta.search_fields`` will be used by default. Returns: peewee.SelectQuery: An unexecuted query for the records. Raises: AttributeError: Raised if `search_fields` isn't defined in the class and `fields` aren't provided for the function. """ if not any((cls._meta.search_fields, fields)): raise AttributeError( "A list of searchable fields must be provided in the class's " "search_fields or provided to this function in the `fields` " "kwarg." ) # If fields are provided, override the ones in the class if not fields: fields = cls._meta.search_fields query = cls.select() # Cache the LIKE terms like_term = ''.join((term, '%')) full_like_term = ''.join(('%', term, '%')) # Cache the order by terms # @TODO Peewee's order_by supports an `extend` kwarg will will allow # for updating of the order by part of the query, but it's only # supported in Peewee 2.8.5 and newer. Determine if we can support this # before switching. # http://docs.peewee-orm.com/en/stable/peewee/api.html#SelectQuery.order_by order_by = [] # Store the clauses seperately because it is needed to perform an OR on # them and that's somehow impossible with their query builder in # a loop. clauses = [] for field_name in fields: # Cache the field, raising an exception if the field doesn't # exist. field = getattr(cls, field_name) # Apply the search term case insensitively clauses.append( (field == term) | (field ** like_term) | (field ** full_like_term) ) order_by.append(case(None, ( # Straight matches should show up first (field == term, 0), # Similar terms should show up second (field ** like_term, 1), # Substring matches should show up third (field ** full_like_term, 2), ), default=3).asc()) # Apply the clauses to the query query = query.where(reduce(operator.or_, clauses)) # Apply the sort order so it's influenced by the search term relevance. query = query.order_by(*order_by) return query
python
def search(cls, term, fields=()): if not any((cls._meta.search_fields, fields)): raise AttributeError( "A list of searchable fields must be provided in the class's " "search_fields or provided to this function in the `fields` " "kwarg." ) # If fields are provided, override the ones in the class if not fields: fields = cls._meta.search_fields query = cls.select() # Cache the LIKE terms like_term = ''.join((term, '%')) full_like_term = ''.join(('%', term, '%')) # Cache the order by terms # @TODO Peewee's order_by supports an `extend` kwarg will will allow # for updating of the order by part of the query, but it's only # supported in Peewee 2.8.5 and newer. Determine if we can support this # before switching. # http://docs.peewee-orm.com/en/stable/peewee/api.html#SelectQuery.order_by order_by = [] # Store the clauses seperately because it is needed to perform an OR on # them and that's somehow impossible with their query builder in # a loop. clauses = [] for field_name in fields: # Cache the field, raising an exception if the field doesn't # exist. field = getattr(cls, field_name) # Apply the search term case insensitively clauses.append( (field == term) | (field ** like_term) | (field ** full_like_term) ) order_by.append(case(None, ( # Straight matches should show up first (field == term, 0), # Similar terms should show up second (field ** like_term, 1), # Substring matches should show up third (field ** full_like_term, 2), ), default=3).asc()) # Apply the clauses to the query query = query.where(reduce(operator.or_, clauses)) # Apply the sort order so it's influenced by the search term relevance. query = query.order_by(*order_by) return query
[ "def", "search", "(", "cls", ",", "term", ",", "fields", "=", "(", ")", ")", ":", "if", "not", "any", "(", "(", "cls", ".", "_meta", ".", "search_fields", ",", "fields", ")", ")", ":", "raise", "AttributeError", "(", "\"A list of searchable fields must b...
Generic SQL search function that uses SQL ``LIKE`` to search the database for matching records. The records are sorted by their relavancey to the search term. The query searches and sorts on the folling criteria, in order, where the target string is ``exactly``: 1. Straight equality (``x = 'exactly'``) 2. Right hand ``LIKE`` (``x LIKE 'exact%'``) 3. Substring ``LIKE`` (``x LIKE %act%``) Args: term (str): The search term to apply to the query. Keyword Args: fields (list|tuple|None): An optional list of fields to apply the search to. If not provided, the class variable ``Meta.search_fields`` will be used by default. Returns: peewee.SelectQuery: An unexecuted query for the records. Raises: AttributeError: Raised if `search_fields` isn't defined in the class and `fields` aren't provided for the function.
[ "Generic", "SQL", "search", "function", "that", "uses", "SQL", "LIKE", "to", "search", "the", "database", "for", "matching", "records", ".", "The", "records", "are", "sorted", "by", "their", "relavancey", "to", "the", "search", "term", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/search.py#L97-L180
8,007
croscon/fleaker
fleaker/marshmallow/fields/foreign_key.py
ForeignKeyField._add_to_schema
def _add_to_schema(self, field_name, schema): """Set the ``attribute`` attr to the field in question so this always gets deserialzed into the field name without ``_id``. Args: field_name (str): The name of the field (the attribute name being set in the schema). schema (marshmallow.Schema): The actual parent schema this field belongs to. """ super(ForeignKeyField, self)._add_to_schema(field_name, schema) if self.get_field_value('convert_fks', default=True): self.attribute = field_name.replace('_id', '')
python
def _add_to_schema(self, field_name, schema): super(ForeignKeyField, self)._add_to_schema(field_name, schema) if self.get_field_value('convert_fks', default=True): self.attribute = field_name.replace('_id', '')
[ "def", "_add_to_schema", "(", "self", ",", "field_name", ",", "schema", ")", ":", "super", "(", "ForeignKeyField", ",", "self", ")", ".", "_add_to_schema", "(", "field_name", ",", "schema", ")", "if", "self", ".", "get_field_value", "(", "'convert_fks'", ","...
Set the ``attribute`` attr to the field in question so this always gets deserialzed into the field name without ``_id``. Args: field_name (str): The name of the field (the attribute name being set in the schema). schema (marshmallow.Schema): The actual parent schema this field belongs to.
[ "Set", "the", "attribute", "attr", "to", "the", "field", "in", "question", "so", "this", "always", "gets", "deserialzed", "into", "the", "field", "name", "without", "_id", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/foreign_key.py#L36-L49
8,008
croscon/fleaker
fleaker/marshmallow/fields/foreign_key.py
ForeignKeyField._serialize
def _serialize(self, value, attr, obj): """Grab the ID value off the Peewee model so we serialize an ID back. """ # this might be an optional field if value: value = value.id return super(ForeignKeyField, self)._serialize(value, attr, obj)
python
def _serialize(self, value, attr, obj): # this might be an optional field if value: value = value.id return super(ForeignKeyField, self)._serialize(value, attr, obj)
[ "def", "_serialize", "(", "self", ",", "value", ",", "attr", ",", "obj", ")", ":", "# this might be an optional field", "if", "value", ":", "value", "=", "value", ".", "id", "return", "super", "(", "ForeignKeyField", ",", "self", ")", ".", "_serialize", "(...
Grab the ID value off the Peewee model so we serialize an ID back.
[ "Grab", "the", "ID", "value", "off", "the", "Peewee", "model", "so", "we", "serialize", "an", "ID", "back", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/foreign_key.py#L51-L58
8,009
croscon/fleaker
fleaker/orm.py
_discover_ideal_backend
def _discover_ideal_backend(orm_backend): """Auto-discover the ideal backend based on what is installed. Right now, handles discovery of: * PeeWee * SQLAlchemy Args: orm_backend (str): The ``orm_backend`` value that was passed to the ``create_app`` function. That is, the ORM Backend the User indicated they wanted to use. Returns: str|fleaker.missing.MissingSentinel: Returns a string for the ideal backend if it found one, or :obj:`fleaker.MISSING` if we couldn't find one. Raises: RuntimeError: Raised if no user provided ORM Backend is given and BOTH PeeWee and SQLAlchemy are installed. """ if orm_backend: return orm_backend if peewee is not MISSING and sqlalchemy is not MISSING: raise RuntimeError('Both PeeWee and SQLAlchemy detected as installed, ' 'but no explicit backend provided! Please specify ' 'one!') if peewee is not MISSING: return _PEEWEE_BACKEND elif sqlalchemy is not MISSING: return _SQLALCHEMY_BACKEND else: return MISSING
python
def _discover_ideal_backend(orm_backend): if orm_backend: return orm_backend if peewee is not MISSING and sqlalchemy is not MISSING: raise RuntimeError('Both PeeWee and SQLAlchemy detected as installed, ' 'but no explicit backend provided! Please specify ' 'one!') if peewee is not MISSING: return _PEEWEE_BACKEND elif sqlalchemy is not MISSING: return _SQLALCHEMY_BACKEND else: return MISSING
[ "def", "_discover_ideal_backend", "(", "orm_backend", ")", ":", "if", "orm_backend", ":", "return", "orm_backend", "if", "peewee", "is", "not", "MISSING", "and", "sqlalchemy", "is", "not", "MISSING", ":", "raise", "RuntimeError", "(", "'Both PeeWee and SQLAlchemy de...
Auto-discover the ideal backend based on what is installed. Right now, handles discovery of: * PeeWee * SQLAlchemy Args: orm_backend (str): The ``orm_backend`` value that was passed to the ``create_app`` function. That is, the ORM Backend the User indicated they wanted to use. Returns: str|fleaker.missing.MissingSentinel: Returns a string for the ideal backend if it found one, or :obj:`fleaker.MISSING` if we couldn't find one. Raises: RuntimeError: Raised if no user provided ORM Backend is given and BOTH PeeWee and SQLAlchemy are installed.
[ "Auto", "-", "discover", "the", "ideal", "backend", "based", "on", "what", "is", "installed", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/orm.py#L83-L116
8,010
croscon/fleaker
fleaker/orm.py
ORMAwareApp._init_peewee_ext
def _init_peewee_ext(cls, app, dummy_configuration=None, dummy_configure_args=None): """Init the actual PeeWee extension with the app that was created. Since PeeWee requires the ``DATABASE`` config parameter to be present IMMEDIATELY upon initializing the application, we need to delay this construction. This is because, in standard use, we will create the app and attempt to init this extension BEFORE we configure the app, which is totally fine. To fix this, we just need to set this up to try and run after every call to configure. If there is not ``DATABASE`` config parameter present when run, this method does nothing other than reschedule itself to run in the future. In all cases, this is a Post Configure Hook that should RUN ONCE! Args: app (flask.Flask): The application you want to init the PeeWee Flask extension for. Hint: if you need to use this as a callback, use a partial to provide this. dummy_configuration (dict): The resulting application configuration that the post_configure hook provides to all of it's callbacks. We will NEVER use this, but since we utilize the post_configure system to register this for complicated apps, we gotta accept it. dummy_configure_args (list[object]): The args passed to the :meth:`configure` function that triggered this callback. Just like the above arg, we'll never use it, but we must accept it. """ # the database still isn't present, go ahead and register the callback # again, so we can try later. if 'DATABASE' not in app.config: app.add_post_configure_callback(partial(cls._init_peewee_ext, app), run_once=True) return _PEEWEE_EXT.init_app(app)
python
def _init_peewee_ext(cls, app, dummy_configuration=None, dummy_configure_args=None): # the database still isn't present, go ahead and register the callback # again, so we can try later. if 'DATABASE' not in app.config: app.add_post_configure_callback(partial(cls._init_peewee_ext, app), run_once=True) return _PEEWEE_EXT.init_app(app)
[ "def", "_init_peewee_ext", "(", "cls", ",", "app", ",", "dummy_configuration", "=", "None", ",", "dummy_configure_args", "=", "None", ")", ":", "# the database still isn't present, go ahead and register the callback", "# again, so we can try later.", "if", "'DATABASE'", "not"...
Init the actual PeeWee extension with the app that was created. Since PeeWee requires the ``DATABASE`` config parameter to be present IMMEDIATELY upon initializing the application, we need to delay this construction. This is because, in standard use, we will create the app and attempt to init this extension BEFORE we configure the app, which is totally fine. To fix this, we just need to set this up to try and run after every call to configure. If there is not ``DATABASE`` config parameter present when run, this method does nothing other than reschedule itself to run in the future. In all cases, this is a Post Configure Hook that should RUN ONCE! Args: app (flask.Flask): The application you want to init the PeeWee Flask extension for. Hint: if you need to use this as a callback, use a partial to provide this. dummy_configuration (dict): The resulting application configuration that the post_configure hook provides to all of it's callbacks. We will NEVER use this, but since we utilize the post_configure system to register this for complicated apps, we gotta accept it. dummy_configure_args (list[object]): The args passed to the :meth:`configure` function that triggered this callback. Just like the above arg, we'll never use it, but we must accept it.
[ "Init", "the", "actual", "PeeWee", "extension", "with", "the", "app", "that", "was", "created", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/orm.py#L303-L338
8,011
croscon/fleaker
fleaker/config.py
MultiStageConfigurableApp.configure
def configure(self, *args, **kwargs): """Configure the Application through a varied number of sources of different types. This function chains multiple possible configuration methods together in order to just "make it work". You can pass multiple configuration sources in to the method and each one will be tried in a sane fashion. Later sources will override earlier sources if keys collide. For example: .. code:: python from application import default_config app.configure(default_config, os.environ, '.secrets') In the above example, values stored in ``default_config`` will be loaded first, then overwritten by those in ``os.environ``, and so on. An endless number of configuration sources may be passed. Configuration sources are type checked and processed according to the following rules: * ``string`` - if the source is a ``str``, we will assume it is a file or module that should be loaded. If the file ends in ``.json``, then :meth:`flask.Config.from_json` is used; if the file ends in ``.py`` or ``.cfg``, then :meth:`flask.Config.from_pyfile` is used; if the module has any other extension we assume it is an import path, import the module and pass that to :meth:`flask.Config.from_object`. See below for a few more semantics on module loading. * ``dict-like`` - if the source is ``dict-like``, then :meth:`flask.Config.from_mapping` will be used. ``dict-like`` is defined as anything implementing an ``items`` method that returns a tuple of ``key``, ``val``. * ``class`` or ``module`` - if the source is an uninstantiated ``class`` or ``module``, then :meth:`flask.Config.from_object` will be used. Just like Flask's standard configuration, only uppercased keys will be loaded into the config. If the item we are passed is a ``string`` and it is determined to be a possible Python module, then a leading ``.`` is relevant. If a leading ``.`` is provided, we assume that the module to import is located in the current package and operate as such; if it begins with anything else we assume the import path provided is absolute. This allows you to source configuration stored in a module in your package, or in another package. Args: *args (object): Any object you want us to try to configure from. Keyword Args: whitelist_keys_from_mappings (bool): Should we whitelist the keys we pull from mappings? Very useful if you're passing in an entire OS ``environ`` and you want to omit things like ``LESSPIPE``. If no whitelist is provided, we use the pre-existing config keys as a whitelist. whitelist (list[str]): An explicit list of keys that should be allowed. If provided and ``whitelist_keys`` is ``True``, we will use that as our whitelist instead of pre-existing app config keys. """ whitelist_keys_from_mappings = kwargs.get( 'whitelist_keys_from_mappings', False ) whitelist = kwargs.get('whitelist') for item in args: if isinstance(item, string_types): _, ext = splitext(item) if ext == '.json': self._configure_from_json(item) elif ext in ('.cfg', '.py'): self._configure_from_pyfile(item) else: self._configure_from_module(item) elif isinstance(item, (types.ModuleType, type)): self._configure_from_object(item) elif hasattr(item, 'items'): # assume everything else is a mapping like object; ``.items()`` # is what Flask uses under the hood for this method # @TODO: This doesn't handle the edge case of using a tuple of # two element tuples to config; but Flask does that. IMO, if # you do that, you're a monster. self._configure_from_mapping( item, whitelist_keys=whitelist_keys_from_mappings, whitelist=whitelist ) else: raise TypeError("Could not determine a valid type for this" " configuration object: `{}`!".format(item)) # we just finished here, run the post configure callbacks self._run_post_configure_callbacks(args)
python
def configure(self, *args, **kwargs): whitelist_keys_from_mappings = kwargs.get( 'whitelist_keys_from_mappings', False ) whitelist = kwargs.get('whitelist') for item in args: if isinstance(item, string_types): _, ext = splitext(item) if ext == '.json': self._configure_from_json(item) elif ext in ('.cfg', '.py'): self._configure_from_pyfile(item) else: self._configure_from_module(item) elif isinstance(item, (types.ModuleType, type)): self._configure_from_object(item) elif hasattr(item, 'items'): # assume everything else is a mapping like object; ``.items()`` # is what Flask uses under the hood for this method # @TODO: This doesn't handle the edge case of using a tuple of # two element tuples to config; but Flask does that. IMO, if # you do that, you're a monster. self._configure_from_mapping( item, whitelist_keys=whitelist_keys_from_mappings, whitelist=whitelist ) else: raise TypeError("Could not determine a valid type for this" " configuration object: `{}`!".format(item)) # we just finished here, run the post configure callbacks self._run_post_configure_callbacks(args)
[ "def", "configure", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "whitelist_keys_from_mappings", "=", "kwargs", ".", "get", "(", "'whitelist_keys_from_mappings'", ",", "False", ")", "whitelist", "=", "kwargs", ".", "get", "(", "'whitelis...
Configure the Application through a varied number of sources of different types. This function chains multiple possible configuration methods together in order to just "make it work". You can pass multiple configuration sources in to the method and each one will be tried in a sane fashion. Later sources will override earlier sources if keys collide. For example: .. code:: python from application import default_config app.configure(default_config, os.environ, '.secrets') In the above example, values stored in ``default_config`` will be loaded first, then overwritten by those in ``os.environ``, and so on. An endless number of configuration sources may be passed. Configuration sources are type checked and processed according to the following rules: * ``string`` - if the source is a ``str``, we will assume it is a file or module that should be loaded. If the file ends in ``.json``, then :meth:`flask.Config.from_json` is used; if the file ends in ``.py`` or ``.cfg``, then :meth:`flask.Config.from_pyfile` is used; if the module has any other extension we assume it is an import path, import the module and pass that to :meth:`flask.Config.from_object`. See below for a few more semantics on module loading. * ``dict-like`` - if the source is ``dict-like``, then :meth:`flask.Config.from_mapping` will be used. ``dict-like`` is defined as anything implementing an ``items`` method that returns a tuple of ``key``, ``val``. * ``class`` or ``module`` - if the source is an uninstantiated ``class`` or ``module``, then :meth:`flask.Config.from_object` will be used. Just like Flask's standard configuration, only uppercased keys will be loaded into the config. If the item we are passed is a ``string`` and it is determined to be a possible Python module, then a leading ``.`` is relevant. If a leading ``.`` is provided, we assume that the module to import is located in the current package and operate as such; if it begins with anything else we assume the import path provided is absolute. This allows you to source configuration stored in a module in your package, or in another package. Args: *args (object): Any object you want us to try to configure from. Keyword Args: whitelist_keys_from_mappings (bool): Should we whitelist the keys we pull from mappings? Very useful if you're passing in an entire OS ``environ`` and you want to omit things like ``LESSPIPE``. If no whitelist is provided, we use the pre-existing config keys as a whitelist. whitelist (list[str]): An explicit list of keys that should be allowed. If provided and ``whitelist_keys`` is ``True``, we will use that as our whitelist instead of pre-existing app config keys.
[ "Configure", "the", "Application", "through", "a", "varied", "number", "of", "sources", "of", "different", "types", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/config.py#L56-L156
8,012
croscon/fleaker
fleaker/config.py
MultiStageConfigurableApp._configure_from_module
def _configure_from_module(self, item): """Configure from a module by import path. Effectively, you give this an absolute or relative import path, it will import it, and then pass the resulting object to ``_configure_from_object``. Args: item (str): A string pointing to a valid import path. Returns: fleaker.App: Returns itself. """ package = None if item[0] == '.': package = self.import_name obj = importlib.import_module(item, package=package) self.config.from_object(obj) return self
python
def _configure_from_module(self, item): package = None if item[0] == '.': package = self.import_name obj = importlib.import_module(item, package=package) self.config.from_object(obj) return self
[ "def", "_configure_from_module", "(", "self", ",", "item", ")", ":", "package", "=", "None", "if", "item", "[", "0", "]", "==", "'.'", ":", "package", "=", "self", ".", "import_name", "obj", "=", "importlib", ".", "import_module", "(", "item", ",", "pa...
Configure from a module by import path. Effectively, you give this an absolute or relative import path, it will import it, and then pass the resulting object to ``_configure_from_object``. Args: item (str): A string pointing to a valid import path. Returns: fleaker.App: Returns itself.
[ "Configure", "from", "a", "module", "by", "import", "path", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/config.py#L195-L218
8,013
croscon/fleaker
fleaker/config.py
MultiStageConfigurableApp._configure_from_mapping
def _configure_from_mapping(self, item, whitelist_keys=False, whitelist=None): """Configure from a mapping, or dict, like object. Args: item (dict): A dict-like object that we can pluck values from. Keyword Args: whitelist_keys (bool): Should we whitelist the keys before adding them to the configuration? If no whitelist is provided, we use the pre-existing config keys as a whitelist. whitelist (list[str]): An explicit list of keys that should be allowed. If provided and ``whitelist_keys`` is true, we will use that as our whitelist instead of pre-existing app config keys. Returns: fleaker.App: Returns itself. """ if whitelist is None: whitelist = self.config.keys() if whitelist_keys: item = {k: v for k, v in item.items() if k in whitelist} self.config.from_mapping(item) return self
python
def _configure_from_mapping(self, item, whitelist_keys=False, whitelist=None): if whitelist is None: whitelist = self.config.keys() if whitelist_keys: item = {k: v for k, v in item.items() if k in whitelist} self.config.from_mapping(item) return self
[ "def", "_configure_from_mapping", "(", "self", ",", "item", ",", "whitelist_keys", "=", "False", ",", "whitelist", "=", "None", ")", ":", "if", "whitelist", "is", "None", ":", "whitelist", "=", "self", ".", "config", ".", "keys", "(", ")", "if", "whiteli...
Configure from a mapping, or dict, like object. Args: item (dict): A dict-like object that we can pluck values from. Keyword Args: whitelist_keys (bool): Should we whitelist the keys before adding them to the configuration? If no whitelist is provided, we use the pre-existing config keys as a whitelist. whitelist (list[str]): An explicit list of keys that should be allowed. If provided and ``whitelist_keys`` is true, we will use that as our whitelist instead of pre-existing app config keys. Returns: fleaker.App: Returns itself.
[ "Configure", "from", "a", "mapping", "or", "dict", "like", "object", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/config.py#L220-L250
8,014
croscon/fleaker
fleaker/config.py
MultiStageConfigurableApp.configure_from_environment
def configure_from_environment(self, whitelist_keys=False, whitelist=None): """Configure from the entire set of available environment variables. This is really a shorthand for grabbing ``os.environ`` and passing to :meth:`_configure_from_mapping`. As always, only uppercase keys are loaded. Keyword Args: whitelist_keys (bool): Should we whitelist the keys by only pulling those that are already present in the config? Useful for avoiding adding things like ``LESSPIPE`` to your app config. If no whitelist is provided, we use the current config keys as our whitelist. whitelist (list[str]): An explicit list of keys that should be allowed. If provided and ``whitelist_keys`` is true, we will use that as our whitelist instead of pre-existing app config keys. Returns: fleaker.base.BaseApplication: Returns itself. """ self._configure_from_mapping(os.environ, whitelist_keys=whitelist_keys, whitelist=whitelist) return self
python
def configure_from_environment(self, whitelist_keys=False, whitelist=None): self._configure_from_mapping(os.environ, whitelist_keys=whitelist_keys, whitelist=whitelist) return self
[ "def", "configure_from_environment", "(", "self", ",", "whitelist_keys", "=", "False", ",", "whitelist", "=", "None", ")", ":", "self", ".", "_configure_from_mapping", "(", "os", ".", "environ", ",", "whitelist_keys", "=", "whitelist_keys", ",", "whitelist", "="...
Configure from the entire set of available environment variables. This is really a shorthand for grabbing ``os.environ`` and passing to :meth:`_configure_from_mapping`. As always, only uppercase keys are loaded. Keyword Args: whitelist_keys (bool): Should we whitelist the keys by only pulling those that are already present in the config? Useful for avoiding adding things like ``LESSPIPE`` to your app config. If no whitelist is provided, we use the current config keys as our whitelist. whitelist (list[str]): An explicit list of keys that should be allowed. If provided and ``whitelist_keys`` is true, we will use that as our whitelist instead of pre-existing app config keys. Returns: fleaker.base.BaseApplication: Returns itself.
[ "Configure", "from", "the", "entire", "set", "of", "available", "environment", "variables", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/config.py#L267-L293
8,015
croscon/fleaker
fleaker/config.py
MultiStageConfigurableApp._run_post_configure_callbacks
def _run_post_configure_callbacks(self, configure_args): """Run all post configure callbacks we have stored. Functions are passed the configuration that resulted from the call to :meth:`configure` as the first argument, in an immutable form; and are given the arguments passed to :meth:`configure` for the second argument. Returns from callbacks are ignored in all fashion. Args: configure_args (list[object]): The full list of arguments passed to :meth:`configure`. Returns: None: Does not return anything. """ resulting_configuration = ImmutableDict(self.config) # copy callbacks in case people edit them while running multiple_callbacks = copy.copy( self._post_configure_callbacks['multiple'] ) single_callbacks = copy.copy(self._post_configure_callbacks['single']) # clear out the singles self._post_configure_callbacks['single'] = [] for callback in multiple_callbacks: callback(resulting_configuration, configure_args) # now do the single run callbacks for callback in single_callbacks: callback(resulting_configuration, configure_args)
python
def _run_post_configure_callbacks(self, configure_args): resulting_configuration = ImmutableDict(self.config) # copy callbacks in case people edit them while running multiple_callbacks = copy.copy( self._post_configure_callbacks['multiple'] ) single_callbacks = copy.copy(self._post_configure_callbacks['single']) # clear out the singles self._post_configure_callbacks['single'] = [] for callback in multiple_callbacks: callback(resulting_configuration, configure_args) # now do the single run callbacks for callback in single_callbacks: callback(resulting_configuration, configure_args)
[ "def", "_run_post_configure_callbacks", "(", "self", ",", "configure_args", ")", ":", "resulting_configuration", "=", "ImmutableDict", "(", "self", ".", "config", ")", "# copy callbacks in case people edit them while running", "multiple_callbacks", "=", "copy", ".", "copy",...
Run all post configure callbacks we have stored. Functions are passed the configuration that resulted from the call to :meth:`configure` as the first argument, in an immutable form; and are given the arguments passed to :meth:`configure` for the second argument. Returns from callbacks are ignored in all fashion. Args: configure_args (list[object]): The full list of arguments passed to :meth:`configure`. Returns: None: Does not return anything.
[ "Run", "all", "post", "configure", "callbacks", "we", "have", "stored", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/config.py#L346-L379
8,016
croscon/fleaker
fleaker/marshmallow/schema.py
Schema.make_instance
def make_instance(cls, data): """Validate the data and create a model instance from the data. Args: data (dict): The unserialized data to insert into the new model instance through it's constructor. Returns: peewee.Model|sqlalchemy.Model: The model instance with it's data inserted into it. Raises: AttributeError: This is raised if ``Meta.model`` isn't set on the schema's definition. """ schema = cls() if not hasattr(schema.Meta, 'model'): raise AttributeError("In order to make an instance, a model for " "the schema must be defined in the Meta " "class.") serialized_data = schema.load(data).data return cls.Meta.model(**serialized_data)
python
def make_instance(cls, data): schema = cls() if not hasattr(schema.Meta, 'model'): raise AttributeError("In order to make an instance, a model for " "the schema must be defined in the Meta " "class.") serialized_data = schema.load(data).data return cls.Meta.model(**serialized_data)
[ "def", "make_instance", "(", "cls", ",", "data", ")", ":", "schema", "=", "cls", "(", ")", "if", "not", "hasattr", "(", "schema", ".", "Meta", ",", "'model'", ")", ":", "raise", "AttributeError", "(", "\"In order to make an instance, a model for \"", "\"the sc...
Validate the data and create a model instance from the data. Args: data (dict): The unserialized data to insert into the new model instance through it's constructor. Returns: peewee.Model|sqlalchemy.Model: The model instance with it's data inserted into it. Raises: AttributeError: This is raised if ``Meta.model`` isn't set on the schema's definition.
[ "Validate", "the", "data", "and", "create", "a", "model", "instance", "from", "the", "data", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/schema.py#L41-L65
8,017
croscon/fleaker
fleaker/marshmallow/schema.py
Schema.invalid_fields
def invalid_fields(self, data, original_data): """Validator that checks if any keys provided aren't in the schema. Say your schema has support for keys ``a`` and ``b`` and the data provided has keys ``a``, ``b``, and ``c``. When the data is loaded into the schema, a :class:`marshmallow.ValidationError` will be raised informing the developer that excess keys have been provided. Raises: marshmallow.ValidationError: Raised if extra keys exist in the passed in data. """ errors = [] for field in original_data: # Skip nested fields because they will loop infinitely if isinstance(field, (set, list, tuple, dict)): continue if field not in self.fields.keys(): errors.append(field) if errors: raise ValidationError("Invalid field", field_names=errors)
python
def invalid_fields(self, data, original_data): errors = [] for field in original_data: # Skip nested fields because they will loop infinitely if isinstance(field, (set, list, tuple, dict)): continue if field not in self.fields.keys(): errors.append(field) if errors: raise ValidationError("Invalid field", field_names=errors)
[ "def", "invalid_fields", "(", "self", ",", "data", ",", "original_data", ")", ":", "errors", "=", "[", "]", "for", "field", "in", "original_data", ":", "# Skip nested fields because they will loop infinitely", "if", "isinstance", "(", "field", ",", "(", "set", "...
Validator that checks if any keys provided aren't in the schema. Say your schema has support for keys ``a`` and ``b`` and the data provided has keys ``a``, ``b``, and ``c``. When the data is loaded into the schema, a :class:`marshmallow.ValidationError` will be raised informing the developer that excess keys have been provided. Raises: marshmallow.ValidationError: Raised if extra keys exist in the passed in data.
[ "Validator", "that", "checks", "if", "any", "keys", "provided", "aren", "t", "in", "the", "schema", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/schema.py#L68-L91
8,018
croscon/fleaker
fleaker/peewee/fields/arrow.py
ArrowDateTimeField.python_value
def python_value(self, value): """Return the value in the data base as an arrow object. Returns: arrow.Arrow: An instance of arrow with the field filled in. """ value = super(ArrowDateTimeField, self).python_value(value) if (isinstance(value, (datetime.datetime, datetime.date, string_types))): return arrow.get(value) return value
python
def python_value(self, value): value = super(ArrowDateTimeField, self).python_value(value) if (isinstance(value, (datetime.datetime, datetime.date, string_types))): return arrow.get(value) return value
[ "def", "python_value", "(", "self", ",", "value", ")", ":", "value", "=", "super", "(", "ArrowDateTimeField", ",", "self", ")", ".", "python_value", "(", "value", ")", "if", "(", "isinstance", "(", "value", ",", "(", "datetime", ".", "datetime", ",", "...
Return the value in the data base as an arrow object. Returns: arrow.Arrow: An instance of arrow with the field filled in.
[ "Return", "the", "value", "in", "the", "data", "base", "as", "an", "arrow", "object", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/fields/arrow.py#L68-L80
8,019
croscon/fleaker
fleaker/peewee/fields/arrow.py
ArrowDateTimeField.db_value
def db_value(self, value): """Convert the Arrow instance to a datetime for saving in the db.""" if isinstance(value, string_types): value = arrow.get(value) if isinstance(value, arrow.Arrow): value = value.datetime return super(ArrowDateTimeField, self).db_value(value)
python
def db_value(self, value): if isinstance(value, string_types): value = arrow.get(value) if isinstance(value, arrow.Arrow): value = value.datetime return super(ArrowDateTimeField, self).db_value(value)
[ "def", "db_value", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "string_types", ")", ":", "value", "=", "arrow", ".", "get", "(", "value", ")", "if", "isinstance", "(", "value", ",", "arrow", ".", "Arrow", ")", ":", "...
Convert the Arrow instance to a datetime for saving in the db.
[ "Convert", "the", "Arrow", "instance", "to", "a", "datetime", "for", "saving", "in", "the", "db", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/fields/arrow.py#L82-L90
8,020
croscon/fleaker
fleaker/component.py
Component._context_callbacks
def _context_callbacks(app, key, original_context=_CONTEXT_MISSING): """Register the callbacks we need to properly pop and push the app-local context for a component. Args: app (flask.Flask): The app who this context belongs to. This is the only sender our Blinker signal will listen to. key (str): The key on ``_CONTEXT_LOCALS`` that this app's context listens to. Kwargs: original_context (dict): The original context present whenever these callbacks were registered. We will restore the context to this value whenever the app context gets popped. Returns: (function, function): A two-element tuple of the dynamic functions we generated as appcontext callbacks. The first element is the callback for ``appcontext_pushed`` (i.e., get and store the current context) and the second element is the callback for ``appcontext_popped`` (i.e., restore the current context to to it's original value). """ def _get_context(dummy_app): """Set the context proxy so that it points to a specific context. """ _CONTEXT_LOCALS.context = _CONTEXT_LOCALS(key) # pylint: disable=assigning-non-slot def _clear_context(dummy_app): """Remove the context proxy that points to a specific context and restore the original context, if there was one. """ try: del _CONTEXT_LOCALS.context except AttributeError: pass if original_context is not _CONTEXT_MISSING: setattr(_CONTEXT_LOCALS, key, original_context) # store for later so Blinker doesn't remove these listeners and so we # don't add them twice _CONTEXT_CALLBACK_MAP[app] = (_get_context, _clear_context) # and listen for any app context changes appcontext_pushed.connect(_get_context, app) appcontext_popped.connect(_clear_context, app) return (_get_context, _clear_context)
python
def _context_callbacks(app, key, original_context=_CONTEXT_MISSING): def _get_context(dummy_app): """Set the context proxy so that it points to a specific context. """ _CONTEXT_LOCALS.context = _CONTEXT_LOCALS(key) # pylint: disable=assigning-non-slot def _clear_context(dummy_app): """Remove the context proxy that points to a specific context and restore the original context, if there was one. """ try: del _CONTEXT_LOCALS.context except AttributeError: pass if original_context is not _CONTEXT_MISSING: setattr(_CONTEXT_LOCALS, key, original_context) # store for later so Blinker doesn't remove these listeners and so we # don't add them twice _CONTEXT_CALLBACK_MAP[app] = (_get_context, _clear_context) # and listen for any app context changes appcontext_pushed.connect(_get_context, app) appcontext_popped.connect(_clear_context, app) return (_get_context, _clear_context)
[ "def", "_context_callbacks", "(", "app", ",", "key", ",", "original_context", "=", "_CONTEXT_MISSING", ")", ":", "def", "_get_context", "(", "dummy_app", ")", ":", "\"\"\"Set the context proxy so that it points to a specific context.\n \"\"\"", "_CONTEXT_LOCALS", "...
Register the callbacks we need to properly pop and push the app-local context for a component. Args: app (flask.Flask): The app who this context belongs to. This is the only sender our Blinker signal will listen to. key (str): The key on ``_CONTEXT_LOCALS`` that this app's context listens to. Kwargs: original_context (dict): The original context present whenever these callbacks were registered. We will restore the context to this value whenever the app context gets popped. Returns: (function, function): A two-element tuple of the dynamic functions we generated as appcontext callbacks. The first element is the callback for ``appcontext_pushed`` (i.e., get and store the current context) and the second element is the callback for ``appcontext_popped`` (i.e., restore the current context to to it's original value).
[ "Register", "the", "callbacks", "we", "need", "to", "properly", "pop", "and", "push", "the", "app", "-", "local", "context", "for", "a", "component", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/component.py#L127-L175
8,021
croscon/fleaker
fleaker/component.py
Component.update_context
def update_context(self, context, app=None): """Replace the component's context with a new one. Args: context (dict): The new context to set this component's context to. Keyword Args: app (flask.Flask, optional): The app to update this context for. If not provided, the result of ``Component.app`` will be used. """ if (app is None and self._context is _CONTEXT_MISSING and not in_app_context()): raise RuntimeError("Attempted to update component context without" " a bound app context or eager app set! Please" " pass the related app you want to update the" " context for!") if self._context is not _CONTEXT_MISSING: self._context = ImmutableDict(context) else: key = self._get_context_name(app=app) setattr(_CONTEXT_LOCALS, key, ImmutableDict(context))
python
def update_context(self, context, app=None): if (app is None and self._context is _CONTEXT_MISSING and not in_app_context()): raise RuntimeError("Attempted to update component context without" " a bound app context or eager app set! Please" " pass the related app you want to update the" " context for!") if self._context is not _CONTEXT_MISSING: self._context = ImmutableDict(context) else: key = self._get_context_name(app=app) setattr(_CONTEXT_LOCALS, key, ImmutableDict(context))
[ "def", "update_context", "(", "self", ",", "context", ",", "app", "=", "None", ")", ":", "if", "(", "app", "is", "None", "and", "self", ".", "_context", "is", "_CONTEXT_MISSING", "and", "not", "in_app_context", "(", ")", ")", ":", "raise", "RuntimeError"...
Replace the component's context with a new one. Args: context (dict): The new context to set this component's context to. Keyword Args: app (flask.Flask, optional): The app to update this context for. If not provided, the result of ``Component.app`` will be used.
[ "Replace", "the", "component", "s", "context", "with", "a", "new", "one", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/component.py#L199-L220
8,022
croscon/fleaker
fleaker/component.py
Component.clear_context
def clear_context(self, app=None): """Clear the component's context. Keyword Args: app (flask.Flask, optional): The app to clear this component's context for. If omitted, the value from ``Component.app`` is used. """ if (app is None and self._context is _CONTEXT_MISSING and not in_app_context()): raise RuntimeError("Attempted to clear component context without" " a bound app context or eager app set! Please" " pass the related app you want to update the" " context for!") if self._context is not _CONTEXT_MISSING: self._context = DEFAULT_DICT else: key = self._get_context_name(app=app) setattr(_CONTEXT_LOCALS, key, DEFAULT_DICT)
python
def clear_context(self, app=None): if (app is None and self._context is _CONTEXT_MISSING and not in_app_context()): raise RuntimeError("Attempted to clear component context without" " a bound app context or eager app set! Please" " pass the related app you want to update the" " context for!") if self._context is not _CONTEXT_MISSING: self._context = DEFAULT_DICT else: key = self._get_context_name(app=app) setattr(_CONTEXT_LOCALS, key, DEFAULT_DICT)
[ "def", "clear_context", "(", "self", ",", "app", "=", "None", ")", ":", "if", "(", "app", "is", "None", "and", "self", ".", "_context", "is", "_CONTEXT_MISSING", "and", "not", "in_app_context", "(", ")", ")", ":", "raise", "RuntimeError", "(", "\"Attempt...
Clear the component's context. Keyword Args: app (flask.Flask, optional): The app to clear this component's context for. If omitted, the value from ``Component.app`` is used.
[ "Clear", "the", "component", "s", "context", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/component.py#L222-L241
8,023
croscon/fleaker
fleaker/component.py
Component.app
def app(self): """Internal method that will supply the app to use internally. Returns: flask.Flask: The app to use within the component. Raises: RuntimeError: This is raised if no app was provided to the component and the method is being called outside of an application context. """ app = self._app or current_app if not in_app_context(app): raise RuntimeError("This component hasn't been initialized yet " "and an app context doesn't exist.") # If current_app is the app, this must be used in order for their IDs # to be the same, as current_app will wrap the app in a proxy. if hasattr(app, '_get_current_object'): app = app._get_current_object() return app
python
def app(self): app = self._app or current_app if not in_app_context(app): raise RuntimeError("This component hasn't been initialized yet " "and an app context doesn't exist.") # If current_app is the app, this must be used in order for their IDs # to be the same, as current_app will wrap the app in a proxy. if hasattr(app, '_get_current_object'): app = app._get_current_object() return app
[ "def", "app", "(", "self", ")", ":", "app", "=", "self", ".", "_app", "or", "current_app", "if", "not", "in_app_context", "(", "app", ")", ":", "raise", "RuntimeError", "(", "\"This component hasn't been initialized yet \"", "\"and an app context doesn't exist.\"", ...
Internal method that will supply the app to use internally. Returns: flask.Flask: The app to use within the component. Raises: RuntimeError: This is raised if no app was provided to the component and the method is being called outside of an application context.
[ "Internal", "method", "that", "will", "supply", "the", "app", "to", "use", "internally", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/component.py#L244-L266
8,024
croscon/fleaker
fleaker/component.py
Component._get_context_name
def _get_context_name(self, app=None): """Generate the name of the context variable for this component & app. Because we store the ``context`` in a Local so the component can be used across multiple apps, we cannot store the context on the instance itself. This function will generate a unique and predictable key in which to store the context. Returns: str: The name of the context variable to set and get the context from. """ elements = [ self.__class__.__name__, 'context', text_type(id(self)), ] if app: elements.append(text_type(id(app))) else: try: elements.append(text_type(id(self.app))) except RuntimeError: pass return '_'.join(elements)
python
def _get_context_name(self, app=None): elements = [ self.__class__.__name__, 'context', text_type(id(self)), ] if app: elements.append(text_type(id(app))) else: try: elements.append(text_type(id(self.app))) except RuntimeError: pass return '_'.join(elements)
[ "def", "_get_context_name", "(", "self", ",", "app", "=", "None", ")", ":", "elements", "=", "[", "self", ".", "__class__", ".", "__name__", ",", "'context'", ",", "text_type", "(", "id", "(", "self", ")", ")", ",", "]", "if", "app", ":", "elements",...
Generate the name of the context variable for this component & app. Because we store the ``context`` in a Local so the component can be used across multiple apps, we cannot store the context on the instance itself. This function will generate a unique and predictable key in which to store the context. Returns: str: The name of the context variable to set and get the context from.
[ "Generate", "the", "name", "of", "the", "context", "variable", "for", "this", "component", "&", "app", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/component.py#L277-L303
8,025
croscon/fleaker
fleaker/base.py
BaseApplication.create_app
def create_app(cls, import_name, **settings): """Create a standard Fleaker web application. This is the main entrypoint for creating your Fleaker application. Instead of defining your own app factory function, it's preferred that you use :meth:`create_app`, which is responsible for automatically configuring extensions (such as your ORM), parsing setup code for mixins, and calling relevant hooks (such as to setup logging). Usage is easy: .. code:: python from fleaker import App def my_create_app(): app = App.create_app(__name__) return app And the rest works like a normal Flask app with application factories setup! .. versionadded:: 0.1.0 This has always been the preferred way to create Fleaker Applications. """ settings = cls.pre_create_app(**settings) # now whitelist the settings flask_kwargs = cls._whitelist_standard_flask_kwargs(settings) app = cls(import_name, **flask_kwargs) return cls.post_create_app(app, **settings)
python
def create_app(cls, import_name, **settings): settings = cls.pre_create_app(**settings) # now whitelist the settings flask_kwargs = cls._whitelist_standard_flask_kwargs(settings) app = cls(import_name, **flask_kwargs) return cls.post_create_app(app, **settings)
[ "def", "create_app", "(", "cls", ",", "import_name", ",", "*", "*", "settings", ")", ":", "settings", "=", "cls", ".", "pre_create_app", "(", "*", "*", "settings", ")", "# now whitelist the settings", "flask_kwargs", "=", "cls", ".", "_whitelist_standard_flask_k...
Create a standard Fleaker web application. This is the main entrypoint for creating your Fleaker application. Instead of defining your own app factory function, it's preferred that you use :meth:`create_app`, which is responsible for automatically configuring extensions (such as your ORM), parsing setup code for mixins, and calling relevant hooks (such as to setup logging). Usage is easy: .. code:: python from fleaker import App def my_create_app(): app = App.create_app(__name__) return app And the rest works like a normal Flask app with application factories setup! .. versionadded:: 0.1.0 This has always been the preferred way to create Fleaker Applications.
[ "Create", "a", "standard", "Fleaker", "web", "application", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/base.py#L72-L104
8,026
croscon/fleaker
fleaker/logging.py
FleakerLogFormatter.format
def format(self, record): """Format the log record.""" levelname = getattr(record, 'levelname', None) record.levelcolor = '' record.endlevelcolor = '' if levelname: level_color = getattr(self.TermColors, levelname, '') record.levelcolor = level_color record.endlevelcolor = self.TermColors.ENDC if level_color else '' return super(FleakerLogFormatter, self).format(record)
python
def format(self, record): levelname = getattr(record, 'levelname', None) record.levelcolor = '' record.endlevelcolor = '' if levelname: level_color = getattr(self.TermColors, levelname, '') record.levelcolor = level_color record.endlevelcolor = self.TermColors.ENDC if level_color else '' return super(FleakerLogFormatter, self).format(record)
[ "def", "format", "(", "self", ",", "record", ")", ":", "levelname", "=", "getattr", "(", "record", ",", "'levelname'", ",", "None", ")", "record", ".", "levelcolor", "=", "''", "record", ".", "endlevelcolor", "=", "''", "if", "levelname", ":", "level_col...
Format the log record.
[ "Format", "the", "log", "record", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/logging.py#L59-L70
8,027
croscon/fleaker
fleaker/exceptions.py
FleakerBaseException.errorhandler_callback
def errorhandler_callback(cls, exc): """This function should be called in the global error handlers. This will allow for consolidating of cleanup tasks if the exception bubbles all the way to the top of the stack. For example, this method will automatically rollback the database session if the exception bubbles to the top. This is the method that :meth:`register_errorhandler` adds as an errorhandler. See the documentation there for more info. Args: exc (FleakerBaseException): The exception that was thrown that we are to handle. """ # @TODO (orm, exc): Implement this when the ORM/DB stuff is done # if not exc.prevent_rollback: # db.session.rollback() if exc.flash_message: flash(exc.flash_message, exc.flash_level) if exc.redirect is not MISSING: return redirect(url_for(exc.redirect, **exc.redirect_args)) error_result = exc.error_page() if error_result is not None: return error_result, exc.status_code or 500
python
def errorhandler_callback(cls, exc): # @TODO (orm, exc): Implement this when the ORM/DB stuff is done # if not exc.prevent_rollback: # db.session.rollback() if exc.flash_message: flash(exc.flash_message, exc.flash_level) if exc.redirect is not MISSING: return redirect(url_for(exc.redirect, **exc.redirect_args)) error_result = exc.error_page() if error_result is not None: return error_result, exc.status_code or 500
[ "def", "errorhandler_callback", "(", "cls", ",", "exc", ")", ":", "# @TODO (orm, exc): Implement this when the ORM/DB stuff is done", "# if not exc.prevent_rollback:", "# db.session.rollback()", "if", "exc", ".", "flash_message", ":", "flash", "(", "exc", ".", "flash_mess...
This function should be called in the global error handlers. This will allow for consolidating of cleanup tasks if the exception bubbles all the way to the top of the stack. For example, this method will automatically rollback the database session if the exception bubbles to the top. This is the method that :meth:`register_errorhandler` adds as an errorhandler. See the documentation there for more info. Args: exc (FleakerBaseException): The exception that was thrown that we are to handle.
[ "This", "function", "should", "be", "called", "in", "the", "global", "error", "handlers", ".", "This", "will", "allow", "for", "consolidating", "of", "cleanup", "tasks", "if", "the", "exception", "bubbles", "all", "the", "way", "to", "the", "top", "of", "t...
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/exceptions.py#L116-L144
8,028
croscon/fleaker
fleaker/exceptions.py
ErrorAwareApp.post_create_app
def post_create_app(cls, app, **settings): """Register the errorhandler for the AppException to the passed in App. Args: app (fleaker.base.BaseApplication): A Flask application that extends the Fleaker Base Application, such that the hooks are implemented. Kwargs: register_errorhandler (bool): A boolean indicating if we want to automatically register an errorhandler for the :class:`AppException` exception class after we create this App. Pass ``False`` to prevent registration. Default is ``True``. Returns: fleaker.base.BaseApplication: Returns the app it was given. """ register_errorhandler = settings.pop('register_errorhandler', True) if register_errorhandler: AppException.register_errorhandler(app) return app
python
def post_create_app(cls, app, **settings): register_errorhandler = settings.pop('register_errorhandler', True) if register_errorhandler: AppException.register_errorhandler(app) return app
[ "def", "post_create_app", "(", "cls", ",", "app", ",", "*", "*", "settings", ")", ":", "register_errorhandler", "=", "settings", ".", "pop", "(", "'register_errorhandler'", ",", "True", ")", "if", "register_errorhandler", ":", "AppException", ".", "register_erro...
Register the errorhandler for the AppException to the passed in App. Args: app (fleaker.base.BaseApplication): A Flask application that extends the Fleaker Base Application, such that the hooks are implemented. Kwargs: register_errorhandler (bool): A boolean indicating if we want to automatically register an errorhandler for the :class:`AppException` exception class after we create this App. Pass ``False`` to prevent registration. Default is ``True``. Returns: fleaker.base.BaseApplication: Returns the app it was given.
[ "Register", "the", "errorhandler", "for", "the", "AppException", "to", "the", "passed", "in", "App", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/exceptions.py#L349-L373
8,029
croscon/fleaker
examples/fleaker_config/fleaker_config/fleaker_config.py
create_app
def create_app(): """Create the standard app for ``fleaker_config`` and register the two routes required. """ app = App.create_app(__name__) app.configure('.configs.settings') # yes, I should use blueprints; but I don't really care for such a small # toy app @app.route('/config') def get_config(): """Get the current configuration of the app.""" return jsonify(app.config) @app.route('/put_config', methods=['PUT']) def put_config(): """Add to the current configuration of the app. Takes any JSON body and adds all keys to the configs with the provided values. """ data = request.json() for key, val in data.items(): app.config[key] = val return jsonify({'message': 'Config updated!'}) return app
python
def create_app(): app = App.create_app(__name__) app.configure('.configs.settings') # yes, I should use blueprints; but I don't really care for such a small # toy app @app.route('/config') def get_config(): """Get the current configuration of the app.""" return jsonify(app.config) @app.route('/put_config', methods=['PUT']) def put_config(): """Add to the current configuration of the app. Takes any JSON body and adds all keys to the configs with the provided values. """ data = request.json() for key, val in data.items(): app.config[key] = val return jsonify({'message': 'Config updated!'}) return app
[ "def", "create_app", "(", ")", ":", "app", "=", "App", ".", "create_app", "(", "__name__", ")", "app", ".", "configure", "(", "'.configs.settings'", ")", "# yes, I should use blueprints; but I don't really care for such a small", "# toy app", "@", "app", ".", "route",...
Create the standard app for ``fleaker_config`` and register the two routes required.
[ "Create", "the", "standard", "app", "for", "fleaker_config", "and", "register", "the", "two", "routes", "required", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/examples/fleaker_config/fleaker_config/fleaker_config.py#L15-L43
8,030
croscon/fleaker
fleaker/peewee/mixins/field_signature.py
FieldSignatureMixin.update_signature
def update_signature(self): """Update the signature field by hashing the ``signature_fields``. Raises: AttributeError: This is raised if ``Meta.signature_fields`` has no values in it or if a field in there is not a field on the model. """ if not self._meta.signature_fields: raise AttributeError( "No fields defined in {}.Meta.signature_fields. Please define " "at least one.".format(type(self).__name__) ) # If the field is archived, unset the signature so records in the # future can have this value. if getattr(self, 'archived', False): self.signature = None return # Otherwise, combine the values of the fields together and SHA1 them computed = [getattr(self, value) or ' ' for value in self._meta.signature_fields] computed = ''.join([text_type(value) for value in computed]) # If computed is a falsey value, that means all the fields were # None or blank and that will lead to some pain. if computed: self.signature = sha1(computed.encode('utf-8')).hexdigest()
python
def update_signature(self): if not self._meta.signature_fields: raise AttributeError( "No fields defined in {}.Meta.signature_fields. Please define " "at least one.".format(type(self).__name__) ) # If the field is archived, unset the signature so records in the # future can have this value. if getattr(self, 'archived', False): self.signature = None return # Otherwise, combine the values of the fields together and SHA1 them computed = [getattr(self, value) or ' ' for value in self._meta.signature_fields] computed = ''.join([text_type(value) for value in computed]) # If computed is a falsey value, that means all the fields were # None or blank and that will lead to some pain. if computed: self.signature = sha1(computed.encode('utf-8')).hexdigest()
[ "def", "update_signature", "(", "self", ")", ":", "if", "not", "self", ".", "_meta", ".", "signature_fields", ":", "raise", "AttributeError", "(", "\"No fields defined in {}.Meta.signature_fields. Please define \"", "\"at least one.\"", ".", "format", "(", "type", "(", ...
Update the signature field by hashing the ``signature_fields``. Raises: AttributeError: This is raised if ``Meta.signature_fields`` has no values in it or if a field in there is not a field on the model.
[ "Update", "the", "signature", "field", "by", "hashing", "the", "signature_fields", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/field_signature.py#L102-L130
8,031
mozilla-releng/mozapkpublisher
mozapkpublisher/common/googleplay.py
connect
def connect(service_account, credentials_file_path, api_version='v2'): """ Connect to the google play interface """ # Create an httplib2.Http object to handle our HTTP requests an # authorize it with the Credentials. Note that the first parameter, # service_account_name, is the Email address created for the Service # account. It must be the email address associated with the key that # was created. scope = 'https://www.googleapis.com/auth/androidpublisher' credentials = ServiceAccountCredentials.from_p12_keyfile(service_account, credentials_file_path, scopes=scope) http = httplib2.Http() http = credentials.authorize(http) service = build('androidpublisher', api_version, http=http, cache_discovery=False) return service
python
def connect(service_account, credentials_file_path, api_version='v2'): # Create an httplib2.Http object to handle our HTTP requests an # authorize it with the Credentials. Note that the first parameter, # service_account_name, is the Email address created for the Service # account. It must be the email address associated with the key that # was created. scope = 'https://www.googleapis.com/auth/androidpublisher' credentials = ServiceAccountCredentials.from_p12_keyfile(service_account, credentials_file_path, scopes=scope) http = httplib2.Http() http = credentials.authorize(http) service = build('androidpublisher', api_version, http=http, cache_discovery=False) return service
[ "def", "connect", "(", "service_account", ",", "credentials_file_path", ",", "api_version", "=", "'v2'", ")", ":", "# Create an httplib2.Http object to handle our HTTP requests an", "# authorize it with the Credentials. Note that the first parameter,", "# service_account_name, is the Ema...
Connect to the google play interface
[ "Connect", "to", "the", "google", "play", "interface" ]
df61034220153cbb98da74c8ef6de637f9185e12
https://github.com/mozilla-releng/mozapkpublisher/blob/df61034220153cbb98da74c8ef6de637f9185e12/mozapkpublisher/common/googleplay.py#L159-L175
8,032
croscon/fleaker
fleaker/marshmallow/fields/pendulum.py
PendulumField._deserialize
def _deserialize(self, value, attr, obj): """Deserializes a string into a Pendulum object.""" if not self.context.get('convert_dates', True) or not value: return value value = super(PendulumField, self)._deserialize(value, attr, value) timezone = self.get_field_value('timezone') target = pendulum.instance(value) if (timezone and (text_type(target) != text_type(target.in_timezone(timezone)))): raise ValidationError( "The provided datetime is not in the " "{} timezone.".format(timezone) ) return target
python
def _deserialize(self, value, attr, obj): if not self.context.get('convert_dates', True) or not value: return value value = super(PendulumField, self)._deserialize(value, attr, value) timezone = self.get_field_value('timezone') target = pendulum.instance(value) if (timezone and (text_type(target) != text_type(target.in_timezone(timezone)))): raise ValidationError( "The provided datetime is not in the " "{} timezone.".format(timezone) ) return target
[ "def", "_deserialize", "(", "self", ",", "value", ",", "attr", ",", "obj", ")", ":", "if", "not", "self", ".", "context", ".", "get", "(", "'convert_dates'", ",", "True", ")", "or", "not", "value", ":", "return", "value", "value", "=", "super", "(", ...
Deserializes a string into a Pendulum object.
[ "Deserializes", "a", "string", "into", "a", "Pendulum", "object", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/pendulum.py#L42-L58
8,033
croscon/fleaker
fleaker/marshmallow/fields/phone_number.py
PhoneNumberField._format_phone_number
def _format_phone_number(self, value, attr): """Format and validate a phone number.""" strict_validation = self.get_field_value( 'strict_phone_validation', default=False ) strict_region = self.get_field_value( 'strict_phone_region', default=strict_validation ) region = self.get_field_value('region', 'US') phone_number_format = self.get_field_value( 'phone_number_format', default=phonenumbers.PhoneNumberFormat.INTERNATIONAL ) # Remove excess special chars, except for the plus sign stripped_value = re.sub(r'[^\w+]', '', value) try: if not stripped_value.startswith('+') and not strict_region: phone = phonenumbers.parse(stripped_value, region) else: phone = phonenumbers.parse(stripped_value) if (not phonenumbers.is_possible_number(phone) or not phonenumbers.is_valid_number(phone) and strict_validation): raise ValidationError( "The value for {} ({}) is not a valid phone " "number.".format(attr, value) ) return phonenumbers.format_number(phone, phone_number_format) except phonenumbers.phonenumberutil.NumberParseException as exc: if strict_validation or strict_region: raise ValidationError(exc)
python
def _format_phone_number(self, value, attr): strict_validation = self.get_field_value( 'strict_phone_validation', default=False ) strict_region = self.get_field_value( 'strict_phone_region', default=strict_validation ) region = self.get_field_value('region', 'US') phone_number_format = self.get_field_value( 'phone_number_format', default=phonenumbers.PhoneNumberFormat.INTERNATIONAL ) # Remove excess special chars, except for the plus sign stripped_value = re.sub(r'[^\w+]', '', value) try: if not stripped_value.startswith('+') and not strict_region: phone = phonenumbers.parse(stripped_value, region) else: phone = phonenumbers.parse(stripped_value) if (not phonenumbers.is_possible_number(phone) or not phonenumbers.is_valid_number(phone) and strict_validation): raise ValidationError( "The value for {} ({}) is not a valid phone " "number.".format(attr, value) ) return phonenumbers.format_number(phone, phone_number_format) except phonenumbers.phonenumberutil.NumberParseException as exc: if strict_validation or strict_region: raise ValidationError(exc)
[ "def", "_format_phone_number", "(", "self", ",", "value", ",", "attr", ")", ":", "strict_validation", "=", "self", ".", "get_field_value", "(", "'strict_phone_validation'", ",", "default", "=", "False", ")", "strict_region", "=", "self", ".", "get_field_value", ...
Format and validate a phone number.
[ "Format", "and", "validate", "a", "phone", "number", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/phone_number.py#L50-L87
8,034
croscon/fleaker
fleaker/marshmallow/fields/phone_number.py
PhoneNumberField._deserialize
def _deserialize(self, value, attr, data): """Format and validate the phone number using libphonenumber.""" if value: value = self._format_phone_number(value, attr) return super(PhoneNumberField, self)._deserialize(value, attr, data)
python
def _deserialize(self, value, attr, data): if value: value = self._format_phone_number(value, attr) return super(PhoneNumberField, self)._deserialize(value, attr, data)
[ "def", "_deserialize", "(", "self", ",", "value", ",", "attr", ",", "data", ")", ":", "if", "value", ":", "value", "=", "self", ".", "_format_phone_number", "(", "value", ",", "attr", ")", "return", "super", "(", "PhoneNumberField", ",", "self", ")", "...
Format and validate the phone number using libphonenumber.
[ "Format", "and", "validate", "the", "phone", "number", "using", "libphonenumber", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/phone_number.py#L89-L94
8,035
croscon/fleaker
fleaker/marshmallow/fields/phone_number.py
PhoneNumberField._serialize
def _serialize(self, value, attr, obj): """Format and validate the phone number user libphonenumber.""" value = super(PhoneNumberField, self)._serialize(value, attr, obj) if value: value = self._format_phone_number(value, attr) return value
python
def _serialize(self, value, attr, obj): value = super(PhoneNumberField, self)._serialize(value, attr, obj) if value: value = self._format_phone_number(value, attr) return value
[ "def", "_serialize", "(", "self", ",", "value", ",", "attr", ",", "obj", ")", ":", "value", "=", "super", "(", "PhoneNumberField", ",", "self", ")", ".", "_serialize", "(", "value", ",", "attr", ",", "obj", ")", "if", "value", ":", "value", "=", "s...
Format and validate the phone number user libphonenumber.
[ "Format", "and", "validate", "the", "phone", "number", "user", "libphonenumber", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/phone_number.py#L96-L103
8,036
croscon/fleaker
fleaker/json.py
FleakerJSONEncoder.default
def default(self, obj): """Encode individual objects into their JSON representation. This method is used by :class:`flask.json.JSONEncoder` to encode individual items in the JSON object. Args: obj (object): Any Python object we wish to convert to JSON. Returns: str: The stringified, valid JSON representation of our provided object. """ if isinstance(obj, decimal.Decimal): obj = format(obj, 'f') str_digit = text_type(obj) return (str_digit.rstrip('0').rstrip('.') if '.' in str_digit else str_digit) elif isinstance(obj, phonenumbers.PhoneNumber): return phonenumbers.format_number( obj, phonenumbers.PhoneNumberFormat.E164 ) elif isinstance(obj, pendulum.Pendulum): return text_type(obj) elif isinstance(obj, arrow.Arrow): return text_type(obj) elif isinstance(obj, (datetime.datetime, datetime.date)): return obj.isoformat() try: return list(iter(obj)) except TypeError: pass return super(FleakerJSONEncoder, self).default(obj)
python
def default(self, obj): if isinstance(obj, decimal.Decimal): obj = format(obj, 'f') str_digit = text_type(obj) return (str_digit.rstrip('0').rstrip('.') if '.' in str_digit else str_digit) elif isinstance(obj, phonenumbers.PhoneNumber): return phonenumbers.format_number( obj, phonenumbers.PhoneNumberFormat.E164 ) elif isinstance(obj, pendulum.Pendulum): return text_type(obj) elif isinstance(obj, arrow.Arrow): return text_type(obj) elif isinstance(obj, (datetime.datetime, datetime.date)): return obj.isoformat() try: return list(iter(obj)) except TypeError: pass return super(FleakerJSONEncoder, self).default(obj)
[ "def", "default", "(", "self", ",", "obj", ")", ":", "if", "isinstance", "(", "obj", ",", "decimal", ".", "Decimal", ")", ":", "obj", "=", "format", "(", "obj", ",", "'f'", ")", "str_digit", "=", "text_type", "(", "obj", ")", "return", "(", "str_di...
Encode individual objects into their JSON representation. This method is used by :class:`flask.json.JSONEncoder` to encode individual items in the JSON object. Args: obj (object): Any Python object we wish to convert to JSON. Returns: str: The stringified, valid JSON representation of our provided object.
[ "Encode", "individual", "objects", "into", "their", "JSON", "representation", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/json.py#L63-L104
8,037
croscon/fleaker
fleaker/marshmallow/fields/arrow.py
ArrowField._serialize
def _serialize(self, value, attr, obj): """Convert the Arrow object into a string.""" if isinstance(value, arrow.arrow.Arrow): value = value.datetime return super(ArrowField, self)._serialize(value, attr, obj)
python
def _serialize(self, value, attr, obj): if isinstance(value, arrow.arrow.Arrow): value = value.datetime return super(ArrowField, self)._serialize(value, attr, obj)
[ "def", "_serialize", "(", "self", ",", "value", ",", "attr", ",", "obj", ")", ":", "if", "isinstance", "(", "value", ",", "arrow", ".", "arrow", ".", "Arrow", ")", ":", "value", "=", "value", ".", "datetime", "return", "super", "(", "ArrowField", ","...
Convert the Arrow object into a string.
[ "Convert", "the", "Arrow", "object", "into", "a", "string", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/arrow.py#L42-L47
8,038
croscon/fleaker
fleaker/marshmallow/fields/arrow.py
ArrowField._deserialize
def _deserialize(self, value, attr, data): """Deserializes a string into an Arrow object.""" if not self.context.get('convert_dates', True) or not value: return value value = super(ArrowField, self)._deserialize(value, attr, data) timezone = self.get_field_value('timezone') target = arrow.get(value) if timezone and text_type(target.to(timezone)) != text_type(target): raise ValidationError( "The provided datetime is not in the " "{} timezone.".format(timezone) ) return target
python
def _deserialize(self, value, attr, data): if not self.context.get('convert_dates', True) or not value: return value value = super(ArrowField, self)._deserialize(value, attr, data) timezone = self.get_field_value('timezone') target = arrow.get(value) if timezone and text_type(target.to(timezone)) != text_type(target): raise ValidationError( "The provided datetime is not in the " "{} timezone.".format(timezone) ) return target
[ "def", "_deserialize", "(", "self", ",", "value", ",", "attr", ",", "data", ")", ":", "if", "not", "self", ".", "context", ".", "get", "(", "'convert_dates'", ",", "True", ")", "or", "not", "value", ":", "return", "value", "value", "=", "super", "(",...
Deserializes a string into an Arrow object.
[ "Deserializes", "a", "string", "into", "an", "Arrow", "object", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/arrow.py#L49-L64
8,039
croscon/fleaker
fleaker/peewee/fields/pendulum.py
PendulumDateTimeField.python_value
def python_value(self, value): """Return the value in the database as an Pendulum object. Returns: pendulum.Pendulum: An instance of Pendulum with the field filled in. """ value = super(PendulumDateTimeField, self).python_value(value) if isinstance(value, datetime.datetime): value = pendulum.instance(value) elif isinstance(value, datetime.date): value = pendulum.instance( datetime.datetime.combine( value, datetime.datetime.min.time() ) ) elif isinstance(value, string_types): value = pendulum.parse(value) return value
python
def python_value(self, value): value = super(PendulumDateTimeField, self).python_value(value) if isinstance(value, datetime.datetime): value = pendulum.instance(value) elif isinstance(value, datetime.date): value = pendulum.instance( datetime.datetime.combine( value, datetime.datetime.min.time() ) ) elif isinstance(value, string_types): value = pendulum.parse(value) return value
[ "def", "python_value", "(", "self", ",", "value", ")", ":", "value", "=", "super", "(", "PendulumDateTimeField", ",", "self", ")", ".", "python_value", "(", "value", ")", "if", "isinstance", "(", "value", ",", "datetime", ".", "datetime", ")", ":", "valu...
Return the value in the database as an Pendulum object. Returns: pendulum.Pendulum: An instance of Pendulum with the field filled in.
[ "Return", "the", "value", "in", "the", "database", "as", "an", "Pendulum", "object", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/fields/pendulum.py#L68-L88
8,040
croscon/fleaker
fleaker/peewee/fields/pendulum.py
PendulumDateTimeField.db_value
def db_value(self, value): """Convert the Pendulum instance to a datetime for saving in the db.""" if isinstance(value, pendulum.Pendulum): value = datetime.datetime( value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, value.tzinfo ) return super(PendulumDateTimeField, self).db_value(value)
python
def db_value(self, value): if isinstance(value, pendulum.Pendulum): value = datetime.datetime( value.year, value.month, value.day, value.hour, value.minute, value.second, value.microsecond, value.tzinfo ) return super(PendulumDateTimeField, self).db_value(value)
[ "def", "db_value", "(", "self", ",", "value", ")", ":", "if", "isinstance", "(", "value", ",", "pendulum", ".", "Pendulum", ")", ":", "value", "=", "datetime", ".", "datetime", "(", "value", ".", "year", ",", "value", ".", "month", ",", "value", ".",...
Convert the Pendulum instance to a datetime for saving in the db.
[ "Convert", "the", "Pendulum", "instance", "to", "a", "datetime", "for", "saving", "in", "the", "db", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/fields/pendulum.py#L90-L98
8,041
mozilla-releng/mozapkpublisher
mozapkpublisher/check_rollout.py
check_rollout
def check_rollout(edits_service, package_name, days): """Check if package_name has a release on staged rollout for too long""" edit = edits_service.insert(body={}, packageName=package_name).execute() response = edits_service.tracks().get(editId=edit['id'], track='production', packageName=package_name).execute() releases = response['releases'] for release in releases: if release['status'] == 'inProgress': url = 'https://archive.mozilla.org/pub/mobile/releases/{}/SHA512SUMS'.format(release['name']) resp = requests.head(url) if resp.status_code != 200: if resp.status_code != 404: # 404 is expected for release candidates logger.warning("Could not check %s: %s", url, resp.status_code) continue age = time.time() - calendar.timegm(eu.parsedate(resp.headers['Last-Modified'])) if age >= days * DAY: yield release, age
python
def check_rollout(edits_service, package_name, days): edit = edits_service.insert(body={}, packageName=package_name).execute() response = edits_service.tracks().get(editId=edit['id'], track='production', packageName=package_name).execute() releases = response['releases'] for release in releases: if release['status'] == 'inProgress': url = 'https://archive.mozilla.org/pub/mobile/releases/{}/SHA512SUMS'.format(release['name']) resp = requests.head(url) if resp.status_code != 200: if resp.status_code != 404: # 404 is expected for release candidates logger.warning("Could not check %s: %s", url, resp.status_code) continue age = time.time() - calendar.timegm(eu.parsedate(resp.headers['Last-Modified'])) if age >= days * DAY: yield release, age
[ "def", "check_rollout", "(", "edits_service", ",", "package_name", ",", "days", ")", ":", "edit", "=", "edits_service", ".", "insert", "(", "body", "=", "{", "}", ",", "packageName", "=", "package_name", ")", ".", "execute", "(", ")", "response", "=", "e...
Check if package_name has a release on staged rollout for too long
[ "Check", "if", "package_name", "has", "a", "release", "on", "staged", "rollout", "for", "too", "long" ]
df61034220153cbb98da74c8ef6de637f9185e12
https://github.com/mozilla-releng/mozapkpublisher/blob/df61034220153cbb98da74c8ef6de637f9185e12/mozapkpublisher/check_rollout.py#L19-L34
8,042
croscon/fleaker
fleaker/marshmallow/json_schema.py
FleakerJSONSchema.generate_json_schema
def generate_json_schema(cls, schema, context=DEFAULT_DICT): """Generate a JSON Schema from a Marshmallow schema. Args: schema (marshmallow.Schema|str): The Marshmallow schema, or the Python path to one, to create the JSON schema for. Keyword Args: file_pointer (file, optional): The path or pointer to the file to write this schema to. If not provided, the schema will be dumped to ``sys.stdout``. Returns: dict: The JSON schema in dictionary form. """ schema = cls._get_schema(schema) # Generate the JSON Schema return cls(context=context).dump(schema).data
python
def generate_json_schema(cls, schema, context=DEFAULT_DICT): schema = cls._get_schema(schema) # Generate the JSON Schema return cls(context=context).dump(schema).data
[ "def", "generate_json_schema", "(", "cls", ",", "schema", ",", "context", "=", "DEFAULT_DICT", ")", ":", "schema", "=", "cls", ".", "_get_schema", "(", "schema", ")", "# Generate the JSON Schema", "return", "cls", "(", "context", "=", "context", ")", ".", "d...
Generate a JSON Schema from a Marshmallow schema. Args: schema (marshmallow.Schema|str): The Marshmallow schema, or the Python path to one, to create the JSON schema for. Keyword Args: file_pointer (file, optional): The path or pointer to the file to write this schema to. If not provided, the schema will be dumped to ``sys.stdout``. Returns: dict: The JSON schema in dictionary form.
[ "Generate", "a", "JSON", "Schema", "from", "a", "Marshmallow", "schema", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/json_schema.py#L96-L114
8,043
croscon/fleaker
fleaker/marshmallow/json_schema.py
FleakerJSONSchema.write_schema_to_file
def write_schema_to_file(cls, schema, file_pointer=stdout, folder=MISSING, context=DEFAULT_DICT): """Given a Marshmallow schema, create a JSON Schema for it. Args: schema (marshmallow.Schema|str): The Marshmallow schema, or the Python path to one, to create the JSON schema for. Keyword Args: file_pointer (file, optional): The pointer to the file to write this schema to. If not provided, the schema will be dumped to ``sys.stdout``. folder (str, optional): The folder in which to save the JSON schema. The name of the schema file can be optionally controlled my the schema's ``Meta.json_schema_filename``. If that attribute is not set, the class's name will be used for the filename. If writing the schema to a specific file is desired, please pass in a ``file_pointer``. context (dict, optional): The Marshmallow context to be pushed to the schema generates the JSONSchema. Returns: dict: The JSON schema in dictionary form. """ schema = cls._get_schema(schema) json_schema = cls.generate_json_schema(schema, context=context) if folder: schema_filename = getattr( schema.Meta, 'json_schema_filename', '.'.join([schema.__class__.__name__, 'json']) ) json_path = os.path.join(folder, schema_filename) file_pointer = open(json_path, 'w') json.dump(json_schema, file_pointer, indent=2) return json_schema
python
def write_schema_to_file(cls, schema, file_pointer=stdout, folder=MISSING, context=DEFAULT_DICT): schema = cls._get_schema(schema) json_schema = cls.generate_json_schema(schema, context=context) if folder: schema_filename = getattr( schema.Meta, 'json_schema_filename', '.'.join([schema.__class__.__name__, 'json']) ) json_path = os.path.join(folder, schema_filename) file_pointer = open(json_path, 'w') json.dump(json_schema, file_pointer, indent=2) return json_schema
[ "def", "write_schema_to_file", "(", "cls", ",", "schema", ",", "file_pointer", "=", "stdout", ",", "folder", "=", "MISSING", ",", "context", "=", "DEFAULT_DICT", ")", ":", "schema", "=", "cls", ".", "_get_schema", "(", "schema", ")", "json_schema", "=", "c...
Given a Marshmallow schema, create a JSON Schema for it. Args: schema (marshmallow.Schema|str): The Marshmallow schema, or the Python path to one, to create the JSON schema for. Keyword Args: file_pointer (file, optional): The pointer to the file to write this schema to. If not provided, the schema will be dumped to ``sys.stdout``. folder (str, optional): The folder in which to save the JSON schema. The name of the schema file can be optionally controlled my the schema's ``Meta.json_schema_filename``. If that attribute is not set, the class's name will be used for the filename. If writing the schema to a specific file is desired, please pass in a ``file_pointer``. context (dict, optional): The Marshmallow context to be pushed to the schema generates the JSONSchema. Returns: dict: The JSON schema in dictionary form.
[ "Given", "a", "Marshmallow", "schema", "create", "a", "JSON", "Schema", "for", "it", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/json_schema.py#L117-L155
8,044
croscon/fleaker
fleaker/marshmallow/json_schema.py
FleakerJSONSchema._get_schema
def _get_schema(cls, schema): """Method that will fetch a Marshmallow schema flexibly. Args: schema (marshmallow.Schema|str): Either the schema class, an instance of a schema, or a Python path to a schema. Returns: marshmallow.Schema: The desired schema. Raises: TypeError: This is raised if the provided object isn't a Marshmallow schema. """ if isinstance(schema, string_types): schema = cls._get_object_from_python_path(schema) if isclass(schema): schema = schema() if not isinstance(schema, Schema): raise TypeError("The schema must be a path to a Marshmallow " "schema or a Marshmallow schema.") return schema
python
def _get_schema(cls, schema): if isinstance(schema, string_types): schema = cls._get_object_from_python_path(schema) if isclass(schema): schema = schema() if not isinstance(schema, Schema): raise TypeError("The schema must be a path to a Marshmallow " "schema or a Marshmallow schema.") return schema
[ "def", "_get_schema", "(", "cls", ",", "schema", ")", ":", "if", "isinstance", "(", "schema", ",", "string_types", ")", ":", "schema", "=", "cls", ".", "_get_object_from_python_path", "(", "schema", ")", "if", "isclass", "(", "schema", ")", ":", "schema", ...
Method that will fetch a Marshmallow schema flexibly. Args: schema (marshmallow.Schema|str): Either the schema class, an instance of a schema, or a Python path to a schema. Returns: marshmallow.Schema: The desired schema. Raises: TypeError: This is raised if the provided object isn't a Marshmallow schema.
[ "Method", "that", "will", "fetch", "a", "Marshmallow", "schema", "flexibly", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/json_schema.py#L158-L182
8,045
croscon/fleaker
fleaker/marshmallow/json_schema.py
FleakerJSONSchema._get_object_from_python_path
def _get_object_from_python_path(python_path): """Method that will fetch a Marshmallow schema from a path to it. Args: python_path (str): The string path to the Marshmallow schema. Returns: marshmallow.Schema: The schema matching the provided path. Raises: TypeError: This is raised if the specified object isn't a Marshmallow schema. """ # Dissect the path python_path = python_path.split('.') module_path = python_path[:-1] object_class = python_path[-1] if isinstance(module_path, list): module_path = '.'.join(module_path) # Grab the object module = import_module(module_path) schema = getattr(module, object_class) if isclass(schema): schema = schema() return schema
python
def _get_object_from_python_path(python_path): # Dissect the path python_path = python_path.split('.') module_path = python_path[:-1] object_class = python_path[-1] if isinstance(module_path, list): module_path = '.'.join(module_path) # Grab the object module = import_module(module_path) schema = getattr(module, object_class) if isclass(schema): schema = schema() return schema
[ "def", "_get_object_from_python_path", "(", "python_path", ")", ":", "# Dissect the path", "python_path", "=", "python_path", ".", "split", "(", "'.'", ")", "module_path", "=", "python_path", "[", ":", "-", "1", "]", "object_class", "=", "python_path", "[", "-",...
Method that will fetch a Marshmallow schema from a path to it. Args: python_path (str): The string path to the Marshmallow schema. Returns: marshmallow.Schema: The schema matching the provided path. Raises: TypeError: This is raised if the specified object isn't a Marshmallow schema.
[ "Method", "that", "will", "fetch", "a", "Marshmallow", "schema", "from", "a", "path", "to", "it", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/json_schema.py#L185-L213
8,046
croscon/fleaker
fleaker/marshmallow/extension.py
MarshmallowAwareApp.post_create_app
def post_create_app(cls, app, **settings): """Automatically register and init the Flask Marshmallow extension. Args: app (flask.Flask): The application instance in which to initialize Flask Marshmallow upon. Kwargs: settings (dict): The settings passed to this method from the parent app. Returns: flask.Flask: The Flask application that was passed in. """ super(MarshmallowAwareApp, cls).post_create_app(app, **settings) marsh.init_app(app) return app
python
def post_create_app(cls, app, **settings): super(MarshmallowAwareApp, cls).post_create_app(app, **settings) marsh.init_app(app) return app
[ "def", "post_create_app", "(", "cls", ",", "app", ",", "*", "*", "settings", ")", ":", "super", "(", "MarshmallowAwareApp", ",", "cls", ")", ".", "post_create_app", "(", "app", ",", "*", "*", "settings", ")", "marsh", ".", "init_app", "(", "app", ")", ...
Automatically register and init the Flask Marshmallow extension. Args: app (flask.Flask): The application instance in which to initialize Flask Marshmallow upon. Kwargs: settings (dict): The settings passed to this method from the parent app. Returns: flask.Flask: The Flask application that was passed in.
[ "Automatically", "register", "and", "init", "the", "Flask", "Marshmallow", "extension", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/extension.py#L37-L55
8,047
croscon/fleaker
fleaker/peewee/mixins/event.py
get_original_before_save
def get_original_before_save(sender, instance, created): """Event listener to get the original instance before it's saved.""" if not instance._meta.event_ready or created: return instance.get_original()
python
def get_original_before_save(sender, instance, created): if not instance._meta.event_ready or created: return instance.get_original()
[ "def", "get_original_before_save", "(", "sender", ",", "instance", ",", "created", ")", ":", "if", "not", "instance", ".", "_meta", ".", "event_ready", "or", "created", ":", "return", "instance", ".", "get_original", "(", ")" ]
Event listener to get the original instance before it's saved.
[ "Event", "listener", "to", "get", "the", "original", "instance", "before", "it", "s", "saved", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L623-L628
8,048
croscon/fleaker
fleaker/peewee/mixins/event.py
post_save_event_listener
def post_save_event_listener(sender, instance, created): """Event listener to create creation and update events.""" if not instance._meta.event_ready: return if created: instance.create_creation_event() else: instance.create_update_event() # Reset the original key instance._original = None
python
def post_save_event_listener(sender, instance, created): if not instance._meta.event_ready: return if created: instance.create_creation_event() else: instance.create_update_event() # Reset the original key instance._original = None
[ "def", "post_save_event_listener", "(", "sender", ",", "instance", ",", "created", ")", ":", "if", "not", "instance", ".", "_meta", ".", "event_ready", ":", "return", "if", "created", ":", "instance", ".", "create_creation_event", "(", ")", "else", ":", "ins...
Event listener to create creation and update events.
[ "Event", "listener", "to", "create", "creation", "and", "update", "events", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L632-L643
8,049
croscon/fleaker
fleaker/peewee/mixins/event.py
validate_event_type
def validate_event_type(sender, event, created): """Verify that the Event's code is a valid one.""" if event.code not in sender.event_codes(): raise ValueError("The Event.code '{}' is not a valid Event " "code.".format(event.code))
python
def validate_event_type(sender, event, created): if event.code not in sender.event_codes(): raise ValueError("The Event.code '{}' is not a valid Event " "code.".format(event.code))
[ "def", "validate_event_type", "(", "sender", ",", "event", ",", "created", ")", ":", "if", "event", ".", "code", "not", "in", "sender", ".", "event_codes", "(", ")", ":", "raise", "ValueError", "(", "\"The Event.code '{}' is not a valid Event \"", "\"code.\"", "...
Verify that the Event's code is a valid one.
[ "Verify", "that", "the", "Event", "s", "code", "is", "a", "valid", "one", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L732-L736
8,050
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.get_original
def get_original(self): """Get the original instance of this instance before it's updated. Returns: fleaker.peewee.EventMixin: The original instance of the model. """ pk_value = self._get_pk_value() if isinstance(pk_value, int) and not self._original: self._original = ( self.select().where(self.__class__.id == pk_value).get() ) return self._original
python
def get_original(self): pk_value = self._get_pk_value() if isinstance(pk_value, int) and not self._original: self._original = ( self.select().where(self.__class__.id == pk_value).get() ) return self._original
[ "def", "get_original", "(", "self", ")", ":", "pk_value", "=", "self", ".", "_get_pk_value", "(", ")", "if", "isinstance", "(", "pk_value", ",", "int", ")", "and", "not", "self", ".", "_original", ":", "self", ".", "_original", "=", "(", "self", ".", ...
Get the original instance of this instance before it's updated. Returns: fleaker.peewee.EventMixin: The original instance of the model.
[ "Get", "the", "original", "instance", "of", "this", "instance", "before", "it", "s", "updated", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L398-L412
8,051
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.create_creation_event
def create_creation_event(self): """Parse the create message DSL to insert the data into the Event. Returns: fleaker.peewee.EventStorageMixin: A new Event instance with data put in it """ event = self.create_audit_event(code='AUDIT_CREATE') if self._meta.create_message: event.body = self._meta.create_message['message'] event.code = self._meta.create_message['code'] event.meta = self.parse_meta(self._meta.create_message['meta']) self.create_event_callback(event) event.save() return event
python
def create_creation_event(self): event = self.create_audit_event(code='AUDIT_CREATE') if self._meta.create_message: event.body = self._meta.create_message['message'] event.code = self._meta.create_message['code'] event.meta = self.parse_meta(self._meta.create_message['meta']) self.create_event_callback(event) event.save() return event
[ "def", "create_creation_event", "(", "self", ")", ":", "event", "=", "self", ".", "create_audit_event", "(", "code", "=", "'AUDIT_CREATE'", ")", "if", "self", ".", "_meta", ".", "create_message", ":", "event", ".", "body", "=", "self", ".", "_meta", ".", ...
Parse the create message DSL to insert the data into the Event. Returns: fleaker.peewee.EventStorageMixin: A new Event instance with data put in it
[ "Parse", "the", "create", "message", "DSL", "to", "insert", "the", "data", "into", "the", "Event", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L414-L432
8,052
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.create_update_event
def create_update_event(self): """Parse the update messages DSL to insert the data into the Event. Returns: list[fleaker.peewee.EventStorageMixin]: All the events that were created for the update. """ events = [] for fields, rules in iteritems(self._meta.update_messages): if not isinstance(fields, (list, tuple, set)): fields = (fields,) changed = any([ getattr(self, field) != getattr(self.get_original(), field) for field in fields ]) if changed: event = self.create_audit_event(code=rules['code']) event.body = rules['message'] event.meta = self.parse_meta(rules['meta']) events.append(event) self.update_event_callback(events) with db.database.atomic(): for event in events: event.save() return events
python
def create_update_event(self): events = [] for fields, rules in iteritems(self._meta.update_messages): if not isinstance(fields, (list, tuple, set)): fields = (fields,) changed = any([ getattr(self, field) != getattr(self.get_original(), field) for field in fields ]) if changed: event = self.create_audit_event(code=rules['code']) event.body = rules['message'] event.meta = self.parse_meta(rules['meta']) events.append(event) self.update_event_callback(events) with db.database.atomic(): for event in events: event.save() return events
[ "def", "create_update_event", "(", "self", ")", ":", "events", "=", "[", "]", "for", "fields", ",", "rules", "in", "iteritems", "(", "self", ".", "_meta", ".", "update_messages", ")", ":", "if", "not", "isinstance", "(", "fields", ",", "(", "list", ","...
Parse the update messages DSL to insert the data into the Event. Returns: list[fleaker.peewee.EventStorageMixin]: All the events that were created for the update.
[ "Parse", "the", "update", "messages", "DSL", "to", "insert", "the", "data", "into", "the", "Event", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L434-L464
8,053
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.create_deletion_event
def create_deletion_event(self): """Parse the delete message DSL to insert data into the Event. Return: Event: The Event with the relevant information put in it. """ event = self.create_audit_event(code='AUDIT_DELETE') if self._meta.delete_message: event.code = self._meta.delete_message['code'] event.body = self._meta.delete_message['message'] event.meta = self.parse_meta(self._meta.delete_message['meta']) self.delete_event_callback(event) event.save() return event
python
def create_deletion_event(self): event = self.create_audit_event(code='AUDIT_DELETE') if self._meta.delete_message: event.code = self._meta.delete_message['code'] event.body = self._meta.delete_message['message'] event.meta = self.parse_meta(self._meta.delete_message['meta']) self.delete_event_callback(event) event.save() return event
[ "def", "create_deletion_event", "(", "self", ")", ":", "event", "=", "self", ".", "create_audit_event", "(", "code", "=", "'AUDIT_DELETE'", ")", "if", "self", ".", "_meta", ".", "delete_message", ":", "event", ".", "code", "=", "self", ".", "_meta", ".", ...
Parse the delete message DSL to insert data into the Event. Return: Event: The Event with the relevant information put in it.
[ "Parse", "the", "delete", "message", "DSL", "to", "insert", "data", "into", "the", "Event", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L466-L483
8,054
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.parse_meta
def parse_meta(self, meta): """Parses the meta field in the message, copies it's keys into a new dict and replaces the values, which should be attribute paths relative to the passed in object, with the current value at the end of that path. This function will run recursively when it encounters other dicts inside the meta dict. Args: meta (dict): The dictionary of mappings to pull structure of the meta from. Returns: dict: A copy of the keys from the meta dict with the values pulled from the paths. """ res = {} for key, val in meta.items(): if not val: continue elif isinstance(val, dict): res[key] = self.parse_meta(val) elif val.startswith('current_user.'): res[key] = self.get_path_attribute(current_user, val) elif val.startswith('original.'): res[key] = self.get_path_attribute(self.get_original(), val) else: res[key] = self.get_path_attribute(self, val) return res
python
def parse_meta(self, meta): res = {} for key, val in meta.items(): if not val: continue elif isinstance(val, dict): res[key] = self.parse_meta(val) elif val.startswith('current_user.'): res[key] = self.get_path_attribute(current_user, val) elif val.startswith('original.'): res[key] = self.get_path_attribute(self.get_original(), val) else: res[key] = self.get_path_attribute(self, val) return res
[ "def", "parse_meta", "(", "self", ",", "meta", ")", ":", "res", "=", "{", "}", "for", "key", ",", "val", "in", "meta", ".", "items", "(", ")", ":", "if", "not", "val", ":", "continue", "elif", "isinstance", "(", "val", ",", "dict", ")", ":", "r...
Parses the meta field in the message, copies it's keys into a new dict and replaces the values, which should be attribute paths relative to the passed in object, with the current value at the end of that path. This function will run recursively when it encounters other dicts inside the meta dict. Args: meta (dict): The dictionary of mappings to pull structure of the meta from. Returns: dict: A copy of the keys from the meta dict with the values pulled from the paths.
[ "Parses", "the", "meta", "field", "in", "the", "message", "copies", "it", "s", "keys", "into", "a", "new", "dict", "and", "replaces", "the", "values", "which", "should", "be", "attribute", "paths", "relative", "to", "the", "passed", "in", "object", "with",...
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L485-L515
8,055
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.get_path_attribute
def get_path_attribute(obj, path): """Given a path like `related_record.related_record2.id`, this method will be able to pull the value of ID from that object, returning None if it doesn't exist. Args: obj (fleaker.db.Model): The object to attempt to pull the value from path (str): The path to follow to pull the value from Returns: (int|str|None): The value at the end of the path. None if it doesn't exist at any point in the path. """ # Strip out ignored keys passed in path = path.replace('original.', '').replace('current_user.', '') attr_parts = path.split('.') res = obj try: for part in attr_parts: try: res = getattr(res, part) except AttributeError: res = getattr(res.get(), part) except (peewee.DoesNotExist, AttributeError): return None return res
python
def get_path_attribute(obj, path): # Strip out ignored keys passed in path = path.replace('original.', '').replace('current_user.', '') attr_parts = path.split('.') res = obj try: for part in attr_parts: try: res = getattr(res, part) except AttributeError: res = getattr(res.get(), part) except (peewee.DoesNotExist, AttributeError): return None return res
[ "def", "get_path_attribute", "(", "obj", ",", "path", ")", ":", "# Strip out ignored keys passed in", "path", "=", "path", ".", "replace", "(", "'original.'", ",", "''", ")", ".", "replace", "(", "'current_user.'", ",", "''", ")", "attr_parts", "=", "path", ...
Given a path like `related_record.related_record2.id`, this method will be able to pull the value of ID from that object, returning None if it doesn't exist. Args: obj (fleaker.db.Model): The object to attempt to pull the value from path (str): The path to follow to pull the value from Returns: (int|str|None): The value at the end of the path. None if it doesn't exist at any point in the path.
[ "Given", "a", "path", "like", "related_record", ".", "related_record2", ".", "id", "this", "method", "will", "be", "able", "to", "pull", "the", "value", "of", "ID", "from", "that", "object", "returning", "None", "if", "it", "doesn", "t", "exist", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L518-L550
8,056
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.copy_foreign_keys
def copy_foreign_keys(self, event): """Copies possible foreign key values from the object into the Event, skipping common keys like modified and created. Args: event (Event): The Event instance to copy the FKs into obj (fleaker.db.Model): The object to pull the values from """ event_keys = set(event._meta.fields.keys()) obj_keys = self._meta.fields.keys() matching_keys = event_keys.intersection(obj_keys) for key in matching_keys: # Skip created_by because that will always be the current_user # for the Event. if key == 'created_by': continue # Skip anything that isn't a FK if not isinstance(self._meta.fields[key], peewee.ForeignKeyField): continue setattr(event, key, getattr(self, key)) # Attempt to set the obj's ID in the correct FK field on Event, if it # exists. If this conflicts with desired behavior, handle this in the # respective callback. This does rely on the FK matching the lower case # version of the class name and that the event isn't trying to delete # the current record, becuase that ends badly. possible_key = self.__class__.__name__.lower() if possible_key in event_keys and event.code != 'AUDIT_DELETE': setattr(event, possible_key, self)
python
def copy_foreign_keys(self, event): event_keys = set(event._meta.fields.keys()) obj_keys = self._meta.fields.keys() matching_keys = event_keys.intersection(obj_keys) for key in matching_keys: # Skip created_by because that will always be the current_user # for the Event. if key == 'created_by': continue # Skip anything that isn't a FK if not isinstance(self._meta.fields[key], peewee.ForeignKeyField): continue setattr(event, key, getattr(self, key)) # Attempt to set the obj's ID in the correct FK field on Event, if it # exists. If this conflicts with desired behavior, handle this in the # respective callback. This does rely on the FK matching the lower case # version of the class name and that the event isn't trying to delete # the current record, becuase that ends badly. possible_key = self.__class__.__name__.lower() if possible_key in event_keys and event.code != 'AUDIT_DELETE': setattr(event, possible_key, self)
[ "def", "copy_foreign_keys", "(", "self", ",", "event", ")", ":", "event_keys", "=", "set", "(", "event", ".", "_meta", ".", "fields", ".", "keys", "(", ")", ")", "obj_keys", "=", "self", ".", "_meta", ".", "fields", ".", "keys", "(", ")", "matching_k...
Copies possible foreign key values from the object into the Event, skipping common keys like modified and created. Args: event (Event): The Event instance to copy the FKs into obj (fleaker.db.Model): The object to pull the values from
[ "Copies", "possible", "foreign", "key", "values", "from", "the", "object", "into", "the", "Event", "skipping", "common", "keys", "like", "modified", "and", "created", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L552-L584
8,057
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.create_audit_event
def create_audit_event(self, code='AUDIT'): """Creates a generic auditing Event logging the changes between saves and the initial data in creates. Kwargs: code (str): The code to set the new Event to. Returns: Event: A new event with relevant info inserted into it """ event = self._meta.event_model( code=code, model=self.__class__.__name__, ) # Use the logged in User, if possible if current_user: event.created_by = current_user.get_id() self.copy_foreign_keys(event) self.populate_audit_fields(event) return event
python
def create_audit_event(self, code='AUDIT'): event = self._meta.event_model( code=code, model=self.__class__.__name__, ) # Use the logged in User, if possible if current_user: event.created_by = current_user.get_id() self.copy_foreign_keys(event) self.populate_audit_fields(event) return event
[ "def", "create_audit_event", "(", "self", ",", "code", "=", "'AUDIT'", ")", ":", "event", "=", "self", ".", "_meta", ".", "event_model", "(", "code", "=", "code", ",", "model", "=", "self", ".", "__class__", ".", "__name__", ",", ")", "# Use the logged i...
Creates a generic auditing Event logging the changes between saves and the initial data in creates. Kwargs: code (str): The code to set the new Event to. Returns: Event: A new event with relevant info inserted into it
[ "Creates", "a", "generic", "auditing", "Event", "logging", "the", "changes", "between", "saves", "and", "the", "initial", "data", "in", "creates", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L586-L608
8,058
croscon/fleaker
fleaker/peewee/mixins/event.py
EventMixin.populate_audit_fields
def populate_audit_fields(self, event): """Populates the the audit JSON fields with raw data from the model, so all changes can be tracked and diffed. Args: event (Event): The Event instance to attach the data to instance (fleaker.db.Model): The newly created/updated model """ event.updated = self._data event.original = self.get_original()._data
python
def populate_audit_fields(self, event): event.updated = self._data event.original = self.get_original()._data
[ "def", "populate_audit_fields", "(", "self", ",", "event", ")", ":", "event", ".", "updated", "=", "self", ".", "_data", "event", ".", "original", "=", "self", ".", "get_original", "(", ")", ".", "_data" ]
Populates the the audit JSON fields with raw data from the model, so all changes can be tracked and diffed. Args: event (Event): The Event instance to attach the data to instance (fleaker.db.Model): The newly created/updated model
[ "Populates", "the", "the", "audit", "JSON", "fields", "with", "raw", "data", "from", "the", "model", "so", "all", "changes", "can", "be", "tracked", "and", "diffed", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L610-L619
8,059
croscon/fleaker
fleaker/peewee/mixins/event.py
EventStorageMixin.formatted_message
def formatted_message(self): """Method that will return the formatted message for the event. This formatting is done with Jinja and the template text is stored in the ``body`` attribute. The template is supplied the following variables, as well as the built in Flask ones: - ``event``: This is the event instance that this method belongs to. - ``meta``: This is a dictionary of cached values that have been stored when the event was created based upon the event's DSL. - ``original``: This is a dump of the instance before the instance was updated. - ``updated``: This is a dump of the instance after it was updated. - ``version``: This is the version of the event DSL. This property is cached because Jinja rendering is slower than raw Python string formatting. """ return render_template_string( self.body, event=self, meta=self.meta, original=self.original, updated=self.updated, version=self.version, )
python
def formatted_message(self): return render_template_string( self.body, event=self, meta=self.meta, original=self.original, updated=self.updated, version=self.version, )
[ "def", "formatted_message", "(", "self", ")", ":", "return", "render_template_string", "(", "self", ".", "body", ",", "event", "=", "self", ",", "meta", "=", "self", ".", "meta", ",", "original", "=", "self", ".", "original", ",", "updated", "=", "self",...
Method that will return the formatted message for the event. This formatting is done with Jinja and the template text is stored in the ``body`` attribute. The template is supplied the following variables, as well as the built in Flask ones: - ``event``: This is the event instance that this method belongs to. - ``meta``: This is a dictionary of cached values that have been stored when the event was created based upon the event's DSL. - ``original``: This is a dump of the instance before the instance was updated. - ``updated``: This is a dump of the instance after it was updated. - ``version``: This is the version of the event DSL. This property is cached because Jinja rendering is slower than raw Python string formatting.
[ "Method", "that", "will", "return", "the", "formatted", "message", "for", "the", "event", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/event.py#L695-L720
8,060
croscon/fleaker
fleaker/peewee/mixins/time/base.py
CreatedMixin._get_cached_time
def _get_cached_time(self): """Method that will allow for consistent modified and archived timestamps. Returns: self.Meta.datetime: This method will return a datetime that is compatible with the current class's datetime library. """ if not self._cached_time: self._cached_time = self._meta.datetime.utcnow() return self._cached_time
python
def _get_cached_time(self): if not self._cached_time: self._cached_time = self._meta.datetime.utcnow() return self._cached_time
[ "def", "_get_cached_time", "(", "self", ")", ":", "if", "not", "self", ".", "_cached_time", ":", "self", ".", "_cached_time", "=", "self", ".", "_meta", ".", "datetime", ".", "utcnow", "(", ")", "return", "self", ".", "_cached_time" ]
Method that will allow for consistent modified and archived timestamps. Returns: self.Meta.datetime: This method will return a datetime that is compatible with the current class's datetime library.
[ "Method", "that", "will", "allow", "for", "consistent", "modified", "and", "archived", "timestamps", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/mixins/time/base.py#L77-L88
8,061
mozilla-releng/mozapkpublisher
mozapkpublisher/common/store_l10n.py
_get_list_of_completed_locales
def _get_list_of_completed_locales(product, channel): """ Get all the translated locales supported by Google play So, locale unsupported by Google play won't be downloaded Idem for not translated locale """ return utils.load_json_url(_ALL_LOCALES_URL.format(product=product, channel=channel))
python
def _get_list_of_completed_locales(product, channel): return utils.load_json_url(_ALL_LOCALES_URL.format(product=product, channel=channel))
[ "def", "_get_list_of_completed_locales", "(", "product", ",", "channel", ")", ":", "return", "utils", ".", "load_json_url", "(", "_ALL_LOCALES_URL", ".", "format", "(", "product", "=", "product", ",", "channel", "=", "channel", ")", ")" ]
Get all the translated locales supported by Google play So, locale unsupported by Google play won't be downloaded Idem for not translated locale
[ "Get", "all", "the", "translated", "locales", "supported", "by", "Google", "play", "So", "locale", "unsupported", "by", "Google", "play", "won", "t", "be", "downloaded", "Idem", "for", "not", "translated", "locale" ]
df61034220153cbb98da74c8ef6de637f9185e12
https://github.com/mozilla-releng/mozapkpublisher/blob/df61034220153cbb98da74c8ef6de637f9185e12/mozapkpublisher/common/store_l10n.py#L107-L112
8,062
croscon/fleaker
fleaker/marshmallow/fields/mixin.py
FleakerFieldMixin.get_field_value
def get_field_value(self, key, default=MISSING): """Method to fetch a value from either the fields metadata or the schemas context, in that order. Args: key (str): The name of the key to grab the value for. Keyword Args: default (object, optional): If the value doesn't exist in the schema's ``context`` or the field's ``metadata``, this value will be returned. By default this will be ``MISSING``. Returns: object: This will be the correct value to use given the parameters. """ meta_value = self.metadata.get(key) context_value = self.context.get(key) if context_value is not None: return context_value elif meta_value is not None: return meta_value return default
python
def get_field_value(self, key, default=MISSING): meta_value = self.metadata.get(key) context_value = self.context.get(key) if context_value is not None: return context_value elif meta_value is not None: return meta_value return default
[ "def", "get_field_value", "(", "self", ",", "key", ",", "default", "=", "MISSING", ")", ":", "meta_value", "=", "self", ".", "metadata", ".", "get", "(", "key", ")", "context_value", "=", "self", ".", "context", ".", "get", "(", "key", ")", "if", "co...
Method to fetch a value from either the fields metadata or the schemas context, in that order. Args: key (str): The name of the key to grab the value for. Keyword Args: default (object, optional): If the value doesn't exist in the schema's ``context`` or the field's ``metadata``, this value will be returned. By default this will be ``MISSING``. Returns: object: This will be the correct value to use given the parameters.
[ "Method", "to", "fetch", "a", "value", "from", "either", "the", "fields", "metadata", "or", "the", "schemas", "context", "in", "that", "order", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/marshmallow/fields/mixin.py#L10-L33
8,063
croscon/fleaker
fleaker/peewee/model.py
Model.get_by_id
def get_by_id(cls, record_id, execute=True): """Return a single instance of the model queried by ID. Args: record_id (int): Integer representation of the ID to query on. Keyword Args: execute (bool, optional): Should this method execute the query or return a query object for further manipulation? Returns: cls | :py:class:`peewee.SelectQuery`: If ``execute`` is ``True``, the query is executed, otherwise a query is returned. Raises: :py:class:`peewee.DoesNotExist`: Raised if a record with that ID doesn't exist. """ query = cls.base_query().where(cls.id == record_id) if execute: return query.get() return query
python
def get_by_id(cls, record_id, execute=True): query = cls.base_query().where(cls.id == record_id) if execute: return query.get() return query
[ "def", "get_by_id", "(", "cls", ",", "record_id", ",", "execute", "=", "True", ")", ":", "query", "=", "cls", ".", "base_query", "(", ")", ".", "where", "(", "cls", ".", "id", "==", "record_id", ")", "if", "execute", ":", "return", "query", ".", "g...
Return a single instance of the model queried by ID. Args: record_id (int): Integer representation of the ID to query on. Keyword Args: execute (bool, optional): Should this method execute the query or return a query object for further manipulation? Returns: cls | :py:class:`peewee.SelectQuery`: If ``execute`` is ``True``, the query is executed, otherwise a query is returned. Raises: :py:class:`peewee.DoesNotExist`: Raised if a record with that ID doesn't exist.
[ "Return", "a", "single", "instance", "of", "the", "model", "queried", "by", "ID", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/model.py#L133-L158
8,064
croscon/fleaker
fleaker/peewee/model.py
Model.update_instance
def update_instance(self, data): """Update a single record by id with the provided data. Args: data (dict): The new data to update the record with. Returns: self: This is an instance of itself with the updated data. Raises: AttributeError: This is raised if a key in the ``data`` isn't a field on the model. """ for key, val in iteritems(data): if not hasattr(self, key): raise AttributeError( "No field named {key} for model {model}".format( key=key, model=self.__class__.__name__ ) ) setattr(self, key, val) self.save() return self
python
def update_instance(self, data): for key, val in iteritems(data): if not hasattr(self, key): raise AttributeError( "No field named {key} for model {model}".format( key=key, model=self.__class__.__name__ ) ) setattr(self, key, val) self.save() return self
[ "def", "update_instance", "(", "self", ",", "data", ")", ":", "for", "key", ",", "val", "in", "iteritems", "(", "data", ")", ":", "if", "not", "hasattr", "(", "self", ",", "key", ")", ":", "raise", "AttributeError", "(", "\"No field named {key} for model {...
Update a single record by id with the provided data. Args: data (dict): The new data to update the record with. Returns: self: This is an instance of itself with the updated data. Raises: AttributeError: This is raised if a key in the ``data`` isn't a field on the model.
[ "Update", "a", "single", "record", "by", "id", "with", "the", "provided", "data", "." ]
046b026b79c9912bceebb17114bc0c5d2d02e3c7
https://github.com/croscon/fleaker/blob/046b026b79c9912bceebb17114bc0c5d2d02e3c7/fleaker/peewee/model.py#L160-L186
8,065
pytest-dev/pytest-xprocess
xprocess.py
ProcessStarter.wait
def wait(self, log_file): "Wait until the process is ready." lines = map(self.log_line, self.filter_lines(self.get_lines(log_file))) return any( std.re.search(self.pattern, line) for line in lines )
python
def wait(self, log_file): "Wait until the process is ready." lines = map(self.log_line, self.filter_lines(self.get_lines(log_file))) return any( std.re.search(self.pattern, line) for line in lines )
[ "def", "wait", "(", "self", ",", "log_file", ")", ":", "lines", "=", "map", "(", "self", ".", "log_line", ",", "self", ".", "filter_lines", "(", "self", ".", "get_lines", "(", "log_file", ")", ")", ")", "return", "any", "(", "std", ".", "re", ".", ...
Wait until the process is ready.
[ "Wait", "until", "the", "process", "is", "ready", "." ]
c3ee760b02dce2d0eed960b3ab0e28379853c3ef
https://github.com/pytest-dev/pytest-xprocess/blob/c3ee760b02dce2d0eed960b3ab0e28379853c3ef/xprocess.py#L188-L194
8,066
pytest-dev/pytest-xprocess
xprocess.py
CompatStarter.prep
def prep(self, wait, args, env=None): """ Given the return value of a preparefunc, prepare this CompatStarter. """ self.pattern = wait self.env = env self.args = args # wait is a function, supersedes the default behavior if callable(wait): self.wait = lambda lines: wait()
python
def prep(self, wait, args, env=None): self.pattern = wait self.env = env self.args = args # wait is a function, supersedes the default behavior if callable(wait): self.wait = lambda lines: wait()
[ "def", "prep", "(", "self", ",", "wait", ",", "args", ",", "env", "=", "None", ")", ":", "self", ".", "pattern", "=", "wait", "self", ".", "env", "=", "env", "self", ".", "args", "=", "args", "# wait is a function, supersedes the default behavior", "if", ...
Given the return value of a preparefunc, prepare this CompatStarter.
[ "Given", "the", "return", "value", "of", "a", "preparefunc", "prepare", "this", "CompatStarter", "." ]
c3ee760b02dce2d0eed960b3ab0e28379853c3ef
https://github.com/pytest-dev/pytest-xprocess/blob/c3ee760b02dce2d0eed960b3ab0e28379853c3ef/xprocess.py#L227-L238
8,067
pytest-dev/pytest-xprocess
xprocess.py
CompatStarter.wrap
def wrap(self, starter_cls): """ If starter_cls is not a ProcessStarter, assume it's the legacy preparefunc and return it bound to a CompatStarter. """ if isinstance(starter_cls, type) and issubclass(starter_cls, ProcessStarter): return starter_cls depr_msg = 'Pass a ProcessStarter for preparefunc' warnings.warn(depr_msg, DeprecationWarning, stacklevel=3) return functools.partial(CompatStarter, starter_cls)
python
def wrap(self, starter_cls): if isinstance(starter_cls, type) and issubclass(starter_cls, ProcessStarter): return starter_cls depr_msg = 'Pass a ProcessStarter for preparefunc' warnings.warn(depr_msg, DeprecationWarning, stacklevel=3) return functools.partial(CompatStarter, starter_cls)
[ "def", "wrap", "(", "self", ",", "starter_cls", ")", ":", "if", "isinstance", "(", "starter_cls", ",", "type", ")", "and", "issubclass", "(", "starter_cls", ",", "ProcessStarter", ")", ":", "return", "starter_cls", "depr_msg", "=", "'Pass a ProcessStarter for pr...
If starter_cls is not a ProcessStarter, assume it's the legacy preparefunc and return it bound to a CompatStarter.
[ "If", "starter_cls", "is", "not", "a", "ProcessStarter", "assume", "it", "s", "the", "legacy", "preparefunc", "and", "return", "it", "bound", "to", "a", "CompatStarter", "." ]
c3ee760b02dce2d0eed960b3ab0e28379853c3ef
https://github.com/pytest-dev/pytest-xprocess/blob/c3ee760b02dce2d0eed960b3ab0e28379853c3ef/xprocess.py#L241-L250
8,068
kmadac/bitstamp-python-client
bitstamp/client.py
BaseClient._construct_url
def _construct_url(self, url, base, quote): """ Adds the orderbook to the url if base and quote are specified. """ if not base and not quote: return url else: url = url + base.lower() + quote.lower() + "/" return url
python
def _construct_url(self, url, base, quote): if not base and not quote: return url else: url = url + base.lower() + quote.lower() + "/" return url
[ "def", "_construct_url", "(", "self", ",", "url", ",", "base", ",", "quote", ")", ":", "if", "not", "base", "and", "not", "quote", ":", "return", "url", "else", ":", "url", "=", "url", "+", "base", ".", "lower", "(", ")", "+", "quote", ".", "lowe...
Adds the orderbook to the url if base and quote are specified.
[ "Adds", "the", "orderbook", "to", "the", "url", "if", "base", "and", "quote", "are", "specified", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L56-L64
8,069
kmadac/bitstamp-python-client
bitstamp/client.py
BaseClient._request
def _request(self, func, url, version=1, *args, **kwargs): """ Make a generic request, adding in any proxy defined by the instance. Raises a ``requests.HTTPError`` if the response status isn't 200, and raises a :class:`BitstampError` if the response contains a json encoded error message. """ return_json = kwargs.pop('return_json', False) url = self.api_url[version] + url response = func(url, *args, **kwargs) if 'proxies' not in kwargs: kwargs['proxies'] = self.proxydict # Check for error, raising an exception if appropriate. response.raise_for_status() try: json_response = response.json() except ValueError: json_response = None if isinstance(json_response, dict): error = json_response.get('error') if error: raise BitstampError(error) elif json_response.get('status') == "error": raise BitstampError(json_response.get('reason')) if return_json: if json_response is None: raise BitstampError( "Could not decode json for: " + response.text) return json_response return response
python
def _request(self, func, url, version=1, *args, **kwargs): return_json = kwargs.pop('return_json', False) url = self.api_url[version] + url response = func(url, *args, **kwargs) if 'proxies' not in kwargs: kwargs['proxies'] = self.proxydict # Check for error, raising an exception if appropriate. response.raise_for_status() try: json_response = response.json() except ValueError: json_response = None if isinstance(json_response, dict): error = json_response.get('error') if error: raise BitstampError(error) elif json_response.get('status') == "error": raise BitstampError(json_response.get('reason')) if return_json: if json_response is None: raise BitstampError( "Could not decode json for: " + response.text) return json_response return response
[ "def", "_request", "(", "self", ",", "func", ",", "url", ",", "version", "=", "1", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "return_json", "=", "kwargs", ".", "pop", "(", "'return_json'", ",", "False", ")", "url", "=", "self", ".", "a...
Make a generic request, adding in any proxy defined by the instance. Raises a ``requests.HTTPError`` if the response status isn't 200, and raises a :class:`BitstampError` if the response contains a json encoded error message.
[ "Make", "a", "generic", "request", "adding", "in", "any", "proxy", "defined", "by", "the", "instance", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L66-L101
8,070
kmadac/bitstamp-python-client
bitstamp/client.py
Public.ticker
def ticker(self, base="btc", quote="usd"): """ Returns dictionary. """ url = self._construct_url("ticker/", base, quote) return self._get(url, return_json=True, version=2)
python
def ticker(self, base="btc", quote="usd"): url = self._construct_url("ticker/", base, quote) return self._get(url, return_json=True, version=2)
[ "def", "ticker", "(", "self", ",", "base", "=", "\"btc\"", ",", "quote", "=", "\"usd\"", ")", ":", "url", "=", "self", ".", "_construct_url", "(", "\"ticker/\"", ",", "base", ",", "quote", ")", "return", "self", ".", "_get", "(", "url", ",", "return_...
Returns dictionary.
[ "Returns", "dictionary", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L106-L111
8,071
kmadac/bitstamp-python-client
bitstamp/client.py
Public.order_book
def order_book(self, group=True, base="btc", quote="usd"): """ Returns dictionary with "bids" and "asks". Each is a list of open orders and each order is represented as a list of price and amount. """ params = {'group': group} url = self._construct_url("order_book/", base, quote) return self._get(url, params=params, return_json=True, version=2)
python
def order_book(self, group=True, base="btc", quote="usd"): params = {'group': group} url = self._construct_url("order_book/", base, quote) return self._get(url, params=params, return_json=True, version=2)
[ "def", "order_book", "(", "self", ",", "group", "=", "True", ",", "base", "=", "\"btc\"", ",", "quote", "=", "\"usd\"", ")", ":", "params", "=", "{", "'group'", ":", "group", "}", "url", "=", "self", ".", "_construct_url", "(", "\"order_book/\"", ",", ...
Returns dictionary with "bids" and "asks". Each is a list of open orders and each order is represented as a list of price and amount.
[ "Returns", "dictionary", "with", "bids", "and", "asks", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L120-L129
8,072
kmadac/bitstamp-python-client
bitstamp/client.py
Public.transactions
def transactions(self, time=TransRange.HOUR, base="btc", quote="usd"): """ Returns transactions for the last 'timedelta' seconds. Parameter time is specified by one of two values of TransRange class. """ params = {'time': time} url = self._construct_url("transactions/", base, quote) return self._get(url, params=params, return_json=True, version=2)
python
def transactions(self, time=TransRange.HOUR, base="btc", quote="usd"): params = {'time': time} url = self._construct_url("transactions/", base, quote) return self._get(url, params=params, return_json=True, version=2)
[ "def", "transactions", "(", "self", ",", "time", "=", "TransRange", ".", "HOUR", ",", "base", "=", "\"btc\"", ",", "quote", "=", "\"usd\"", ")", ":", "params", "=", "{", "'time'", ":", "time", "}", "url", "=", "self", ".", "_construct_url", "(", "\"t...
Returns transactions for the last 'timedelta' seconds. Parameter time is specified by one of two values of TransRange class.
[ "Returns", "transactions", "for", "the", "last", "timedelta", "seconds", ".", "Parameter", "time", "is", "specified", "by", "one", "of", "two", "values", "of", "TransRange", "class", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L131-L138
8,073
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.get_nonce
def get_nonce(self): """ Get a unique nonce for the bitstamp API. This integer must always be increasing, so use the current unix time. Every time this variable is requested, it automatically increments to allow for more than one API request per second. This isn't a thread-safe function however, so you should only rely on a single thread if you have a high level of concurrent API requests in your application. """ nonce = getattr(self, '_nonce', 0) if nonce: nonce += 1 # If the unix time is greater though, use that instead (helps low # concurrency multi-threaded apps always call with the largest nonce). self._nonce = max(int(time.time()), nonce) return self._nonce
python
def get_nonce(self): nonce = getattr(self, '_nonce', 0) if nonce: nonce += 1 # If the unix time is greater though, use that instead (helps low # concurrency multi-threaded apps always call with the largest nonce). self._nonce = max(int(time.time()), nonce) return self._nonce
[ "def", "get_nonce", "(", "self", ")", ":", "nonce", "=", "getattr", "(", "self", ",", "'_nonce'", ",", "0", ")", "if", "nonce", ":", "nonce", "+=", "1", "# If the unix time is greater though, use that instead (helps low", "# concurrency multi-threaded apps always call w...
Get a unique nonce for the bitstamp API. This integer must always be increasing, so use the current unix time. Every time this variable is requested, it automatically increments to allow for more than one API request per second. This isn't a thread-safe function however, so you should only rely on a single thread if you have a high level of concurrent API requests in your application.
[ "Get", "a", "unique", "nonce", "for", "the", "bitstamp", "API", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L177-L195
8,074
kmadac/bitstamp-python-client
bitstamp/client.py
Trading._default_data
def _default_data(self, *args, **kwargs): """ Generate a one-time signature and other data required to send a secure POST request to the Bitstamp API. """ data = super(Trading, self)._default_data(*args, **kwargs) data['key'] = self.key nonce = self.get_nonce() msg = str(nonce) + self.username + self.key signature = hmac.new( self.secret.encode('utf-8'), msg=msg.encode('utf-8'), digestmod=hashlib.sha256).hexdigest().upper() data['signature'] = signature data['nonce'] = nonce return data
python
def _default_data(self, *args, **kwargs): data = super(Trading, self)._default_data(*args, **kwargs) data['key'] = self.key nonce = self.get_nonce() msg = str(nonce) + self.username + self.key signature = hmac.new( self.secret.encode('utf-8'), msg=msg.encode('utf-8'), digestmod=hashlib.sha256).hexdigest().upper() data['signature'] = signature data['nonce'] = nonce return data
[ "def", "_default_data", "(", "self", ",", "*", "args", ",", "*", "*", "kwargs", ")", ":", "data", "=", "super", "(", "Trading", ",", "self", ")", ".", "_default_data", "(", "*", "args", ",", "*", "*", "kwargs", ")", "data", "[", "'key'", "]", "="...
Generate a one-time signature and other data required to send a secure POST request to the Bitstamp API.
[ "Generate", "a", "one", "-", "time", "signature", "and", "other", "data", "required", "to", "send", "a", "secure", "POST", "request", "to", "the", "Bitstamp", "API", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L197-L212
8,075
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.cancel_order
def cancel_order(self, order_id, version=1): """ Cancel the order specified by order_id. Version 1 (default for backwards compatibility reasons): Returns True if order was successfully canceled, otherwise raise a BitstampError. Version 2: Returns dictionary of the canceled order, containing the keys: id, type, price, amount """ data = {'id': order_id} return self._post("cancel_order/", data=data, return_json=True, version=version)
python
def cancel_order(self, order_id, version=1): data = {'id': order_id} return self._post("cancel_order/", data=data, return_json=True, version=version)
[ "def", "cancel_order", "(", "self", ",", "order_id", ",", "version", "=", "1", ")", ":", "data", "=", "{", "'id'", ":", "order_id", "}", "return", "self", ".", "_post", "(", "\"cancel_order/\"", ",", "data", "=", "data", ",", "return_json", "=", "True"...
Cancel the order specified by order_id. Version 1 (default for backwards compatibility reasons): Returns True if order was successfully canceled, otherwise raise a BitstampError. Version 2: Returns dictionary of the canceled order, containing the keys: id, type, price, amount
[ "Cancel", "the", "order", "specified", "by", "order_id", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L295-L309
8,076
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.buy_limit_order
def buy_limit_order(self, amount, price, base="btc", quote="usd", limit_price=None): """ Order to buy amount of bitcoins for specified price. """ data = {'amount': amount, 'price': price} if limit_price is not None: data['limit_price'] = limit_price url = self._construct_url("buy/", base, quote) return self._post(url, data=data, return_json=True, version=2)
python
def buy_limit_order(self, amount, price, base="btc", quote="usd", limit_price=None): data = {'amount': amount, 'price': price} if limit_price is not None: data['limit_price'] = limit_price url = self._construct_url("buy/", base, quote) return self._post(url, data=data, return_json=True, version=2)
[ "def", "buy_limit_order", "(", "self", ",", "amount", ",", "price", ",", "base", "=", "\"btc\"", ",", "quote", "=", "\"usd\"", ",", "limit_price", "=", "None", ")", ":", "data", "=", "{", "'amount'", ":", "amount", ",", "'price'", ":", "price", "}", ...
Order to buy amount of bitcoins for specified price.
[ "Order", "to", "buy", "amount", "of", "bitcoins", "for", "specified", "price", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L320-L328
8,077
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.buy_market_order
def buy_market_order(self, amount, base="btc", quote="usd"): """ Order to buy amount of bitcoins for market price. """ data = {'amount': amount} url = self._construct_url("buy/market/", base, quote) return self._post(url, data=data, return_json=True, version=2)
python
def buy_market_order(self, amount, base="btc", quote="usd"): data = {'amount': amount} url = self._construct_url("buy/market/", base, quote) return self._post(url, data=data, return_json=True, version=2)
[ "def", "buy_market_order", "(", "self", ",", "amount", ",", "base", "=", "\"btc\"", ",", "quote", "=", "\"usd\"", ")", ":", "data", "=", "{", "'amount'", ":", "amount", "}", "url", "=", "self", ".", "_construct_url", "(", "\"buy/market/\"", ",", "base", ...
Order to buy amount of bitcoins for market price.
[ "Order", "to", "buy", "amount", "of", "bitcoins", "for", "market", "price", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L330-L336
8,078
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.check_bitstamp_code
def check_bitstamp_code(self, code): """ Returns JSON dictionary containing USD and BTC amount included in given bitstamp code. """ data = {'code': code} return self._post("check_code/", data=data, return_json=True, version=1)
python
def check_bitstamp_code(self, code): data = {'code': code} return self._post("check_code/", data=data, return_json=True, version=1)
[ "def", "check_bitstamp_code", "(", "self", ",", "code", ")", ":", "data", "=", "{", "'code'", ":", "code", "}", "return", "self", ".", "_post", "(", "\"check_code/\"", ",", "data", "=", "data", ",", "return_json", "=", "True", ",", "version", "=", "1",...
Returns JSON dictionary containing USD and BTC amount included in given bitstamp code.
[ "Returns", "JSON", "dictionary", "containing", "USD", "and", "BTC", "amount", "included", "in", "given", "bitstamp", "code", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L356-L363
8,079
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.redeem_bitstamp_code
def redeem_bitstamp_code(self, code): """ Returns JSON dictionary containing USD and BTC amount added to user's account. """ data = {'code': code} return self._post("redeem_code/", data=data, return_json=True, version=1)
python
def redeem_bitstamp_code(self, code): data = {'code': code} return self._post("redeem_code/", data=data, return_json=True, version=1)
[ "def", "redeem_bitstamp_code", "(", "self", ",", "code", ")", ":", "data", "=", "{", "'code'", ":", "code", "}", "return", "self", ".", "_post", "(", "\"redeem_code/\"", ",", "data", "=", "data", ",", "return_json", "=", "True", ",", "version", "=", "1...
Returns JSON dictionary containing USD and BTC amount added to user's account.
[ "Returns", "JSON", "dictionary", "containing", "USD", "and", "BTC", "amount", "added", "to", "user", "s", "account", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L365-L372
8,080
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.withdrawal_requests
def withdrawal_requests(self, timedelta = 86400): """ Returns list of withdrawal requests. Each request is represented as a dictionary. By default, the last 24 hours (86400 seconds) are returned. """ data = {'timedelta': timedelta} return self._post("withdrawal_requests/", return_json=True, version=1, data=data)
python
def withdrawal_requests(self, timedelta = 86400): data = {'timedelta': timedelta} return self._post("withdrawal_requests/", return_json=True, version=1, data=data)
[ "def", "withdrawal_requests", "(", "self", ",", "timedelta", "=", "86400", ")", ":", "data", "=", "{", "'timedelta'", ":", "timedelta", "}", "return", "self", ".", "_post", "(", "\"withdrawal_requests/\"", ",", "return_json", "=", "True", ",", "version", "="...
Returns list of withdrawal requests. Each request is represented as a dictionary. By default, the last 24 hours (86400 seconds) are returned.
[ "Returns", "list", "of", "withdrawal", "requests", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L374-L383
8,081
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.litecoin_withdrawal
def litecoin_withdrawal(self, amount, address): """ Send litecoins to another litecoin wallet specified by address. """ data = {'amount': amount, 'address': address} return self._post("ltc_withdrawal/", data=data, return_json=True, version=2)
python
def litecoin_withdrawal(self, amount, address): data = {'amount': amount, 'address': address} return self._post("ltc_withdrawal/", data=data, return_json=True, version=2)
[ "def", "litecoin_withdrawal", "(", "self", ",", "amount", ",", "address", ")", ":", "data", "=", "{", "'amount'", ":", "amount", ",", "'address'", ":", "address", "}", "return", "self", ".", "_post", "(", "\"ltc_withdrawal/\"", ",", "data", "=", "data", ...
Send litecoins to another litecoin wallet specified by address.
[ "Send", "litecoins", "to", "another", "litecoin", "wallet", "specified", "by", "address", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L415-L421
8,082
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.ripple_withdrawal
def ripple_withdrawal(self, amount, address, currency): """ Returns true if successful. """ data = {'amount': amount, 'address': address, 'currency': currency} response = self._post("ripple_withdrawal/", data=data, return_json=True) return self._expect_true(response)
python
def ripple_withdrawal(self, amount, address, currency): data = {'amount': amount, 'address': address, 'currency': currency} response = self._post("ripple_withdrawal/", data=data, return_json=True) return self._expect_true(response)
[ "def", "ripple_withdrawal", "(", "self", ",", "amount", ",", "address", ",", "currency", ")", ":", "data", "=", "{", "'amount'", ":", "amount", ",", "'address'", ":", "address", ",", "'currency'", ":", "currency", "}", "response", "=", "self", ".", "_pos...
Returns true if successful.
[ "Returns", "true", "if", "successful", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L445-L452
8,083
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.xrp_withdrawal
def xrp_withdrawal(self, amount, address, destination_tag=None): """ Sends xrps to another xrp wallet specified by address. Returns withdrawal id. """ data = {'amount': amount, 'address': address} if destination_tag: data['destination_tag'] = destination_tag return self._post("xrp_withdrawal/", data=data, return_json=True, version=2)["id"]
python
def xrp_withdrawal(self, amount, address, destination_tag=None): data = {'amount': amount, 'address': address} if destination_tag: data['destination_tag'] = destination_tag return self._post("xrp_withdrawal/", data=data, return_json=True, version=2)["id"]
[ "def", "xrp_withdrawal", "(", "self", ",", "amount", ",", "address", ",", "destination_tag", "=", "None", ")", ":", "data", "=", "{", "'amount'", ":", "amount", ",", "'address'", ":", "address", "}", "if", "destination_tag", ":", "data", "[", "'destination...
Sends xrps to another xrp wallet specified by address. Returns withdrawal id.
[ "Sends", "xrps", "to", "another", "xrp", "wallet", "specified", "by", "address", ".", "Returns", "withdrawal", "id", "." ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L461-L470
8,084
kmadac/bitstamp-python-client
bitstamp/client.py
Trading.transfer_to_main
def transfer_to_main(self, amount, currency, subaccount=None): """ Returns dictionary with status. subaccount has to be the numerical id of the subaccount, not the name """ data = {'amount': amount, 'currency': currency,} if subaccount is not None: data['subAccount'] = subaccount return self._post("transfer-to-main/", data=data, return_json=True, version=2)
python
def transfer_to_main(self, amount, currency, subaccount=None): data = {'amount': amount, 'currency': currency,} if subaccount is not None: data['subAccount'] = subaccount return self._post("transfer-to-main/", data=data, return_json=True, version=2)
[ "def", "transfer_to_main", "(", "self", ",", "amount", ",", "currency", ",", "subaccount", "=", "None", ")", ":", "data", "=", "{", "'amount'", ":", "amount", ",", "'currency'", ":", "currency", ",", "}", "if", "subaccount", "is", "not", "None", ":", "...
Returns dictionary with status. subaccount has to be the numerical id of the subaccount, not the name
[ "Returns", "dictionary", "with", "status", ".", "subaccount", "has", "to", "be", "the", "numerical", "id", "of", "the", "subaccount", "not", "the", "name" ]
35b9a61f3892cc281de89963d210f7bd5757c717
https://github.com/kmadac/bitstamp-python-client/blob/35b9a61f3892cc281de89963d210f7bd5757c717/bitstamp/client.py#L495-L505
8,085
pierre-rouanet/aupyom
aupyom/sound.py
Sound.resample
def resample(self, target_sr): """ Returns a new sound with a samplerate of target_sr. """ y_hat = librosa.core.resample(self.y, self.sr, target_sr) return Sound(y_hat, target_sr)
python
def resample(self, target_sr): y_hat = librosa.core.resample(self.y, self.sr, target_sr) return Sound(y_hat, target_sr)
[ "def", "resample", "(", "self", ",", "target_sr", ")", ":", "y_hat", "=", "librosa", ".", "core", ".", "resample", "(", "self", ".", "y", ",", "self", ".", "sr", ",", "target_sr", ")", "return", "Sound", "(", "y_hat", ",", "target_sr", ")" ]
Returns a new sound with a samplerate of target_sr.
[ "Returns", "a", "new", "sound", "with", "a", "samplerate", "of", "target_sr", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sound.py#L36-L39
8,086
pierre-rouanet/aupyom
aupyom/sound.py
Sound.as_ipywidget
def as_ipywidget(self): """ Provides an IPywidgets player that can be used in a notebook. """ from IPython.display import Audio return Audio(data=self.y, rate=self.sr)
python
def as_ipywidget(self): from IPython.display import Audio return Audio(data=self.y, rate=self.sr)
[ "def", "as_ipywidget", "(", "self", ")", ":", "from", "IPython", ".", "display", "import", "Audio", "return", "Audio", "(", "data", "=", "self", ".", "y", ",", "rate", "=", "self", ".", "sr", ")" ]
Provides an IPywidgets player that can be used in a notebook.
[ "Provides", "an", "IPywidgets", "player", "that", "can", "be", "used", "in", "a", "notebook", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sound.py#L43-L47
8,087
pierre-rouanet/aupyom
aupyom/sound.py
Sound.from_file
def from_file(cls, filename, sr=22050): """ Loads an audiofile, uses sr=22050 by default. """ y, sr = librosa.load(filename, sr=sr) return cls(y, sr)
python
def from_file(cls, filename, sr=22050): y, sr = librosa.load(filename, sr=sr) return cls(y, sr)
[ "def", "from_file", "(", "cls", ",", "filename", ",", "sr", "=", "22050", ")", ":", "y", ",", "sr", "=", "librosa", ".", "load", "(", "filename", ",", "sr", "=", "sr", ")", "return", "cls", "(", "y", ",", "sr", ")" ]
Loads an audiofile, uses sr=22050 by default.
[ "Loads", "an", "audiofile", "uses", "sr", "=", "22050", "by", "default", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sound.py#L50-L53
8,088
pierre-rouanet/aupyom
aupyom/sound.py
Sound.chunks
def chunks(self): """ Returns a chunk iterator over the sound. """ if not hasattr(self, '_it'): class ChunkIterator(object): def __iter__(iter): return iter def __next__(iter): try: chunk = self._next_chunk() except StopIteration: if self.loop: self._init_stretching() return iter.__next__() raise return chunk next = __next__ self._it = ChunkIterator() return self._it
python
def chunks(self): if not hasattr(self, '_it'): class ChunkIterator(object): def __iter__(iter): return iter def __next__(iter): try: chunk = self._next_chunk() except StopIteration: if self.loop: self._init_stretching() return iter.__next__() raise return chunk next = __next__ self._it = ChunkIterator() return self._it
[ "def", "chunks", "(", "self", ")", ":", "if", "not", "hasattr", "(", "self", ",", "'_it'", ")", ":", "class", "ChunkIterator", "(", "object", ")", ":", "def", "__iter__", "(", "iter", ")", ":", "return", "iter", "def", "__next__", "(", "iter", ")", ...
Returns a chunk iterator over the sound.
[ "Returns", "a", "chunk", "iterator", "over", "the", "sound", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sound.py#L70-L92
8,089
pierre-rouanet/aupyom
aupyom/sound.py
Sound.pitch_shifter
def pitch_shifter(self, chunk, shift): """ Pitch-Shift the given chunk by shift semi-tones. """ freq = numpy.fft.rfft(chunk) N = len(freq) shifted_freq = numpy.zeros(N, freq.dtype) S = numpy.round(shift if shift > 0 else N + shift, 0) s = N - S shifted_freq[:S] = freq[s:] shifted_freq[S:] = freq[:s] shifted_chunk = numpy.fft.irfft(shifted_freq) return shifted_chunk.astype(chunk.dtype)
python
def pitch_shifter(self, chunk, shift): freq = numpy.fft.rfft(chunk) N = len(freq) shifted_freq = numpy.zeros(N, freq.dtype) S = numpy.round(shift if shift > 0 else N + shift, 0) s = N - S shifted_freq[:S] = freq[s:] shifted_freq[S:] = freq[:s] shifted_chunk = numpy.fft.irfft(shifted_freq) return shifted_chunk.astype(chunk.dtype)
[ "def", "pitch_shifter", "(", "self", ",", "chunk", ",", "shift", ")", ":", "freq", "=", "numpy", ".", "fft", ".", "rfft", "(", "chunk", ")", "N", "=", "len", "(", "freq", ")", "shifted_freq", "=", "numpy", ".", "zeros", "(", "N", ",", "freq", "."...
Pitch-Shift the given chunk by shift semi-tones.
[ "Pitch", "-", "Shift", "the", "given", "chunk", "by", "shift", "semi", "-", "tones", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sound.py#L108-L123
8,090
pierre-rouanet/aupyom
aupyom/sound.py
Sound._time_stretcher
def _time_stretcher(self, stretch_factor): """ Real time time-scale without pitch modification. :param int i: index of the beginning of the chunk to stretch :param float stretch_factor: audio scale factor (if > 1 speed up the sound else slow it down) .. warning:: This method needs to store the phase computed from the previous chunk. Thus, it can only be called chunk by chunk. """ start = self._i2 end = min(self._i2 + self._N, len(self._sy) - (self._N + self._H)) if start >= end: raise StopIteration # The not so clean code below basically implements a phase vocoder out = numpy.zeros(self._N, dtype=numpy.complex) while self._i2 < end: if self._i1 + self._N + self._H > len(self.y): raise StopIteration a, b = self._i1, self._i1 + self._N S1 = numpy.fft.fft(self._win * self.y[a: b]) S2 = numpy.fft.fft(self._win * self.y[a + self._H: b + self._H]) self._phi += (numpy.angle(S2) - numpy.angle(S1)) self._phi = self._phi - 2.0 * numpy.pi * numpy.round(self._phi / (2.0 * numpy.pi)) out.real, out.imag = numpy.cos(self._phi), numpy.sin(self._phi) self._sy[self._i2: self._i2 + self._N] += self._win * numpy.fft.ifft(numpy.abs(S2) * out).real self._i1 += int(self._H * self.stretch_factor) self._i2 += self._H chunk = self._sy[start:end] if stretch_factor == 1.0: chunk = self.y[start:end] return chunk
python
def _time_stretcher(self, stretch_factor): start = self._i2 end = min(self._i2 + self._N, len(self._sy) - (self._N + self._H)) if start >= end: raise StopIteration # The not so clean code below basically implements a phase vocoder out = numpy.zeros(self._N, dtype=numpy.complex) while self._i2 < end: if self._i1 + self._N + self._H > len(self.y): raise StopIteration a, b = self._i1, self._i1 + self._N S1 = numpy.fft.fft(self._win * self.y[a: b]) S2 = numpy.fft.fft(self._win * self.y[a + self._H: b + self._H]) self._phi += (numpy.angle(S2) - numpy.angle(S1)) self._phi = self._phi - 2.0 * numpy.pi * numpy.round(self._phi / (2.0 * numpy.pi)) out.real, out.imag = numpy.cos(self._phi), numpy.sin(self._phi) self._sy[self._i2: self._i2 + self._N] += self._win * numpy.fft.ifft(numpy.abs(S2) * out).real self._i1 += int(self._H * self.stretch_factor) self._i2 += self._H chunk = self._sy[start:end] if stretch_factor == 1.0: chunk = self.y[start:end] return chunk
[ "def", "_time_stretcher", "(", "self", ",", "stretch_factor", ")", ":", "start", "=", "self", ".", "_i2", "end", "=", "min", "(", "self", ".", "_i2", "+", "self", ".", "_N", ",", "len", "(", "self", ".", "_sy", ")", "-", "(", "self", ".", "_N", ...
Real time time-scale without pitch modification. :param int i: index of the beginning of the chunk to stretch :param float stretch_factor: audio scale factor (if > 1 speed up the sound else slow it down) .. warning:: This method needs to store the phase computed from the previous chunk. Thus, it can only be called chunk by chunk.
[ "Real", "time", "time", "-", "scale", "without", "pitch", "modification", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sound.py#L158-L199
8,091
vlasovskikh/funcparserlib
funcparserlib/parser.py
Parser.define
def define(self, p): """Defines a parser wrapped into this object.""" f = getattr(p, 'run', p) if debug: setattr(self, '_run', f) else: setattr(self, 'run', f) self.named(getattr(p, 'name', p.__doc__))
python
def define(self, p): f = getattr(p, 'run', p) if debug: setattr(self, '_run', f) else: setattr(self, 'run', f) self.named(getattr(p, 'name', p.__doc__))
[ "def", "define", "(", "self", ",", "p", ")", ":", "f", "=", "getattr", "(", "p", ",", "'run'", ",", "p", ")", "if", "debug", ":", "setattr", "(", "self", ",", "'_run'", ",", "f", ")", "else", ":", "setattr", "(", "self", ",", "'run'", ",", "f...
Defines a parser wrapped into this object.
[ "Defines", "a", "parser", "wrapped", "into", "this", "object", "." ]
0b689920babcf6079a4b3e8721cc10bbc089d81c
https://github.com/vlasovskikh/funcparserlib/blob/0b689920babcf6079a4b3e8721cc10bbc089d81c/funcparserlib/parser.py#L90-L97
8,092
pierre-rouanet/aupyom
aupyom/sampler.py
Sampler.play
def play(self, sound): """ Adds and plays a new Sound to the Sampler. :param sound: sound to play .. note:: If the sound is already playing, it will restart from the beginning. """ self.is_done.clear() # hold is_done until the sound is played if self.sr != sound.sr: raise ValueError('You can only play sound with a samplerate of {} (here {}). Use the Sound.resample method for instance.', self.sr, sound.sr) if sound in self.sounds: self.remove(sound) with self.chunk_available: self.sounds.append(sound) sound.playing = True self.chunk_available.notify() self.is_done.wait()
python
def play(self, sound): self.is_done.clear() # hold is_done until the sound is played if self.sr != sound.sr: raise ValueError('You can only play sound with a samplerate of {} (here {}). Use the Sound.resample method for instance.', self.sr, sound.sr) if sound in self.sounds: self.remove(sound) with self.chunk_available: self.sounds.append(sound) sound.playing = True self.chunk_available.notify() self.is_done.wait()
[ "def", "play", "(", "self", ",", "sound", ")", ":", "self", ".", "is_done", ".", "clear", "(", ")", "# hold is_done until the sound is played", "if", "self", ".", "sr", "!=", "sound", ".", "sr", ":", "raise", "ValueError", "(", "'You can only play sound with a...
Adds and plays a new Sound to the Sampler. :param sound: sound to play .. note:: If the sound is already playing, it will restart from the beginning.
[ "Adds", "and", "plays", "a", "new", "Sound", "to", "the", "Sampler", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sampler.py#L48-L68
8,093
pierre-rouanet/aupyom
aupyom/sampler.py
Sampler.remove
def remove(self, sound): """ Remove a currently played sound. """ with self.chunk_available: sound.playing = False self.sounds.remove(sound)
python
def remove(self, sound): with self.chunk_available: sound.playing = False self.sounds.remove(sound)
[ "def", "remove", "(", "self", ",", "sound", ")", ":", "with", "self", ".", "chunk_available", ":", "sound", ".", "playing", "=", "False", "self", ".", "sounds", ".", "remove", "(", "sound", ")" ]
Remove a currently played sound.
[ "Remove", "a", "currently", "played", "sound", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sampler.py#L70-L74
8,094
pierre-rouanet/aupyom
aupyom/sampler.py
Sampler.next_chunks
def next_chunks(self): """ Gets a new chunk from all played sound and mix them together. """ with self.chunk_available: while True: playing_sounds = [s for s in self.sounds if s.playing] chunks = [] for s in playing_sounds: try: chunks.append(next(s.chunks)) except StopIteration: s.playing = False self.sounds.remove(s) self.is_done.set() # sound was played, release is_done to end the wait in play if chunks: break self.chunk_available.wait() return numpy.mean(chunks, axis=0)
python
def next_chunks(self): with self.chunk_available: while True: playing_sounds = [s for s in self.sounds if s.playing] chunks = [] for s in playing_sounds: try: chunks.append(next(s.chunks)) except StopIteration: s.playing = False self.sounds.remove(s) self.is_done.set() # sound was played, release is_done to end the wait in play if chunks: break self.chunk_available.wait() return numpy.mean(chunks, axis=0)
[ "def", "next_chunks", "(", "self", ")", ":", "with", "self", ".", "chunk_available", ":", "while", "True", ":", "playing_sounds", "=", "[", "s", "for", "s", "in", "self", ".", "sounds", "if", "s", ".", "playing", "]", "chunks", "=", "[", "]", "for", ...
Gets a new chunk from all played sound and mix them together.
[ "Gets", "a", "new", "chunk", "from", "all", "played", "sound", "and", "mix", "them", "together", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sampler.py#L78-L98
8,095
pierre-rouanet/aupyom
aupyom/sampler.py
Sampler.run
def run(self): """ Play loop, i.e. send all sound chunk by chunk to the soundcard. """ self.running = True def chunks_producer(): while self.running: self.chunks.put(self.next_chunks()) t = Thread(target=chunks_producer) t.start() with self.BackendStream(samplerate=self.sr, channels=1) as stream: while self.running: try: stream.write(self.chunks.get(timeout=self.timeout)) # timeout so stream.write() thread can exit except Empty: self.running = False
python
def run(self): self.running = True def chunks_producer(): while self.running: self.chunks.put(self.next_chunks()) t = Thread(target=chunks_producer) t.start() with self.BackendStream(samplerate=self.sr, channels=1) as stream: while self.running: try: stream.write(self.chunks.get(timeout=self.timeout)) # timeout so stream.write() thread can exit except Empty: self.running = False
[ "def", "run", "(", "self", ")", ":", "self", ".", "running", "=", "True", "def", "chunks_producer", "(", ")", ":", "while", "self", ".", "running", ":", "self", ".", "chunks", ".", "put", "(", "self", ".", "next_chunks", "(", ")", ")", "t", "=", ...
Play loop, i.e. send all sound chunk by chunk to the soundcard.
[ "Play", "loop", "i", ".", "e", ".", "send", "all", "sound", "chunk", "by", "chunk", "to", "the", "soundcard", "." ]
90f819b2d0b6cf7467b1945af029317a61e52e56
https://github.com/pierre-rouanet/aupyom/blob/90f819b2d0b6cf7467b1945af029317a61e52e56/aupyom/sampler.py#L100-L116
8,096
suds-community/suds
suds/xsd/depsort.py
dependency_sort
def dependency_sort(dependency_tree): """ Sorts items 'dependencies first' in a given dependency tree. A dependency tree is a dictionary mapping an object to a collection its dependency objects. Result is a properly sorted list of items, where each item is a 2-tuple containing an object and its dependency list, as given in the input dependency tree. If B is directly or indirectly dependent on A and they are not both a part of the same dependency cycle (i.e. then A is neither directly nor indirectly dependent on B) then A needs to come before B. If A and B are a part of the same dependency cycle, i.e. if they are both directly or indirectly dependent on each other, then it does not matter which comes first. Any entries found listed as dependencies, but that do not have their own dependencies listed as well, are logged & ignored. @return: The sorted items. @rtype: list """ sorted = [] processed = set() for key, deps in dependency_tree.iteritems(): _sort_r(sorted, processed, key, deps, dependency_tree) return sorted
python
def dependency_sort(dependency_tree): sorted = [] processed = set() for key, deps in dependency_tree.iteritems(): _sort_r(sorted, processed, key, deps, dependency_tree) return sorted
[ "def", "dependency_sort", "(", "dependency_tree", ")", ":", "sorted", "=", "[", "]", "processed", "=", "set", "(", ")", "for", "key", ",", "deps", "in", "dependency_tree", ".", "iteritems", "(", ")", ":", "_sort_r", "(", "sorted", ",", "processed", ",", ...
Sorts items 'dependencies first' in a given dependency tree. A dependency tree is a dictionary mapping an object to a collection its dependency objects. Result is a properly sorted list of items, where each item is a 2-tuple containing an object and its dependency list, as given in the input dependency tree. If B is directly or indirectly dependent on A and they are not both a part of the same dependency cycle (i.e. then A is neither directly nor indirectly dependent on B) then A needs to come before B. If A and B are a part of the same dependency cycle, i.e. if they are both directly or indirectly dependent on each other, then it does not matter which comes first. Any entries found listed as dependencies, but that do not have their own dependencies listed as well, are logged & ignored. @return: The sorted items. @rtype: list
[ "Sorts", "items", "dependencies", "first", "in", "a", "given", "dependency", "tree", "." ]
6fb0a829337b5037a66c20aae6f89b41acd77e40
https://github.com/suds-community/suds/blob/6fb0a829337b5037a66c20aae6f89b41acd77e40/suds/xsd/depsort.py#L27-L57
8,097
suds-community/suds
suds/xsd/depsort.py
_sort_r
def _sort_r(sorted, processed, key, deps, dependency_tree): """Recursive topological sort implementation.""" if key in processed: return processed.add(key) for dep_key in deps: dep_deps = dependency_tree.get(dep_key) if dep_deps is None: log.debug('"%s" not found, skipped', Repr(dep_key)) continue _sort_r(sorted, processed, dep_key, dep_deps, dependency_tree) sorted.append((key, deps))
python
def _sort_r(sorted, processed, key, deps, dependency_tree): if key in processed: return processed.add(key) for dep_key in deps: dep_deps = dependency_tree.get(dep_key) if dep_deps is None: log.debug('"%s" not found, skipped', Repr(dep_key)) continue _sort_r(sorted, processed, dep_key, dep_deps, dependency_tree) sorted.append((key, deps))
[ "def", "_sort_r", "(", "sorted", ",", "processed", ",", "key", ",", "deps", ",", "dependency_tree", ")", ":", "if", "key", "in", "processed", ":", "return", "processed", ".", "add", "(", "key", ")", "for", "dep_key", "in", "deps", ":", "dep_deps", "=",...
Recursive topological sort implementation.
[ "Recursive", "topological", "sort", "implementation", "." ]
6fb0a829337b5037a66c20aae6f89b41acd77e40
https://github.com/suds-community/suds/blob/6fb0a829337b5037a66c20aae6f89b41acd77e40/suds/xsd/depsort.py#L60-L71
8,098
suds-community/suds
suds/xsd/sxbasic.py
TypedContent.resolve
def resolve(self, nobuiltin=False): """ Resolve the node's type reference and return the referenced type node. Returns self if the type is defined locally, e.g. as a <complexType> subnode. Otherwise returns the referenced external node. @param nobuiltin: Flag indicating whether resolving to XSD built-in types should not be allowed. @return: The resolved (true) type. @rtype: L{SchemaObject} """ cached = self.resolved_cache.get(nobuiltin) if cached is not None: return cached resolved = self.__resolve_type(nobuiltin) self.resolved_cache[nobuiltin] = resolved return resolved
python
def resolve(self, nobuiltin=False): cached = self.resolved_cache.get(nobuiltin) if cached is not None: return cached resolved = self.__resolve_type(nobuiltin) self.resolved_cache[nobuiltin] = resolved return resolved
[ "def", "resolve", "(", "self", ",", "nobuiltin", "=", "False", ")", ":", "cached", "=", "self", ".", "resolved_cache", ".", "get", "(", "nobuiltin", ")", "if", "cached", "is", "not", "None", ":", "return", "cached", "resolved", "=", "self", ".", "__res...
Resolve the node's type reference and return the referenced type node. Returns self if the type is defined locally, e.g. as a <complexType> subnode. Otherwise returns the referenced external node. @param nobuiltin: Flag indicating whether resolving to XSD built-in types should not be allowed. @return: The resolved (true) type. @rtype: L{SchemaObject}
[ "Resolve", "the", "node", "s", "type", "reference", "and", "return", "the", "referenced", "type", "node", "." ]
6fb0a829337b5037a66c20aae6f89b41acd77e40
https://github.com/suds-community/suds/blob/6fb0a829337b5037a66c20aae6f89b41acd77e40/suds/xsd/sxbasic.py#L45-L63
8,099
suds-community/suds
suds/xsd/sxbasic.py
Element.namespace
def namespace(self, prefix=None): """ Get this schema element's target namespace. In case of reference elements, the target namespace is defined by the referenced and not the referencing element node. @param prefix: The default prefix. @type prefix: str @return: The schema element's target namespace @rtype: (I{prefix},I{URI}) """ e = self.__deref() if e is not None: return e.namespace(prefix) return super(Element, self).namespace()
python
def namespace(self, prefix=None): e = self.__deref() if e is not None: return e.namespace(prefix) return super(Element, self).namespace()
[ "def", "namespace", "(", "self", ",", "prefix", "=", "None", ")", ":", "e", "=", "self", ".", "__deref", "(", ")", "if", "e", "is", "not", "None", ":", "return", "e", ".", "namespace", "(", "prefix", ")", "return", "super", "(", "Element", ",", "...
Get this schema element's target namespace. In case of reference elements, the target namespace is defined by the referenced and not the referencing element node. @param prefix: The default prefix. @type prefix: str @return: The schema element's target namespace @rtype: (I{prefix},I{URI})
[ "Get", "this", "schema", "element", "s", "target", "namespace", "." ]
6fb0a829337b5037a66c20aae6f89b41acd77e40
https://github.com/suds-community/suds/blob/6fb0a829337b5037a66c20aae6f89b41acd77e40/suds/xsd/sxbasic.py#L443-L459