Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/ui.py @ 34146:0fa781320203
doctest: bulk-replace string literals with b'' for Python 3
Our code transformer can't rewrite string literals in docstrings, and I
don't want to make the transformer more complex.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 03 Sep 2017 14:32:11 +0900 |
parents | 3c82b14d2838 |
children | 0a2fd3bfc704 |
comparison
equal
deleted
inserted
replaced
34145:ada8a19672ab | 34146:0fa781320203 |
---|---|
529 return v | 529 return v |
530 | 530 |
531 def configbool(self, section, name, default=_unset, untrusted=False): | 531 def configbool(self, section, name, default=_unset, untrusted=False): |
532 """parse a configuration element as a boolean | 532 """parse a configuration element as a boolean |
533 | 533 |
534 >>> u = ui(); s = 'foo' | 534 >>> u = ui(); s = b'foo' |
535 >>> u.setconfig(s, 'true', 'yes') | 535 >>> u.setconfig(s, b'true', b'yes') |
536 >>> u.configbool(s, 'true') | 536 >>> u.configbool(s, b'true') |
537 True | 537 True |
538 >>> u.setconfig(s, 'false', 'no') | 538 >>> u.setconfig(s, b'false', b'no') |
539 >>> u.configbool(s, 'false') | 539 >>> u.configbool(s, b'false') |
540 False | 540 False |
541 >>> u.configbool(s, 'unknown') | 541 >>> u.configbool(s, b'unknown') |
542 False | 542 False |
543 >>> u.configbool(s, 'unknown', True) | 543 >>> u.configbool(s, b'unknown', True) |
544 True | 544 True |
545 >>> u.setconfig(s, 'invalid', 'somevalue') | 545 >>> u.setconfig(s, b'invalid', b'somevalue') |
546 >>> u.configbool(s, 'invalid') | 546 >>> u.configbool(s, b'invalid') |
547 Traceback (most recent call last): | 547 Traceback (most recent call last): |
548 ... | 548 ... |
549 ConfigError: foo.invalid is not a boolean ('somevalue') | 549 ConfigError: foo.invalid is not a boolean ('somevalue') |
550 """ | 550 """ |
551 | 551 |
566 | 566 |
567 def configwith(self, convert, section, name, default=_unset, | 567 def configwith(self, convert, section, name, default=_unset, |
568 desc=None, untrusted=False): | 568 desc=None, untrusted=False): |
569 """parse a configuration element with a conversion function | 569 """parse a configuration element with a conversion function |
570 | 570 |
571 >>> u = ui(); s = 'foo' | 571 >>> u = ui(); s = b'foo' |
572 >>> u.setconfig(s, 'float1', '42') | 572 >>> u.setconfig(s, b'float1', b'42') |
573 >>> u.configwith(float, s, 'float1') | 573 >>> u.configwith(float, s, b'float1') |
574 42.0 | 574 42.0 |
575 >>> u.setconfig(s, 'float2', '-4.25') | 575 >>> u.setconfig(s, b'float2', b'-4.25') |
576 >>> u.configwith(float, s, 'float2') | 576 >>> u.configwith(float, s, b'float2') |
577 -4.25 | 577 -4.25 |
578 >>> u.configwith(float, s, 'unknown', 7) | 578 >>> u.configwith(float, s, b'unknown', 7) |
579 7.0 | 579 7.0 |
580 >>> u.setconfig(s, 'invalid', 'somevalue') | 580 >>> u.setconfig(s, b'invalid', b'somevalue') |
581 >>> u.configwith(float, s, 'invalid') | 581 >>> u.configwith(float, s, b'invalid') |
582 Traceback (most recent call last): | 582 Traceback (most recent call last): |
583 ... | 583 ... |
584 ConfigError: foo.invalid is not a valid float ('somevalue') | 584 ConfigError: foo.invalid is not a valid float ('somevalue') |
585 >>> u.configwith(float, s, 'invalid', desc='womble') | 585 >>> u.configwith(float, s, b'invalid', desc=b'womble') |
586 Traceback (most recent call last): | 586 Traceback (most recent call last): |
587 ... | 587 ... |
588 ConfigError: foo.invalid is not a valid womble ('somevalue') | 588 ConfigError: foo.invalid is not a valid womble ('somevalue') |
589 """ | 589 """ |
590 | 590 |
600 % (section, name, desc, v)) | 600 % (section, name, desc, v)) |
601 | 601 |
602 def configint(self, section, name, default=_unset, untrusted=False): | 602 def configint(self, section, name, default=_unset, untrusted=False): |
603 """parse a configuration element as an integer | 603 """parse a configuration element as an integer |
604 | 604 |
605 >>> u = ui(); s = 'foo' | 605 >>> u = ui(); s = b'foo' |
606 >>> u.setconfig(s, 'int1', '42') | 606 >>> u.setconfig(s, b'int1', b'42') |
607 >>> u.configint(s, 'int1') | 607 >>> u.configint(s, b'int1') |
608 42 | 608 42 |
609 >>> u.setconfig(s, 'int2', '-42') | 609 >>> u.setconfig(s, b'int2', b'-42') |
610 >>> u.configint(s, 'int2') | 610 >>> u.configint(s, b'int2') |
611 -42 | 611 -42 |
612 >>> u.configint(s, 'unknown', 7) | 612 >>> u.configint(s, b'unknown', 7) |
613 7 | 613 7 |
614 >>> u.setconfig(s, 'invalid', 'somevalue') | 614 >>> u.setconfig(s, b'invalid', b'somevalue') |
615 >>> u.configint(s, 'invalid') | 615 >>> u.configint(s, b'invalid') |
616 Traceback (most recent call last): | 616 Traceback (most recent call last): |
617 ... | 617 ... |
618 ConfigError: foo.invalid is not a valid integer ('somevalue') | 618 ConfigError: foo.invalid is not a valid integer ('somevalue') |
619 """ | 619 """ |
620 | 620 |
625 """parse a configuration element as a quantity in bytes | 625 """parse a configuration element as a quantity in bytes |
626 | 626 |
627 Units can be specified as b (bytes), k or kb (kilobytes), m or | 627 Units can be specified as b (bytes), k or kb (kilobytes), m or |
628 mb (megabytes), g or gb (gigabytes). | 628 mb (megabytes), g or gb (gigabytes). |
629 | 629 |
630 >>> u = ui(); s = 'foo' | 630 >>> u = ui(); s = b'foo' |
631 >>> u.setconfig(s, 'val1', '42') | 631 >>> u.setconfig(s, b'val1', b'42') |
632 >>> u.configbytes(s, 'val1') | 632 >>> u.configbytes(s, b'val1') |
633 42 | 633 42 |
634 >>> u.setconfig(s, 'val2', '42.5 kb') | 634 >>> u.setconfig(s, b'val2', b'42.5 kb') |
635 >>> u.configbytes(s, 'val2') | 635 >>> u.configbytes(s, b'val2') |
636 43520 | 636 43520 |
637 >>> u.configbytes(s, 'unknown', '7 MB') | 637 >>> u.configbytes(s, b'unknown', b'7 MB') |
638 7340032 | 638 7340032 |
639 >>> u.setconfig(s, 'invalid', 'somevalue') | 639 >>> u.setconfig(s, b'invalid', b'somevalue') |
640 >>> u.configbytes(s, 'invalid') | 640 >>> u.configbytes(s, b'invalid') |
641 Traceback (most recent call last): | 641 Traceback (most recent call last): |
642 ... | 642 ... |
643 ConfigError: foo.invalid is not a byte quantity ('somevalue') | 643 ConfigError: foo.invalid is not a byte quantity ('somevalue') |
644 """ | 644 """ |
645 | 645 |
658 | 658 |
659 def configlist(self, section, name, default=_unset, untrusted=False): | 659 def configlist(self, section, name, default=_unset, untrusted=False): |
660 """parse a configuration element as a list of comma/space separated | 660 """parse a configuration element as a list of comma/space separated |
661 strings | 661 strings |
662 | 662 |
663 >>> u = ui(); s = 'foo' | 663 >>> u = ui(); s = b'foo' |
664 >>> u.setconfig(s, 'list1', 'this,is "a small" ,test') | 664 >>> u.setconfig(s, b'list1', b'this,is "a small" ,test') |
665 >>> u.configlist(s, 'list1') | 665 >>> u.configlist(s, b'list1') |
666 ['this', 'is', 'a small', 'test'] | 666 ['this', 'is', 'a small', 'test'] |
667 """ | 667 """ |
668 # default is not always a list | 668 # default is not always a list |
669 v = self.configwith(config.parselist, section, name, default, | 669 v = self.configwith(config.parselist, section, name, default, |
670 'list', untrusted) | 670 'list', untrusted) |
675 return v | 675 return v |
676 | 676 |
677 def configdate(self, section, name, default=_unset, untrusted=False): | 677 def configdate(self, section, name, default=_unset, untrusted=False): |
678 """parse a configuration element as a tuple of ints | 678 """parse a configuration element as a tuple of ints |
679 | 679 |
680 >>> u = ui(); s = 'foo' | 680 >>> u = ui(); s = b'foo' |
681 >>> u.setconfig(s, 'date', '0 0') | 681 >>> u.setconfig(s, b'date', b'0 0') |
682 >>> u.configdate(s, 'date') | 682 >>> u.configdate(s, b'date') |
683 (0, 0) | 683 (0, 0) |
684 """ | 684 """ |
685 if self.config(section, name, default, untrusted): | 685 if self.config(section, name, default, untrusted): |
686 return self.configwith(util.parsedate, section, name, default, | 686 return self.configwith(util.parsedate, section, name, default, |
687 'date', untrusted) | 687 'date', untrusted) |
1254 """Extract prompt message and list of choices from specified prompt. | 1254 """Extract prompt message and list of choices from specified prompt. |
1255 | 1255 |
1256 This returns tuple "(message, choices)", and "choices" is the | 1256 This returns tuple "(message, choices)", and "choices" is the |
1257 list of tuple "(response character, text without &)". | 1257 list of tuple "(response character, text without &)". |
1258 | 1258 |
1259 >>> ui.extractchoices("awake? $$ &Yes $$ &No") | 1259 >>> ui.extractchoices(b"awake? $$ &Yes $$ &No") |
1260 ('awake? ', [('y', 'Yes'), ('n', 'No')]) | 1260 ('awake? ', [('y', 'Yes'), ('n', 'No')]) |
1261 >>> ui.extractchoices("line\\nbreak? $$ &Yes $$ &No") | 1261 >>> ui.extractchoices(b"line\\nbreak? $$ &Yes $$ &No") |
1262 ('line\\nbreak? ', [('y', 'Yes'), ('n', 'No')]) | 1262 ('line\\nbreak? ', [('y', 'Yes'), ('n', 'No')]) |
1263 >>> ui.extractchoices("want lots of $$money$$?$$Ye&s$$N&o") | 1263 >>> ui.extractchoices(b"want lots of $$money$$?$$Ye&s$$N&o") |
1264 ('want lots of $$money$$?', [('s', 'Yes'), ('o', 'No')]) | 1264 ('want lots of $$money$$?', [('s', 'Yes'), ('o', 'No')]) |
1265 """ | 1265 """ |
1266 | 1266 |
1267 # Sadly, the prompt string may have been built with a filename | 1267 # Sadly, the prompt string may have been built with a filename |
1268 # containing "$$" so let's try to find the first valid-looking | 1268 # containing "$$" so let's try to find the first valid-looking |