• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.OrderedDict类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



在下文中一共展示了OrderedDict类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: __init__

 def __init__(self, model, **kwargs):
     BaseFieldSet.__init__(self, model, **kwargs)
     self.iface = model
     self.rebind(model)
     self._fields = OrderedDict()
     self._render_fields = OrderedDict()
     self._bound_pk = None
     for name, field in schema.getFieldsInOrder(self.iface):
         klass = field.__class__
         try:
             t = self._fields_mapping[klass]
         except KeyError:
             raise NotImplementedError('%s is not mapped to a type' % klass)
         else:
             self.append(Field(name=name, type=t))
             self._fields[name].label_text = field.title or name
             if field.description:
                 self._fields[name].set(instructions=field.description)
             if field.required:
                 self._fields[name].validators.append(validators.required)
             if klass is schema.Password:
                 self._fields[name].set(renderer=fields.PasswordFieldRenderer)
             if klass is schema.Text:
                 self._fields[name].set(renderer=fields.TextAreaFieldRenderer)
             if klass is schema.List:
                 value_type = self.iface[name].value_type
                 if isinstance(value_type, schema.Choice):
                     self._fields[name].set(options=value_type, multiple=True)
                 else:
                     self._fields[name].set(multiple=True)
             elif klass is schema.Choice:
                 self._fields[name].set(renderer=fields.SelectFieldRenderer,
                                        options=self.iface[name])
开发者ID:FormAlchemy,项目名称:formalchemy,代码行数:33,代码来源:__init__.py


示例2: insert_after

    def insert_after(self, field, new_field):
        """Insert a new field *after* an existing field.

        Use this if your business logic requires to add after a certain field,
        and not before.
        """
        fields_ = self._render_fields or self._fields
        if not isinstance(new_field, fields.Field):
            raise ValueError('Can only add Field objects; got %s instead' % field)
        if isinstance(field, fields.AbstractField):
            try:
                index = fields_.keys().index(field.name)
            except ValueError:
                raise ValueError('%s not in fields' % field.name)
        else:
            raise TypeError('field must be a Field. Got %r' % field)
        new_field.parent = self
        items = list(fields_.iteritems())
        new_item = (new_field.name, new_field)
        if index + 1 == len(items): # after the last element ?
            items.append(new_item)
        else:
            items.insert(index + 1, new_item)
        if self._render_fields:
            self._render_fields = OrderedDict(items)
        else:
            self._fields = OrderedDict(items)
开发者ID:svarks,项目名称:bind_config_manager,代码行数:27,代码来源:base.py


示例3: ResponseTimer

class ResponseTimer(object):
    """Nearly trivial class, used for tracking how long the page took to
    create.

    Properties are `total_time`, `sql_time`, and `sql_queries`.

    In SQL debug mode, `sql_query_log` is also populated.  Its keys are
    queries; values are dicts of parameters, time, and caller.
    """

    def __init__(self):
        self._start_time = datetime.now()
        self._total_time = None

        self.from_cache = None

        # SQLAlchemy will add to these using the above event listeners; see
        # spline.config.environment
        self.sql_time = timedelta()
        self.sql_queries = 0
        self.sql_query_log = OrderedDict()

    @property
    def total_time(self):
        # Calculate and save the total render time as soon as this is accessed
        if self._total_time is None:
            self._total_time = datetime.now() - self._start_time
        return self._total_time

    def add_log(self, log):
        self.sql_query_log.setdefault(log["statement"], []).append(log)
开发者ID:veekun,项目名称:spline,代码行数:31,代码来源:base.py


示例4: FieldSet

