Mercurial > p > roundup > code
diff scripts/import_sf.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 | 3fa026621f69 |
| children | fed0f839c260 |
line wrap: on
line diff
--- a/scripts/import_sf.py Wed Jul 25 00:40:26 2018 +0000 +++ b/scripts/import_sf.py Wed Jul 25 09:05:58 2018 +0000 @@ -30,6 +30,7 @@ from roundup import instance, hyperdb, date, support, password from roundup.anypy import http_, urllib_ +from roundup.anypy.strings import s2b, us2s today = date.Date('.') @@ -295,7 +296,7 @@ files.append(fid) name = name.strip() try: - f = open(os.path.join(file_dir, fid)) + f = open(os.path.join(file_dir, fid), 'rb') content = f.read() f.close() except: @@ -384,11 +385,11 @@ if isinstance(klass, hyperdb.FileClass) and entry.get('content'): fname = klass.exportFilename('/tmp/imported/', entry['id']) support.ensureParentsExist(fname) - c = open(fname, 'w') - if isinstance(entry['content'], unicode): - c.write(entry['content'].encode('utf8')) + c = open(fname, 'wb') + if isinstance(entry['content'], bytes): + c.write(entry['content']) else: - c.write(entry['content']) + c.write(s2b(us2s(entry['content']))) c.close() f.close()
