civics-cdf-validator 1.67.dev4__py3-none-any.whl → 1.67.dev6__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,12 +17,13 @@ from __future__ import print_function
17
17
 
18
18
  import datetime
19
19
  import enum
20
- import re
21
20
 
22
21
  from botocore import utils as botocore_utils
23
22
  from civics_cdf_validator import base
24
23
  from civics_cdf_validator import loggers
24
+ from civics_cdf_validator.rulesets import committee_rules
25
25
  from civics_cdf_validator.rulesets import common_rules
26
+ from civics_cdf_validator.rulesets import election_dates_rules
26
27
  from civics_cdf_validator.rulesets import election_rules
27
28
  from civics_cdf_validator.rulesets import officeholder_rules
28
29
  from civics_cdf_validator.rulesets import rule_util
@@ -39,79 +40,6 @@ _VALID_FEED_LONGEVITY_BY_FEED_TYPE = frozendict({
39
40
  })
40
41
 
41
42
 
42
- class CommitteeClassificationEndDateOccursAfterStartDate(base.DateRule):
43
- """CommitteeClassification elements should have end dates that occur after the start dates."""
44
-
45
- def elements(self):
46
- return ["CommitteeClassification"]
47
-
48
- def check(self, element):
49
- self.reset_instance_vars()
50
- self.gather_dates(element)
51
-
52
- if self.end_date and self.start_date:
53
- self.check_end_after_start()
54
- if self.error_log:
55
- raise loggers.ElectionError(self.error_log)
56
-
57
-
58
- class AffiliationEndDateOccursAfterStartDate(base.DateRule):
59
- """Affiliation elements should have end dates that occur after the start dates."""
60
-
61
- def elements(self):
62
- return ["Affiliation"]
63
-
64
- def check(self, element):
65
- self.reset_instance_vars()
66
- self.gather_dates(element)
67
-
68
- if self.end_date and self.start_date:
69
- self.check_end_after_start()
70
- if self.error_log:
71
- raise loggers.ElectionError(self.error_log)
72
-
73
-
74
- class EinMatchesFormat(base.BaseRule):
75
- """EIN id should be in the following format: XX-XXXXXXX."""
76
-
77
- def __init__(self, election_tree, schema_tree, **kwargs):
78
- super(EinMatchesFormat, self).__init__(election_tree, schema_tree, **kwargs)
79
- regex = r"\d{2}(-\d{7})?"
80
- self.ein_id_matcher = re.compile(regex, flags=re.U)
81
-
82
- def elements(self):
83
- return ["Committee"]
84
-
85
- def check(self, element):
86
- external_identifiers = element.find("ExternalIdentifiers")
87
- if external_identifiers is not None:
88
- ein_ids = rule_util.get_external_id_values(external_identifiers, "ein")
89
- if ein_ids:
90
- e_id = ein_ids.pop()
91
- if not self.ein_id_matcher.match(e_id):
92
- raise loggers.ElectionError.from_message(
93
- "EIN id '{}' is not in the correct format.".format(e_id),
94
- [element],
95
- )
96
-
97
-
98
- class AffiliationHasEitherPartyOrPerson(base.BaseRule):
99
- """Affiliation should contain either a Party or a Person objectId."""
100
-
101
- def elements(self):
102
- return ["Affiliation"]
103
-
104
- def check(self, element):
105
- party_id = element.find("PartyId")
106
- person_id = element.find("PersonId")
107
- if not ((party_id is None) ^ (person_id is None)):
108
- raise loggers.ElectionError.from_message(
109
- "Affiliation must have one of: PartyId, PersonId. Cannot include"
110
- " both.",
111
- [element],
112
- )
113
-
114
-
115
43
  class FeedTypeHasValidFeedLongevity(base.BaseRule):
116
44
  """Feeds types should have valid corresponding FeedLongevity."""
117
45
 
@@ -489,22 +417,6 @@ class FeedInactiveDateSetForNonEvergreenFeed(base.BaseRule):
489
417
  )
490
418
 
491
419
 
