本文整理汇总了Python中six.moves.filterfalse函数的典型用法代码示例。如果您正苦于以下问题:Python filterfalse函数的具体用法?Python filterfalse怎么用?Python filterfalse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了filterfalse函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _assert_file
def _assert_file(self, obj, fn_tested, fn_correct, compression=None, file_filter=lambda _: False):
"""Compare files."""
open_kwargs = {}
if compression is None:
open_fn = open
# by default, open() will open files as text and return str
# objects, but we need bytes objects
open_kwargs['mode'] = 'rb'
elif compression == 'gzip':
open_fn = gzip.open
elif compression == 'zip':
open_fn = zipfile.ZipFile.open
else:
raise ValueError("Unsupported compression format.")
output = os.path.join(settings.FLOW_EXECUTOR['DATA_DIR'], str(obj.pk), fn_tested)
with open_fn(output, **open_kwargs) as output_file:
output_contents = b"".join([line for line in filterfalse(file_filter, output_file)])
output_hash = hashlib.sha256(output_contents).hexdigest()
correct_path = os.path.join(self.files_path, fn_correct)
if not os.path.isfile(correct_path):
shutil.copyfile(output, correct_path)
self.fail(msg="Output file {} missing so it was created.".format(fn_correct))
with open_fn(correct_path, **open_kwargs) as correct_file:
correct_contents = b"".join([line for line in filterfalse(file_filter, correct_file)])
correct_hash = hashlib.sha256(correct_contents).hexdigest()
self.assertEqual(correct_hash, output_hash,
msg="File contents hash mismatch: {} != {}".format(
correct_hash, output_hash) + self._debug_info(obj))
开发者ID:hadalin,项目名称:resolwe,代码行数:32,代码来源:test.py
示例2: __iter__
def __iter__(self):
if self.cache_location is not None:
filenames = iglob(self.filename('*'))
keys = map(lambda f: os.path.splitext(os.path.basename(f))[0], filenames)
new_keys = filterfalse(lambda key: key in self._cache.keys(), keys)
return chain(iterkeys(self._cache), new_keys)
else:
return iterkeys(self._cache)
开发者ID:aldongqing,项目名称:pysaliency,代码行数:8,代码来源:utils.py
示例3: _process_pbs_nodefile
def _process_pbs_nodefile(pbs_nodefile, hostname):
with open(pbs_nodefile) as in_file:
nodelist = in_file.read().splitlines()
slave_compute_node_list = [
node for node, _ in groupby(filterfalse(lambda x: x == hostname,
nodelist))
]
return slave_compute_node_list
开发者ID:jkglasbrenner,项目名称:sshcustodian,代码行数:8,代码来源:sshcustodian.py
示例4: unique
def unique(iterable, filterfalse=filterfalse):
"""
Return only unique elements from the sequence.
"""
seen = set()
add = seen.add
for element in filterfalse(seen.__contains__, iterable):
add(element)
yield element
开发者ID:dhaffner,项目名称:dhaffner.py,代码行数:9,代码来源:iterators.py
示例5: partition
def partition(pred, iterable):
"""
Partition the iterable into two disjoint entries based
on the predicate.
@return: Tuple (iterable1, iterable2)
"""
iter1, iter2 = itertools.tee(iterable)
return filterfalse(pred, iter1), filter(pred, iter2)
开发者ID:BenJamesbabala,项目名称:dist-dqn,代码行数:9,代码来源:utils.py
示例6: args_to_string
def args_to_string(*args, **kwargs):
invalid = tuple(filterfalse(repr_is_constructor,
chain(args, kwargs.values())))
if invalid:
raise ValueError
return ', '.join(chain((repr(a) for a in args),
('{0}={1}'.format(str(k), repr(v))
for k, v in kwargs.items())))
开发者ID:mambocab,项目名称:rumble,代码行数:9,代码来源:utils.py
示例7: load_rule_set
def load_rule_set(rules_file_name):
with open(os.path.join(os.path.dirname(__file__), data_dir_name, "rules_{}.dat".format(rules_file_name))) as rules_file:
reader = csv.reader(filterfalse(lambda x: re.match(r"^\s*(?:#|$)", x), rules_file), delimiter="\t") # SMARTS and name, tab-seperated
rule_set = [{"n": n, "SMARTS": x[0], "rxn": AllChem.ReactionFromSmarts(x[0]), "name": x[1]} for n, x in enumerate(reader, 1)]
return rule_set
开发者ID:DmitriR,项目名称:standardiser,代码行数:9,代码来源:rules.py
示例8: ls_moduledirs
def ls_moduledirs(path, private=True, full=True):
""" lists all dirs which are python modules in path """
dir_list = ls_dirs(path)
module_dir_iter = filter(is_module_dir, dir_list)
if not private:
module_dir_iter = filterfalse(is_private_module, module_dir_iter)
if not full:
module_dir_iter = map(basename, module_dir_iter)
return list(module_dir_iter)
开发者ID:animalus,项目名称:utool,代码行数:9,代码来源:util_path.py
示例9: to_datetime
def to_datetime(content, dt_format=None, warn=False):
"""Parses and formats strings into datetimes.
Args:
content (str): The string to parse.
dt_format (str): Date format passed to `strftime()`
(default: None).
warn (bool): raise error if content can't be safely converted
(default: False)
Returns:
obj: The datetime object or formatted datetime string.
See also:
`tabutils.process.type_cast`
Examples:
>>> fmt = '%Y-%m-%d %H:%M:%S'
>>> to_datetime('5/4/82 2:00 pm')
datetime.datetime(1982, 5, 4, 14, 0)
>>> to_datetime('5/4/82 10:00', fmt) == '1982-05-04 10:00:00'
True
>>> to_datetime('2/32/82 12:15', fmt) == '1982-02-28 12:15:00'
True
>>> to_datetime('spam')
datetime.datetime(9999, 12, 31, 0, 0)
>>> to_datetime('spam', warn=True)
Traceback (most recent call last):
ValueError: Invalid datetime value: `spam`.
Returns:
datetime
"""
bad_nums = map(str, range(29, 33))
good_nums = map(str, range(31, 27, -1))
try:
bad_num = next(x for x in bad_nums if x in content)
except StopIteration:
options = [content]
else:
possibilities = (content.replace(bad_num, x) for x in good_nums)
options = it.chain([content], possibilities)
# Fix impossible dates, e.g., 2/31/15
results = filterfalse(lambda x: x[1], map(_to_datetime, options))
value = next(results)[0]
if warn and value == DEFAULT_DATETIME:
raise ValueError("Invalid datetime value: `%s`." % content)
else:
datetime = value.strftime(dt_format) if dt_format else value
return datetime
开发者ID:chrisorwa,项目名称:tabutils,代码行数:56,代码来源:convert.py
示例10: ls_modulefiles
def ls_modulefiles(path, private=True, full=True, noext=False):
module_file_list = ls(path, '*.py')
module_file_iter = iter(module_file_list)
if not private:
module_file_iter = filterfalse(is_private_module, module_file_iter)
if not full:
module_file_iter = map(basename, module_file_iter)
if noext:
module_file_iter = (splitext(path)[0] for path in module_file_iter)
return list(module_file_iter)
开发者ID:animalus,项目名称:utool,代码行数:10,代码来源:util_path.py
示例11: _candidate_dirs
def _candidate_dirs(base_path):
"""
Return all dirs in base_path that might be packages.
"""
has_dot = lambda name: '.' in name
for root, dirs, files in os.walk(base_path, followlinks=True):
# Exclude directories that contain a period, as they cannot be
# packages. Mutate the list to avoid traversal.
dirs[:] = filterfalse(has_dot, dirs)
for dir in dirs:
yield os.path.relpath(os.path.join(root, dir), base_path)
开发者ID:bron84,项目名称:stash,代码行数:11,代码来源:pip.py
示例12: equivalentMessage
def equivalentMessage(self, msg1, msg2):
msg1_count = count_messages(msg1)
msg2_count = count_messages(msg2)
if msg1_count != msg2_count:
return False
# Do some basic payload checking
msg1_msgs = [m for m in msg1.walk()]
msg1_msgs = [m for m in filterfalse(ud.is_skippable, msg1_msgs)]
msg2_msgs = [m for m in msg2.walk()]
msg2_msgs = [m for m in filterfalse(ud.is_skippable, msg2_msgs)]
for i in range(0, len(msg2_msgs)):
m1_msg = msg1_msgs[i]
m2_msg = msg2_msgs[i]
if m1_msg.get_charset() != m2_msg.get_charset():
return False
if m1_msg.is_multipart() != m2_msg.is_multipart():
return False
m1_py = m1_msg.get_payload(decode=True)
m2_py = m2_msg.get_payload(decode=True)
if m1_py != m2_py:
return False
return True
开发者ID:BenjaminSchiborr,项目名称:cloud-init,代码行数:22,代码来源:test_launch_index.py
示例13: unique_everseen
def unique_everseen(iterable, key=None):
"List unique elements, preserving order. Remember all elements ever seen."
# http://docs.python.org/2/library/itertools.html
seen = set()
seen_add = seen.add
if key is None:
for element in filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element
开发者ID:DjangoBD,项目名称:django-widgy,代码行数:15,代码来源:utils.py
示例14: partition
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)
开发者ID:pombredanne,项目名称:more-itertools,代码行数:16,代码来源:recipes.py
示例15: wrapper
def wrapper(*args, **kwds):
# cache key records both positional and keyword args
key = args
if kwds:
key += (kwd_mark,) + tuple(sorted(kwds.items()))
# record recent use of this key
queue_append(key)
refcount[key] += 1
# get cache entry or compute if not found
try:
result, expire_time = cache[key]
if expire_time and time() > expire_time:
raise KeyError('Expired')
wrapper.hits += 1
except KeyError:
result = user_function(*args, **kwds)
if maxtime:
expire_time = time() + maxtime
else:
expire_time = None
cache[key] = result, expire_time
wrapper.misses += 1
# purge least recently used cache entry
if len(cache) > maxsize:
key = queue_popleft()
refcount[key] -= 1
while refcount[key]:
key = queue_popleft()
refcount[key] -= 1
del cache[key], refcount[key]
# periodically compact the queue by eliminating duplicate keys
# while preserving order of most recent access
if len(queue) > maxqueue:
refcount.clear()
queue_appendleft(sentinel)
for key in filterfalse(refcount.__contains__, iter(queue_pop, sentinel)):
queue_appendleft(key)
refcount[key] = 1
return result
开发者ID:CivicKnowledge,项目名称:ambry,代码行数:47,代码来源:__init__.py
示例16: modify_interp_node
def modify_interp_node(self, node):
"""Add extra fields which only exist on interp nodes"""
# ['105', '22', 'Interp'] => section header
node['section_header'] = len(node['label']) == 3
is_header = lambda child: child['label'][-1] == 'Interp'
node['header_children'] = list(filter(is_header, node['children']))
node['par_children'] = list(filterfalse(is_header, node['children']))
if 'header' in node:
node['header_markup'] = node['header']
citation = list(takewhile(lambda p: p != 'Interp',
node['label']))
icl = self.inline_applier.layers.get(
InternalCitationLayer.shorthand)
if icl and len(citation) > 2:
text = '%s(%s)' % (citation[1], ')('.join(citation[2:]))
node['header_markup'] = node['header_markup'].replace(
text, icl.render_url(citation, text))
开发者ID:anthonygarvan,项目名称:regulations-site,代码行数:18,代码来源:html_builder.py
示例17: modify_interp_node
def modify_interp_node(self, node):
"""Add extra fields which only exist on interp nodes"""
# ['105', '22', 'Interp'] => section header
node['section_header'] = len(node['label']) == 3
def is_header(child):
return child['label'][-1] == 'Interp'
node['header_children'] = list(filter(is_header, node['children']))
node['par_children'] = list(filterfalse(is_header, node['children']))
if 'header' in node:
node['header_markup'] = node['header']
citation = list(takewhile(lambda p: p != 'Interp',
node['label']))
for layer in self.layers:
if (isinstance(layer, InternalCitationLayer) and
len(citation) > 2):
text = '%s(%s)' % (citation[1], ')('.join(citation[2:]))
node['header_markup'] = node['header_markup'].replace(
text, layer.render_url(citation, text))
开发者ID:eregs,项目名称:regulations-site,代码行数:20,代码来源:html_builder.py
示例18: _unique_everseen
def _unique_everseen(self, iterable, key=None):
"""
List unique elements, preserving order.
Remember all elements ever seen.
_unique_everseen('AAAABBBCCDAABBB') --> A B C D
_unique_everseen('ABBCcAD', str.lower) --> A B C D
"""
seen = set()
seen_add = seen.add
if key is None:
for element in filterfalse(seen.__contains__, iterable):
seen_add(element)
yield element
else:
for element in iterable:
k = key(element)
if k not in seen:
seen_add(k)
yield element
开发者ID:DanielPearl,项目名称:top_commodities,代码行数:21,代码来源:msvc.py
示例19: __init__
def __init__(self, filenames):
''' Constructor, takes in the list of filenames to load, who's
workspaces will be iterated over. '''
# Validate.
if not isinstance(filenames, list):
raise TypeError("Expected a list.")
if not all([self._is_string(s) for s in filenames]):
raise TypeError("Expected a list of strings.")
if len(filenames) < 1:
raise ValueError("Expected at least one filename.")
# In the general case, we may or may not have checked for the existance
# of the files previously, so before we even start iterating throw if
# any are missing.
missing_files = list(filterfalse(os.path.exists, filenames))
if len(missing_files) > 0:
raise ValueError("One or more files are missing: " +
str(missing_files))
self._filenames = filenames
self._loaded_ws = None
开发者ID:DanNixon,项目名称:mantid,代码行数:21,代码来源:RetrieveRunInfo.py
示例20: find
def find(cls, where='.', exclude=(), include=('*',)):
"""Return a list all Python packages found within directory 'where'
'where' should be supplied as a "cross-platform" (i.e. URL-style)
path; it will be converted to the appropriate local path syntax.
'exclude' is a sequence of package names to exclude; '*' can be used
as a wildcard in the names, such that 'foo.*' will exclude all
subpackages of 'foo' (but not 'foo' itself).
'include' is a sequence of package names to include. If it's
specified, only the named packages will be included. If it's not
specified, all found packages will be included. 'include' can contain
shell style wildcard patterns just like 'exclude'.
The list of included packages is built up first and then any
explicitly excluded packages are removed from it.
"""
out = cls._find_packages_iter(convert_path(where))
out = cls.require_parents(out)
includes = cls._build_filter(*include)
excludes = cls._build_filter('ez_setup', '*__pycache__', *exclude)
out = filter(includes, out)
out = filterfalse(excludes, out)
return list(out)
开发者ID:bron84,项目名称:stash,代码行数:24,代码来源:pip.py
注:本文中的six.moves.filterfalse函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论