Patchwork D2903: utils: add isauthorwellformed function

login
register
mail settings
Submitter phabricator
Date March 20, 2018, 5:56 p.m.
Message ID <differential-rev-PHID-DREV-i6pxfp4irmlfhhqgymnx-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/29677/
State Superseded
Headers show

Comments

phabricator - March 20, 2018, 5:56 p.m.
sheehan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Adds a function to determine if an author field is formatted
  correctly (ie "Contributor Name <something@something.com>")

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




To: sheehan, #hg-reviewers
Cc: mercurial-devel
phabricator - March 21, 2018, 8:57 a.m.
lothiraldan added subscribers: pulkit, lothiraldan.
lothiraldan added a comment.


  We are trying to slim down util.py, do you think it would be possible to put it in a new module, something like `utils/authorutil.py`?
  
  @pulkit do we need the b prefix when calling `re.compile` for Python3 compat?

REPOSITORY
  rHG Mercurial

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

To: sheehan, #hg-reviewers
Cc: lothiraldan, pulkit, mercurial-devel
phabricator - March 21, 2018, 11:03 a.m.
pulkit added a comment.


  In https://phab.mercurial-scm.org/D2903#46731, @lothiraldan wrote:
  
  > @pulkit do we need the b prefix when calling `re.compile` for Python3 compat?
  
  
  Not necessary, transformer will do that but it will be good adding the b'' prefix.

REPOSITORY
  rHG Mercurial

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

To: sheehan, #hg-reviewers
Cc: lothiraldan, pulkit, mercurial-devel
phabricator - March 21, 2018, 1:03 p.m.
yuja added a comment.


  > We are trying to slim down util.py, do you think it would be possible to
  >  put it in a new module, something like `utils/authorutil.py`?
  
  +1. It could be `utils/stringutil.py` if "author" is too specific.
  
  Some potential functions that should be moved:
  
  - stringmatcher() (if "stringutil")
  - shortuser()
  - emailuser()
  - email()
  - ellipsis() (if "stringutil")
  - escapestr() (if "stringutil")
  - unescapestr() (if "stringutil")
  - forcebytestr() (if "stringutil")
  - uirepr() (maybe if "stringutil")
  - wrap() (maybe if "stringutil")

REPOSITORY
  rHG Mercurial

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

To: sheehan, #hg-reviewers
Cc: yuja, lothiraldan, pulkit, mercurial-devel
phabricator - March 21, 2018, 1:12 p.m.
yuja added a comment.


  > Not necessary, transformer will do that but it will be good adding the b'' prefix.
  
  br'' is preferred here because Python 3 is getting stricter on invalid `\<char>`
  escapes.

REPOSITORY
  rHG Mercurial

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

To: sheehan, #hg-reviewers
Cc: yuja, lothiraldan, pulkit, mercurial-devel
phabricator - March 22, 2018, 3:10 p.m.
yuja added a comment.


  Done.
  https://www.mercurial-scm.org/pipermail/mercurial-devel/2018-March/114254.html

REPOSITORY
  rHG Mercurial

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

To: sheehan, #hg-reviewers
Cc: yuja, lothiraldan, pulkit, mercurial-devel
phabricator - March 31, 2018, 2:03 p.m.
sheehan abandoned this revision.
sheehan added a comment.


  Abandoning, this was landed as another differential.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2615,6 +2615,12 @@ 
         r = None
     return author[author.find('<') + 1:r]
 
+_correctauthorformat = re.compile('^[^<]+\s\<[^<>]+@[^<>]+\>$')
+def isauthorwellformed(author):
+    '''Return True if the author field is well formed
+    (ie "Contributor Name <contrib@email.dom>")'''
+    return bool(_correctauthorformat.match(author))
+
 def ellipsis(text, maxlength=400):
     """Trim string to at most maxlength (default: 400) columns in display."""
     return encoding.trim(text, maxlength, ellipsis='...')