当前位置: 首页>>代码示例>>Python>>正文


Python sets.frozenset函数代码示例

本文整理汇总了Python中sets.frozenset函数的典型用法代码示例。如果您正苦于以下问题:Python frozenset函数的具体用法?Python frozenset怎么用?Python frozenset使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了frozenset函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的sets.frozenset函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。