Esempio n. 1
0
def serializer_factory_for_field(field_iface):
    '''Get an XML serializer factory for a zope.schema.Field interface.
    '''
    assert field_iface.extends(IField)
    factory = adapter_registry.lookup([field_iface], IXmlSerializer,
                                      'serialize-xml')
    return factory
Esempio n. 2
0
def serializer_factory_for_object(obj_iface):
    '''Get an XML serializer factory for an IObject-based interface.
    '''
    assert obj_iface.isOrExtends(IObject)
    factory = adapter_registry.lookup([obj_iface], IXmlSerializer,
                                      'serialize-xml')
    return factory
Esempio n. 3
0
    def _get_field_factory(cls, key, field):
        '''Find a factory for a field. 
        
        If key is supplied, we try to find it via a class attribute. If it fails 
        (or key is not supplied), we fall back to an adapter lookup on field's 
        schema.
        '''

        # Check if a factory is defined explicitly as a class attribute

        if key and hasattr(cls, key):
            factory = getattr(cls, key)
            return factory if callable(factory) else None

        # If reached here, there is no hint via class attribute.
        # Try to find a factory for this field.

        if not field:
            schema = cls.get_schema()
            field = schema.get(key)
            assert field, 'No field %r in schema %s' % (key, schema)

        factory = None
        if isinstance(field, zope.schema.Object):
            factory = adapter_registry.lookup([], field.schema)
        else:
            factory = field.defaultFactory

        return factory
def serializer_factory_for_field(field_iface, name='default'):
    '''Get a proper serializer factory for a zope.schema.Field interface.
    ''' 
    assert field_iface.extends(IField)
    assert name in supported_formats
    factory = adapter_registry.lookup(
        [field_iface], ISerializer, 'serialize:%s' %(name))
    return factory
def serializer_factory_for_field(field_iface, name='default'):
    '''Get a proper serializer factory for a zope.schema.Field interface.
    ''' 
    assert field_iface.extends(IField)
    assert name in supported_formats
    factory = adapter_registry.lookup(
        [field_iface], ISerializer, 'serialize:%s' %(name))
    return factory
def test_adapter_registry():
    info1 = adapter_registry.queryMultiAdapter([], IContactInfo)
    assert info1
    assert zope.interface.verify.verifyObject(IContactInfo, info1)

    pt1 = adapter_registry.queryMultiAdapter([], IPoint)
    assert pt1
    assert zope.interface.verify.verifyObject(IPoint, pt1)

    cls = adapter_registry.lookup([], IContactInfo)
    assert cls
    assert zope.interface.verify.verifyClass(IContactInfo, cls)
def test_adapter_registry():
    info1 = adapter_registry.queryMultiAdapter([], IContactInfo)
    assert info1
    assert zope.interface.verify.verifyObject(IContactInfo, info1)

    pt1 = adapter_registry.queryMultiAdapter([], IPoint)
    assert pt1
    assert zope.interface.verify.verifyObject(IPoint, pt1)

    cls = adapter_registry.lookup([], IContactInfo)
    assert cls
    assert zope.interface.verify.verifyClass(IContactInfo, cls)
Esempio n. 8
0
        def __init__(self, iface, name='', opts={}):
            if not iface.extends(IObject):
                raise ValueError('Expected an interface based on IObject')

            self.target_iface = iface
            self.name = name
            self.target_factory = adapter_registry.lookup([], iface, name)
            if not self.target_factory:
                raise LookupError(
                    'Cannot find an implementor for %s named %r' %
                    (iface, name))

            self.opts = {'unserialize-values': False}
            self.opts.update(opts)
def serializer_factory_for_object(obj_iface):
    """Get an XML serializer factory for an IObject-based interface.
    """
    assert obj_iface.isOrExtends(IObject)
    factory = adapter_registry.lookup([obj_iface], IXmlSerializer, "serialize-xml")
    return factory
def serializer_factory_for_field(field_iface):
    """Get an XML serializer factory for a zope.schema.Field interface.
    """
    assert field_iface.extends(IField)
    factory = adapter_registry.lookup([field_iface], IXmlSerializer, "serialize-xml")
    return factory
def serializer_factory_for_key_tuple():
    '''Get a proper serializer factory for the tuple-typed keys of a dict.
    '''
    factory = adapter_registry.lookup([], ISerializer, 'serialize-key')
    return factory
def serializer_factory_for_key_tuple():
    '''Get a proper serializer factory for the tuple-typed keys of a dict.
    '''
    factory = adapter_registry.lookup([], ISerializer, 'serialize-key')
    return factory