279
279
# We need to iterate until no more refs appear ({{foo}} will need two
280
280
# iterations for example).
283
raw_chunks = self.option_ref_re.split(result)
285
import pdb; pdb.set_trace()
282
raw_chunks = self.option_ref_re.split(result)
286
283
if len(raw_chunks) == 1:
287
284
# Shorcut the trivial case: no refs
444
441
the concrete policy type is checked, and finally
445
442
$EMAIL is examined.
446
443
If no username can be found, errors.NoWhoami exception is raised.
448
TODO: Check it's reasonably well-formed.
450
445
v = os.environ.get('BZR_EMAIL')
452
447
return v.decode(osutils.get_user_encoding())
454
448
v = self._get_user_id()
458
451
v = os.environ.get('EMAIL')
460
453
return v.decode(osutils.get_user_encoding())
454
name, email = _auto_user_id()
456
return '%s <%s>' % (name, email)
462
459
raise errors.NoWhoami()
464
461
def ensure_username(self):
1410
1407
return os.path.expanduser('~/.cache')
1410
def _get_default_mail_domain():
1411
"""If possible, return the assumed default email domain.
1413
:returns: string mail domain, or None.
1415
if sys.platform == 'win32':
1416
# No implementation yet; patches welcome
1419
f = open('/etc/mailname')
1420
except (IOError, OSError), e:
1423
domain = f.read().strip()
1429
def _auto_user_id():
1430
"""Calculate automatic user identification.
1432
:returns: (realname, email), either of which may be None if they can't be
1435
Only used when none is set in the environment or the id file.
1437
This only returns an email address if we can be fairly sure the
1438
address is reasonable, ie if /etc/mailname is set on unix.
1440
This doesn't use the FQDN as the default domain because that may be
1441
slow, and it doesn't use the hostname alone because that's not normally
1442
a reasonable address.
1444
if sys.platform == 'win32':
1445
# No implementation to reliably determine Windows default mail
1446
# address; please add one.
1449
default_mail_domain = _get_default_mail_domain()
1450
if not default_mail_domain:
1456
w = pwd.getpwuid(uid)
1458
mutter('no passwd entry for uid %d?' % uid)
1461
# we try utf-8 first, because on many variants (like Linux),
1462
# /etc/passwd "should" be in utf-8, and because it's unlikely to give
1463
# false positives. (many users will have their user encoding set to
1464
# latin-1, which cannot raise UnicodeError.)
1466
gecos = w.pw_gecos.decode('utf-8')
1468
except UnicodeError:
1470
encoding = osutils.get_user_encoding()
1471
gecos = w.pw_gecos.decode(encoding)
1472
except UnicodeError, e:
1473
mutter("cannot decode passwd entry %s" % w)
1476
username = w.pw_name.decode(encoding)
1477
except UnicodeError, e:
1478
mutter("cannot decode passwd entry %s" % w)
1481
comma = gecos.find(',')
1485
realname = gecos[:comma]
1487
return realname, (username + '@' + default_mail_domain)
1413
1490
def parse_username(username):
1414
1491
"""Parse e-mail username and return a (name, address) tuple."""
1415
1492
match = re.match(r'(.*?)\s*<?([\w+.-]+@[\w+.-]+)>?', username)