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