本文整理汇总了Python中sets.frozenset函数的典型用法代码示例。如果您正苦于以下问题:Python frozenset函数的具体用法?Python frozenset怎么用?Python frozenset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了frozenset函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _defaults
def _defaults(self, routekeys, reserved_keys, kargs):
"""Creates default set with values stringified
Put together our list of defaults, stringify non-None values
and add in our action/id default if they use it and didn't
specify it.
defaultkeys is a list of the currently assumed default keys
routekeys is a list of the keys found in the route path
reserved_keys is a list of keys that are not
"""
defaults = {}
# Add in a controller/action default if they don't exist
if "controller" not in routekeys and "controller" not in kargs and not self.explicit:
kargs["controller"] = "content"
if "action" not in routekeys and "action" not in kargs and not self.explicit:
kargs["action"] = "index"
defaultkeys = frozenset([key for key in kargs.keys() if key not in reserved_keys])
for key in defaultkeys:
if kargs[key] is not None:
defaults[key] = self.make_unicode(kargs[key])
else:
defaults[key] = None
if "action" in routekeys and not defaults.has_key("action") and not self.explicit:
defaults["action"] = "index"
if "id" in routekeys and not defaults.has_key("id") and not self.explicit:
defaults["id"] = None
newdefaultkeys = frozenset([key for key in defaults.keys() if key not in reserved_keys])
return (defaults, newdefaultkeys)
开发者ID:GaryMMugford,项目名称:calibre,代码行数:31,代码来源:route.py
示例2: _minkeys
def _minkeys(self, routelist):
"""Utility function to walk the route backwards
Will also determine the minimum keys we can handle to generate
a working route.
routelist is a list of the '/' split route path
defaults is a dict of all the defaults provided for the route
"""
minkeys = []
backcheck = routelist[:]
# If we don't honor minimization, we need all the keys in the
# route path
if not self.minimization:
for part in backcheck:
if isinstance(part, dict):
minkeys.append(part['name'])
return (frozenset(minkeys), backcheck)
gaps = False
backcheck.reverse()
for part in backcheck:
if not isinstance(part, dict) and part not in self.done_chars:
gaps = True
continue
elif not isinstance(part, dict):
continue
key = part['name']
if self.defaults.has_key(key) and not gaps:
continue
minkeys.append(key)
gaps = True
return (frozenset(minkeys), backcheck)
开发者ID:Halicea,项目名称:HalWebSite,代码行数:35,代码来源:route.py
示例3: _setup_route
def _setup_route(self):
# Build our routelist, and the keys used in the route
self.routelist = routelist = self._pathkeys(self.routepath)
routekeys = frozenset([key['name'] for key in routelist
if isinstance(key, dict)])
self.dotkeys = frozenset([key['name'] for key in routelist
if isinstance(key, dict) and
key['type'] == '.'])
if not self.minimization:
self.make_full_route()
# Build a req list with all the regexp requirements for our args
self.req_regs = {}
for key, val in self.reqs.iteritems():
self.req_regs[key] = re.compile('^' + val + '$')
# Update our defaults and set new default keys if needed. defaults
# needs to be saved
(self.defaults, defaultkeys) = self._defaults(routekeys,
self.reserved_keys,
self._kargs.copy())
# Save the maximum keys we could utilize
self.maxkeys = defaultkeys | routekeys
# Populate our minimum keys, and save a copy of our backward keys for
# quicker generation later
(self.minkeys, self.routebackwards) = self._minkeys(routelist[:])
# Populate our hardcoded keys, these are ones that are set and don't
# exist in the route
self.hardcoded = frozenset([key for key in self.maxkeys \
if key not in routekeys and self.defaults[key] is not None])
# Cache our default keys
self._default_keys = frozenset(self.defaults.keys())
开发者ID:Halicea,项目名称:HalWebSite,代码行数:35,代码来源:route.py
示例4: _defaults
def _defaults(self, routekeys, reserved_keys, kargs):
"""Creates default set with values stringified
Put together our list of defaults, stringify non-None values
and add in our action/id default if they use it and didn't specify it
defaultkeys is a list of the currently assumed default keys
routekeys is a list of the keys found in the route path
reserved_keys is a list of keys that are not
"""
defaults = {}
# Add in a controller/action default if they don't exist
if 'controller' not in routekeys and 'controller' not in kargs \
and not self.explicit:
kargs['controller'] = 'content'
if 'action' not in routekeys and 'action' not in kargs \
and not self.explicit:
kargs['action'] = 'index'
defaultkeys = frozenset([key for key in kargs.keys() \
if key not in reserved_keys])
for key in defaultkeys:
if kargs[key] != None:
defaults[key] = unicode(kargs[key])
else:
defaults[key] = None
if 'action' in routekeys and not defaults.has_key('action') \
and not self.explicit:
defaults['action'] = 'index'
if 'id' in routekeys and not defaults.has_key('id') \
and not self.explicit:
defaults['id'] = None
newdefaultkeys = frozenset([key for key in defaults.keys() \
if key not in reserved_keys])
return (defaults, newdefaultkeys)
开发者ID:ChaoKong,项目名称:Mobilyzer-GAE,代码行数:35,代码来源:base.py
示例5: reorder_steps
def reorder_steps(self, id_list):
"""
Reorders steps based on order provided in id_list.
Raises ValueError if id_list contains invalid ids, or
does not contain ids of all corresponding steps.
"""
if type(id_list) != type([]):
raise ValueError("id_list must be a list")
L = map(int, id_list) # cast all to int()
S = dict((x.id, x) for x in self.step_set.all()) # map of ids to Step object
sk = S.keys()
if L == sk: return # order is the same. nothing to do.
if len(L) != len(S) or frozenset(L) != frozenset(sk):
raise ValueError("id_list does not match list of current steps")
# set position of all steps to temp value
self.step_set.update(position=(models.F('position') + 1) * -1)
# update positions of steps
for i,v in enumerate(L):
S[v].position = i
S[v].save()
开发者ID:shawnchin,项目名称:bbotui,代码行数:25,代码来源:builder.py
示例6: _get_permissions
def _get_permissions(self):
try:
return self._permissions
except AttributeError:
# Permissions haven't been computed yet
pass
if not self.user:
self._permissions= frozenset()
else:
self._permissions= frozenset([p.permission_name for p in self.user.permissions])
return self._permissions
开发者ID:thraxil,项目名称:gtreed,代码行数:11,代码来源:soprovider.py
示例7: _get_groups
def _get_groups(self):
try:
return self._groups
except AttributeError:
# Groups haven't been computed yet
pass
if not self.user:
self._groups= frozenset()
else:
self._groups= frozenset([g.group_name for g in self.user.groups])
return self._groups
开发者ID:thraxil,项目名称:gtreed,代码行数:11,代码来源:soprovider.py
示例8: _get_group_ids
def _get_group_ids(self):
"""Get set of group IDs of this identity."""
try:
return self._group_ids
except AttributeError:
# Groups haven't been computed yet
pass
if not self.user:
self._group_ids = frozenset()
else:
self._group_ids = frozenset([g.id for g in self.user.groups])
return self._group_ids
开发者ID:OnShift,项目名称:turbogears,代码行数:12,代码来源:soprovider.py
示例9: _get_group_ids
def _get_group_ids(self):
'''Get set of group IDs of this identity.'''
try:
return self._group_ids
except AttributeError: # pylint: disable-msg=W0704
# :W0704: Groups haven't been computed yet
pass
if not self.groups:
self._group_ids = frozenset()
else:
self._group_ids = frozenset([g.id for g in
self._user.approved_memberships])
return self._group_ids
开发者ID:davidhrbac,项目名称:cnucnu,代码行数:13,代码来源:jsonfasprovider2.py
示例10: _get_permissions
def _get_permissions(self):
"""Get set of permission names of this identity."""
try:
return self._permissions
except AttributeError:
# Permissions haven't been computed yet
pass
if not self.user:
self._permissions = frozenset()
else:
self._permissions = frozenset(
[p.permission_name for p in self.user.permissions])
return self._permissions
开发者ID:OnShift,项目名称:turbogears,代码行数:13,代码来源:soprovider.py
示例11: _get_permissions
def _get_permissions(self):
try:
return self._permissions
except AttributeError:
# Permissions haven't been computed yet
pass
if not self.user:
self._permissions= frozenset()
else:
box = hub.getConnection()
box.start( isolation = dejavu.storage.isolation.READ_COMMITTED )
self._permissions = frozenset( [ p.permission_name for p in self.user.permissions ] )
box.flush_all()
return self._permissions
开发者ID:jrodrigog,项目名称:dejagears,代码行数:14,代码来源:djprovider.py
示例12: _get_groups
def _get_groups(self):
try:
return self._groups
except AttributeError:
# Groups haven't been computed yet
pass
if not self.user:
self._groups= frozenset()
else:
box = hub.getConnection()
box.start( isolation = dejavu.storage.isolation.READ_COMMITTED )
self._groups = frozenset( [ g.group_name for g in self.user.groups ] )
box.flush_all()
return self._groups
开发者ID:jrodrigog,项目名称:dejagears,代码行数:14,代码来源:djprovider.py
示例13: _get_group_ids
def _get_group_ids(self):
'''Get set of group IDs of this identity.'''
try:
return self._group_ids
except AttributeError:
# Groups haven't been computed yet
pass
if not self.user:
self._group_ids = frozenset()
else:
### TG: Difference. Our model has a many::many for people:groups
# And an association proxy that links them together
self._group_ids = frozenset([g.id for g in self.user.approved_memberships])
return self._group_ids
开发者ID:Affix,项目名称:fas,代码行数:14,代码来源:safasprovider.py
示例14: get_wa_runners
def get_wa_runners(lines = []):
'''Parses predefined file for information about available Wak / Waf runners.
We are looking into file named wa_runners.conf. If one is not found, or none
of the entries refer to existing paths, we scan parent folder (.../project/tests/../)
for filenames matching the following set ("wak.py", "waf-light", "waf")
@param lines: (Default: []) A list of strings representing the contents of
the config file. If list is nonempty, we bypass reading the file
and parse the lines instead.
@return: A tuple of form: (
list of runner labels (often the file name) in order as presented in the file,
dictionary that maps the label to absolute path
)
'''
print("\nDetecting Wak / Waf runners...")
values = {}
if not lines:
try:
lines = open('wa_runners.conf').readlines()
except:
pass
for line in lines:
if line.strip() and not line.strip().startswith("#"):
k, v = line.split("=", 1)
k = k.strip()
v = os.path.abspath( os.path.expanduser(v.strip()) )
if os.path.exists(v):
print("Detected %s at %s" % (k, v))
values[k] = v
else:
print("Skipping %s. Path not found: %s" % (k, v))
if not len(values.keys()):
# you had your chance to specify the runners by hand, it seems we are forced to guess...
# we are supposed to be in %PROJECTFOLDER%/tests. wak.py or waf are likely in %PROJECT FOLDER%
matches = frozenset(('wak.py', 'waf-light', 'waf')).intersection( frozenset(os.listdir("../")) )
if not matches:
raise Exception("No Wak / Waf runners found. Please, insure that wa_runners.conf file has entries proper for your project.")
for match in matches:
values[match] = os.path.abspath(os.path.normpath(os.path.join(
'../'
, match
)))
print("%s Wak / Waf runners found.\n" % len(values.keys()))
return sorted(values.keys()), values
开发者ID:dvdotsenko,项目名称:Wak,代码行数:49,代码来源:common_test_tools.py
示例15: _get_user
def _get_user(self):
'''Get user instance for this identity.'''
visit = self.visit_key
if not visit:
# No visit, no user
self._user = None
else:
if not (self.username and self.password):
# Unless we were given the user_name and password to login on
# this request, a CSRF token is required
if (not '_csrf_token' in cherrypy.request.params or
cherrypy.request.params['_csrf_token'] !=
hash_constructor(self.visit_key).hexdigest()):
self.log.info("Bad _csrf_token")
if '_csrf_token' in cherrypy.request.params:
self.log.info("visit: %s token: %s" % (self.visit_key,
cherrypy.request.params['_csrf_token']))
else:
self.log.info('No _csrf_token present')
cherrypy.request.fas_identity_failure_reason = 'bad_csrf'
self._user = None
# pylint: disable-msg=W0704
try:
return self._user
except AttributeError:
# User hasn't already been set
# Attempt to load the user. After this code executes, there
# *will* be a _user attribute, even if the value is None.
self._user = self.__retrieve_user()
self._groups = frozenset(
[g['name'] for g in self._user.approved_memberships]
)
# pylint: enable-msg=W0704
return self._user
开发者ID:davidhrbac,项目名称:cnucnu,代码行数:35,代码来源:jsonfasprovider2.py
示例16: __init__
def __init__(self, visit_key, user=None, username=None, password=None):
if user:
self._user = user
self._groups = frozenset(
[g['name'] for g in user['approved_memberships']]
)
self.visit_key = visit_key
if visit_key:
# Set the cookie to the user's tg_visit key before requesting
# authentication. That way we link the two together.
session_id = visit_key
else:
session_id = None
debug = config.get('jsonfas.debug', False)
super(JsonFasIdentity, self).__init__(self.fas_url,
useragent=self.useragent, debug=debug,
username=username, password=password,
session_id=session_id, cache_session=self.cache_session)
if self.debug:
import inspect
caller = inspect.getouterframes(inspect.currentframe())[1][3]
log.debug('JsonFasIdentity.__init__ caller: %s' % caller)
response.simple_cookie[self.cookie_name] = visit_key
# Send a request so that we associate the visit_cookie with the user
self.send_request('', auth=True)
log.debug('Leaving JsonFasIdentity.__init__')
开发者ID:davidhrbac,项目名称:cnucnu,代码行数:30,代码来源:jsonfasprovider1.py
示例17: generate
def generate(self, _ignore_req_list=False, _append_slash=False, **kargs):
"""Generate a URL from ourself given a set of keyword arguments
Toss an exception if this
set of keywords would cause a gap in the url.
"""
# Verify that our args pass any regexp requirements
if not _ignore_req_list:
for key in self.reqs.keys():
val = kargs.get(key)
if val and not self.req_regs[key].match(self.make_unicode(val)):
return False
# Verify that if we have a method arg, its in the method accept list.
# Also, method will be changed to _method for route generation
meth = as_unicode(kargs.get('method'), self.encoding)
if meth:
if self.conditions and 'method' in self.conditions \
and meth.upper() not in self.conditions['method']:
return False
kargs.pop('method')
if self.minimization:
url = self.generate_minimized(kargs)
else:
url = self.generate_non_minimized(kargs)
if url is False:
return url
if not url.startswith('/') and not self.static:
url = '/' + url
extras = frozenset(kargs.keys()) - self.maxkeys
if extras:
if _append_slash and not url.endswith('/'):
url += '/'
fragments = []
# don't assume the 'extras' set preserves order: iterate
# through the ordered kargs instead
for key in kargs:
if key not in extras:
continue
if key == 'action' or key == 'controller':
continue
val = kargs[key]
if isinstance(val, (tuple, list)):
for value in val:
value = as_unicode(value, self.encoding)
fragments.append((key, _str_encode(value,
self.encoding)))
else:
val = as_unicode(val, self.encoding)
fragments.append((key, _str_encode(val, self.encoding)))
if fragments:
url += '?'
url += urlparse.urlencode(fragments)
elif _append_slash and not url.endswith('/'):
url += '/'
return url
开发者ID:bbangert,项目名称:routes,代码行数:60,代码来源:route.py
示例18: _mergePage
def _mergePage(self, page2, page2transformation = None):
newResources = DictionaryObject()
rename = {}
originalResources = self['/Resources'].getObject()
page2Resources = page2['/Resources'].getObject()
for res in ('/ExtGState', '/Font', '/XObject', '/ColorSpace', '/Pattern', '/Shading', '/Properties'):
new, newrename = PageObject._mergeResources(originalResources, page2Resources, res)
if new:
newResources[NameObject(res)] = new
rename.update(newrename)
newResources[NameObject('/ProcSet')] = ArrayObject(frozenset(originalResources.get('/ProcSet', ArrayObject()).getObject()).union(frozenset(page2Resources.get('/ProcSet', ArrayObject()).getObject())))
newContentArray = ArrayObject()
originalContent = self.getContents()
if originalContent is not None:
newContentArray.append(PageObject._pushPopGS(originalContent, self.pdf))
page2Content = page2.getContents()
if page2Content is not None:
if page2transformation is not None:
page2Content = page2transformation(page2Content)
page2Content = PageObject._contentStreamRename(page2Content, rename, self.pdf)
page2Content = PageObject._pushPopGS(page2Content, self.pdf)
newContentArray.append(page2Content)
self[NameObject('/Contents')] = ContentStream(newContentArray, self.pdf)
self[NameObject('/Resources')] = newResources
开发者ID:bizonix,项目名称:DropBoxLibrarySRC,代码行数:25,代码来源:pdf.py
示例19: get_dfa_state
def get_dfa_state(states):
states = self.epsilon_closure(states)
frozenstates = frozenset(states)
if frozenstates in set_to_state:
return set_to_state[frozenstates] # already created this state
if states == self.start_states:
assert not set_to_state
final = bool(
filter(None, [state in self.final_states for state in states]))
name = ", ".join([self.names[state] for state in states])
if name_precedence is not None:
name_index = len(name_precedence)
unmergeable = False
for state in states:
#print state
if state in self.unmergeable_states:
new_name = self.names[state]
if name_precedence is not None:
try:
index = name_precedence.index(new_name)
except ValueError:
index = name_index
#print new_name, index, name_precedence
if index < name_index:
name_index = index
name = new_name
else:
name = new_name
unmergeable = True
result = set_to_state[frozenstates] = fda.add_state(
name, final, unmergeable)
stack.append((result, states))
return result
开发者ID:alkorzt,项目名称:pypy,代码行数:33,代码来源:deterministic.py
示例20: generateImpliedEndTags
def generateImpliedEndTags(self, exclude=None):
name = self.openElements[-1].name
# XXX td, th and tr are not actually needed
if name in frozenset(("dd", "dt", "li", "option", "optgroup", "p", "rp", "rt")) and name != exclude:
self.openElements.pop()
# XXX This is not entirely what the specification says. We should
# investigate it more closely.
self.generateImpliedEndTags(exclude)
开发者ID:JLP001ES,项目名称:Mr-Orange-Sick-Beard,代码行数:8,代码来源:_base.py
注:本文中的sets.frozenset函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论