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

Python interfaces.IField类代码示例

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

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



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

示例1: __init__

 def __init__(self, key_type=None, value_type=None, **kw):
     super(Dict, self).__init__(**kw)
     # whine if key_type or value_type is not a field
     if key_type is not None and not IField.providedBy(key_type):
         raise ValueError("'key_type' must be field instance.")
     if value_type is not None and not IField.providedBy(value_type):
         raise ValueError("'value_type' must be field instance.")
     self.key_type = key_type
     self.value_type = value_type
开发者ID:RadioFreeAsia,项目名称:zope.schema,代码行数:9,代码来源:_field.py


示例2: __call__

    def __call__(self, value):
        kdeserializer = lambda k: k
        vdeserializer = lambda v: v
        if IField.providedBy(self.field.key_type):
            kdeserializer = getMultiAdapter((self.field.key_type, self.context, self.request), IFieldDeserializer)
        if IField.providedBy(self.field.value_type):
            vdeserializer = getMultiAdapter((self.field.value_type, self.context, self.request), IFieldDeserializer)

        new_value = {}
        for k, v in value.items():
            new_value[kdeserializer(k)] = vdeserializer(v)

        self.field.validate(new_value)
        return new_value
开发者ID:casdr,项目名称:plone.restapi,代码行数:14,代码来源:dxfields.py


示例3: __init__

 def __init__(self, fields, **kw):
     for ix, field in enumerate(fields):
         if not IField.providedBy(field):
             raise DoesNotImplement(IField)
         field.__name__ = "combination_%02d" % ix
     self.fields = tuple(fields)
     super(Combination, self).__init__(**kw)
开发者ID:zopefoundation,项目名称:zc.form,代码行数:7,代码来源:field.py


示例4: _validate_fields

def _validate_fields(schema, value, errors=None):
    if errors is None:
        errors = []
    # Interface can be used as schema property for Object fields that plan to
    # hold values of any type.
    # Because Interface does not include any Attribute, it is obviously not
    # worth looping on its methods and filter them all out.
    if schema is Interface:
        return errors
    # if `value` is part of a cyclic graph, we need to break the cycle to avoid
    # infinite recursion.
    #
    # (use volatile attribute to avoid persistency/conflicts)
    if hasattr(value, '_v_schema_being_validated'):
        return errors
    # Mark the value as being validated.
    value._v_schema_being_validated = True
    # (If we have gotten here, we know that `value` provides an interface
    # other than zope.interface.Interface;
    # iow, we can rely on the fact that it is an instance
    # that supports attribute assignment.)
    try:
        for name in schema.names(all=True):
            if not IMethod.providedBy(schema[name]):
                try:
                    attribute = schema[name]
                    if IField.providedBy(attribute):
                        # validate attributes that are fields
                        attribute.validate(getattr(value, name))
                except ValidationError, error:
                    errors.append(error)
                except AttributeError, error:
                    # property for the given name is not implemented
                    errors.append(SchemaNotFullyImplemented(error))
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:34,代码来源:_field.py


示例5: portletManagerDirective

def portletManagerDirective(
    _context, name, title, for_=None, description=u'',
    class_=None, schema=None, layer=IDefaultBrowserLayer,
    provides=(), portlettype=IPortlet, **kw):

    # Build a new class
    ManagerClass = PortletManager(
        name, class_, provides, title, description, schema, portlettype, **kw)

    # Set up permission mapping for various accessible attributes
    required = {'__call__': CheckerPublic,
                'browserDefault': CheckerPublic,
                'publishTraverse': CheckerPublic}

    for iname in IPortletManager:
        required[iname] = CheckerPublic

    # security checker
    defineChecker(ManagerClass, Checker(required))

    # security for schema fields
    for iface in (IPortletManagerConfiguration, schema):
        if iface is None:
            continue
        for f_id in iface:
            field = iface[f_id]
            if IField.providedBy(field) and not field.readonly:
                protectSetAttribute(ManagerClass, f_id, 'zojax.ManagePortlets')
            protectName(ManagerClass, f_id, 'zope.Public')

    # register the portlet manager
    adapter(_context, (ManagerClass,),
            IPortletManager, (for_, layer, None), name=name)
