~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

- add extract_email_address

Show diffs side-by-side

added added

removed removed

Lines of Context:
159
159
    """Return just the email component of a username."""
160
160
    e = _get_user_id(branch)
161
161
    if e:
162
 
        m = re.search(r'[\w+.-]+@[\w+.-]+', e)
163
 
        if not m:
164
 
            raise BzrError("%r doesn't seem to contain "
165
 
                           "a reasonable email address" % e)
166
 
        return m.group(0)
167
 
 
 
162
        return extract_email_address(e)
168
163
    return _auto_user_id()[1]
169
164
 
170
165
 
 
166
def extract_email_address(e):
 
167
    """Return just the address part of an email string.
 
168
    
 
169
    That is just the user@domain part, nothing else. 
 
170
    This part is required to contain only ascii characters.
 
171
    If it can't be extracted, raises an error.
 
172
    
 
173
    >>> extract_email_address('Jane Tester <jane@test.com>')
 
174
    "jane@test.com"
 
175
    """
 
176
    m = re.search(r'[\w+.-]+@[\w+.-]+', e)
 
177
    if not m:
 
178
        raise BzrError("%r doesn't seem to contain "
 
179
                       "a reasonable email address" % e)
 
180
    return m.group(0)