class FieldSet(BaseFieldSet):
    def __init__(self, model, session=None, data=None, prefix=None):
        self._fields = OrderedDict()
        self._render_fields = OrderedDict()
        self.model = self.session = None
        BaseFieldSet.rebind(self, model, data=data)
        self.prefix = prefix
        self.model = model
        self.readonly = False
        self.focus = True
        self._errors = []
        focus = True
        for k, v in model().iteritems():
            if not k.startswith('_'):
                try:
                    t = getattr(fatypes, v.__class__.__name__.replace('Property',''))
                except AttributeError:
                    raise NotImplementedError('%s is not mapped to a type' % v.__class__)
                else:
                    self.add(Field(name=k, type=t))
                    if v.required:
                        self._fields[k].validators.append(validators.required)

    def bind(self, model, session=None, data=None):
        """Bind to an instance"""
        if not (model or session or data):
            raise Exception('must specify at least one of {model, session, data}')
        if not model:
            if not self.model:
                raise Exception('model must be specified when none is already set')
            model = fields._pk(self.model) is None and type(self.model) or self.model
        # copy.copy causes a stacktrace on python 2.5.2/OSX + pylons.  unable to reproduce w/ simpler sample.
        mr = object.__new__(self.__class__)
        mr.__dict__ = dict(self.__dict__)
        # two steps so bind's error checking can work
        mr.rebind(model, session, data)
        mr._fields = OrderedDict([(key, renderer.bind(mr)) for key, renderer in self._fields.iteritems()])
        if self._render_fields:
            mr._render_fields = OrderedDict([(field.key, field) for field in
                                             [field.bind(mr) for field in self._render_fields.itervalues()]])
        return mr

    def rebind(self, model, session=None, data=None):
        if model:
            if isinstance(model, type):
                try:
                    model = model()
                except:
                    raise Exception('%s appears to be a class, not an instance, but FormAlchemy cannot instantiate it.  (Make sure all constructor parameters are optional!)' % model)
            self.model = model
            self._bound_pk = model._doc.get('_id', None)
        if data is None:
            self.data = None
        elif hasattr(data, 'getall') and hasattr(data, 'getone'):
            self.data = data
        else:
            try:
                self.data = SimpleMultiDict(data)
            except:
                raise Exception('unsupported data object %s.  currently only dicts and Paste multidicts are supported' % self.data)
开发者ID:abourget,项目名称:formalchemy-abourget,代码行数:60,代码来源:couchdb.py


示例5: FieldSet

class FieldSet(BaseFieldSet):
    def __init__(self, model, session=None, data=None, prefix=None):
        self._fields = OrderedDict()
        self._render_fields = OrderedDict()
        self.model = self.session = None
        self.prefix = prefix
        self.model = model
        self.readonly = False
        self.focus = True
        self._errors = []
        self.iface = model
        focus = True
        for name, field in schema.getFieldsInOrder(model):
            try:
                t = FIELDS_MAPPING[field.__class__]
            except KeyError:
                raise NotImplementedError('%s is not mapped to a type' % field.__class__)
            else:
                self.add(Field(name=name, type=t))
                if field.title:
                    self._fields[name].label_text = field.title
                if field.required:
                    self._fields[name].validators.append(validators.required)

    def bind(self, model, session=None, data=None):
        """Bind to an instance"""
        if not (model or session or data):
            raise Exception('must specify at least one of {model, session, data}')
        if not model:
            if not self.model:
                raise Exception('model must be specified when none is already set')
            model = fields._pk(self.model) is None and type(self.model) or self.model
        # copy.copy causes a stacktrace on python 2.5.2/OSX + pylons.  unable to reproduce w/ simpler sample.
        mr = object.__new__(self.__class__)
        mr.__dict__ = dict(self.__dict__)
        # two steps so bind's error checking can work
        mr.rebind(model, session, data)
        mr._fields = OrderedDict([(key, renderer.bind(mr)) for key, renderer in self._fields.iteritems()])
        if self._render_fields:
            mr._render_fields = OrderedDict([(field.key, field) for field in
                                             [field.bind(mr) for field in self._render_fields.itervalues()]])
        return mr

    def rebind(self, model, session=None, data=None):
        if model:
            if not self.iface.providedBy(model):
                raise Exception('%r is not provided by %r' % (self.iface, model))
            self.model = model
            self._bound_pk = None
        if data is None:
            self.data = None
        elif hasattr(data, 'getall') and hasattr(data, 'getone'):
            self.data = data
        else:
            try:
                self.data = SimpleMultiDict(data)
            except:
                raise Exception('unsupported data object %s.  currently only dicts and Paste multidicts are supported' % self.data)
开发者ID:abourget,项目名称:formalchemy-abourget,代码行数:58,代码来源:__init__.py


