civics-cdf-validator 1.67.dev5__tar.gz → 1.67.dev6__tar.gz

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.
Files changed (29) hide show
  1. {civics_cdf_validator-1.67.dev5/civics_cdf_validator.egg-info → civics_cdf_validator-1.67.dev6}/PKG-INFO +1 -1
  2. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6/civics_cdf_validator.egg-info}/PKG-INFO +1 -1
  3. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/SOURCES.txt +1 -0
  4. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rules.py +2 -85
  5. civics_cdf_validator-1.67.dev6/rulesets/committee_rules.py +107 -0
  6. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/version.py +1 -1
  7. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/CONTRIBUTING.md +0 -0
  8. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/LICENSE-2.0.txt +0 -0
  9. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/MANIFEST.in +0 -0
  10. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/README.md +0 -0
  11. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/__init__.py +0 -0
  12. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/base.py +0 -0
  13. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/dependency_links.txt +0 -0
  14. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/entry_points.txt +0 -0
  15. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/requires.txt +0 -0
  16. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/civics_cdf_validator.egg-info/top_level.txt +0 -0
  17. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/gpunit_rules.py +0 -0
  18. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/loggers.py +0 -0
  19. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/office_utils.py +0 -0
  20. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rulesets/__init__.py +0 -0
  21. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rulesets/common_rules.py +0 -0
  22. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rulesets/election_dates_rules.py +0 -0
  23. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rulesets/election_rules.py +0 -0
  24. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rulesets/officeholder_rules.py +0 -0
  25. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/rulesets/rule_util.py +0 -0
  26. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/setup.cfg +0 -0
  27. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/setup.py +0 -0
  28. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/stats.py +0 -0
  29. {civics_cdf_validator-1.67.dev5 → civics_cdf_validator-1.67.dev6}/validator.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.67.dev5
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: civics_cdf_validator
3
- Version: 1.67.dev5
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
@@ -16,6 +16,7 @@ setup.py
16
16
  ./validator.py
17
17
  ./version.py
18
18
  ./rulesets/__init__.py
19
+ ./rulesets/committee_rules.py
19
20
  ./rulesets/common_rules.py
20
21
  ./rulesets/election_dates_rules.py
21
22
  ./rulesets/election_rules.py
@@ -17,11 +17,11 @@ 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
26
  from civics_cdf_validator.rulesets import election_dates_rules
27
27
  from civics_cdf_validator.rulesets import election_rules
@@ -40,79 +40,6 @@ _VALID_FEED_LONGEVITY_BY_FEED_TYPE = frozendict({
40
40
  })
41
41
 
42
42
 
43
- class CommitteeClassificationEndDateOccursAfterStartDate(base.DateRule):
44
- """CommitteeClassification elements should have end dates that occur after the start dates."""
45
-
46
- def elements(self):
47
- return ["CommitteeClassification"]
48
-
49
- def check(self, element):
50
- self.reset_instance_vars()
51
- self.gather_dates(element)
52
-
53
- if self.end_date and self.start_date:
54
- self.check_end_after_start()
55
- if self.error_log:
56
- raise loggers.ElectionError(self.error_log)
57
-
58
-
59
- class AffiliationEndDateOccursAfterStartDate(base.DateRule):
60
- """Affiliation elements should have end dates that occur after the start dates."""
61
-
62
- def elements(self):
63
- return ["Affiliation"]
64
-
65
- def check(self, element):
66
- self.reset_instance_vars()
67
- self.gather_dates(element)
68
-
69
- if self.end_date and self.start_date:
70
- self.check_end_after_start()
71
- if self.error_log:
72
- raise loggers.ElectionError(self.error_log)
73
-
74
-
75
- class EinMatchesFormat(base.BaseRule):
76
- """EIN id should be in the following format: XX-XXXXXXX."""
77
-
78
- def __init__(self, election_tree, schema_tree, **kwargs):
79
- super(EinMatchesFormat, self).__init__(election_tree, schema_tree, **kwargs)
80
- regex = r"\d{2}(-\d{7})?"
81
- self.ein_id_matcher = re.compile(regex, flags=re.U)
82
-
83
- def elements(self):
84
- return ["Committee"]
85
-
86
- def check(self, element):
87
- external_identifiers = element.find("ExternalIdentifiers")
88
- if external_identifiers is not None:
89
- ein_ids = rule_util.get_external_id_values(external_identifiers, "ein")
90
- if ein_ids:
91
- e_id = ein_ids.pop()
92
- if not self.ein_id_matcher.match(e_id):
93
- raise loggers.ElectionError.from_message(
94
- "EIN id '{}' is not in the correct format.".format(e_id),
95
- [element],
96
- )
97
-
98
-
99
- class AffiliationHasEitherPartyOrPerson(base.BaseRule):
100
- """Affiliation should contain either a Party or a Person objectId."""
101
-
102
- def elements(self):
103
- return ["Affiliation"]
104
-
105
- def check(self, element):
106
- party_id = element.find("PartyId")
107
- person_id = element.find("PersonId")
108
- if not ((party_id is None) ^ (person_id is None)):
109
- raise loggers.ElectionError.from_message(
110
- "Affiliation must have one of: PartyId, PersonId. Cannot include"
111
- " both.",
112
- [element],
113
- )
114
-
115
-
116
43
  class FeedTypeHasValidFeedLongevity(base.BaseRule):
117
44
  """Feeds types should have valid corresponding FeedLongevity."""
118
45
 
@@ -659,17 +586,7 @@ COMMON_RULES = common_rules.COMMON_RULES
659
586
  OFFICEHOLDER_RULES = officeholder_rules.OFFICEHOLDER_RULES
660
587
  ELECTION_RULES = election_rules.ELECTION_RULES
661
588
  ELECTION_DATES_RULES = election_dates_rules.ELECTION_DATES_RULES
662
-
663
-
664
- COMMITTEE_RULES = COMMON_RULES + (
665
- # go/keep-sorted start
666
- AffiliationEndDateOccursAfterStartDate,
667
- AffiliationHasEitherPartyOrPerson,
668
- CommitteeClassificationEndDateOccursAfterStartDate,
669
- EinMatchesFormat,
670
- common_rules.ProhibitElectionData,
671
- # go/keep-sorted end
672
- )
589
+ COMMITTEE_RULES = committee_rules.COMMITTEE_RULES
673
590
 
674
591
 
675
592
  METADATA_RULES = (
@@ -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
+ )
@@ -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.dev5'
8
+ __version__ = '1.67.dev6'