mercurial/utils/stringutil.py
changeset 37155 fb7140f1d09d
parent 37154 f8e1f48de118
child 37210 2a2ce93e12f4
equal deleted inserted replaced
37154:f8e1f48de118 37155:fb7140f1d09d
   129     r = author.find('>')
   129     r = author.find('>')
   130     if r == -1:
   130     if r == -1:
   131         r = None
   131         r = None
   132     return author[author.find('<') + 1:r]
   132     return author[author.find('<') + 1:r]
   133 
   133 
       
   134 def person(author):
       
   135     """Returns the name before an email address,
       
   136     interpreting it as per RFC 5322
       
   137 
       
   138     >>> person(b'foo@bar')
       
   139     'foo'
       
   140     >>> person(b'Foo Bar <foo@bar>')
       
   141     'Foo Bar'
       
   142     >>> person(b'"Foo Bar" <foo@bar>')
       
   143     'Foo Bar'
       
   144     >>> person(b'"Foo \"buz\" Bar" <foo@bar>')
       
   145     'Foo "buz" Bar'
       
   146     >>> # The following are invalid, but do exist in real-life
       
   147     ...
       
   148     >>> person(b'Foo "buz" Bar <foo@bar>')
       
   149     'Foo "buz" Bar'
       
   150     >>> person(b'"Foo Bar <foo@bar>')
       
   151     'Foo Bar'
       
   152     """
       
   153     if '@' not in author:
       
   154         return author
       
   155     f = author.find('<')
       
   156     if f != -1:
       
   157         return author[:f].strip(' "').replace('\\"', '"')
       
   158     f = author.find('@')
       
   159     return author[:f].replace('.', ' ')
       
   160 
   134 _correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
   161 _correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
   135 
   162 
   136 def isauthorwellformed(author):
   163 def isauthorwellformed(author):
   137     '''Return True if the author field is well formed
   164     '''Return True if the author field is well formed
   138     (ie "Contributor Name <contrib@email.dom>")
   165     (ie "Contributor Name <contrib@email.dom>")