开发者ID:Zojax,项目名称:zojax.portlet,代码行数:33,代码来源:zcml.py


示例6: writeAttribute

    def writeAttribute(self, attributeField, field, ignoreDefault=True):
        """Create and return a element that describes the given attribute
        field on the given field
        """

        elementName = attributeField.__name__
        attributeField = attributeField.bind(field)
        value = attributeField.get(field)

        force = (elementName in self.forcedFields)

        if ignoreDefault and value == attributeField.default:
            return None

        # The value points to another field. Recurse.
        if IField.providedBy(value):
            value_fieldType = IFieldNameExtractor(value)()
            handler = queryUtility(IFieldExportImportHandler, name=value_fieldType)
            if handler is None:
                return None
            return handler.write(value, name=None, type=value_fieldType, elementName=elementName)

        # For 'default', 'missing_value' etc, we want to validate against
        # the imported field type itself, not the field type of the attribute
        if elementName in self.fieldTypeAttributes or \
                elementName in self.nonValidatedfieldTypeAttributes:
            attributeField = field

        return valueToElement(attributeField, value, name=elementName, force=force)
开发者ID:seanupton,项目名称:plone.supermodel,代码行数:29,代码来源:exportimport.py


示例7: __call__

    def __call__(self, context):
        # we take the fti type settings to get the selected connections and table
        if ISQLTypeSchemaContext.providedBy(context):
            context = ISQLTypeSettings(context.fti)
        elif IField.providedBy(context):
            context = ISQLTypeSettings(aq_parent(context.context).fti)
        urls = ISQLAlchemyConnectionStrings(component.getUtility(ISiteRoot)).values()
        if not getattr(context, 'sql_table', None):
            return SimpleVocabulary([])
        items = []
        connection = queryUtility(ISQLConnectionsUtility, name=context.id, default=None)
        if not connection:
            connection = registerConnectionUtilityForFTI(context.context)
        columns = []
        for a in inspect(connection.tableClass).columns:
            if a.name:
                items.append(SimpleTerm(a.name, a.name, a.name+' ('+str(a.type)+')'))
                columns.append(a.name)
        for a in getattr(inspect(connection.tableClass), 'relationships', []):
            if a.key in columns:
                continue
            items.append(SimpleTerm(a.key, a.key, a.key+' (Relation)'))
            for b in inspect(a.table).columns:
                if b.name:
                    items.append(SimpleTerm(a.key+'.'+b.name, a.key+'.'+b.name, a.key+'.'+b.name+' ('+str(b.type)+')'))
                    columns.append(a.key+'.'+b.name)
#            for b in getattr(inspect(connection.tableClass), 'relationships', []):
#                if a.key+'.'+b.key in columns:
#                    continue
#                items.append(SimpleTerm(a.key+'.'+b.key, a.key+'.'+b.key, a.key+'.'+b.key+' (Relation)'))
        items.sort( lambda x, y: cmp(x.value, y.value ) )
        return SimpleVocabulary(items)
开发者ID:Martronic-SA,项目名称:collective.behavior.sql,代码行数:32,代码来源:vocabularies.py


示例8: what_changed

def what_changed(sqlobject_modified_event):
    before = sqlobject_modified_event.object_before_modification
    after = sqlobject_modified_event.object
    fields = sqlobject_modified_event.edited_fields
    changes = {}
    for fieldname in fields:
        # XXX 2011-01-21 gmb bug=705955:
        #     Sometimes, something (webservice, I'm looking at you
        #     here), will create an ObjectModifiedEvent where the
        #     edited_fields list is actually a list of field instances
        #     instead of strings. We special-case that here, but we
        #     shouldn't have to.
        if IField.providedBy(fieldname):
            fieldname = fieldname.getName()
        val_before = getattr(before, fieldname, None)
        val_after = getattr(after, fieldname, None)

        #XXX Bjorn Tillenius 2005-06-09: This shouldn't be necessary.
        # peel off the zope stuff
        if isProxy(val_before):
            val_before = removeSecurityProxy(val_before)
        if isProxy(val_after):
            val_after = removeSecurityProxy(val_after)

        before_string = get_string_representation(val_before)
        after_string = get_string_representation(val_after)

        if before_string != after_string:
            changes[fieldname] = [before_string, after_string]

    return changes
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:31,代码来源:bugactivity.py


示例9: schema_from_model

def schema_from_model(model):
    table = model.__table__
    bases = (Interface,)
    attrs = {}
    for i, column in enumerate(table.columns):
        if len(column.foreign_keys) or column.primary_key:
            continue
        field = IField(column.type)
        field.__name__ = str(column.name)
        field.title = unicode(column.name)
        field.required = not column.nullable
        attrs[column.name] = field
        field.order = i
       
    return InterfaceClass(name=model.__table__.name,
                          bases=bases,
                          attrs=attrs,
                          __doc__='Generated from metadata')
开发者ID:hexsprite,项目名称:plock,代码行数:18,代码来源:schema.py


示例10: __init__

 def __init__(self, fields, **kw):
     if len(fields) < 2:
         raise ValueError(_("combination must combine two or more fields"))
     for ix, field in enumerate(fields):
         if not IField.providedBy(field):
             raise DoesNotImplement(IField)
         field.__name__ = "combination_%02d" % ix
     self.fields = tuple(fields)
     super(Combination, self).__init__(**kw)
开发者ID:imegorskaya,项目名称:py,代码行数:9,代码来源:field.py


示例11: export_assignment

    def export_assignment(self, interface, doc, node):
        for field_name in interface:
            field = interface[field_name]

            if not IField.providedBy(field):
                continue

            child = self.export_field(doc, field)
            node.appendChild(child)
开发者ID:SyZn,项目名称:plone.app.portlets,代码行数:9,代码来源:portlets.py


示例12: Fields

def Fields(*args, **kw):
    fields = []
    for key, value in kw.items():
        if IField.providedBy(value):
            value.__name__ = key
            fields.append(value)
            del kw[key]
    fields.sort(key=lambda field: field.order)
    return form.Fields(*(args + tuple(fields)), **kw)
开发者ID:janwijbrand,项目名称:grokcore.formlib,代码行数:9,代码来源:formlib.py


示例13: __init__

    def __init__(self, value_type=_NotGiven, unique=_NotGiven, **kw):
        super(Collection, self).__init__(**kw)
        # whine if value_type is not a field
        if value_type is not _NotGiven:
            self.value_type = value_type

        if self.value_type is not None and not IField.providedBy(self.value_type):
            raise ValueError("'value_type' must be field instance.")
        if unique is not _NotGiven:
            self.unique = unique
开发者ID:marcosptf,项目名称:fedora,代码行数:10,代码来源:_field.py


示例14: getFields

def getFields(schema):
    """Return a dictionary containing all the Fields in a schema.
    """
    from zope.schema.interfaces import IField
    fields = {}
    for name in schema:
        attr = schema[name]
        if IField.providedBy(attr):
            fields[name] = attr
    return fields
开发者ID:RadioFreeAsia,项目名称:zope.schema,代码行数:10,代码来源:_schema.py


示例15: traverse

    def traverse(self, name, ignore):
        field = providedBy(self.context).get(name)
        if field is not None and IField.providedBy(field):
            value = getattr(self.context, name, _marker)
            if value is not _marker:
                bound_field = field.bind(value)
                bound_field.__parent__ = self.context
                return bound_field

        raise NotFound(self.context, name, self.request)
