Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/utils/stringutil.py @ 45957:89a2afe31e82
formating: upgrade to black 20.8b1
This required a couple of small tweaks to un-confuse black, but now it
works. Big formatting changes come from:
* Dramatically improved collection-splitting logic upstream
* Black having a strong (correct IMO) opinion that """ is better than '''
Differential Revision: https://phab.mercurial-scm.org/D9430
author | Augie Fackler <raf@durin42.com> |
---|---|
date | Fri, 27 Nov 2020 17:03:29 -0500 |
parents | ac39a8a214b1 |
children | d4ba4d51f85f |
comparison
equal
deleted
inserted
replaced
45956:346af7687c6f | 45957:89a2afe31e82 |
---|---|
492 return author[:f].replace(b'.', b' ') | 492 return author[:f].replace(b'.', b' ') |
493 | 493 |
494 | 494 |
495 @attr.s(hash=True) | 495 @attr.s(hash=True) |
496 class mailmapping(object): | 496 class mailmapping(object): |
497 '''Represents a username/email key or value in | 497 """Represents a username/email key or value in |
498 a mailmap file''' | 498 a mailmap file""" |
499 | 499 |
500 email = attr.ib() | 500 email = attr.ib() |
501 name = attr.ib(default=None) | 501 name = attr.ib(default=None) |
502 | 502 |
503 | 503 |
504 def _ismailmaplineinvalid(names, emails): | 504 def _ismailmaplineinvalid(names, emails): |
505 '''Returns True if the parsed names and emails | 505 """Returns True if the parsed names and emails |
506 in a mailmap entry are invalid. | 506 in a mailmap entry are invalid. |
507 | 507 |
508 >>> # No names or emails fails | 508 >>> # No names or emails fails |
509 >>> names, emails = [], [] | 509 >>> names, emails = [], [] |
510 >>> _ismailmaplineinvalid(names, emails) | 510 >>> _ismailmaplineinvalid(names, emails) |
520 >>> # No names but two emails passes | 520 >>> # No names but two emails passes |
521 >>> names = [] | 521 >>> names = [] |
522 >>> emails = [b'proper@email.com', b'commit@email.com'] | 522 >>> emails = [b'proper@email.com', b'commit@email.com'] |
523 >>> _ismailmaplineinvalid(names, emails) | 523 >>> _ismailmaplineinvalid(names, emails) |
524 False | 524 False |
525 ''' | 525 """ |
526 return not emails or not names and len(emails) < 2 | 526 return not emails or not names and len(emails) < 2 |
527 | 527 |
528 | 528 |
529 def parsemailmap(mailmapcontent): | 529 def parsemailmap(mailmapcontent): |
530 """Parses data in the .mailmap format | 530 """Parses data in the .mailmap format |
595 # name or a second email | 595 # name or a second email |
596 if _ismailmaplineinvalid(names, emails): | 596 if _ismailmaplineinvalid(names, emails): |
597 continue | 597 continue |
598 | 598 |
599 mailmapkey = mailmapping( | 599 mailmapkey = mailmapping( |
600 email=emails[-1], name=names[-1] if len(names) == 2 else None, | 600 email=emails[-1], |
601 name=names[-1] if len(names) == 2 else None, | |
601 ) | 602 ) |
602 | 603 |
603 mailmap[mailmapkey] = mailmapping( | 604 mailmap[mailmapkey] = mailmapping( |
604 email=emails[0], name=names[0] if names else None, | 605 email=emails[0], |
606 name=names[0] if names else None, | |
605 ) | 607 ) |
606 | 608 |
607 return mailmap | 609 return mailmap |
608 | 610 |
609 | 611 |
657 | 659 |
658 _correctauthorformat = remod.compile(br'^[^<]+\s<[^<>]+@[^<>]+>$') | 660 _correctauthorformat = remod.compile(br'^[^<]+\s<[^<>]+@[^<>]+>$') |
659 | 661 |
660 | 662 |
661 def isauthorwellformed(author): | 663 def isauthorwellformed(author): |
662 '''Return True if the author field is well formed | 664 """Return True if the author field is well formed |
663 (ie "Contributor Name <contrib@email.dom>") | 665 (ie "Contributor Name <contrib@email.dom>") |
664 | 666 |
665 >>> isauthorwellformed(b'Good Author <good@author.com>') | 667 >>> isauthorwellformed(b'Good Author <good@author.com>') |
666 True | 668 True |
667 >>> isauthorwellformed(b'Author <good@author.com>') | 669 >>> isauthorwellformed(b'Author <good@author.com>') |
674 False | 676 False |
675 >>> isauthorwellformed(b'<author@author.com>') | 677 >>> isauthorwellformed(b'<author@author.com>') |
676 False | 678 False |
677 >>> isauthorwellformed(b'Bad Author <author>') | 679 >>> isauthorwellformed(b'Bad Author <author>') |
678 False | 680 False |
679 ''' | 681 """ |
680 return _correctauthorformat.match(author) is not None | 682 return _correctauthorformat.match(author) is not None |
681 | 683 |
682 | 684 |
683 def ellipsis(text, maxlength=400): | 685 def ellipsis(text, maxlength=400): |
684 """Trim string to at most maxlength (default: 400) columns in display.""" | 686 """Trim string to at most maxlength (default: 400) columns in display.""" |