Mercurial > p > roundup > code
comparison roundup/backends/back_sqlite.py @ 5416:56c9bcdea47f
Python 3 preparation: unicode.
This patch introduces roundup/anypy/strings.py, which has a comment
explaining the string representations generally used and common
functions to handle the required conversions. Places in the code that
explicitly reference the "unicode" type / built-in function are
generally changed to use the new functions (or, in a few places where
those new functions don't seem to fit well, other approaches such as
references to type(u'') or use of the codecs module). This patch does
not generally attempt to address text conversions in any places not
currently referencing the "unicode" type (although
scripts/import_sf.py is made to use binary I/O in places as fixing the
"unicode" reference didn't seem coherent otherwise).
| author | Joseph Myers <jsm@polyomino.org.uk> |
|---|---|
| date | Wed, 25 Jul 2018 09:05:58 +0000 |
| parents | 62de601bdf6f |
| children | ee2e8f8d6648 |
comparison
equal
deleted
inserted
replaced
| 5415:2d6a92c3e212 | 5416:56c9bcdea47f |
|---|---|
| 11 import os, base64, marshal, shutil, time, logging | 11 import os, base64, marshal, shutil, time, logging |
| 12 | 12 |
| 13 from roundup import hyperdb, date, password | 13 from roundup import hyperdb, date, password |
| 14 from roundup.backends import rdbms_common | 14 from roundup.backends import rdbms_common |
| 15 from roundup.backends.sessions_dbm import Sessions, OneTimeKeys | 15 from roundup.backends.sessions_dbm import Sessions, OneTimeKeys |
| 16 from roundup.anypy.strings import uany2s | |
| 16 | 17 |
| 17 sqlite_version = None | 18 sqlite_version = None |
| 18 try: | 19 try: |
| 19 import sqlite3 as sqlite | 20 import sqlite3 as sqlite |
| 20 sqlite_version = 3 | 21 sqlite_version = 3 |
| 83 hyperdb.Integer : int, | 84 hyperdb.Integer : int, |
| 84 hyperdb.Number : lambda x: x, | 85 hyperdb.Number : lambda x: x, |
| 85 hyperdb.Multilink : lambda x: x, # used in journal marshalling | 86 hyperdb.Multilink : lambda x: x, # used in journal marshalling |
| 86 } | 87 } |
| 87 sql_to_hyperdb_value = { | 88 sql_to_hyperdb_value = { |
| 88 hyperdb.String : lambda x: isinstance(x, unicode) and x.encode('utf8') or str(x), | 89 hyperdb.String : uany2s, |
| 89 hyperdb.Date : lambda x: date.Date(str(x)), | 90 hyperdb.Date : lambda x: date.Date(str(x)), |
| 90 hyperdb.Link : str, # XXX numeric ids | 91 hyperdb.Link : str, # XXX numeric ids |
| 91 hyperdb.Interval : date.Interval, | 92 hyperdb.Interval : date.Interval, |
| 92 hyperdb.Password : lambda x: password.Password(encrypted=x), | 93 hyperdb.Password : lambda x: password.Password(encrypted=x), |
| 93 hyperdb.Boolean : int, | 94 hyperdb.Boolean : int, |
