def __getattr__(pm, key):
     """look up default property values."""
     sd = schemadict(implementedBy(pm))
     # should we raise ``AttributeError``, when ``default`` is ``None``?
     if key in sd:
         return sd[key].default
     raise AttributeError(key)
 def __get__(self, instance, cls=None):
     if instance is None:
         # class level access
         return _properties_from_schema(schemadict(implmentedBy(cls)), None)
     else:
         return _properties_from_instance.__of__(instance)
    # override ``PropertyManager`` methods
    #  we are not extensible -- maybe, we should provide our own
    #  template instead, to get rid of the ``management_page_charset`` hackles???
    manage_propertiesForm = pmm.DTMLFile("dtml/properties", pmm.__dict__, property_extensible_schema__=False)

    def _not_extensible(*args):
        raise NotImplementedError("property schema not extensible")

    _setProperty = _not_extensible
    _delProperty = _not_extensible
    manage_addProperty = _not_extensible


_properties_from_instance = ComputedAttribute(
    lambda instance: _properties_from_schema(schemadict(providedBy(instance)), instance), True
)


def _properties_from_schema(sd, context):
    """derive property descriptions from schema dict *sd*.

  *context* is used to access ``management_page_charset`` in order
  to determine whether we can use unicode properties.
  """
    mpc = getattr(context, "management_page_charset", None)
    if callable(mpc):
        mpc = mpc()
    uprops = mpc is None or mpc.upper() == "UTF-8"

    def u(t):
예제 #4
0
 def __getattr__(pm, key):
     """look up default property values."""
     sd = schemadict(implementedBy(pm))
     # should we raise ``AttributeError``, when ``default`` is ``None``?
     if key in sd: return sd[key].default
     raise AttributeError(key)
예제 #5
0
 def __get__(self, instance, cls=None):
     if instance is None:
         # class level access
         return _properties_from_schema(schemadict(implmentedBy(cls)), None)
     else:
         return _properties_from_instance.__of__(instance)
예제 #6
0
    #  we are not extensible -- maybe, we should provide our own
    #  template instead, to get rid of the ``management_page_charset`` hackles???
    manage_propertiesForm = pmm.DTMLFile('dtml/properties',
                                         pmm.__dict__,
                                         property_extensible_schema__=False)

    def _not_extensible(*args):
        raise NotImplementedError('property schema not extensible')

    _setProperty = _not_extensible
    _delProperty = _not_extensible
    manage_addProperty = _not_extensible


_properties_from_instance = ComputedAttribute(
    lambda instance: _properties_from_schema(schemadict(providedBy(instance)),
                                             instance), True)


def _properties_from_schema(sd, context):
    """derive property descriptions from schema dict *sd*.

  *context* is used to access ``management_page_charset`` in order
  to determine whether we can use unicode properties.
  """
    mpc = getattr(context, 'management_page_charset', None)
    if callable(mpc): mpc = mpc()
    uprops = mpc is None or mpc.upper() == 'UTF-8'

    def u(t):
        return uprops and 'u' + t or t