/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/plugins/fastimport/user_mapper.py

  • Committer: Breezy landing bot
  • Author(s): Jelmer Vernooij
  • Date: 2018-07-04 12:50:55 UTC
  • mfrom: (7027.2.8 git-fixes)
  • Revision ID: breezy.the.bot@gmail.com-20180704125055-8nni25pn2439p48v
Fix eol handling in knits on Python 3, port fastimport plugin to Python 3.

Merged from https://code.launchpad.net/~jelmer/brz/fastimport-fixes/+merge/348924

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
 
16
16
from __future__ import absolute_import
17
17
 
18
 
from email import Utils
 
18
try:
 
19
    from email.utils import parseaddr
 
20
except ImportError:
 
21
    from email.Utils import parseaddr
19
22
 
20
23
 
21
24
class UserMapper(object):
43
46
        self._default_domain = None
44
47
        for line in lines:
45
48
            line = line.strip()
46
 
            if len(line) == 0 or line.startswith('#'):
 
49
            if len(line) == 0 or line.startswith(b'#'):
47
50
                continue
48
 
            old, new = line.split('=', 1)
 
51
            old, new = line.split(b'=', 1)
49
52
            old = old.strip()
50
53
            new = new.strip()
51
 
            if old == '@':
 
54
            if old == b'@':
52
55
                self._default_domain = new
53
56
                continue
54
57
            # Parse each id into a name and email address
58
61
            self._user_map[(old_name, old_email)] = (new_name, new_email)
59
62
 
60
63
    def _parse_id(self, id):
61
 
        if id.find('<') == -1:
62
 
            return id, ""
 
64
        if id.find(b'<') == -1:
 
65
            return id, b""
63
66
        else:
64
 
            return Utils.parseaddr(id)
 
67
            return parseaddr(id)
65
68
 
66
69
    def map_name_and_email(self, name, email):
67
70
        """Map a name and an email to the preferred name and email.
75
78
        except KeyError:
76
79
            new_name = name
77
80
            if self._default_domain and not email:
78
 
                new_email = "%s@%s" % (name, self._default_domain)
 
81
                new_email = b"%s@%s" % (name, self._default_domain)
79
82
            else:
80
83
                new_email = email
81
84
        return new_name, new_email