merge stable
authorAlexandre Fayolle <alexandre.fayolle@logilab.fr>
Thu, 03 Jun 2010 15:13:41 +0200
branchstable
changeset 5660 97343804414b
parent 5659 755f56f01c9d (current diff)
parent 5657 8f56691f01de (diff)
child 5661 84ef08bbda3c
merge
etwist/server.py
--- a/etwist/server.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/etwist/server.py	Thu Jun 03 15:13:41 2010 +0200
@@ -25,6 +25,7 @@
 import select
 import errno
 import traceback
+import threading
 from os.path import join
 from time import mktime
 from datetime import date, timedelta
@@ -407,8 +408,11 @@
         os.setuid(uid)
     root_resource.start_service()
     logger.info('instance started on %s', root_resource.base_url)
+    # avoid annoying warnign if not in Main Thread
+    signals = threading.currentThread().getName() == 'MainThread'
     if config['profile']:
         import cProfile
-        cProfile.runctx('reactor.run()', globals(), locals(), config['profile'])
+        cProfile.runctx('reactor.run(installSignalHandlers=%s)' % signals,
+                        globals(), locals(), config['profile'])
     else:
-        reactor.run()
+        reactor.run(installSignalHandlers=signals)
--- a/server/querier.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/server/querier.py	Thu Jun 03 15:13:41 2010 +0200
@@ -419,7 +419,7 @@
         # list of new or updated entities definition (utils.Entity)
         self.e_defs = [[]]
         # list of new relation definition (3-uple (from_eid, r_type, to_eid)
-        self.r_defs = []
+        self.r_defs = set()
         # indexes to track entity definitions bound to relation definitions
         self._r_subj_index = {}
         self._r_obj_index = {}
@@ -432,7 +432,7 @@
 
     def add_relation_def(self, rdef):
         """add an relation definition to build"""
-        self.r_defs.append(rdef)
+        self.r_defs.add(rdef)
         if not isinstance(rdef[0], int):
             self._r_subj_index.setdefault(rdef[0], []).append(rdef)
         if not isinstance(rdef[2], int):
@@ -458,9 +458,9 @@
         for i, row in enumerate(self.e_defs[:]):
             self.e_defs[i][colidx] = edefs[0]
             samplerow = self.e_defs[i]
-            for edef in edefs[1:]:
+            for edef_ in edefs[1:]:
                 row = samplerow[:]
-                row[colidx] = edef
+                row[colidx] = edef_
                 self.e_defs.append(row)
         # now, see if this entity def is referenced as subject in some relation
         # definition
@@ -469,8 +469,8 @@
                 expanded = self._expanded(rdef)
                 result = []
                 for exp_rdef in expanded:
-                    for edef in edefs:
-                        result.append( (edef, exp_rdef[1], exp_rdef[2]) )
+                    for edef_ in edefs:
+                        result.append( (edef_, exp_rdef[1], exp_rdef[2]) )
                 self._expanded_r_defs[rdef] = result
         # and finally, see if this entity def is referenced as object in some
         # relation definition
@@ -479,8 +479,8 @@
                 expanded = self._expanded(rdef)
                 result = []
                 for exp_rdef in expanded:
-                    for edef in edefs:
-                        result.append( (exp_rdef[0], exp_rdef[1], edef) )
+                    for edef_ in edefs:
+                        result.append( (exp_rdef[0], exp_rdef[1], edef_) )
                 self._expanded_r_defs[rdef] = result
 
     def _expanded(self, rdef):
--- a/server/test/unittest_querier.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/server/test/unittest_querier.py	Thu Jun 03 15:13:41 2010 +0200
@@ -915,12 +915,33 @@
         self.assert_(rset.rows)
         self.assertEquals(rset.description, [('Personne', 'Societe',)])
 