示例6: pkg_xl_dict_to_fs_dict

    def pkg_xl_dict_to_fs_dict(cls, pkg_xl_dict, logger=None):
        '''Convert a Package represented in an Excel-type dictionary to a
        dictionary suitable for fieldset data.
        Takes Excel-type dict:
            {'name':'wikipedia', 
             'resource-0-url':'http://static.wikipedia.org/'}
        Returns Fieldset-type dict:
            {'name':'wikipedia',
             'resources':[{'url':'http://static.wikipedia.org/'}]}
        '''
        import ckan.forms
        standard_fields = model.Package.get_fields()

        pkg_fs_dict = OrderedDict()
        for title, cell in pkg_xl_dict.items():
            if cell:
                if title in standard_fields:
                    pkg_fs_dict[title] = cell
                elif title == 'license':
                    license_id = cls.license_2_license_id(cell)
                    if license:
                        pkg_fs_dict['license_id'] = license_id
                    else:
                        logger('Warning: No license name matches \'%s\'. Ignoring license.' % cell)
                elif title.startswith('resource-'):
                    match = re.match('resource-(\d+)-(\w+)', title)
                    if match:
                        res_index, field = match.groups()
                        res_index = int(res_index)
                        field = str(field)
                        if not pkg_fs_dict.has_key('resources'):
                            pkg_fs_dict['resources'] = []
                        resources = pkg_fs_dict['resources']
                        num_new_resources = 1 + res_index - len(resources)
                        for i in range(num_new_resources):
                            blank_dict = OrderedDict()
                            for blank_field in model.Resource.get_columns():
                                blank_dict[blank_field] = u''
                            pkg_fs_dict['resources'].append(blank_dict)

                        pkg_fs_dict['resources'][res_index][field] = cell
                    else:
                        logger('Warning: Could not understand resource title \'%s\'. Ignoring value: %s' % (title, cell))
                elif title.startswith('relationships'):
                    # TODO
                    pass
                elif title == 'download_url':
                    # deprecated - only in there for compatibility
                    pass
                elif title in readonly_keys:
                    pass
                else:
                    if not pkg_fs_dict.has_key('extras'):
                        pkg_fs_dict['extras'] = {}
                    pkg_fs_dict['extras'][title] = cell
        return pkg_fs_dict
开发者ID:okfn,项目名称:ckanext-importlib,代码行数:56,代码来源:spreadsheet_importer.py


示例7: records

 def records(self):
     """Returns each record as a dict."""
     for row_index in range(self._first_record_row, self._data.get_num_rows()):
         row = self._data.get_row(row_index)
         row_has_content = False
         for cell in row:
             if cell:
                 row_has_content = True
                 break
         if row_has_content:
             record_dict = OrderedDict(zip(self.titles, row))
             if record_dict.has_key(None):
                 del record_dict[None]
             yield record_dict
开发者ID:okfn,项目名称:ckanext-ngds,代码行数:14,代码来源:importer.py


示例8: _grab_table_elements

    def _grab_table_elements(self):
        schema = self.table.schema
        self.columns = OrderedDict()
        for c in self.table.c:
            c_copy = c.copy(schema=schema)
            c_copy.unique = c_copy.index = False
            # ensure that the type object was copied,
            # as we may need to modify it in-place
            if isinstance(c.type, SchemaEventTarget):
                assert c_copy.type is not c.type
            self.columns[c.name] = c_copy
        self.named_constraints = {}
        self.unnamed_constraints = []
        self.indexes = {}
        self.new_indexes = {}
        for const in self.table.constraints:
            if _is_type_bound(const):
                continue
            elif self.reflected and isinstance(const, CheckConstraint):
                # TODO: we are skipping reflected CheckConstraint because
                # we have no way to determine _is_type_bound() for these.
                pass
            elif const.name:
                self.named_constraints[const.name] = const
            else:
                self.unnamed_constraints.append(const)

        for idx in self.table.indexes:
            self.indexes[idx.name] = idx

        for k in self.table.kwargs:
            self.table_kwargs.setdefault(k, self.table.kwargs[k])
开发者ID:zzzeek,项目名称:alembic,代码行数:32,代码来源:batch.py


