D2959: stringutil: add isauthorwellformed function

2018-03-30 Thread sheehan (Connor Sheehan)
This revision was automatically updated to reflect the committed changes.
Closed by commit rHGf8e1f48de118: stringutil: add isauthorwellformed function 
(authored by sheehan, committed by ).

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D2959?vs=7359&id=7379#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2959?vs=7359&id=7379

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

AFFECTED FILES
  mercurial/utils/stringutil.py

CHANGE DETAILS

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,29 @@
 r = None
 return author[author.find('<') + 1:r]
 
+_correctauthorformat = remod.compile(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
+
+def isauthorwellformed(author):
+'''Return True if the author field is well formed
+(ie "Contributor Name ")
+
+>>> isauthorwellformed(b'Good Author ')
+True
+>>> isauthorwellformed(b'Author ')
+True
+>>> isauthorwellformed(b'Bad Author')
+False
+>>> isauthorwellformed(b'Bad Author >> isauthorwellformed(b'Bad Author aut...@author.com')
+False
+>>> isauthorwellformed(b'')
+False
+>>> isauthorwellformed(b'Bad Author ')
+False
+'''
+return _correctauthorformat.match(author) is not None
+
 def ellipsis(text, maxlength=400):
 """Trim string to at most maxlength (default: 400) columns in display."""
 return encoding.trim(text, maxlength, ellipsis='...')



To: sheehan, #hg-reviewers, yuja
Cc: yuja, av6, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2959: stringutil: add isauthorwellformed function

2018-03-29 Thread sheehan (Connor Sheehan)
sheehan updated this revision to Diff 7359.
sheehan marked 3 inline comments as done.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2959?vs=7343&id=7359

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

AFFECTED FILES
  mercurial/utils/stringutil.py

CHANGE DETAILS

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(br'^[^<]+\s\<[^<>]+@[^<>]+\>$')
+def isauthorwellformed(author):
+'''Return True if the author field is well formed
+(ie "Contributor Name ")
+
+>>> isauthorwellformed(b'Good Author ')
+True
+>>> isauthorwellformed(b'Author ')
+True
+>>> isauthorwellformed(b'Bad Author')
+False
+>>> isauthorwellformed(b'Bad Author >> isauthorwellformed(b'Bad Author aut...@author.com')
+False
+>>> isauthorwellformed(b'')
+False
+>>> isauthorwellformed(b'Bad Author ')
+False
+'''
+return _correctauthorformat.match(author) is not None



To: sheehan, #hg-reviewers, yuja
Cc: yuja, av6, mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2959: stringutil: add isauthorwellformed function

2018-03-28 Thread yuja (Yuya Nishihara)
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 ')
> +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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2959: stringutil: add isauthorwellformed function

2018-03-27 Thread av6 (Anton Shestakov)
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
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel


D2959: stringutil: add isauthorwellformed function

2018-03-27 Thread sheehan (Connor Sheehan)
sheehan created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The regular expression for this function formerly lived at
  
https://hg.mozilla.org/hgcustom/version-control-tools/file/tip/hghooks/mozhghooks/author_format.py#l13

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/utils/stringutil.py

CHANGE DETAILS

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 ")
+
+>>> isauthorwellformed('Good Author ')
+True
+>>> isauthorwellformed('Author ')
+True
+>>> isauthorwellformed('Bad Author')
+False
+>>> isauthorwellformed('Bad Author >> isauthorwellformed('Bad Author aut...@author.com')
+False
+>>> isauthorwellformed('')
+False
+>>> isauthorwellformed('Bad Author ')
+False
+'''
+return bool(_correctauthorformat.match(author))



To: sheehan, #hg-reviewers
Cc: mercurial-devel
___
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel