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


Python IField.providedBy方法代码示例

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


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

示例1: __init__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
 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,代码行数:11,代码来源:_field.py

示例2: __call__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:16,代码来源:dxfields.py

示例3: _validate_fields

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
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,代码行数:36,代码来源:_field.py

示例4: __call__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:34,代码来源:vocabularies.py

示例5: portletManagerDirective

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
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,代码行数:35,代码来源:zcml.py

示例6: writeAttribute

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:31,代码来源:exportimport.py

示例7: what_changed

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
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,代码行数:33,代码来源:bugactivity.py

示例8: __init__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
 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,代码行数:9,代码来源:field.py

示例9: __init__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
 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,代码行数:11,代码来源:field.py

示例10: export_assignment

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:11,代码来源:portlets.py

示例11: Fields

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
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,代码行数:11,代码来源:formlib.py

示例12: __init__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:12,代码来源:_field.py

示例13: getFields

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
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,代码行数:12,代码来源:_schema.py

示例14: traverse

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:12,代码来源:webdav.py

示例15: __init__

# 需要导入模块: from zope.schema.interfaces import IField [as 别名]
# 或者: from zope.schema.interfaces.IField import providedBy [as 别名]
    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,代码行数:13,代码来源:property.py


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