Patchwork D2960: stringutil: move person function from templatefilters

login
register
mail settings
Submitter phabricator
Date March 30, 2018, 12:56 p.m.
Message ID <a9cb55bb24d102919f1fc6f25982154d@localhost.localdomain>
Download mbox | patch
Permalink /patch/29957/
State Not Applicable
Headers show

Comments

phabricator - March 30, 2018, 12:56 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGfb7140f1d09d: stringutil: move person function from templatefilters (authored by sheehan, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D2960?vs=7360&id=7380#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2960?vs=7360&id=7380

REVISION DETAIL
  https://phab.mercurial-scm.org/D2960

AFFECTED FILES
  mercurial/templatefilters.py
  mercurial/utils/stringutil.py

CHANGE DETAILS




To: sheehan, #hg-reviewers, av6, yuja
Cc: av6, mercurial-devel

Patch

diff --git a/mercurial/utils/stringutil.py b/mercurial/utils/stringutil.py
--- a/mercurial/utils/stringutil.py
+++ b/mercurial/utils/stringutil.py
@@ -131,6 +131,33 @@ 
         r = None
     return author[author.find('<') + 1:r]
 
+def person(author):
+    """Returns the name before an email address,
+    interpreting it as per RFC 5322
+
+    >>> person(b'foo@bar')
+    'foo'
+    >>> person(b'Foo Bar <foo@bar>')
+    'Foo Bar'
+    >>> person(b'"Foo Bar" <foo@bar>')
+    'Foo Bar'
+    >>> person(b'"Foo \"buz\" Bar" <foo@bar>')
+    'Foo "buz" Bar'
+    >>> # The following are invalid, but do exist in real-life
+    ...
+    >>> person(b'Foo "buz" Bar <foo@bar>')
+    'Foo "buz" Bar'
+    >>> person(b'"Foo Bar <foo@bar>')
+    'Foo Bar'
+    """
+    if '@' not in author:
+        return author
+    f = author.find('<')
+    if f != -1:
+        return author[:f].strip(' "').replace('\\"', '"')
+    f = author.find('@')
+    return author[:f].replace('.', ' ')
+
 _correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
 
 def isauthorwellformed(author):
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -292,29 +292,8 @@ 
 def person(author):
     """Any text. Returns the name before an email address,
     interpreting it as per RFC 5322.
-
-    >>> person(b'foo@bar')
-    'foo'
-    >>> person(b'Foo Bar <foo@bar>')
-    'Foo Bar'
-    >>> person(b'"Foo Bar" <foo@bar>')
-    'Foo Bar'
-    >>> person(b'"Foo \"buz\" Bar" <foo@bar>')
-    'Foo "buz" Bar'
-    >>> # The following are invalid, but do exist in real-life
-    ...
-    >>> person(b'Foo "buz" Bar <foo@bar>')
-    'Foo "buz" Bar'
-    >>> person(b'"Foo Bar <foo@bar>')
-    'Foo Bar'
     """
-    if '@' not in author:
-        return author
-    f = author.find('<')
-    if f != -1:
-        return author[:f].strip(' "').replace('\\"', '"')
-    f = author.find('@')
-    return author[:f].replace('.', ' ')
+    return stringutil.person(author)
 
 @templatefilter('revescape')
 def revescape(text):