text
stringlengths
0
828
getter = functools.partial(
registry.retrieve,
bearer=bearer_cls,
target=target)
try:
# Generate a hash of {rulefn: permission} that we can use later
# to collect all of the rules.
if len(permissions):
rules = {getter(permission=x): x for x in permissions}
else:
rules = {getter(): None}
except KeyError:
# No rules defined. Default to no permission.
return query.filter(sql.false())
# Invoke all the rules and collect the results
# Abusing reduce here to invoke each rule and send the return value (query)
# from one rule to the next one. In this way the query becomes
# increasingly decorated as it marches through the system.
# q == query
# r = (rulefn, permission)
reducer = lambda q, r: r[0](permission=r[1], query=q, bearer=bearer)
return reduce(reducer, six.iteritems(rules), query)"
4936,"def has(*permissions, **kwargs):
""""""
Checks if the passed bearer has the passed permissions (optionally on
the passed target).
""""""
target = kwargs['target']
kwargs['target'] = type_for(target)
# TODO: Predicate evaluation?
return target in filter_(*permissions, **kwargs)"
4937,"def get_now_datetime_filestamp(longTime=False):
""""""
*A datetime stamp to be appended to the end of filenames: ``YYYYMMDDtHHMMSS``*
**Key Arguments:**
- ``longTime`` -- make time string longer (more change of filenames being unique)
**Return:**
- ``now`` -- current time and date in filename format
**Usage:**
.. code-block:: python
from fundamentals.download import get_now_datetime_filestamp
get_now_datetime_filestamp(longTime=False)
#Out: '20160316t154635'
get_now_datetime_filestamp(longTime=True)
#Out: '20160316t154644133638'
""""""
## > IMPORTS ##
from datetime import datetime, date, time
now = datetime.now()
if longTime:
now = now.strftime(""%Y%m%dt%H%M%S%f"")
else:
now = now.strftime(""%Y%m%dt%H%M%S"")
return now"
4938,"def create_app(application, request_class=Request):
""""""
Create a WSGI application out of the given Minion app.
Arguments:
application (Application):
a minion app
request_class (callable):
a class to use for constructing incoming requests out of the WSGI
environment. It will be passed a single arg, the environ.
By default, this is :class:`minion.request.WSGIRequest` if
unprovided.
""""""
def wsgi(environ, start_response):
response = application.serve(
request=request_class(environ),
path=environ.get(""PATH_INFO"", """"),
)
start_response(
response.status, [
(name, b"","".join(values))
for name, values in response.headers.canonicalized()
],
)
return [response.content]
return wsgi"