~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Martin Pool
  • Date: 2006-03-20 09:02:42 UTC
  • mfrom: (1610.1.11 bzr.mbp.integration)
  • mto: This revision was merged to the branch mainline in revision 1616.
  • Revision ID: mbp@sourcefrog.net-20060320090242-b1e492be1b6bcb7e
[merge] my previous work, including pycurl regression

Show diffs side-by-side

added added

removed removed

Lines of Context:
524
524
        import pwd
525
525
        uid = os.getuid()
526
526
        w = pwd.getpwuid(uid)
527
 
        gecos = w.pw_gecos.decode(bzrlib.user_encoding)
528
 
        username = w.pw_name.decode(bzrlib.user_encoding)
 
527
 
 
528
        try:
 
529
            gecos = w.pw_gecos.decode(bzrlib.user_encoding)
 
530
            username = w.pw_name.decode(bzrlib.user_encoding)
 
531
        except UnicodeDecodeError:
 
532
            # We're using pwd, therefore we're on Unix, so /etc/passwd is ok.
 
533
            raise errors.BzrError("Can't decode username in " \
 
534
                    "/etc/passwd as %s." % bzrlib.user_encoding)
 
535
 
529
536
        comma = gecos.find(',')
530
537
        if comma == -1:
531
538
            realname = gecos
536
543
 
537
544
    except ImportError:
538
545
        import getpass
539
 
        realname = username = getpass.getuser().decode(bzrlib.user_encoding)
 
546
        try:
 
547
            realname = username = getpass.getuser().decode(bzrlib.user_encoding)
 
548
        except UnicodeDecodeError:
 
549
            raise errors.BzrError("Can't decode username as %s." % \
 
550
                    bzrlib.user_encoding)
540
551
 
541
552
    return realname, (username + '@' + socket.gethostname())
542
553