[Pkg-bazaar-commits] ./bzr/unstable r251: - factor out locale.getpreferredencoding()
mbp at sourcefrog.net
mbp at sourcefrog.net
Fri Apr 10 07:43:56 UTC 2009
------------------------------------------------------------
revno: 251
committer: mbp at sourcefrog.net
timestamp: Fri 2005-04-15 09:43:01 +1000
message:
- factor out locale.getpreferredencoding()
- fix problems with EMAIL not being defined
modified:
bzrlib/__init__.py
bzrlib/commands.py
bzrlib/osutils.py
-------------- next part --------------
=== modified file 'bzrlib/__init__.py'
--- a/bzrlib/__init__.py 2005-04-12 06:20:20 +0000
+++ b/bzrlib/__init__.py 2005-04-14 23:43:01 +0000
@@ -36,6 +36,8 @@
IGNORE_FILENAME = ".bzrignore"
+import locale
+user_encoding = locale.getpreferredencoding()
__copyright__ = "Copyright 2005 Canonical Development Ltd."
__author__ = "Martin Pool <mbp at canonical.com>"
=== modified file 'bzrlib/commands.py'
--- a/bzrlib/commands.py 2005-04-14 07:31:35 +0000
+++ b/bzrlib/commands.py 2005-04-14 23:43:01 +0000
@@ -936,9 +936,7 @@
logging and error handling.
"""
- import locale
- enc = locale.getpreferredencoding()
- argv = [a.decode(enc) for a in argv]
+ argv = [a.decode(bzrlib.user_encoding) for a in argv]
try:
args, opts = parse_args(argv[1:])
=== modified file 'bzrlib/osutils.py'
--- a/bzrlib/osutils.py 2005-04-13 04:43:23 +0000
+++ b/bzrlib/osutils.py 2005-04-14 23:43:01 +0000
@@ -21,6 +21,7 @@
from errors import bailout, BzrError
from trace import mutter
+import bzrlib
def make_readonly(filename):
"""Make a filename read-only."""
@@ -136,20 +137,18 @@
Only used when none is set in the environment.
"""
- import socket, locale
+ import socket
# XXX: Any good way to get real user name on win32?
# XXX: can the FQDN be non-ascii?
- enc = locale.getpreferredencoding()
-
try:
import pwd
uid = os.getuid()
w = pwd.getpwuid(uid)
- gecos = w.pw_gecos.decode(enc)
- username = w.pw_name.decode(enc)
+ gecos = w.pw_gecos.decode(bzrlib.user_encoding)
+ username = w.pw_name.decode(bzrlib.user_encoding)
comma = gecos.find(',')
if comma == -1:
realname = gecos
@@ -160,7 +159,8 @@
except ImportError:
import getpass
- return '', (getpass.getuser().decode(enc) + '@' + socket.getfqdn())
+ getpass.getuser().decode(bzrlib.user_encoding)
+ return '', (username + '@' + socket.getfqdn())
@@ -174,10 +174,9 @@
:todo: Allow taking it from a dotfile to help people on windows
who can't easily set variables.
"""
- import locale
e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
if e:
- return e.decode(locale.getpreferredencoding())
+ return e.decode(bzrlib.user_encoding)
name, email = auto_user_id()
if name:
@@ -190,9 +189,9 @@
def user_email():
"""Return just the email component of a username."""
e = os.environ.get('BZREMAIL') or os.environ.get('EMAIL')
- import locale
- e = e.decode(locale.getpreferredencoding())
if e:
+ e = e.decode(bzrlib.user_encoding)
+
m = _EMAIL_RE.search(e)
if not m:
bailout('%r is not a reasonable email address' % e)
More information about the Pkg-bazaar-commits
mailing list