@@ -555,21 +555,6 @@ def conforms(self, instance, format):
555
555
556
556
@FormatChecker .cls_checks ("date" )
557
557
def is_date (instance ):
558
- """
559
- Check whether the instance matches a date in ``YYYY-MM-DD`` format.
560
-
561
- :argument str instance: the instance to check
562
- :rtype: bool
563
-
564
- >>> is_date("1970-12-31")
565
- True
566
- >>> is_date("12/31/1970")
567
- False
568
- >>> is_date("0000-13-32")
569
- False
570
-
571
- """
572
-
573
558
try :
574
559
datetime .datetime .strptime (instance , "%Y-%m-%d" )
575
560
return True
@@ -579,21 +564,6 @@ def is_date(instance):
579
564
580
565
@FormatChecker .cls_checks ("time" )
581
566
def is_time (instance ):
582
- """
583
- Check whether the instance matches a time in ``hh:mm:ss`` format.
584
-
585
- :argument str instance: the instance to check
586
- :rtype: bool
587
-
588
- >>> is_time("23:59:59")
589
- True
590
- >>> is_time("11:59:59 PM")
591
- False
592
- >>> is_time("59:60:61")
593
- False
594
-
595
- """
596
-
597
567
try :
598
568
datetime .datetime .strptime (instance , "%H:%M:%S" )
599
569
return True
@@ -603,25 +573,6 @@ def is_time(instance):
603
573
604
574
@FormatChecker .cls_checks ("uri" )
605
575
def is_uri (instance ):
606
- """
607
- Check whether the instance is a valid URI.
608
-
609
- Also supports relative URIs.
610
-
611
- :argument str instance: the instance to check
612
- :rtype: bool
613
-
614
- >>> is_uri("ftp://[email protected] :8080/pub/os/")
615
- True
616
- >>> is_uri("http://www2.example.com:8000/pub/#os?user=joe.bloggs")
617
- True
618
- >>> is_uri(r"\\ \\ WINDOWS\My Files")
619
- False
620
- >>> is_uri("#/properties/foo")
621
- True
622
-
623
- """
624
-
625
576
# URI regex from http://snipplr.com/view/6889/
626
577
abs_uri = (r"^([A-Za-z0-9+.-]+):(?://(?:((?:[A-Za-z0-9-._~!$&'()*+,;=:"
627
578
r"]|%[0-9A-Fa-f]{2})*)@)?((?:[A-Za-z0-9-._~!$&'()*+,;=]|%[0"
@@ -639,23 +590,6 @@ def is_uri(instance):
639
590
640
591
@FormatChecker .cls_checks ("email" )
641
592
def is_email (instance ):
642
- """
643
- Check whether the instance is a valid e-mail address.
644
-
645
- Checking is based on `RFC 2822`_
646
-
647
- :argument str instance: the instance to check
648
- :rtype: bool
649
-
650
-
651
- True
652
- >>> is_email("joe.bloggs")
653
- False
654
-
655
- .. _RFC 2822: http://tools.ietf.org/html/rfc2822
656
-
657
- """
658
-
659
593
pattern = (r"^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_"
660
594
r"`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b"
661
595
r"\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z"
@@ -669,21 +603,6 @@ def is_email(instance):
669
603
670
604
@FormatChecker .cls_checks ("ip-address" )
671
605
def is_ip_address (instance ):
672
- """
673
- Check whether the instance is a valid IP address.
674
-
675
- :argument str instance: the instance to check
676
- :rtype: bool
677
-
678
- >>> is_ip_address("192.168.0.1")
679
- True
680
- >>> is_ip_address("::1")
681
- False
682
- >>> is_ip_address("256.256.256.256")
683
- False
684
-
685
- """
686
-
687
606
try :
688
607
socket .inet_aton (instance )
689
608
return True
@@ -694,21 +613,6 @@ def is_ip_address(instance):
694
613
if hasattr (socket , "inet_pton" ):
695
614
@FormatChecker .cls_checks ("ipv6" )
696
615
def is_ipv6 (instance ):
697
- """
698
- Check whether the instance is a valid IPv6 address.
699
-
700
- :argument str instance: the instance to check
701
- :rtype: bool
702
-
703
- >>> is_ipv6("::1")
704
- True
705
- >>> is_ipv6("192.168.0.1")
706
- False
707
- >>> is_ipv6("1:1:1:1:1:1:1:1:1")
708
- False
709
-
710
- """
711
-
712
616
try :
713
617
socket .inet_pton (socket .AF_INET6 , instance )
714
618
return True
@@ -718,26 +622,6 @@ def is_ipv6(instance):
718
622
719
623
@FormatChecker .cls_checks ("host-name" )
720
624
def is_host_name (instance ):
721
- """
722
- Check if the instance is a valid host name.
723
-
724
- >>> is_host_name("www.example.com")
725
- True
726
- >>> is_host_name("my laptop")
727
- False
728
- >>> is_host_name(
729
- ... "a.vvvvvvvvvvvvvvvvveeeeeeeeeeeeeeeeerrrrrrrrrrrrrrrrryyyyyyyy"
730
- ... "yyyyyyyyy.long.host.name"
731
- ... )
732
- False
733
-
734
- .. note:: Does not perform a DNS lookup.
735
-
736
- >>> is_host_name("www.example.doesnotexist")
737
- True
738
-
739
- """
740
-
741
625
pattern = "^[A-Za-z0-9][A-Za-z0-9\.\-]{1,255}$"
742
626
if not re .match (pattern , instance ):
743
627
return False
@@ -750,19 +634,6 @@ def is_host_name(instance):
750
634
751
635
@FormatChecker .cls_checks ("regex" )
752
636
def is_regex (instance ):
753
- """
754
- Check if the instance is a well-formed regular expression.
755
-
756
- :argument str instance: the instance to check
757
- :rtype: bool
758
-
759
- >>> is_regex("^(bob)?cat$")
760
- True
761
- >>> is_ipv6("^(bob?cat$")
762
- False
763
-
764
- """
765
-
766
637
try :
767
638
re .compile (instance )
768
639
return True
0 commit comments