~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Andrew Bennetts
  • Date: 2008-01-04 03:12:11 UTC
  • mfrom: (3164 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3320.
  • Revision ID: andrew.bennetts@canonical.com-20080104031211-wy4uxo2j4elvip1j
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
862
862
    return realname, (username + '@' + socket.gethostname())
863
863
 
864
864
 
 
865
def parse_username(username):
 
866
    """Parse e-mail username and return a (name, address) tuple."""
 
867
    match = re.match(r'(.*?)\s*<?([\w+.-]+@[\w+.-]+)>?', username)
 
868
    if match is None:
 
869
        return (username, '')
 
870
    else:
 
871
        return (match.group(1), match.group(2))
 
872
 
 
873
 
865
874
def extract_email_address(e):
866
875
    """Return just the address part of an email string.
867
 
    
 
876
 
868
877
    That is just the user@domain part, nothing else. 
869
878
    This part is required to contain only ascii characters.
870
879
    If it can't be extracted, raises an error.
871
 
    
 
880
 
872
881
    >>> extract_email_address('Jane Tester <jane@test.com>')
873
882
    "jane@test.com"
874
883
    """
875
 
    m = re.search(r'[\w+.-]+@[\w+.-]+', e)
876
 
    if not m:
 
884
    name, email = parse_username(e)
 
885
    if not email:
877
886
        raise errors.NoEmailInUsername(e)
878
 
    return m.group(0)
 
887
    return email
879
888
 
880
889
 
881
890
class TreeConfig(IniBasedConfig):