ecourts.entities.court
1from dataclasses import dataclass 2from typing import Optional 3import json 4 5 6@dataclass 7class Court: 8 """ 9 Represents a court entity with state, district, and court codes. 10 """ 11 12 # This is same as the data in courts.csv 13 __ALL_COURTS__ = [ 14 ("1", None), 15 ("1", "2"), 16 ("1", "3"), 17 ("1", "4"), 18 ("1", "5"), 19 ("1", "6"), 20 ("2", None), 21 ("3", None), 22 ("3", "2"), 23 ("3", "3"), 24 ("4", None), 25 ("5", None), 26 ("6", None), 27 ("6", "2"), 28 ("6", "3"), 29 ("6", "4"), 30 ("7", None), 31 ("8", None), 32 ("9", None), 33 ("9", "2"), 34 ("10", None), 35 ("10", "2"), 36 ("11", None), 37 ("12", None), 38 ("12", "2"), 39 ("13", None), 40 ("13", "2"), 41 ("15", None), 42 ("16", None), 43 ("16", "2"), 44 ("16", "3"), 45 ("16", "4"), 46 ("17", None), 47 ("18", None), 48 ("20", None), 49 ("21", None), 50 ("24", None), 51 ("25", None), 52 ("29", None), 53 ] 54 state_code: str 55 """The state code of the court.""" 56 57 district_code: str = "1" 58 """The district code of the court.""" 59 60 court_code: Optional[str] = None 61 """The court code, if applicable.""" 62 63 # These two are part of presentation links, but unused otherwise 64 state_name: Optional[str] = None 65 """The name of the state, if available.""" 66 67 name: Optional[str] = None 68 """The name of the court, if available.""" 69 70 def __post_init__(self): 71 """ 72 Post-initialization processing to validate the court. 73 """ 74 """ 75 Raise an error if the court is not valid 76 """ 77 lcc = self.court_code 78 if self.court_code == "1": 79 lcc = None 80 if (self.state_code, lcc) not in Court.__ALL_COURTS__: 81 if self.court_code: 82 raise ValueError( 83 f"Invalid court: state_code={self.state_code}, court_code={self.court_code}" 84 ) 85 else: 86 raise ValueError(f"Invalid court: state_code={self.state_code}") 87 88 if self.district_code == None: 89 self.district_code = "1" 90 91 @classmethod 92 def enumerate(cls): 93 """ 94 Enumerate all known valid courts. 95 96 Yields: 97 Court: A court object for each valid court. 98 """ 99 for c in cls.__ALL_COURTS__: 100 yield Court(state_code=c[0], court_code=c[1], state_name=None, name=None) 101 102 def queryParams(self): 103 """ 104 Generate query parameters for the court. 105 106 Returns: 107 dict: A dictionary containing the query parameters. 108 """ 109 r = {"state_code": self.state_code, "dist_code": self.district_code} 110 111 r["court_code"] = self.court_code or "1" 112 return r 113 114 def json(self): 115 """ 116 Generate a JSON representation of the court. 117 118 Returns: 119 dict: A dictionary containing the JSON representation. 120 """ 121 return { 122 "state_code": self.state_code, 123 "district_code": self.district_code, 124 "court_code": self.court_code, 125 } 126 127 128 def __eq__(self, other): 129 """ 130 Compare two courts for equality. 131 132 Args: 133 other (Court): The other court to compare against. 134 135 Returns: 136 bool: True if the courts are equal, False otherwise. 137 """ 138 return self.state_code == other.state_code and self.district_code == other.district_code and (self.court_code or "1") == (other.court_code or "1") 139 140 def __iter__(self): 141 for key in ["state_code", "district_code", "court_code"]: 142 yield key, getattr(self, key)
@dataclass
class
Court:
7@dataclass 8class Court: 9 """ 10 Represents a court entity with state, district, and court codes. 11 """ 12 13 # This is same as the data in courts.csv 14 __ALL_COURTS__ = [ 15 ("1", None), 16 ("1", "2"), 17 ("1", "3"), 18 ("1", "4"), 19 ("1", "5"), 20 ("1", "6"), 21 ("2", None), 22 ("3", None), 23 ("3", "2"), 24 ("3", "3"), 25 ("4", None), 26 ("5", None), 27 ("6", None), 28 ("6", "2"), 29 ("6", "3"), 30 ("6", "4"), 31 ("7", None), 32 ("8", None), 33 ("9", None), 34 ("9", "2"), 35 ("10", None), 36 ("10", "2"), 37 ("11", None), 38 ("12", None), 39 ("12", "2"), 40 ("13", None), 41 ("13", "2"), 42 ("15", None), 43 ("16", None), 44 ("16", "2"), 45 ("16", "3"), 46 ("16", "4"), 47 ("17", None), 48 ("18", None), 49 ("20", None), 50 ("21", None), 51 ("24", None), 52 ("25", None), 53 ("29", None), 54 ] 55 state_code: str 56 """The state code of the court.""" 57 58 district_code: str = "1" 59 """The district code of the court.""" 60 61 court_code: Optional[str] = None 62 """The court code, if applicable.""" 63 64 # These two are part of presentation links, but unused otherwise 65 state_name: Optional[str] = None 66 """The name of the state, if available.""" 67 68 name: Optional[str] = None 69 """The name of the court, if available.""" 70 71 def __post_init__(self): 72 """ 73 Post-initialization processing to validate the court. 74 """ 75 """ 76 Raise an error if the court is not valid 77 """ 78 lcc = self.court_code 79 if self.court_code == "1": 80 lcc = None 81 if (self.state_code, lcc) not in Court.__ALL_COURTS__: 82 if self.court_code: 83 raise ValueError( 84 f"Invalid court: state_code={self.state_code}, court_code={self.court_code}" 85 ) 86 else: 87 raise ValueError(f"Invalid court: state_code={self.state_code}") 88 89 if self.district_code == None: 90 self.district_code = "1" 91 92 @classmethod 93 def enumerate(cls): 94 """ 95 Enumerate all known valid courts. 96 97 Yields: 98 Court: A court object for each valid court. 99 """ 100 for c in cls.__ALL_COURTS__: 101 yield Court(state_code=c[0], court_code=c[1], state_name=None, name=None) 102 103 def queryParams(self): 104 """ 105 Generate query parameters for the court. 106 107 Returns: 108 dict: A dictionary containing the query parameters. 109 """ 110 r = {"state_code": self.state_code, "dist_code": self.district_code} 111 112 r["court_code"] = self.court_code or "1" 113 return r 114 115 def json(self): 116 """ 117 Generate a JSON representation of the court. 118 119 Returns: 120 dict: A dictionary containing the JSON representation. 121 """ 122 return { 123 "state_code": self.state_code, 124 "district_code": self.district_code, 125 "court_code": self.court_code, 126 } 127 128 129 def __eq__(self, other): 130 """ 131 Compare two courts for equality. 132 133 Args: 134 other (Court): The other court to compare against. 135 136 Returns: 137 bool: True if the courts are equal, False otherwise. 138 """ 139 return self.state_code == other.state_code and self.district_code == other.district_code and (self.court_code or "1") == (other.court_code or "1") 140 141 def __iter__(self): 142 for key in ["state_code", "district_code", "court_code"]: 143 yield key, getattr(self, key)
Represents a court entity with state, district, and court codes.
Court( state_code: str, district_code: str = '1', court_code: Optional[str] = None, state_name: Optional[str] = None, name: Optional[str] = None)
@classmethod
def
enumerate(cls):
92 @classmethod 93 def enumerate(cls): 94 """ 95 Enumerate all known valid courts. 96 97 Yields: 98 Court: A court object for each valid court. 99 """ 100 for c in cls.__ALL_COURTS__: 101 yield Court(state_code=c[0], court_code=c[1], state_name=None, name=None)
Enumerate all known valid courts.
Yields: Court: A court object for each valid court.
def
queryParams(self):
103 def queryParams(self): 104 """ 105 Generate query parameters for the court. 106 107 Returns: 108 dict: A dictionary containing the query parameters. 109 """ 110 r = {"state_code": self.state_code, "dist_code": self.district_code} 111 112 r["court_code"] = self.court_code or "1" 113 return r
Generate query parameters for the court.
Returns: dict: A dictionary containing the query parameters.
def
json(self):
115 def json(self): 116 """ 117 Generate a JSON representation of the court. 118 119 Returns: 120 dict: A dictionary containing the JSON representation. 121 """ 122 return { 123 "state_code": self.state_code, 124 "district_code": self.district_code, 125 "court_code": self.court_code, 126 }
Generate a JSON representation of the court.
Returns: dict: A dictionary containing the JSON representation.