Beginner: problems with the win packages
Alexander Belchenko
bialix at ukr.net
Fri Nov 10 17:23:33 GMT 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Marcos Chaves пишет:
> On 11/9/06, Alexander Belchenko <bialix at ukr.net> wrote:
>> For standalone bzr.exe in folder where bzr installed there is file
>> start_bzr.bat. You can add command
>>
>> @chcp 1252
>>
>> to the start of this batch file. And then every time open console for
>> bzr session either via Start -> Programs -> Bazaar menu or via Context
>> menu in Explorer. I hope it works for you.
>
> Hi Alexander,
>
> thanks for the info. I was thinking about a workaround similar to
> this, just to get bzr to work for me.
>
>> In long term I think we need explicitly check for codepage 'cp0' and
>> treat them as 'ascii' and/or fallback to bzrlib.user_encoding that seems
>> to have valid value. John, what you think about this patch:
>>
>> === modified file 'bzrlib/osutils.py'
>> - --- bzrlib/osutils.py 2006-11-02 07:29:02 +0000
>> +++ bzrlib/osutils.py 2006-11-09 07:53:01 +0000
>> @@ -372,6 +372,10 @@
>> mutter('encoding stdout as sys.stdin encoding %r',
>> output_encoding)
>> else:
>> mutter('encoding stdout as sys.stdout encoding %r',
>> output_encoding)
>> + if output_encoding == 'cp0':
>> + output_encoding = bzrlib.user_encoding
>> + mutter('cp0 is invalid encoding.'
>> + ' encoding stdout as bzrlib.user_encoding %r',
>> output_encoding)
>> return output_encoding
>>
>>
>> @@ -1085,7 +1089,7 @@
>> " Continuing with ascii encoding.\n"
>> % (e, os.environ.get('LANG')))
>>
>> - - if _cached_user_encoding is None:
>> + if _cached_user_encoding in (None, 'cp0'):
>> _cached_user_encoding = 'ascii'
>> return _cached_user_encoding
>>
>>
>> Marcos, can you try this patch on your system? Is it works for you?
>>
>
> I tried your patch, and it works for me. The second part of the patch
> (if _cached_user_encoding...) did not have any effect - the first part
> solved the problem.
Second part needed because we need to ensure that we always use valid
encoding.
>
> Your patch is similar to something that I was trying, but I still
> didn't read all the posts about the problems that lead to the use this
> mechanism to identify the best encoding, so I don't know if this is
> appropriate. What I don't like about my approach (below) is that I
> don't think it would be nice to list all the exceptions that people
> find (if codepage == 'cp0'... ops, but then another user has 'cp1'...
> and the other one just talked about 'cp2'...). What do you think?
>
> --- bzrlib-orig/osutils.py 2006-11-09 12:14:10.000000000 -0200
> +++ bzrlib/osutils.py 2006-11-09 12:14:04.000000000 -0200
> @@ -364,9 +364,9 @@
> cp1252, but the console is cp437
> """
> output_encoding = getattr(sys.stdout, 'encoding', None)
> - if not output_encoding:
> + if not output_encoding or output_encoding == 'cp0':
> input_encoding = getattr(sys.stdin, 'encoding', None)
> - if not input_encoding:
> + if not input_encoding or input_encoding == 'cp0':
> output_encoding = bzrlib.user_encoding
> mutter('encoding stdout as bzrlib.user_encoding %r',
> output_encoding)
> else:
My first patch check for 'cp0' at the end of function
get_terminal_encoding() so we don't need to duplicate checks.
But if you talk about 'cp1' or so (that seems impossible) then we can be
*really* paranoid and do following checks:
=== modified file 'bzrlib/osutils.py'
- --- bzrlib/osutils.py 2006-11-02 07:29:02 +0000
+++ bzrlib/osutils.py 2006-11-10 17:12:33 +0000
@@ -25,6 +25,7 @@
from bzrlib.lazy_import import lazy_import
lazy_import(globals(), """
+import codecs
import errno
from ntpath import (abspath as _nt_abspath,
join as _nt_join,
@@ -372,6 +373,18 @@
mutter('encoding stdout as sys.stdin encoding %r',
output_encoding)
else:
mutter('encoding stdout as sys.stdout encoding %r',
output_encoding)
+
+ # check encoding
+ try:
+ codecs.lookup(output_encoding)
+ except LookupError:
+ mutter('%s is invalid encoding.'
+ ' encoding stdout as'
+ ' bzrlib.user_encoding %s', (output_encoding,
+ bzrlib.user_encoding)
+ )
+ output_encoding = bzrlib.user_encoding
+
return output_encoding
@@ -1087,6 +1100,13 @@
if _cached_user_encoding is None:
_cached_user_encoding = 'ascii'
+ else:
+ # check encoding
+ try:
+ codecs.lookup(_cached_user_encoding)
+ except LookupError:
+ _cached_user_encoding = 'ascii'
+
return _cached_user_encoding
But I think it's superfluous.
Alexander
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFFVLWUzYr338mxwCURAgNjAKCCSK2xg1UL5YXPt4dFWXXBDEP5RgCggEvB
EJasJf1U2LBxea/kOMO/T6o=
=FNyr
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list