summaryrefslogtreecommitdiff
path: root/lib/git/actor.py
blob: ed21d8ba7decf3915ccbd2420842a631cc64b6a9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import re

class Actor(object):
    def __init__(self, name, email):
        self.name = name
        self.email = email

    def __str__(self):
        return self.name

    def __repr__(self):
        return '<GitPython.Actor "%s <%s>">' % (self.name, self.email)

    @classmethod
    def from_string(cls, string):
        """
        Create an Actor from a string.

        ``str``
            is the string, which is expected to be in regular git format

        Format
            John Doe <jdoe@example.com>

        Returns
            Actor
        """
        if re.search(r'<.+>', string):
            m = re.search(r'(.*) <(.+?)>', string)
            name, email = m.groups()
            return Actor(name, email)
        else:
            return Actor(string, None)