开发者ID:BenoitTalbot,项目名称:bungeni-portal,代码行数:10,代码来源:webdav.py


示例16: __init__

    def __init__(self, field, factory, name=None):

        if not IField.providedBy(field):
            raise ValueError("Provided field must be an IField object")

        if not IFile.implementedBy(factory):
            raise ValueError("Provided factory is not a valid IFile")

        self.__field = field
        self.__name = name or field.__name__
        self.__factory = factory
开发者ID:Cromlech,项目名称:cromlech.file,代码行数:11,代码来源:property.py


示例17: schema_indexes

def schema_indexes(context):
    if IField.providedBy(context):
        _index_types = schema_index_types(context)
        _name = lambda idx, n: "%s_%s" % (idx, n)
        name = context.__name__
        return tuple(_name(idx, name) for idx in _index_types)
    if IInterface.providedBy(context):
        r = []
        for name, field in getFieldsInOrder(context):
            r += list(schema_indexes(field))
        return tuple(r)
    raise ValueError("context must be interface or field")
开发者ID:upiq,项目名称:uu.retrieval,代码行数:12,代码来源:__init__.py


示例18: export_element

    def export_element(self, doc, node):
        if self.descriptor.schema is None:
            return

        for field_name in self.descriptor.schema:
            field = self.descriptor.schema[field_name]

            if not IField.providedBy(field):
                continue

            child = self.export_field(doc, field)
            node.appendChild(child)
开发者ID:alecghica,项目名称:plone.app.contentrules,代码行数:12,代码来源:rules.py


示例19: sortedFields

def sortedFields(schema):
    """ Like getFieldsInOrder, but does not include fields from bases

        This is verbatim from plone.supermodel's utils.py but I didn't
        want to create a dependency.
    """
    fields = []
    for name in schema.names(all=False):
        field = schema[name]
        if IField.providedBy(field):
            fields.append((name, field,))
    fields.sort(key=lambda item: item[1].order)
    return fields
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:13,代码来源:utils.py


示例20: __init__

    def __init__(self, *args, **kw):
        # Most of this code is copied from zope.formlib.form.Formfields
        # licensed under the ZPL 2.1
        keep_readonly, omit_readonly, defaults = _initkw(**kw)

        fields = []
        fieldsets = ()
        for arg in args:
            if isinstance(arg, InterfaceClass):
                for name, field in getFieldsInOrder(arg):
                    fields.append((name, field))
            elif IField.providedBy(arg):
                name = arg.__name__
                if not name:
                    raise ValueError("Field has no name")
                fields.append((name, arg))
            elif isinstance(arg, FormFieldsets):
                fieldsets = fieldsets + (arg, )
                for form_field in arg:
                    fields.append((form_field.__name__, form_field))
            elif isinstance(arg, FormFields):
                for form_field in arg:
                    fields.append((form_field.__name__, form_field))
            elif isinstance(arg, FormField):
                fields.append((arg.__name__, arg))
            else:
                raise TypeError("Unrecognized argument type", arg)

        self.fieldsets = fieldsets

        seq = []
        byname = {}
        for name, field in fields:
            if isinstance(field, FormField):
                form_field = field
            else:
                if field.readonly:
                    if omit_readonly and (name not in keep_readonly):
                        continue
                form_field = FormField(field, **defaults)
                name = form_field.__name__

            if name in byname:
                raise ValueError("Duplicate name", name)
            seq.append(form_field)
            byname[name] = form_field

        self.__FormFields_seq__ = seq
        self.__FormFields_byname__ = byname
开发者ID:CGTIC,项目名称:Plone_SP,代码行数:49,代码来源:fieldsets.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python interfaces.ISequence类代码示例发布时间:2022-05-26
下一篇:
Python interfaces.IContextSourceBinder类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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