[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/rdb/ Added database encoding

Dmitry Vasiliev dima at hlabs.spb.ru
Fri Jul 22 04:32:05 EDT 2005


Log message for revision 37378:
  Added database encoding
  

Changed:
  U   Zope3/trunk/src/zope/app/rdb/__init__.py
  U   Zope3/trunk/src/zope/app/rdb/browser/configure.zcml
  U   Zope3/trunk/src/zope/app/rdb/browser/rdb.py
  U   Zope3/trunk/src/zope/app/rdb/browser/rdbconnection.pt
  U   Zope3/trunk/src/zope/app/rdb/interfaces.py
  U   Zope3/trunk/src/zope/app/rdb/tests/stubs.py

-=-
Modified: Zope3/trunk/src/zope/app/rdb/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/__init__.py	2005-07-22 02:50:51 UTC (rev 37377)
+++ Zope3/trunk/src/zope/app/rdb/__init__.py	2005-07-22 08:32:05 UTC (rev 37378)
@@ -42,6 +42,8 @@
 from zope.thread import local
 
 
+DEFAULT_ENCODING = "utf-8"
+
 def sqlquote(x):
     """
     Escape data suitable for inclusion in generated ANSI SQL92 code for
@@ -173,7 +175,16 @@
     # Pessimistic defaults
     paramstyle = 'pyformat'
     threadsafety = 0
+    encoding = DEFAULT_ENCODING
 
+    def setEncoding(self, encoding):
+        # Check the encoding
+        "".decode(encoding)
+        self.encoding = encoding
+
+    def getEncoding(self):
+        return self.encoding
+
     def getConverter(self, type):
         'See IDBITypeInfo'
         return identity
@@ -277,7 +288,8 @@
         connection with the transaction system.  """
 
         if isinstance(operation, unicode):
-            operation = operation.encode('UTF-8')
+            encoding = self.connection.getTypeInfo().getEncoding()
+            operation = operation.encode(encoding)
         self.connection.registerForTxn()
         if parameters is None:
             return self.cursor.execute(operation)

Modified: Zope3/trunk/src/zope/app/rdb/browser/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/rdb/browser/configure.zcml	2005-07-22 02:50:51 UTC (rev 37377)
+++ Zope3/trunk/src/zope/app/rdb/browser/configure.zcml	2005-07-22 08:32:05 UTC (rev 37378)
@@ -16,7 +16,7 @@
   <view
       name="+"
       for="zope.app.rdb.interfaces.IZopeDatabaseAdapter"
-      class="zope.app.container.browser.adding.Adding" 
+      class="zope.app.container.browser.adding.Adding"
       permission="zope.ManageServices" />
 
   <pages
@@ -24,12 +24,12 @@
       permission="zope.ManageServices"
       class=".rdb.Connection">
 
-    <page name="editForm.html" template="rdbconnection.pt" 
+    <page name="editForm.html" template="rdbconnection.pt"
           menu="zmi_views" title="Edit"/>
     <page name="edit.html" attribute="edit" />
     <page name="connect.html" attribute="connect" />
     <page name="disconnect.html" attribute="disconnect" />
-  
+
   </pages>
 
   <pages

Modified: Zope3/trunk/src/zope/app/rdb/browser/rdb.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/browser/rdb.py	2005-07-22 02:50:51 UTC (rev 37377)
+++ Zope3/trunk/src/zope/app/rdb/browser/rdb.py	2005-07-22 08:32:05 UTC (rev 37378)
@@ -31,8 +31,9 @@
 class Connection(object):
     __used_for__ = IManageableZopeDatabaseAdapter
 
-    def edit(self, dsn):
+    def edit(self, dsn, encoding):
         self.context.setDSN(dsn)
+        self.context.setEncoding(encoding)
         return self.request.response.redirect(self.request.URL[-1])
 
     def connect(self):

Modified: Zope3/trunk/src/zope/app/rdb/browser/rdbconnection.pt
===================================================================
--- Zope3/trunk/src/zope/app/rdb/browser/rdbconnection.pt	2005-07-22 02:50:51 UTC (rev 37377)
+++ Zope3/trunk/src/zope/app/rdb/browser/rdbconnection.pt	2005-07-22 08:32:05 UTC (rev 37378)
@@ -10,7 +10,7 @@
 <div metal:fill-slot="body">
 
   <form action="." method="post" enctype="multipart/form-data">
-  
+
     <div class="row">
       <div class="label" i18n:translate="">Connection URI:</div>
       <div class="field">
@@ -22,6 +22,11 @@
         <input type="text" name="dsn" size="40" value=""
                tal:attributes="value context/dsn" />
       </div>
+      <div class="label" i18n:translate="">Encoding</div>
+      <div class="field">
+        <input type="text" name="encoding" size="20" value=""
+               tal:attributes="value context/encoding" />
+      </div>
     </div>
 
     <div class="row">

Modified: Zope3/trunk/src/zope/app/rdb/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/interfaces.py	2005-07-22 02:50:51 UTC (rev 37377)
+++ Zope3/trunk/src/zope/app/rdb/interfaces.py	2005-07-22 08:32:05 UTC (rev 37378)
@@ -58,6 +58,13 @@
         variables or other external sources that are beyond your control.
         """)
 
+    encoding = TextLine(
+        title=_("Database encoding"),
+        description=_("Encoding of the database content"),
+        default=u"utf-8",
+        required=False
+        )
+
     def getConverter(type):
         """Return a converter function for field type matching key"""
 
@@ -389,6 +396,12 @@
         default=u"dbi://dbname",
         required=True)
 
+    def getEncoding():
+        """Get the database encoding."""
+
+    def setEncoding(encoding):
+        """Set the database encoding."""
+
     def connect():
         """Connect to the specified database."""
 

Modified: Zope3/trunk/src/zope/app/rdb/tests/stubs.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/stubs.py	2005-07-22 02:50:51 UTC (rev 37377)
+++ Zope3/trunk/src/zope/app/rdb/tests/stubs.py	2005-07-22 08:32:05 UTC (rev 37378)
@@ -31,17 +31,21 @@
         v = self._called.setdefault('commit',0)
         v+=1
         self._called['commit']=v
+
     def rollback(self, *ignored):
         v = self._called.setdefault('rollback',0)
         v+=1
         self._called['rollback']=v
 
 class CursorStub(object):
+
     def execute(*args, **kw):
         pass
 
 class TypeInfoStub(object):
     paramstyle = 'pyformat'
     threadsafety = 0
+    encoding = 'utf-8'
+
     def getConverter(self, type):
         return lambda x: x



More information about the Zope3-Checkins mailing list