Ticket #534: plumbing for unicode support.darcspatch

File plumbing for unicode support.darcspatch, 11.6 KB (added by zooko, at 2009-06-09T19:49:58Z)
Line 
1Mon Apr 27 03:58:49 MDT 2009  francois@ctrlaltdel.ch
2  * cli: plumbing for unicode support
3
4New patches:
5
6[cli: plumbing for unicode support
7francois@ctrlaltdel.ch**20090427095849
8 Ignore-this: 9cc8871d8fe54cde0dba52912754e4f4
9] {
10hunk ./src/allmydata/scripts/cli.py 4
11 import os.path, re, sys, fnmatch
12 from twisted.python import usage
13 from allmydata.scripts.common import BaseOptions, get_aliases
14+from allmydata.util.stringutils import argv_to_unicode
15 
16 NODEURL_RE=re.compile("http://([^:]*)(:([1-9][0-9]*))?")
17 
18hunk ./src/allmydata/scripts/common.py 4
19 
20 import os, sys, urllib
21 from twisted.python import usage
22-
23+from allmydata.util.stringutils import unicode_to_url
24 
25 class BaseOptions:
26     # unit tests can override these to point at StringIO instances
27hunk ./src/allmydata/test/test_cli.py 9
28 import urllib
29 import re
30 import simplejson
31+import sys
32 
33 from allmydata.util import fileutil, hashutil, base32
34 from allmydata import uri
35addfile ./src/allmydata/util/stringutils.py
36hunk ./src/allmydata/util/stringutils.py 1
37+"""
38+Functions used to convert inputs from whatever encoding used in the system to
39+unicode and back.
40+
41+TODO:
42+  * Accept two cli arguments --argv-encoding and --filesystem-encoding
43+"""
44+
45+import sys
46+from allmydata.util.assertutil import precondition
47+from twisted.python import usage
48+
49+def argv_to_unicode(s):
50+    """
51+    Decode given argv element to unicode.
52+    """
53+    # sys.argv encoding detection in Python is not trivial so utf-8 is
54+    # currently used by default and an informative error message is given if
55+    # the argument cannot be correctly decoded.
56+
57+    precondition(isinstance(s, str), s)
58+    try:
59+        return unicode(s, 'utf-8')
60+    except UnicodeEncodeError:
61+        raise usageError("Argument '%s' cannot be decoded as UTF-8." % s)
62+
63+def fs_to_unicode(s):
64+    """
65+    Decode a filename (or a directory name) to unicode using the same encoding
66+    as the filesystem.
67+    """
68+    # Filename encoding detection is a little bit better thanks to
69+    # getfilesystemencoding() in the sys module. However, filenames can be
70+    # encoded using another encoding than the one used on the filesystem.
71+   
72+    precondition(isinstance(s, str), s)
73+    encoding = sys.getfilesystemencoding()
74+    try:
75+        return unicode(s, encoding)
76+    except UnicodeDecodeError:
77+        raise usage.UsageError("Filename '%s' cannot be decoded using the current encoding of your filesystem (%s). Please rename this file." % (s, encoding))
78+
79+def unicode_to_fs(s):
80+    """
81+    Encode an unicode object used in file or directoy name.
82+    """
83+
84+    precondition(isinstance(s, unicode), s)
85+    encoding = sys.getfilesystemencoding()
86+    try:
87+        return s.encode(encoding)
88+    except UnicodeEncodeError:
89+        raise usage.UsageError("Filename '%s' cannot be encoded using the current encoding of your filesystem (%s). Please configure your locale correctly or rename this file." % (s, encoding))
90+
91+def unicode_to_url(s):
92+    """
93+    Encode an unicode object used in an URL.
94+    """
95+    # According to RFC 2718, non-ascii characters in url's must be UTF-8 encoded.
96+
97+    precondition(isinstance(s, unicode), s)
98+    return s.encode('utf-8')
99+
100+def unicode_to_stdout(s):
101+    """
102+    Encode an unicode object for representation on stdout.
103+    """
104+
105+    precondition(isinstance(s, unicode), s)
106+    return s.encode(sys.stdout.encoding, 'replace')
107}
108
109Context:
110
111[test_cli.Backup: increase timeout massively, it takes 1200s on zandr's ARM linkstation
112warner@lothar.com**20090609052801] 
113[tests: double the timeouts on some tests which time-out on Francois's box
114zooko@zooko.com**20090609021753
115 Ignore-this: b2727b04402f24a9b9123d2f84068106
116] 
117[tests: bump up timeouts so that the tests can finish before timeout on Francois's little arm box
118zooko@zooko.com**20090608225557
119 Ignore-this: fb83698338b2f12546cd3e1dcb896d34
120] 
121[tests: increase timeouts on some other tests that timed-out on Francois's arm box
122zooko@zooko.com**20090605143437
123 Ignore-this: 2903cc20d914fc074c8d7a6c47740ba6
124] 
125[tests: bump up the timeout on a bunch of tests that took longer than the default timeout (120s) on François Lenny-armv5tel
126zooko@zooko.com**20090605031444
127 Ignore-this: 84d67849b1f8edc88bf7001e31b5f7f3
128] 
129[backup: remove the --no-backupdb command, the handling of "can't import sqlite", and the related tests, and change an error message to more correctly indicate failure to load the database from disk rather than failure to import sqlite module
130zooko@zooko.com**20090604173131
131 Ignore-this: 8200a9fdfc49243c280ecd1d0c44fa19
132 Fixes #728.
133] 
134[more refactoring: move get_all_serverids() and get_nickname_for_serverid() from Client to storage_broker
135warner@lothar.com**20090602030750] 
136[more storage_broker refactoring: downloader gets a broker instead of a client,
137warner@lothar.com**20090602022511
138 use Client.get_storage_broker() accessor instead of direct attribute access.
139] 
140[test_runner.py: remove test_client_no_noise: the issue in question is
141warner@lothar.com**20090601225007
142 ticketed in http://divmod.org/trac/ticket/2830 and doesn't need a Tahoe-side
143 change, plus this test fails on win32 for unrelated reasons (and test_client
144 is the place to think about the win32 issue).
145] 
146[remove plaintext-hashing code from the helper interface, to close #722
147warner@lothar.com**20090601224916
148 and deny the Helper the ability to mount a partial-information-guessing
149 attack. This will probably break compatibility between new clients and very
150 old (pre-1.0) helpers.
151] 
152[start to factor server-connection-management into a distinct 'StorageServerFarmBroker' object, separate from the client and the introducer. This is the starting point for #467: static server selection
153warner@lothar.com**20090601210604] 
154[mutable: catch and display first error, so code bugs which break all servers get displayed better
155warner@lothar.com**20090601210407] 
156[misc/run-with-pythonpath.py: exec() the child (on unix), to remove the intermediate process
157warner@lothar.com**20090601210137] 
158[setup: require pysqlite >= v2.0.5. if we are running on Python < 2.5
159zooko@zooko.com**20090604154548
160 Ignore-this: cf04f46079821df209d01dad2e24b40b
161] 
162[setup: add pysqlite and sqlite to get_package_versions()
163zooko@zooko.com**20090604153728
164 Ignore-this: a1dea7fabeab2b08fb0d8d462facdb4d
165] 
166[docs: small edit to about.html
167zooko@zooko.com**20090528233422
168 Ignore-this: 1cfbb1f8426ed6d63b2d3952e4464ddc
169] 
170[docs: add links to Tahoe-LAFS for Paranoids and Tahoe-LAFS for Corporates in about.html
171zooko@zooko.com**20090528232717
172 Ignore-this: 7b70baa700d6b6f6e9ceec4132efe5
173] 
174[docs: edit about.html and include network-and-reliance-topology.png (loaded from http://allmydata.org )
175zooko@zooko.com**20090527150916
176 Ignore-this: 44adc61cde8ced8be2f0a7dfc7d95dad
177] 
178[docs: a few more edits to network-and-reliance-topology.svg
179zooko@zooko.com**20090527150458
180 Ignore-this: 2eac8c33fe71be25ff809b399c6193c1
181] 
182[docs: update NEWS, relnotes.txt, CREDITS to mention WUI Style
183zooko@zooko.com**20090526233654
184 Ignore-this: 72d16ec833bc4a22af23d29ea1d5ff8b
185] 
186[docs: update network-and-reliance-topology.svg for beauty and clarity
187zooko@zooko.com**20090527031123
188 Ignore-this: 5510914849771900ac29b4312470d84
189] 
190[Modify markup of Tahoe web pages to be more amenable to styling; some minor changes of wording.
191Kevin Reid <kpreid@mac.com>**20090526232545
192 Ignore-this: 8845937f0df6c7ddc07abe3211428a6f
193] 
194[Tweak wording in directory page: not-read-only is "modifiable", mention creating a directory _in this directory_.
195Kevin Reid <kpreid@mac.com>**20090526232414
196 Ignore-this: f006ec52ba2051802e025a60bcface56
197] 
198[Comment on duplication of code/markup found during styling project.
199Kevin Reid <kpreid@mac.com>**20090503203442
200 Ignore-this: a4b7f9f0ab57d2c03be9ba761be8d854
201] 
202[Add CSS styles to spiff up the Tahoe WUI's appearance, particularly the welcome page and directories.
203Kevin Reid <kpreid@mac.com>**20090503203142
204 Ignore-this: 5c50af241c1a958b5180ef2b6a49f626
205] 
206[Link all Tahoe web pages to the /tahoe_css stylesheet which already exists.
207Kevin Reid <kpreid@mac.com>**20090503202533
208 Ignore-this: 2ea8d14d3168b9502cf39d5ea3f2f2a8
209] 
210[Fix broken link from Provisioning to Reliability page.
211Kevin Reid <kpreid@mac.com>**20090501191050
212 Ignore-this: 56dc1a5e659b70cc02dc4df7b5d518cd
213] 
214[docs: network-and-reliance-topology.svg: nicer server icons, mv out of the "specifications" subdir
215zooko@zooko.com**20090526165842
216 Ignore-this: 8f47ab3a0ab782c1f0d46e10bcaebe5b
217] 
218[accounting-overview.txt: more edits
219warner@lothar.com**20090523190359] 
220[accounting-overview.txt: small edits
221warner@lothar.com**20090523184011] 
222[_auto_deps.py: require foolscap-0.4.1, which adds an important fix for py2.4
223warner@lothar.com**20090523011103] 
224[immutable/encode.py: tolerate immediate _remove_shareholder by copying the
225warner@lothar.com**20090522184424
226 landlord list before iterating over it. This can probably only happen in unit
227 tests, but cleaning it up makes certain test failures easier to analyze.
228] 
229[switch to using RemoteException instead of 'wrapped' RemoteReferences. Should fix #653, the rref-EQ problem
230warner@lothar.com**20090522004632] 
231[switch all foolscap imports to use foolscap.api or foolscap.logging
232warner@lothar.com**20090522003823] 
233[_auto_deps.py: bump our foolscap dependency to 0.4.0, since I'm about to start using its new features
234warner@lothar.com**20090522002100] 
235[test_runner.py: fix minor typo
236warner@lothar.com**20090520033620] 
237[docs: update network-and-reliance-topology.svg
238zooko@zooko.com**20090526163105
239 Ignore-this: 2b864b4ed8743d4a15dfbb7eff3fa561
240] 
241[setup: fix bug (wrong import) in error message, as noticed by pyflakes
242zooko@zooko.com**20090519195642
243 Ignore-this: f1b9f8c00b46c1b5f2f20e5fc424f341
244] 
245[setup: fix trivial bug in recent patch to test base64.py at startup
246zooko@zooko.com**20090519195129
247 Ignore-this: f6be038f74b53ca69e7109fe34adfbc
248] 
249[setup: make Tahoe exit at startup with a useful error message if the base64.py module is buggy (fixes part of #710)
250zooko@zooko.com**20090519194555
251 Ignore-this: aa4d398235ddca8d417d61c9688e154
252] 
253[test_introducer.py: add a test for the python2.4.0/2.4.1 bug in base64.b32decode
254warner@lothar.com**20090519034101] 
255[immutable WriteBucketProxy: use pipeline to speed up uploads by overlapping roundtrips, for #392
256warner@lothar.com**20090518234422] 
257[util/pipeline.py: new utility class to manage size-limited work pipelines, for #392
258warner@lothar.com**20090518234326] 
259[docs: add a diagram that I'm about to show to the Boulder Linux Users Group: network-and-reliance-topology.svg
260zooko@zooko.com**20090514232059
261 Ignore-this: 2420c0a7c254c9f0f2349d9130490d33
262] 
263[tests: mark test_runner as coded in utf-8 instead of ascii
264zooko@zooko.com**20090507223151
265 Ignore-this: ccf1ba9e5a9b53602701a36f9fdb545e
266] 
267[tests: raise timeout on test_runner.RunNode.test_introducer from 120s to 240s, since it hit the 120s time-out on François Lenny-armv5tel
268zooko@zooko.com**20090507215012
269 Ignore-this: ba18fe6832ba255d4971e8f623ed7da5
270] 
271[setup: fix comment in setup.py
272zooko@zooko.com**20090507215003
273 Ignore-this: c46ef664630d52733138ef7fbc551c1c
274] 
275[docs: how_to_make_a_tahoe_release.txt: a couple of small edits
276zooko@zooko.com**20090507214932
277 Ignore-this: ae92aa835ad369f4b9e6e49d681957a3
278] 
279[.darcs-boringfile: also ignore .gitignore
280warner@allmydata.com**20090415210550
281 Ignore-this: d29db314a1e506f6240859559436b4c3
282] 
283[.darcs-boringfile: ignore .git, I'm starting to play around with it
284warner@allmydata.com**20090415205929
285 Ignore-this: 89234453516483c9586cd6e1351e88b5
286] 
287[fix quicktest: stop using setuptools, add misc/run-with-pythonpath.py, to make it run faster
288warner@lothar.com**20090414201400] 
289[TAG allmydata-tahoe-1.4.1
290zooko@zooko.com**20090414025636
291 Ignore-this: de78fc32364c83e9f4e26b5abcfdea4a
292] 
293Patch bundle hash:
2944c155d5d10ce71e7847030e7ddfdf575cc2129a2