avoid dependency to common tls-sprint
authorsylvain.thenault@logilab.fr
Tue, 17 Feb 2009 22:59:14 +0100
branchtls-sprint
changeset 709 b21ee900c732
parent 708 b4728112625f
child 714 39a2a6673171
avoid dependency to common
appobject.py
common/uilib.py
entity.py
utils.py
--- a/appobject.py	Tue Feb 17 22:45:55 2009 +0100
+++ b/appobject.py	Tue Feb 17 22:59:14 2009 +0100
@@ -13,6 +13,7 @@
 
 from logilab.common.decorators import classproperty
 from logilab.common.deprecation import obsolete
+from logilab.mtconverter import html_escape
 
 from rql.nodes import VariableRef, SubQuery
 from rql.stmts import Union, Select
@@ -20,8 +21,7 @@
 from cubicweb import Unauthorized
 from cubicweb.vregistry import VObject
 from cubicweb.selectors import yes
-from cubicweb.utils import UStringIO
-from cubicweb.common.uilib import html_escape, ustrftime
+from cubicweb.utils import UStringIO, ustrftime
 from cubicweb.common.registerers import yes_registerer, priority_registerer
 
 
--- a/common/uilib.py	Tue Feb 17 22:45:55 2009 +0100
+++ b/common/uilib.py	Tue Feb 17 22:59:14 2009 +0100
@@ -11,7 +11,6 @@
 
 import csv
 import decimal
-import locale
 import re
 from urllib import quote as urlquote
 from cStringIO import StringIO
@@ -23,16 +22,7 @@
 from logilab.common.textutils import unormalize
 from logilab.mtconverter import html_escape, html_unescape
 
-def ustrftime(date, fmt='%Y-%m-%d'):
-    """like strftime, but returns a unicode string instead of an encoded
-    string which may be problematic with localized date.
-    
-    encoding is guessed by locale.getpreferredencoding()
-    """
-    # date format may depend on the locale
-    encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8'
-    return unicode(date.strftime(fmt), encoding)
-
+from cubicweb.utils import ustrftime
 
 def rql_for_eid(eid):
     """return the rql query necessary to fetch entity with the given eid.  This
--- a/entity.py	Tue Feb 17 22:45:55 2009 +0100
+++ b/entity.py	Tue Feb 17 22:59:14 2009 +0100
@@ -9,7 +9,7 @@
 from logilab.common import interface
 from logilab.common.compat import all
 from logilab.common.decorators import cached
-from logilab.mtconverter import TransformData, TransformError
+from logilab.mtconverter import TransformData, TransformError, html_escape
 
 from rql.utils import rqlvar_maker
 
@@ -18,11 +18,16 @@
 from cubicweb.rset import ResultSet
 from cubicweb.selectors import yes
 from cubicweb.appobject import AppRsetObject
+from cubicweb.schema import RQLVocabularyConstraint, RQLConstraint, bw_normalize_etype
 from cubicweb.common.registerers import id_registerer
-from cubicweb.common.uilib import printable_value, html_escape, soup2xhtml
-from cubicweb.common.mixins import MI_REL_TRIGGERS
-from cubicweb.common.mttransforms import ENGINE
-from cubicweb.schema import RQLVocabularyConstraint, RQLConstraint, bw_normalize_etype
+
+try:
+    from cubicweb.common.uilib import printable_value, soup2xhtml
+    from cubicweb.common.mixins import MI_REL_TRIGGERS
+    from cubicweb.common.mttransforms import ENGINE
+except ImportError:
+    # missing -common
+    MI_REL_TRIGGERS = {}
 
 _marker = object()
 
--- a/utils.py	Tue Feb 17 22:45:55 2009 +0100
+++ b/utils.py	Tue Feb 17 22:59:14 2009 +0100
@@ -6,6 +6,7 @@
 """
 __docformat__ = "restructuredtext en"
 
+import locale
 from md5 import md5
 from time import time
 from random import randint, seed
@@ -42,6 +43,16 @@
             yield date
         date += incr
 
+def ustrftime(date, fmt='%Y-%m-%d'):
+    """like strftime, but returns a unicode string instead of an encoded
+    string which may be problematic with localized date.
+    
+    encoding is guessed by locale.getpreferredencoding()
+    """
+    # date format may depend on the locale
+    encoding = locale.getpreferredencoding(do_setlocale=False) or 'UTF-8'
+    return unicode(date.strftime(fmt), encoding)
+
 
 def dump_class(cls, clsname):
     """create copy of a class by creating an empty class inheriting