本文整理汇总了Python中six.moves.filter方法的典型用法代码示例。如果您正苦于以下问题:Python moves.filter方法的具体用法?Python moves.filter怎么用?Python moves.filter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类six.moves
的用法示例。
在下文中一共展示了moves.filter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _filter_extras
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def _filter_extras(dm):
"""
Given a mapping of extras to dependencies, strip off
environment markers and filter out any dependencies
not matching the markers.
"""
for extra in list(filter(None, dm)):
new_extra = extra
reqs = dm.pop(extra)
new_extra, _, marker = extra.partition(':')
fails_marker = marker and (
invalid_marker(marker)
or not evaluate_marker(marker)
)
if fails_marker:
reqs = []
new_extra = safe_extra(new_extra) or None
dm.setdefault(new_extra, []).extend(reqs)
return dm
示例2: find_data_files
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def find_data_files(self, package, src_dir):
"""Return filenames for package's data files in 'src_dir'"""
patterns = self._get_platform_patterns(
self.package_data,
package,
src_dir,
)
globs_expanded = map(glob, patterns)
# flatten the expanded globs into an iterable of matches
globs_matches = itertools.chain.from_iterable(globs_expanded)
glob_files = filter(os.path.isfile, globs_matches)
files = itertools.chain(
self.manifest_files.get(package, []),
glob_files,
)
return self.exclude_data_files(package, src_dir, files)
示例3: exclude_data_files
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def exclude_data_files(self, package, src_dir, files):
"""Filter filenames for package's data files in 'src_dir'"""
files = list(files)
patterns = self._get_platform_patterns(
self.exclude_package_data,
package,
src_dir,
)
match_groups = (
fnmatch.filter(files, pattern)
for pattern in patterns
)
# flatten the groups of matches into an iterable of matches
matches = itertools.chain.from_iterable(match_groups)
bad = set(matches)
keepers = (
fn
for fn in files
if fn not in bad
)
# ditch dupes
return list(_unique_everseen(keepers))
示例4: partition
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def partition(pred, iterable):
"""
Returns a 2-tuple of iterables derived from the input iterable.
The first yields the items that have ``pred(item) == False``.
The second yields the items that have ``pred(item) == True``.
>>> is_odd = lambda x: x % 2 != 0
>>> iterable = range(10)
>>> even_items, odd_items = partition(is_odd, iterable)
>>> list(even_items), list(odd_items)
([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])
"""
# partition(is_odd, range(10)) --> 0 2 4 6 8 and 1 3 5 7 9
t1, t2 = tee(iterable)
return filterfalse(pred, t1), filter(pred, t2)
示例5: first_true
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def first_true(iterable, default=None, pred=None):
"""
Returns the first true value in the iterable.
If no true value is found, returns *default*
If *pred* is not None, returns the first item for which
``pred(item) == True`` .
>>> first_true(range(10))
1
>>> first_true(range(10), pred=lambda x: x > 5)
6
>>> first_true(range(10), default='missing', pred=lambda x: x > 9)
'missing'
"""
return next(filter(pred, iterable), default)
示例6: exactly_n
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def exactly_n(iterable, n, predicate=bool):
"""Return ``True`` if exactly ``n`` items in the iterable are ``True``
according to the *predicate* function.
>>> exactly_n([True, True, False], 2)
True
>>> exactly_n([True, True, False], 1)
False
>>> exactly_n([0, 1, 2, 3, 4, 5], 3, lambda x: x < 3)
True
The iterable will be advanced until ``n + 1`` truthy items are encountered,
so avoid calling it on infinite iterables.
"""
return len(take(n + 1, filter(predicate, iterable))) == n
示例7: _recalculate_payout_from_request
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def _recalculate_payout_from_request(srp_request, base_payout, *args):
"""Recalculate a Request's payout when the base payout changes."""
if base_payout is None:
base_payout = Decimal(0)
voided = Modifier._voided_select()
modifiers = srp_request.modifiers.join(voided,
voided.c.modifier_id==Modifier.id)\
.filter(~voided.c.voided)\
.order_by(False)
absolute = modifiers.join(AbsoluteModifier).\
with_entities(db.func.sum(AbsoluteModifier.value)).\
scalar()
if not isinstance(absolute, Decimal):
absolute = Decimal(0)
relative = modifiers.join(RelativeModifier).\
with_entities(db.func.sum(RelativeModifier.value)).\
scalar()
if not isinstance(relative, Decimal):
relative = Decimal(0)
payout = (base_payout + absolute) * (Decimal(1) + relative)
srp_request.payout = PrettyDecimal(payout)
示例8: filter_url_query
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def filter_url_query(*names, **kw):
names = set(names)
exclude = kw.pop('exclude', False)
def included(pair):
return pair[0] in names
def excluded(pair):
return pair[0] not in names
if exclude:
pred = excluded
else:
pred = included
@composable
@map_if_iter
def url_query_filter(obj):
parsed = parse_url(obj)
qsl = list(filter(pred, parse_qsl(parsed.query)))
filtered_query = urlencode(qsl)
return urlunparse(parsed._replace(query=filtered_query))
return url_query_filter
示例9: respond
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def respond(self):
"""Process the current request.
From :pep:`333`:
The start_response callable must not actually transmit
the response headers. Instead, it must store them for the
server or gateway to transmit only after the first
iteration of the application return value that yields
a NON-EMPTY string, or upon the application's first
invocation of the write() callable.
"""
response = self.req.server.wsgi_app(self.env, self.start_response)
try:
for chunk in filter(None, response):
if not isinstance(chunk, six.binary_type):
raise ValueError('WSGI Applications must yield bytes')
self.write(chunk)
finally:
# Send headers if not already sent
self.req.ensure_headers_sent()
if hasattr(response, 'close'):
response.close()
示例10: create
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def create(cls, config, app_globals):
# this has evolved over the age of allura, and upgrades of TG
# the parent JinjaRenderer logic is different, some may be better and hasn't been incorporated into ours yet
bcc = cls._setup_bytecode_cache()
jinja2_env = jinja2.Environment(
loader=PackagePathLoader(),
auto_reload=config['auto_reload_templates'],
autoescape=True,
bytecode_cache=bcc,
cache_size=asint(config.get('jinja_cache_size', -1)),
extensions=['jinja2.ext.do', 'jinja2.ext.i18n'])
jinja2_env.install_gettext_translations(tg.i18n)
jinja2_env.filters['datetimeformat'] = helpers.datetimeformat
jinja2_env.filters['filter'] = lambda s, t=None: list(filter(t and jinja2_env.tests[t], s))
jinja2_env.filters['nl2br'] = helpers.nl2br_jinja_filter
jinja2_env.globals.update({'hasattr': hasattr})
config['tg.app_globals'].jinja2_env = jinja2_env # TG doesn't need this, but we use g.jinja2_env a lot
return {'jinja': cls(jinja2_env)}
示例11: prepare_context
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def prepare_context(self, context):
full_timeline = g.director.get_timeline(
self.user, page=0, limit=100,
actor_only=False,
)
filtered_timeline = list(islice(filter(perm_check(c.user), full_timeline),
0, 8))
for activity in filtered_timeline:
# Get the project for the activity.obj so we can use it in the
# template. Expunge first so Ming doesn't try to flush the attr
# we create to temporarily store the project.
#
# The get_activity_object() calls are cheap, pulling from
# the session identity map instead of mongo since identical
# calls are made by perm_check() above.
session(activity).expunge(activity)
activity_obj = get_activity_object(activity.obj)
activity.obj.project = getattr(activity_obj, 'project', None)
context['timeline'] = filtered_timeline
context['activity_app'] = self.activity_app
return context
示例12: DoHttpRequest
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def DoHttpRequest(self,
path='/',
content=None,
content_type='text/plain; charset=utf-8',
headers=None):
connection = six.moves.http_client.HTTPConnection('localhost', self.port)
if content is None:
method = 'GET'
else:
method = 'POST'
headers = {'content=type': content_type}
headers.update(headers)
connection.request(method, path, content, headers)
response = connection.getresponse()
not_date_or_server = lambda header: header[0] not in ('date', 'server')
headers = list(filter(not_date_or_server, response.getheaders()))
return response.status, response.reason, response.read(), dict(headers)
示例13: respond
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def respond(self):
"""Process the current request."""
"""
From PEP 333:
The start_response callable must not actually transmit
the response headers. Instead, it must store them for the
server or gateway to transmit only after the first
iteration of the application return value that yields
a NON-EMPTY string, or upon the application's first
invocation of the write() callable.
"""
response = self.req.server.wsgi_app(self.env, self.start_response)
try:
for chunk in filter(None, response):
if not isinstance(chunk, six.binary_type):
raise ValueError('WSGI Applications must yield bytes')
self.write(chunk)
finally:
if hasattr(response, 'close'):
response.close()
示例14: _version_from_file
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def _version_from_file(lines):
"""
Given an iterable of lines from a Metadata file, return
the value of the Version field, if present, or None otherwise.
"""
is_version_line = lambda line: line.lower().startswith('version:')
version_lines = filter(is_version_line, lines)
line = next(iter(version_lines), '')
_, _, value = line.partition(':')
return safe_version(value.strip()) or None
示例15: _version_from_file
# 需要导入模块: from six import moves [as 别名]
# 或者: from six.moves import filter [as 别名]
def _version_from_file(lines):
"""
Given an iterable of lines from a Metadata file, return
the value of the Version field, if present, or None otherwise.
"""
def is_version_line(line):
return line.lower().startswith('version:')
version_lines = filter(is_version_line, lines)
line = next(iter(version_lines), '')
_, _, value = line.partition(':')
return safe_version(value.strip()) or None