예제 #1
0
def createDirectFieldProperties(__schema, omit=(), adapting=False):
    """
    Like :func:`zope.schema.fieldproperty.createFieldProperties`, except
    only creates properties for fields directly contained within the
    given schema; inherited fields from parent interfaces are assummed
    to be implemented in a base class of the current class::

      >>> from zope import interface
      >>> from nti.schema.field import TextLine, Object
      >>> class IA(interface.Interface):
      ...    a = TextLine(title=u"a")

      >>> class IB(IA):
      ...    b = Object(interface.Interface)

      >>> class A(object):
      ...    createFieldProperties(IA)

      >>> class B(object):
      ...    createDirectFieldProperties(IB, adapting=True)

      >>> 'a' in A.__dict__
      True
      >>> 'a' in B.__dict__
      False
      >>> 'b' in B.__dict__
      True


    :keyword adapting: If set to ``True`` (not the default), fields
        that implement :class:`.IObject` will use an :class:`AdaptingFieldProperty`.
    """

    __my_names = set(__schema.names())
    __all_names = set(__schema.names(all=True))

    __not_my_names = __all_names - __my_names
    __not_my_names.update(omit)

    # The existing implementation relies on getframe(1) to find the caller,
    # which is us. So we do the same and copy to the real caller
    __frame = None
    __before = None
    __before = list(locals().keys())
    createFieldProperties(__schema, omit=__not_my_names)

    __frame = sys._getframe(1) # pylint:disable=protected-access
    for k, v in list(locals().items()):
        if k not in __before:
            if adapting and sch_interfaces.IObject.providedBy(__schema[k]):
                v = AdaptingFieldProperty(__schema[k])
            __frame.f_locals[k] = v
예제 #2
0
class WebhookDeliveryAttempt(_Base, Contained):
    status = None
    internal_info = None
    createFieldProperties(IWebhookDeliveryAttempt,
                          omit=('created', 'modified', 'lastModified'))
    # Allow delayed validation for these things.
    request = None
    response = None
    __parent__ = None

    def __init__(self, **kwargs):
        super(WebhookDeliveryAttempt, self).__init__(**kwargs)
        if self.request is None:
            self.request = WebhookDeliveryAttemptRequest()
        if self.response is None:
            self.response = WebhookDeliveryAttemptResponse()

        self.internal_info = WebhookDeliveryAttemptInternalInfo()
        self.internal_info.__parent__ = self
        self.internal_info.__name__ = 'internal_info'

    def __repr__(self):
        return "<%s.%s at 0x%x created=%s modified=%s status=%r>" % (
            self.__class__.__module__,
            self.__class__.__name__,
            id(self),
            self.created,
            self.modified,
            self.status,
        )

    status = _StatusDescriptor(status)

    def succeeded(self):
        return IWebhookDeliveryAttempt['status'].isSuccess(self.status)

    def failed(self):
        return IWebhookDeliveryAttempt['status'].isFailure(self.status)

    def pending(self):
        return IWebhookDeliveryAttempt['status'].isPending(self.status)

    def resolved(self):
        return IWebhookDeliveryAttempt['status'].isResolved(self.status)
예제 #3
0
class Bar(object):
    createFieldProperties(IBar)
 class Dummy(object):
     createFieldProperties(_getSchema(), omit=['date', 'code'])
 class Dummy(object):
     createFieldProperties(schema)
예제 #6
0
class WebhookDeliveryAttemptResponse(_Base):
    __name__ = 'response'
    createFieldProperties(IWebhookDeliveryAttemptResponse,
                          omit=('created', 'modified'))
예제 #7
0
class WebhookDeliveryAttemptRequest(_Base):
    __name__ = 'request'
    createFieldProperties(IWebhookDeliveryAttemptRequest,
                          omit=('created', 'modified'))
예제 #8
0
class UserProfile(SchemaConfigured):
    createFieldProperties(interfaces.IUserProfile)