+    def test_insert_7_2(self):
+        self.execute("INSERT Personne X, Societe Y: X nom N, Y nom 'toto', X travaille Y WHERE U login N")
+        rset = self.execute('Any X, Y WHERE Y nom "toto", X travaille Y')
+        self.assertEquals(len(rset), 2)
+        self.assertEquals(rset.description, [('Personne', 'Societe',),
+                                             ('Personne', 'Societe',)])
+
     def test_insert_8(self):
         self.execute("INSERT Societe Y, Personne X: Y nom N, X nom 'toto', X travaille Y WHERE U login 'admin', U login N")
         rset = self.execute('Any X, Y WHERE X nom "toto", Y nom "admin", X travaille Y')
         self.assert_(rset.rows)
         self.assertEquals(rset.description, [('Personne', 'Societe',)])
 
+    def test_insert_9(self):
+        self.execute("INSERT Societe X: X nom  'Lo'")
+        self.execute("INSERT Societe X: X nom  'Gi'")
+        self.execute("INSERT SubDivision X: X nom  'Lab'")
+        rset = self.execute("INSERT Personne X: X nom N, X travaille Y, X travaille_subdivision Z WHERE Y is Societe, Z is SubDivision, Y nom N")
+        self.assertEquals(len(rset), 2)
+        self.assertEquals(rset.description, [('Personne',), ('Personne',)])
+        # self.assertSetEquals(set(x.nom for x in rset.entities()),
+        #                      ['Lo', 'Gi'])
+        # self.assertSetEquals(set(y.nom for x in rset.entities() for y in x.travaille),
+        #                      ['Lo', 'Gi'])
+        # self.assertEquals([y.nom for x in rset.entities() for y in x.travaille_subdivision],
+        #                      ['Lab', 'Lab'])
+
     def test_insert_query_error(self):
         self.assertRaises(Exception,
                           self.execute,
--- a/vregistry.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/vregistry.py	Thu Jun 03 15:13:41 2010 +0200
@@ -385,7 +385,7 @@
             registry.register(obj, oid=oid, clear=clear)
             self.debug('registered appobject %s in registry %s with id %s',
                        vname, registryname, oid or class_regid(obj))
-        self._loadedmods[obj.__module__][classid(obj)] = obj
+        self._loadedmods.setdefault(obj.__module__, {})[classid(obj)] = obj
 
     def unregister(self, obj, registryname=None):
         """unregister `obj` application object from the registry `registryname` or
--- a/web/application.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/web/application.py	Thu Jun 03 15:13:41 2010 +0200
@@ -293,7 +293,7 @@
         # connect to the repository and get instance's schema
         self.repo = config.repository(vreg)
         if not vreg.initialized:
-            self.config.init_cubes(self.repo.get_cubes())
+            config.init_cubes(self.repo.get_cubes())
             vreg.init_properties(self.repo.properties())
             vreg.set_schema(self.repo.get_schema())
         # set the correct publish method
--- a/web/views/autoform.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/web/views/autoform.py	Thu Jun 03 15:13:41 2010 +0200
@@ -650,13 +650,13 @@
     # pre 3.8.3 compat
     def set_action(self, action):
         self._action = action
-    @deprecated('[3.9] use form.form_action()')
     def get_action(self):
         try:
             return self._action
         except AttributeError:
             return self._cw.build_url(self._default_form_action_path)
-    action = property(get_action, set_action)
+    action = property(deprecated('[3.9] use form.form_action()')(get_action),
+                      set_action)
 
     @iclassmethod
     def field_by_name(cls_or_self, name, role=None, eschema=None):
--- a/web/views/forms.py	Thu Jun 03 15:10:48 2010 +0000
+++ b/web/views/forms.py	Thu Jun 03 15:13:41 2010 +0200
@@ -196,9 +196,13 @@
 
     _default_form_action_path = 'edit'
     def form_action(self):
-        if self.action is None:
+        try:
+            action = self.get_action() # avoid spurious warning w/ autoform bw compat property
+        except AttributeError:
+            action = self.action
+        if action is None:
             return self._cw.build_url(self._default_form_action_path)
-        return self.action
+        return action
 
     @deprecated('[3.6] use .add_hidden(name, value, **kwargs)')
     def form_add_hidden(self, name, value=None, **kwargs):