From 19971e6e71c5c2e209df717c7c615bc64db4dcab Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 19 Sep 2024 21:56:24 +0200 Subject: [PATCH 1/4] Fixed a rare bug with locals() being changed during iteration --- src/pyrmv/raw/board_arrival.py | 2 +- src/pyrmv/raw/board_departure.py | 2 +- src/pyrmv/raw/him_search.py | 2 +- src/pyrmv/raw/journey_detail.py | 2 +- src/pyrmv/raw/stop_by_coords.py | 2 +- src/pyrmv/raw/stop_by_name.py | 2 +- src/pyrmv/raw/trip_find.py | 2 +- src/pyrmv/raw/trip_recon.py | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/pyrmv/raw/board_arrival.py b/src/pyrmv/raw/board_arrival.py index 1e34527..b6674ec 100644 --- a/src/pyrmv/raw/board_arrival.py +++ b/src/pyrmv/raw/board_arrival.py @@ -64,7 +64,7 @@ def board_arrival( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "date": if val != None: if isinstance(val, datetime): diff --git a/src/pyrmv/raw/board_departure.py b/src/pyrmv/raw/board_departure.py index e3cef29..dafe1fc 100644 --- a/src/pyrmv/raw/board_departure.py +++ b/src/pyrmv/raw/board_departure.py @@ -65,7 +65,7 @@ def board_departure( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "date": if val != None: if isinstance(val, datetime): diff --git a/src/pyrmv/raw/him_search.py b/src/pyrmv/raw/him_search.py index bd6a2c3..535a8e6 100644 --- a/src/pyrmv/raw/him_search.py +++ b/src/pyrmv/raw/him_search.py @@ -97,7 +97,7 @@ def him_search( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) in {"dateB", "dateE"}: if val != None: if isinstance(val, datetime): diff --git a/src/pyrmv/raw/journey_detail.py b/src/pyrmv/raw/journey_detail.py index 81235c2..39236d8 100644 --- a/src/pyrmv/raw/journey_detail.py +++ b/src/pyrmv/raw/journey_detail.py @@ -55,7 +55,7 @@ def journey_detail( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "rtMode": if val != None: payload["rtMode"] = val.upper() diff --git a/src/pyrmv/raw/stop_by_coords.py b/src/pyrmv/raw/stop_by_coords.py index b8c7f05..b4fbdf4 100644 --- a/src/pyrmv/raw/stop_by_coords.py +++ b/src/pyrmv/raw/stop_by_coords.py @@ -54,7 +54,7 @@ def stop_by_coords( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "stopType": if val != None: payload["type"] = val.upper() diff --git a/src/pyrmv/raw/stop_by_name.py b/src/pyrmv/raw/stop_by_name.py index 5355a0b..5ac372c 100644 --- a/src/pyrmv/raw/stop_by_name.py +++ b/src/pyrmv/raw/stop_by_name.py @@ -65,7 +65,7 @@ def stop_by_name( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "inputString": if val != None: payload["input"] = val diff --git a/src/pyrmv/raw/trip_find.py b/src/pyrmv/raw/trip_find.py index 8465074..887b2cd 100644 --- a/src/pyrmv/raw/trip_find.py +++ b/src/pyrmv/raw/trip_find.py @@ -201,7 +201,7 @@ def trip_find( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "date": if val != None: if isinstance(val, datetime): diff --git a/src/pyrmv/raw/trip_recon.py b/src/pyrmv/raw/trip_recon.py index e916e1e..ccb0941 100644 --- a/src/pyrmv/raw/trip_recon.py +++ b/src/pyrmv/raw/trip_recon.py @@ -87,7 +87,7 @@ def trip_recon( payload = {} headers = {"Accept": "application/json"} if json else {"Accept": "application/xml"} - for var, val in locals().items(): + for var, val in locals().copy().items(): if str(var) == "date": if val != None: if isinstance(val, datetime): From 9e12b53c3b36dcdbfe8a59cdeca95c86654f4e7f Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 19 Sep 2024 22:03:02 +0200 Subject: [PATCH 2/4] Trip.duration and Trip.real_time_duration are now nullable --- src/pyrmv/classes/trip.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pyrmv/classes/trip.py b/src/pyrmv/classes/trip.py index dd41494..e62c6dc 100644 --- a/src/pyrmv/classes/trip.py +++ b/src/pyrmv/classes/trip.py @@ -19,8 +19,10 @@ class Trip: self.index: int = data["idx"] self.id: str = data["tripId"] self.ctx_recon: str = data["ctxRecon"] - self.duration: Union[Duration, timedelta] = parse_duration(data["duration"]) - self.real_time_duration: Union[Duration, timedelta] = ( + self.duration: Union[Duration, timedelta, None] = ( + None if "duration" not in data else parse_duration(data["duration"]) + ) + self.real_time_duration: Union[Duration, timedelta, None] = ( None if "rtDuration" not in data else parse_duration(data["rtDuration"]) ) self.checksum: str = data["checksum"] From c06d90b7ceec2d8fe28ef9fd518b0dea05e2fe31 Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 19 Sep 2024 22:03:23 +0200 Subject: [PATCH 3/4] Fixed unavailable Message attributes --- src/pyrmv/classes/message.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pyrmv/classes/message.py b/src/pyrmv/classes/message.py index e7eaa2c..7063e0f 100644 --- a/src/pyrmv/classes/message.py +++ b/src/pyrmv/classes/message.py @@ -59,9 +59,9 @@ class Message: self.channels.extend(Channel(channel) for channel in data["channel"]) self.id: str = data["id"] self.active: bool = data["act"] - self.head: str = data["head"] - self.lead: str = data["lead"] - self.text: str = data["text"] + self.head: str = "" if "head" not in data else data["head"] + self.lead: str = "" if "lead" not in data else data["lead"] + self.text: str = "" if "text" not in data else data["text"] self.company: Union[str, None] = data.get("company") self.category: Union[str, None] = data.get("category") self.priority: Union[int, None] = data.get("priority") From dfb472a4e8718dc34150f9141e9d080f82a55ded Mon Sep 17 00:00:00 2001 From: profitroll Date: Thu, 19 Sep 2024 22:03:57 +0200 Subject: [PATCH 4/4] Possibly fixed false positives on exception detection --- src/pyrmv/classes/client.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/pyrmv/classes/client.py b/src/pyrmv/classes/client.py index d2b0889..51400ff 100644 --- a/src/pyrmv/classes/client.py +++ b/src/pyrmv/classes/client.py @@ -150,7 +150,7 @@ class Client: boardType=board_type.code, ) - find_exception(board_raw) + find_exception(board_raw.copy()) return BoardArrival( board_raw, @@ -219,7 +219,7 @@ class Client: boardType=board_type.code, ) - find_exception(board_raw) + find_exception(board_raw.copy()) return BoardDeparture( board_raw, @@ -343,7 +343,7 @@ class Client: minprio=priority_min, ) - find_exception(messages_raw) + find_exception(messages_raw.copy()) if "Message" in messages_raw: messages.extend(Message(message) for message in messages_raw["Message"]) @@ -402,7 +402,7 @@ class Client: toIdx=to_index, ) - find_exception(journey_raw) + find_exception(journey_raw.copy()) return Journey(journey_raw) @@ -481,7 +481,7 @@ class Client: locationSelectionMode=selection_mode, # type: ignore ) - find_exception(stops_raw) + find_exception(stops_raw.copy()) if "stopLocationOrCoordLocation" in stops_raw: for stop in stops_raw["stopLocationOrCoordLocation"]: @@ -536,7 +536,7 @@ class Client: accessId=self.access_id, inputString=query, lang=lang.code, maxNo=1 ) - find_exception(stops_raw) + find_exception(stops_raw.copy()) if len(stops_raw["stopLocationOrCoordLocation"]) <= 0: return None @@ -642,7 +642,7 @@ class Client: filterMode=filter_mode.code, ) - find_exception(stops_raw) + find_exception(stops_raw.copy()) if "stopLocationOrCoordLocation" in stops_raw: for stop in stops_raw["stopLocationOrCoordLocation"]: @@ -833,7 +833,7 @@ class Client: withFreq=frequency, ) - find_exception(trips_raw) + find_exception(trips_raw.copy()) if "Trip" in trips_raw: trips.extend(Trip(trip) for trip in trips_raw["Trip"]) @@ -913,7 +913,7 @@ class Client: trafficMessages=messages, ) - find_exception(trips_raw) + find_exception(trips_raw.copy()) if "Trip" in trips_raw: trips.extend(Trip(trip) for trip in trips_raw["Trip"])