示例9: create_title_mapping

    def create_title_mapping(self):
        """Creates a mapping between the spreadsheet\'s actual column
        titles and the normalised versions.

        Results in self.title_map and self.title_reverse_map which are
        comprehensive for this spreadsheet.

        """
        self.title_map = OrderedDict()
        for title in self.titles:
            for norm_title, regex in self.title_normaliser:
                if regex.match(title):
                    self.title_map[title] = norm_title
                    break
            else:
                raise AssertionError("Did not recognise title: %r" % title)
        self.title_reverse_map = dict((v, k) for k, v in self.title_map.iteritems())
        # check all keys map both ways
        unmatched_keys = set(self.title_map.keys()) - set(self.title_reverse_map.values())
        if unmatched_keys:
            msg = "Columns not identified by REs: %r" % (
                set(self.title_map.keys()) - set(self.title_reverse_map.values())
            )
            msg += "\nColumns over identified by REs: %r" % (
                set(self.title_reverse_map.keys()) - set(self.title_map.values())
            )
            raise AssertionError(msg)
开发者ID:okfn,项目名称:ckanext-dgu,代码行数:27,代码来源:cospread.py


示例10: __init__

 def __init__(self, table_name, columns=None):
     self.table_name = table_name
     self._options = {}
     self._annot = OrderedDict()
     if columns:
         for info in columns:
             self._annot[ info['name'] ] = info
开发者ID:kapilt,项目名称:zope-alchemist,代码行数:7,代码来源:annotation.py


示例11: Relationship

class Relationship(object):
    def __init__(self, source_cls, target_cls):
        super(Relationship, self).__init__()
        self.source_cls = source_cls
        self.target_cls = target_cls
        self.kwargs = OrderedDict()

    @property
    def suggested_names(self):
        yield self.preferred_name if not iskeyword(self.preferred_name) else self.preferred_name + '_'

        iteration = 0
        while True:
            iteration += 1
            yield self.preferred_name + str(iteration)

    def render(self):
        text = 'relationship('
        args = [repr(self.target_cls)]

        if 'secondaryjoin' in self.kwargs:
            text += '\n        '
            delimiter, end = ',\n        ', '\n    )'
        else:
            delimiter, end = ', ', ')'

        args.extend([key + '=' + value for key, value in list(self.kwargs.items())])
        return text + delimiter.join(args) + end
开发者ID:massanchik,项目名称:alengen,代码行数:28,代码来源:codegen.py


示例12: __init__

 def __init__(self, model, session=None, data=None, prefix=None):
     self._fields = OrderedDict()
     self._render_fields = OrderedDict()
     self.model = self.session = None
     BaseFieldSet.rebind(self, model, data=data)
     self.prefix = prefix
     self.model = model
     self.readonly = False
     self.focus = True
     self._errors = []
     focus = True
     for k, v in model.__dict__.iteritems():
         if not k.startswith("_"):
             descriptor = type(v)
             t = self._mapping.get(descriptor)
             if t:
                 self.append(Field(name=k, type=t))
开发者ID:Alwnikrotikz,项目名称:formalchemy,代码行数:17,代码来源:rdf.py


示例13: render_fields

 def render_fields(self):
     """
     The set of attributes that will be rendered, as a (ordered)
     dict of `{fieldname: Field}` pairs
     """
     if not self._render_fields:
         self._render_fields = OrderedDict([(field.key, field) for field in self._get_fields()])
     return self._render_fields
开发者ID:svarks,项目名称:bind_config_manager,代码行数:8,代码来源:base.py


示例14: TableAnnotation

class TableAnnotation( object ):
    """
    Annotations for Table objects, to annotate as needed, the notion
    is that the annotation keys correspond to column, and values correspond
    to application specific column metadata.
    """

    _marker = object()
    schema_invariants = ()
    
    def __init__(self, table_name, columns=(), properties=(), schema_order=(), listing_columns=(), order_by=()):
        self.table_name = table_name
        self._options = {}
        self._annot = OrderedDict()

        for info in columns:
            self._annot[ info['name'] ] = info

        self.properties = properties
        self.schema_order = schema_order        
        self.listing_columns = listing_columns
        self.order_by = order_by

    def setOption( self, name, value ):
        self._options[ name ] = value
        
    def getOption( self, name, default=None ):
        return self._options.get( name, default )

    def __call__( self, iface ):
        return self
    
    def __setitem__(self, name, value ):
        self._annot[name] = value

    def get( self, name, default=None ):
        return self._annot.get( name, default )

    def __getitem__(self, name):
        return self.get( name )

    def values( self ):
        return self._annot.values()

    def __contains__(self, name ):
        return not self._marker == self.get( name, self._marker )