492
- class UnreferencedEntitiesElectionDates(common_rules.UnreferencedEntitiesBase):
493
- """CDF elections and contests are top-level in election dates feeds.
494
-
495
- All other entity types must be referenced.
496
- """
497
-
498
- def __init__(self, election_tree, schema_tree, **kwargs):
499
- super(UnreferencedEntitiesElectionDates, self).__init__(
500
- election_tree,
501
- schema_tree,
502
- frozenset(["Election", "Contest"]),
503
- frozenset([]),
504
- **kwargs,
505
- )
506
-
507
-
508
420
  class ElectoralCommissionCollectionExists(base.BaseRule):
509
421
  """ElectoralCommissionCollection should exist."""
510
422
 
@@ -673,20 +585,10 @@ class RuleSet(enum.Enum):
673
585
  COMMON_RULES = common_rules.COMMON_RULES
674
586
  OFFICEHOLDER_RULES = officeholder_rules.OFFICEHOLDER_RULES
675
587
  ELECTION_RULES = election_rules.ELECTION_RULES
588
+ ELECTION_DATES_RULES = election_dates_rules.ELECTION_DATES_RULES
589
+ COMMITTEE_RULES = committee_rules.COMMITTEE_RULES
676
590
 
677
591
 
678
- COMMITTEE_RULES = COMMON_RULES + (
679
- # go/keep-sorted start
680
- AffiliationEndDateOccursAfterStartDate,
681
- AffiliationHasEitherPartyOrPerson,
682
- CommitteeClassificationEndDateOccursAfterStartDate,
683
- EinMatchesFormat,
684
- common_rules.ProhibitElectionData,
685
- # go/keep-sorted end
686
- )
687
-
688
- ELECTION_DATES_RULES = ELECTION_RULES + (UnreferencedEntitiesElectionDates,)
689
-
690
592
  METADATA_RULES = (
691
593
  # go/keep-sorted start
692
594
  ElectionEventDatesAreSequential,
@@ -0,0 +1,107 @@
1
+ # Copyright 2020 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Validation rules for committee feeds of the CDF XML validator."""
15
+
16
+ from __future__ import print_function
17
+
18
+ import re
19
+
20
+ from civics_cdf_validator import base
21
+ from civics_cdf_validator import loggers
22
+ from civics_cdf_validator.rulesets import common_rules
23
+ from civics_cdf_validator.rulesets import rule_util
24
+
25
+
26
+ class CommitteeClassificationEndDateOccursAfterStartDate(base.DateRule):
27
+ """CommitteeClassification elements should have end dates that occur after the start dates."""
28
+
29
+ def elements(self):
30
+ return ["CommitteeClassification"]
31
+
32
+ def check(self, element):
33
+ self.reset_instance_vars()
34
+ self.gather_dates(element)
35
+
36
+ if self.end_date and self.start_date:
37
+ self.check_end_after_start()
38
+ if self.error_log:
39
+ raise loggers.ElectionError(self.error_log)
40
+
41
+
42
+ class AffiliationEndDateOccursAfterStartDate(base.DateRule):
43
+ """Affiliation elements should have end dates that occur after the start dates."""
44
+
45
+ def elements(self):
46
+ return ["Affiliation"]
47
+
48
+ def check(self, element):
49
+ self.reset_instance_vars()
50
+ self.gather_dates(element)
51
+
52
+ if self.end_date and self.start_date:
53
+ self.check_end_after_start()
54
+ if self.error_log:
55
+ raise loggers.ElectionError(self.error_log)
56
+
57
+
58
+ class EinMatchesFormat(base.BaseRule):
59
+ """EIN id should be in the following format: XX-XXXXXXX."""
60
+
61
+ def __init__(self, election_tree, schema_tree, **kwargs):
62
+ super(EinMatchesFormat, self).__init__(election_tree, schema_tree, **kwargs)
63
+ regex = r"\d{2}(-\d{7})?"
64
+ self.ein_id_matcher = re.compile(regex, flags=re.U)
65
+
66
+ def elements(self):
67
+ return ["Committee"]
68
+
69
+ def check(self, element):
70
+ external_identifiers = element.find("ExternalIdentifiers")
71
+ if external_identifiers is not None:
72
+ ein_ids = rule_util.get_external_id_values(external_identifiers, "ein")
73
+ if ein_ids:
74
+ e_id = ein_ids.pop()
75
+ if not self.ein_id_matcher.match(e_id):
76
+ raise loggers.ElectionError.from_message(
77
+ "EIN id '{}' is not in the correct format.".format(e_id),
78
+ [element],
79
+ )
80
+
81
+
82
+ class AffiliationHasEitherPartyOrPerson(base.BaseRule):
83
+ """Affiliation should contain either a Party or a Person objectId."""
84
+
85
+ def elements(self):
86
+ return ["Affiliation"]
87
+
88
+ def check(self, element):
89
+ party_id = element.find("PartyId")
90
+ person_id = element.find("PersonId")
91
+ if not ((party_id is None) ^ (person_id is None)):
92
+ raise loggers.ElectionError.from_message(
93
+ "Affiliation must have one of: PartyId, PersonId. Cannot include"
94
+ " both.",
95
+ [element],
96
+ )
97
+
98
+
99
+ COMMITTEE_RULES = common_rules.COMMON_RULES + (
100
+ # go/keep-sorted start
101
+ AffiliationEndDateOccursAfterStartDate,
102
+ AffiliationHasEitherPartyOrPerson,
103
+ CommitteeClassificationEndDateOccursAfterStartDate,
104
+ EinMatchesFormat,
105
+ common_rules.ProhibitElectionData,
106
+ # go/keep-sorted end
107
+ )
@@ -0,0 +1,40 @@
1
+ # Copyright 2020 Google LLC
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ """Validation rules for election dates feeds of the CDF XML validator."""
15
+
16
+ from __future__ import print_function
17
+
18
+ from civics_cdf_validator.rulesets import common_rules
19
+ from civics_cdf_validator.rulesets import election_rules
20
+
21
+
22
+ class UnreferencedEntitiesElectionDates(common_rules.UnreferencedEntitiesBase):
23
+ """CDF elections and contests are top-level in election dates feeds.
24
+
25
+ All other entity types must be referenced.
26
+ """
27
+
28
+ def __init__(self, election_tree, schema_tree, **kwargs):
29
+ super(UnreferencedEntitiesElectionDates, self).__init__(
30
+ election_tree,
31
+ schema_tree,
32
+ frozenset(["Election", "Contest"]),
33
+ frozenset([]),
34
+ **kwargs,
35
+ )
36
+
37
+
38
+ ELECTION_DATES_RULES = election_rules.ELECTION_RULES + (
39
+ UnreferencedEntitiesElectionDates,
40
+ )
@@ -5,4 +5,4 @@ No dependencies should be added to this module.
5
5
  See https://packaging.python.org/guides/single-sourcing-package-version/
6
6
  """
7
7
 
8
- __version__ = '1.67.dev4'
8
+ __version__ = '1.67.dev6'
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.67.dev4
3
+ Version: 1.67.dev6
4
4
  Summary: Checks if an election feed follows best practices
5
5
  Home-page: https://github.com/google/civics_cdf_validator
6
6
  Author: Google Civics
@@ -3,18 +3,20 @@ civics_cdf_validator/base.py,sha256=o2dbEJ4haD4ddA6tGHuV_VApe_7DaslFspDb2IZ3GsY,
3
3
  civics_cdf_validator/gpunit_rules.py,sha256=Cg-qlOeVKTCQ5qUKYSxbVrrh3tdLt1X5Eg-7uyyR_SY,9487
4
4
  civics_cdf_validator/loggers.py,sha256=ZfWFd9yskcd2-qb83EPz7eqa1iGO8BRFMtDZeE1hofA,6921
5
5
  civics_cdf_validator/office_utils.py,sha256=4r0zc6-UB2YdqmUnGznEn5K5WLFRsQNQr-QMrFPo-xc,2721
6
- civics_cdf_validator/rules.py,sha256=YTrmk03gERw3RZZ7Z39GiCNBQZ41CPXsuXjZrYT8Avo,23784
6
+ civics_cdf_validator/rules.py,sha256=AZuetAF_x0zoHa3_tn00MsBXcBxUo_4Vdsj63pb7Gtk,20893
7
7
  civics_cdf_validator/stats.py,sha256=YNqv3Khkt_hJxCIunFBRSl23oXqu5gNjCmWMHFbAcSU,3819
8
8
  civics_cdf_validator/validator.py,sha256=OHXg-VngDdovYyBh0ON5M_vvA8PyKTzvfzR8SwZbEf8,12770
9
- civics_cdf_validator/version.py,sha256=5AkWFmBx3VkiWVj-usv1EFQrLEWG7vNwYUwwstJufU4,188
9
+ civics_cdf_validator/version.py,sha256=1GsGfdEnJlQQePOn-bgFdhhTuzxlCMG40U0Zk-qGots,188
10
10
  civics_cdf_validator/rulesets/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ civics_cdf_validator/rulesets/committee_rules.py,sha256=0hNnpzI-ptZDxErbH2D2r66IiIiioqVXSV3YxgXlhrE,3472
11
12
  civics_cdf_validator/rulesets/common_rules.py,sha256=vCcodXrykZBx-RHCX8J-zsUxwEFCEIl0WARkn4cm6fE,59417
13
+ civics_cdf_validator/rulesets/election_dates_rules.py,sha256=mIOKroJ2z5QI5C_i8JR2fNUuZ_e8DJ3juEB07v8tONY,1363
12
14
  civics_cdf_validator/rulesets/election_rules.py,sha256=ldLXfYgJ3YbapIVZclQPmDemki-txOTOqrp_k8WgSS0,95874
13
15
  civics_cdf_validator/rulesets/officeholder_rules.py,sha256=N5G5Gum685ACXnb0Kwd5DseaCHOOpg3gpYK_uivAegQ,17766
14
16
  civics_cdf_validator/rulesets/rule_util.py,sha256=FWi09R7XWDfZwuHl-k2vhsFHlKuOrD5MD5YQ4QUQyVo,4431
15
- civics_cdf_validator-1.67.dev4.dist-info/licenses/LICENSE-2.0.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
16
- civics_cdf_validator-1.67.dev4.dist-info/METADATA,sha256=eQ7_vRk9uMqaoe1NPMyLJcSpw9KUmAy1HdViPaGm8A8,1280
17
- civics_cdf_validator-1.67.dev4.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
18
- civics_cdf_validator-1.67.dev4.dist-info/entry_points.txt,sha256=QibgvtMOocwDi7fQ1emgMJ2lIlI41sW0__KIQdnVn90,77
19
- civics_cdf_validator-1.67.dev4.dist-info/top_level.txt,sha256=PYT5Eclxbop5o6DJIcgs4IeU6Ds5jqyftjoFbgkkJYo,21
20
- civics_cdf_validator-1.67.dev4.dist-info/RECORD,,
17
+ civics_cdf_validator-1.67.dev6.dist-info/licenses/LICENSE-2.0.txt,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
18
+ civics_cdf_validator-1.67.dev6.dist-info/METADATA,sha256=r5GaEZh7K9Mtg9nNKoqhZX1FWW-8FvqsSpzvl8wSR2A,1280
19
+ civics_cdf_validator-1.67.dev6.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
20
+ civics_cdf_validator-1.67.dev6.dist-info/entry_points.txt,sha256=QibgvtMOocwDi7fQ1emgMJ2lIlI41sW0__KIQdnVn90,77
21
+ civics_cdf_validator-1.67.dev6.dist-info/top_level.txt,sha256=PYT5Eclxbop5o6DJIcgs4IeU6Ds5jqyftjoFbgkkJYo,21
22
+ civics_cdf_validator-1.67.dev6.dist-info/RECORD,,