Skip to content

Commit 17c4ce7

Browse files
chore: auto-fix lint and format issues
1 parent dabcd2e commit 17c4ce7

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

airbyte-integrations/connectors/source-prestashop/components.py

+35-39
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# Copyright (c) 2023 Airbyte, Inc., all rights reserved.
33
#
44

5-
from dataclasses import InitVar, dataclass
6-
from typing import Any, List, Mapping, Optional, Tuple
75
import re
6+
from dataclasses import InitVar, dataclass
87
from datetime import datetime as dt
8+
from typing import Any, List, Mapping, Optional, Tuple
99

1010
from airbyte_cdk.sources.declarative.schema import JsonFileSchemaLoader
1111
from airbyte_cdk.sources.declarative.transformations import RecordTransformation
@@ -14,6 +14,7 @@
1414

1515
class ParserError(Exception):
1616
"""Replacement for pendulum's ParserError"""
17+
1718
pass
1819

1920

@@ -30,7 +31,7 @@ def __post_init__(self, parameters: Optional[Mapping[str, Any]] = None):
3031
# Handle the case when parameters is None
3132
parameters = parameters or {}
3233
self.name = parameters.get("name")
33-
34+
3435
# Skip schema loading if name is None
3536
if self.name is None:
3637
self._schema = {}
@@ -43,7 +44,7 @@ def _get_schema_root_properties(self):
4344
# Only call this if self.name is not None
4445
if not self.name:
4546
return {}
46-
47+
4748
schema_loader = JsonFileSchemaLoader(config=self.config, parameters={"name": self.name})
4849
schema = schema_loader.get_json_schema()
4950
return schema.get("properties", {})
@@ -60,75 +61,71 @@ def parse(self, text):
6061
Handles various date formats including those with timezone information.
6162
"""
6263
# Reject dates with zeros like '0000-00-00' or '0000-00-00 00:00:00'
63-
if re.match(r'^0+[-]0+[-]0+', text):
64+
if re.match(r"^0+[-]0+[-]0+", text):
6465
raise ParserError("Zero date not allowed")
65-
66+
6667
# Comprehensive list of formats to try
6768
formats = [
6869
# Basic formats
69-
'%Y-%m-%d',
70-
'%Y/%m/%d',
71-
'%d-%m-%Y',
72-
'%d/%m/%Y',
73-
70+
"%Y-%m-%d",
71+
"%Y/%m/%d",
72+
"%d-%m-%Y",
73+
"%d/%m/%Y",
7474
# Date and time formats
75-
'%Y-%m-%d %H:%M:%S',
76-
'%Y-%m-%d %H:%M:%S.%f',
77-
'%Y/%m/%d %H:%M:%S',
78-
'%Y/%m/%d %H:%M:%S.%f',
79-
75+
"%Y-%m-%d %H:%M:%S",
76+
"%Y-%m-%d %H:%M:%S.%f",
77+
"%Y/%m/%d %H:%M:%S",
78+
"%Y/%m/%d %H:%M:%S.%f",
8079
# ISO formats
81-
'%Y-%m-%dT%H:%M:%S',
82-
'%Y-%m-%dT%H:%M:%S.%f',
83-
80+
"%Y-%m-%dT%H:%M:%S",
81+
"%Y-%m-%dT%H:%M:%S.%f",
8482
# With timezone
85-
'%Y-%m-%d %H:%M:%S%z',
86-
'%Y-%m-%d %H:%M:%S.%f%z',
87-
'%Y-%m-%dT%H:%M:%S%z',
88-
'%Y-%m-%dT%H:%M:%S.%f%z',
89-
83+
"%Y-%m-%d %H:%M:%S%z",
84+
"%Y-%m-%d %H:%M:%S.%f%z",
85+
"%Y-%m-%dT%H:%M:%S%z",
86+
"%Y-%m-%dT%H:%M:%S.%f%z",
9087
# Using Z for UTC
91-
'%Y-%m-%dT%H:%M:%SZ',
92-
'%Y-%m-%dT%H:%M:%S.%fZ',
88+
"%Y-%m-%dT%H:%M:%SZ",
89+
"%Y-%m-%dT%H:%M:%S.%fZ",
9390
]
9491

9592
# Try parsing with different formats
9693
for fmt in formats:
9794
try:
9895
# Handle 'Z' timezone indicator for UTC
9996
text_to_parse = text
100-
if fmt.endswith('Z') and not text.endswith('Z'):
97+
if fmt.endswith("Z") and not text.endswith("Z"):
10198
continue
102-
if not fmt.endswith('Z') and text.endswith('Z'):
99+
if not fmt.endswith("Z") and text.endswith("Z"):
103100
text_to_parse = text[:-1] # Remove Z
104-
fmt = fmt + 'Z' if 'Z' not in fmt else fmt
105-
101+
fmt = fmt + "Z" if "Z" not in fmt else fmt
102+
106103
date_obj = dt.strptime(text_to_parse, fmt)
107104
# In pendulum, dates with zero components are rejected
108105
if date_obj.year == 0 or date_obj.month == 0 or date_obj.day == 0:
109106
raise ParserError("Date with zero components")
110107
return date_obj
111108
except ValueError:
112109
continue
113-
110+
114111
# Try ISO format as a last resort
115112
try:
116113
# Replace Z with +00:00 for ISO format parsing
117-
iso_text = text.replace('Z', '+00:00')
118-
114+
iso_text = text.replace("Z", "+00:00")
115+
119116
# For Python < 3.11 compatibility, remove microseconds if they have more than 6 digits
120-
microseconds_match = re.search(r'\.(\d{7,})(?=[+-Z]|$)', iso_text)
117+
microseconds_match = re.search(r"\.(\d{7,})(?=[+-Z]|$)", iso_text)
121118
if microseconds_match:
122119
fixed_micro = microseconds_match.group(1)[:6]
123-
iso_text = iso_text.replace(microseconds_match.group(0), f'.{fixed_micro}')
124-
120+
iso_text = iso_text.replace(microseconds_match.group(0), f".{fixed_micro}")
121+
125122
date_obj = dt.fromisoformat(iso_text)
126123
if date_obj.year == 0 or date_obj.month == 0 or date_obj.day == 0:
127124
raise ParserError("Date with zero components")
128125
return date_obj
129126
except (ValueError, AttributeError):
130127
pass
131-
128+
132129
# If nothing worked, raise the error like pendulum would
133130
raise ParserError(f"Unable to parse: {text}")
134131

@@ -142,12 +139,11 @@ def transform(
142139
# If we don't have any fields to check, just return the record as is
143140
if not self._date_and_date_time_fields:
144141
return record
145-
142+
146143
for item in record:
147144
if item in self._date_and_date_time_fields and record.get(item):
148145
try:
149146
self.parse(record[item])
150147
except ParserError:
151148
record[item] = None
152149
return record
153-

0 commit comments

Comments
 (0)