开发者ID:BGCX261,项目名称:zope-alchemist-svn-to-git,代码行数:46,代码来源:sa2zs.py


示例15: __init__

 def __init__(self, table, table_args, table_kwargs):
     self.table = table  # this is a Table object
     self.table_args = table_args
     self.table_kwargs = table_kwargs
     self.new_table = None
     self.column_transfers = OrderedDict(
         (c.name, {'expr': c}) for c in self.table.c
     )
     self._grab_table_elements()
开发者ID:I-am-Gabi,项目名称:AppAdmin,代码行数:9,代码来源:batch.py


示例16: reconfigure

 def reconfigure(self, pk=False, focus=True, readonly=False, global_validator=None, exclude=[], include=[], options=[]):
     """
     Like `configure`, but does not undo the effects of a previous call
     to `configure` or `reconfigure`.
     """
     self.focus = focus
     self.readonly = readonly
     self.validator = global_validator
     self._render_fields = OrderedDict([(field.key, field) for field in self._get_fields(pk, exclude, include, options, use_rendered=True)])
开发者ID:adamandpaul,项目名称:formalchemy,代码行数:9,代码来源:forms.py


示例17: render_fields

 def render_fields(self):
     """
     The set of attributes that will be rendered, as a (ordered)
     dict of `{fieldname: Field}` pairs. If you haven't called configure
     with exclude/include, then this will be the list of default Fields
     as found by introspecting the SQLAlchemy model.
     """
     if not self._render_fields:
         self._render_fields = OrderedDict([(field.key, field) for field in self._get_fields()])
     return self._render_fields
开发者ID:abourget,项目名称:formalchemy-abourget,代码行数:10,代码来源:base.py


示例18: __init__

    def __init__(self):
        self._start_time = datetime.now()
        self._total_time = None

        self.from_cache = None

        # SQLAlchemy will add to these using the above event listeners; see
        # spline.config.environment
        self.sql_time = timedelta()
        self.sql_queries = 0
        self.sql_query_log = OrderedDict()
开发者ID:veekun,项目名称:spline,代码行数:11,代码来源:base.py


示例19: __init__

 def __init__(self, table, table_args, table_kwargs, reflected):
     self.table = table  # this is a Table object
     self.table_args = table_args
     self.table_kwargs = table_kwargs
     self.temp_table_name = self._calc_temp_name(table.name)
     self.new_table = None
     self.column_transfers = OrderedDict(
         (c.name, {"expr": c}) for c in self.table.c
     )
     self.reflected = reflected
     self._grab_table_elements()
开发者ID:zzzeek,项目名称:alembic,代码行数:11,代码来源:batch.py


示例20: insert

 def insert(self, field, new_field):
     """Insert a new field before an existing field"""
     fields_ = self._render_fields or self._fields
     if not isinstance(new_field, fields.Field):
         raise ValueError('Can only add Field objects; got %s instead' % field)
     if isinstance(field, fields.AbstractField):
         try:
             index = fields_.keys().index(field.name)
         except ValueError:
             raise ValueError('%s not in fields' % field.name)
     else:
         raise TypeError('field must be a Field. Got %r' % new_field)
     items = fields_.items()
     new_field.parent = self
     items.insert(index, (new_field.name, new_field))
     if self._render_fields:
         self._render_fields = OrderedDict(items)
     else:
         self._fields = OrderedDict(items)
     return self  # Cascade pattern
开发者ID:abourget,项目名称:formalchemy-abourget,代码行数:20,代码来源:base.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pickle.dumps函数代码示例发布时间:2022-05-27
下一篇:
Python util.warn_deprecated函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap