cwvreg.py
brancholdstable
changeset 8123 a4e667270dd4
parent 7473 a164fdf3de5d
child 7990 a673d1d9a738
--- a/cwvreg.py	Mon Sep 26 18:37:23 2011 +0200
+++ b/cwvreg.py	Fri Dec 09 12:08:27 2011 +0100
@@ -194,17 +194,18 @@
 _ = unicode
 
 from warnings import warn
+from datetime import datetime, date, time, timedelta
 
 from logilab.common.decorators import cached, clear_cache
 from logilab.common.deprecation import deprecated, class_deprecated
 from logilab.common.modutils import cleanup_sys_modules
 
 from rql import RQLHelper
+from yams.constraints import BASE_CONVERTERS
 
 from cubicweb import (ETYPE_NAME_MAP, Binary, UnknownProperty, UnknownEid,
                       ObjectNotFound, NoSelectableObject, RegistryNotFound,
                       CW_EVENT_MANAGER)
-from cubicweb.utils import dump_class
 from cubicweb.vregistry import VRegistry, Registry, class_regid, classid
 from cubicweb.rtags import RTAGS
 
@@ -368,7 +369,10 @@
         # make a copy event if cls.__regid__ == etype, else we may have pb for
         # client application using multiple connections to different
         # repositories (eg shingouz)
-        cls = dump_class(cls, etype)
+        # __autogenerated__ attribute is just a marker
+        cls = type(str(etype), (cls,), {'__autogenerated__': True,
+                                        '__doc__': cls.__doc__,
+                                        '__module__': cls.__module__})
         cls.__regid__ = etype
         cls.__initialize__(self.schema)
         return cls
@@ -412,10 +416,8 @@
                      if not isinstance(view, class_deprecated)]
             try:
                 view = self._select_best(views, req, rset=rset, **kwargs)
-                if view.linkable():
+                if view is not None and view.linkable():
                     yield view
-            except NoSelectableObject:
-                continue
             except Exception:
                 self.exception('error while trying to select %s view for %s',
                                vid, rset)
@@ -849,24 +851,15 @@
         return self['views'].select(__vid, req, rset=rset, **kwargs)
 
 
-import decimal
-from datetime import datetime, date, time, timedelta
-
-YAMS_TO_PY = { # XXX unify with yams.constraints.BASE_CONVERTERS?
-    'String' :  unicode,
-    'Bytes':    Binary,
-    'Password': str,
-
-    'Boolean':  bool,
-    'Int':      int,
-    'Float':    float,
-    'Decimal':  decimal.Decimal,
-
+# XXX unify with yams.constraints.BASE_CONVERTERS?
+YAMS_TO_PY = BASE_CONVERTERS.copy()
+YAMS_TO_PY.update({
+    'Bytes':      Binary,
     'Date':       date,
     'Datetime':   datetime,
     'TZDatetime': datetime,
     'Time':       time,
     'TZTime':     time,
     'Interval':   timedelta,
-    }
+    })