Submitter | phabricator |
---|---|
Date | March 27, 2018, 4:04 p.m. |
Message ID | <differential-rev-PHID-DREV-ugoaadxcmv3ypu7wqrkj-req@phab.mercurial-scm.org> |
Download | mbox | patch |
Permalink | /patch/29909/ |
State | Superseded |
Headers | show |
Comments
av6 added inline comments. INLINE COMMENTS > stringutil.py:310 > + ''' > + return bool(_correctauthorformat.match(author)) Nit: `is not None` is more pythonic. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2959 To: sheehan, #hg-reviewers Cc: av6, mercurial-devel
yuja requested changes to this revision. yuja added a comment. This revision now requires changes to proceed. Looks mostly good, but can you fix these nits? INLINE COMMENTS > stringutil.py:290 > + > +_correctauthorformat = remod.compile('^[^<]+\s\<[^<>]+@[^<>]+\>$') > +def isauthorwellformed(author): Nit: add br'' for Python 3 compatibility. > stringutil.py:295 > + > + >>> isauthorwellformed('Good Author <good@author.com>') > + True b'' for Python 3 compatibility. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D2959 To: sheehan, #hg-reviewers, yuja Cc: yuja, 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 @@ -286,3 +286,25 @@ If s is not a valid boolean, returns None. """ return _booleans.get(s.lower(), None) + +_correctauthorformat = remod.compile('^[^<]+\s\<[^<>]+@[^<>]+\>$') +def isauthorwellformed(author): + '''Return True if the author field is well formed + (ie "Contributor Name <contrib@email.dom>") + + >>> isauthorwellformed('Good Author <good@author.com>') + True + >>> isauthorwellformed('Author <good@author.com>') + True + >>> isauthorwellformed('Bad Author') + False + >>> isauthorwellformed('Bad Author <author@author.com') + False + >>> isauthorwellformed('Bad Author author@author.com') + False + >>> isauthorwellformed('<author@author.com>') + False + >>> isauthorwellformed('Bad Author <author>') + False + ''' + return bool(_correctauthorformat.match(author))