[PATCH] encoding fix
Jan Hudec
bulb at ucw.cz
Tue Apr 4 18:57:46 BST 2006
On Tue, Apr 04, 2006 at 08:43:42 +0200, Olaf Conradi wrote:
> On 04/04/06, Robert Collins <robertc at robertcollins.net> wrote:
> > On Mon, 2006-03-27 at 12:51 +0200, Olaf Conradi wrote:
> > > === modified file 'a/bzrlib/osutils.py'
> > > --- a/bzrlib/osutils.py
> > > +++ b/bzrlib/osutils.py
> > > @@ -186,7 +186,7 @@
> > > # choke on a Unicode string containing a relative path if
> > > # os.getcwd() returns a non-sys.getdefaultencoding()-encoded
> > > # string.
> > > - _fs_enc = sys.getfilesystemencoding()
> > > + _fs_enc = sys.getfilesystemencoding() or 'ascii'
> > > def abspath(path):
> > > return os.path.abspath(path.encode(_fs_enc)).decode(_fs_enc)
> >
> > We have multiple uses of getfilesystemencoding in bzrlib. We should
> > consolidate them so we dont have shotgun surgery with bugs like this.
>
> There is only one place in bzrlib where getfilesystemencoding is
> called. Other two places are in test cases (test_selftest.py and
> test_msgeditor.py).
>
> > Also, a test case is -strongly- desired - encoding issues are some of
> > the most pernacious bugs we encounter.
>
> I would not know how to make a test case for such a lowlevel system
> function. It's not like you can set it. Either your system returns
> None or a proper encoding. I think it gets triggered on openbsd
> systems.
Sure you can:
import sys
def dummy_getfilesystemencoding():
return 'whatever_you_want'
sys.getfilesystemencoding = dummy_getfilesystemencoding
This is a dynamic language!
(in the test-suite it's a bit more tricky, because you have to actually
trigger the call to it and you must reinstate the original version, but this
is the idea)
The other question is, whether the function could ever return an invalid
encoding (the low-level locale stuff will silently return completely bogus
data, so it depends on how well python sanitizes them)
> > Lastly, johns encoding branch is the penultimate fix for this, I'm going
> > to see about getting it passing tests today.
>
> OK, hope you add a check for this function returning None, as the
> pythondoc mentions None can be retuned.
>
> Cheers
> -Olaf
>
--
Jan 'Bulb' Hudec <bulb at ucw.cz>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 191 bytes
Desc: Digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20060404/6c066c11/attachment.pgp
More information about the bazaar
mailing list