Beispiel #1
0
 def __call__(self, instance, *args, **kw):
     list_value = getattr(aq_base(instance), self._storage_id, None)
     # We should not use here self._null but None instead XXX
     if list_value in self._null:
         list_value = args[0] if args else self._default
         if list_value in self._null:
             return list_value
     if self._is_tales_type:
         if kw.get('evaluate', 1):
             if type(list_value) is not str:
                 LOG(
                     'ListGetter', 0,
                     'instance = %r, self._storage_id = %r, list_value = %r'
                     % (
                         instance,
                         self._storage_id,
                         list_value,
                     )
                 )  # If we reach this point, something strange is going on
             list_value = evaluateTales(instance=instance,
                                        value=list_value)
         else:
             return list_value
     # Even if it is already a list, return a copy as callers
     # expect to be able to modify it on place
     if isinstance(list_value, list_type_list):
         return list(list_value
                     )  # Make sure we return a list rather than a tuple
     return list_value
Beispiel #2
0
 def __call__(self, instance, *args, **kw):
   if len(args) > 0:
     default = args[0]
   else:
     default = self._default
   list_value = getattr(aq_base(instance), self._storage_id, default)
   # We should not use here self._null but None instead XXX
   if list_value not in self._null:
     if self._is_tales_type:
       if kw.get('evaluate', 1):
         if type(list_value) != type(''):
           LOG('ListGetter', 0, 'instance = %r, self._storage_id = %r, list_value = %r' % (instance, self._storage_id, list_value,)) # If we reach this point, something strange is going on
         list_value = evaluateTales(instance=instance, value=list_value)
       else:
         return list_value
     # Even if it is already a list, return a copy as callers
     # expect to be able to modify it on place
     if isinstance(list_value, (list, tuple, set)):
       return list(list_value) # Make sure we return a list rather than a tuple
     return list_value
   if default is None:
     return None # nothing was defined as default so None is the appropriate value
   if isinstance(default, (list, tuple, set)):
     return list(default) # Make sure we return a list rather than a tuple
   return default
Beispiel #3
0
 def __call__(self, instance, *args, **kw):
   list_value = getattr(aq_base(instance), self._storage_id, None)
   # We should not use here self._null but None instead XXX
   if list_value in self._null:
     list_value = args[0] if args else self._default
     if list_value in self._null:
       return list_value
   if self._is_tales_type:
     if kw.get('evaluate', 1):
       if type(list_value) is not str:
         LOG('ListGetter', 0, 'instance = %r, self._storage_id = %r, list_value = %r' % (instance, self._storage_id, list_value,)) # If we reach this point, something strange is going on
       list_value = evaluateTales(instance=instance, value=list_value)
     else:
       return list_value
   # Even if it is already a list, return a copy as callers
   # expect to be able to modify it on place
   if isinstance(list_value, list_type_list):
     return list(list_value) # Make sure we return a list rather than a tuple
   return list_value
Beispiel #4
0
 def __call__(self, instance, *args, **kw):
   if len(args) > 0:
     default = args[0]
   else:
     default = self._default
   list_value = getattr(aq_base(instance), self._storage_id, default)
   if list_value is not None:
     if self._is_tales_type:
       if kw.get('evaluate', 1):
         list_value = evaluateTales(instance=instance, value=list_value)
       else:
         return list_value
     if type(list_value) in (ListType, TupleType):
       if len(list_value) > 0:
         return list_value[0]
       else:
         return None
     # This should not happen though
     return list_value
   if default and len(default):
     return default[0]
   return None
Beispiel #5
0
 def __call__(self, instance, *args, **kw):
     if len(args) > 0:
         default = args[0]
     else:
         default = self._default
     list_value = getattr(aq_base(instance), self._storage_id, default)
     if list_value is not None:
         if self._is_tales_type:
             if kw.get('evaluate', 1):
                 list_value = evaluateTales(instance=instance,
                                            value=list_value)
             else:
                 return list_value
         if type(list_value) in (ListType, TupleType):
             if len(list_value) > 0:
                 return list_value[0]
             else:
                 return None
         # This should not happen though
         return list_value
     if default and len(default):
         return default[0]
     return None
Beispiel #6
0
 def __call__(self, instance, *args, **kw):
     if len(args) > 0:
         default = args[0]
     else:
         default = self._default
     list_value = getattr(aq_base(instance), self._storage_id, default)
     # We should not use here self._null but None instead XXX
     if list_value not in self._null:
         if self._is_tales_type:
             if kw.get('evaluate', 1):
                 if type(list_value) != type(''):
                     LOG(
                         'ListGetter', 0,
                         'instance = %r, self._storage_id = %r, list_value = %r'
                         % (
                             instance,
                             self._storage_id,
                             list_value,
                         )
                     )  # If we reach this point, something strange is going on
                 list_value = evaluateTales(instance=instance,
                                            value=list_value)
             else:
                 return list_value
         # Even if it is already a list, return a copy as callers
         # expect to be able to modify it on place
         if isinstance(list_value, (list, tuple, set)):
             return list(list_value
                         )  # Make sure we return a list rather than a tuple
         return list_value
     if default is None:
         return None  # nothing was defined as default so None is the appropriate value
     if isinstance(default, (list, tuple, set)):
         return list(
             default)  # Make sure we return a list rather than a tuple
     return default