/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/osutils.py

  • Committer: Andrew Bennetts
  • Date: 2008-02-18 23:26:27 UTC
  • mto: This revision was merged to the branch mainline in revision 3756.
  • Revision ID: andrew.bennetts@canonical.com-20080218232627-v6cuj0596nh3rw56
Fix test suite, mainly weeding out uses of bzrlib.user_encoding.

Show diffs side-by-side

added added

removed removed

Lines of Context:
422
422
 
423
423
    This attempts to check both sys.stdout and sys.stdin to see
424
424
    what encoding they are in, and if that fails it falls back to
425
 
    bzrlib.user_encoding.
 
425
    osutils.get_user_encoding().
426
426
    The problem is that on Windows, locale.getpreferredencoding()
427
427
    is not the same encoding as that used by the console:
428
428
    http://mail.python.org/pipermail/python-list/2003-May/162357.html
435
435
    if not output_encoding:
436
436
        input_encoding = getattr(sys.stdin, 'encoding', None)
437
437
        if not input_encoding:
438
 
            output_encoding = bzrlib.user_encoding
439
 
            mutter('encoding stdout as bzrlib.user_encoding %r', output_encoding)
 
438
            output_encoding = get_user_encoding()
 
439
            mutter('encoding stdout as osutils.get_user_encoding() %r',
 
440
                   output_encoding)
440
441
        else:
441
442
            output_encoding = input_encoding
442
443
            mutter('encoding stdout as sys.stdin encoding %r', output_encoding)
444
445
        mutter('encoding stdout as sys.stdout encoding %r', output_encoding)
445
446
    if output_encoding == 'cp0':
446
447
        # invalid encoding (cp0 means 'no codepage' on Windows)
447
 
        output_encoding = bzrlib.user_encoding
 
448
        output_encoding = get_user_encoding()
448
449
        mutter('cp0 is invalid encoding.'
449
 
               ' encoding stdout as bzrlib.user_encoding %r', output_encoding)
 
450
               ' encoding stdout as osutils.get_user_encoding() %r',
 
451
               output_encoding)
450
452
    # check encoding
451
453
    try:
452
454
        codecs.lookup(output_encoding)
454
456
        sys.stderr.write('bzr: warning:'
455
457
                         ' unknown terminal encoding %s.\n'
456
458
                         '  Using encoding %s instead.\n'
457
 
                         % (output_encoding, bzrlib.user_encoding)
 
459
                         % (output_encoding, get_user_encoding())
458
460
                        )
459
 
        output_encoding = bzrlib.user_encoding
 
461
        output_encoding = get_user_encoding()
460
462
 
461
463
    return output_encoding
462
464
 
1096
1098
            del os.environ[env_variable]
1097
1099
    else:
1098
1100
        if isinstance(value, unicode):
1099
 
            value = value.encode(bzrlib.user_encoding)
 
1101
            value = value.encode(get_user_encoding())
1100
1102
        os.environ[env_variable] = value
1101
1103
    return orig_val
1102
1104