Skip to content

Commit

Permalink
py3.5 was erroring on use of method, event with exception - using sys…
Browse files Browse the repository at this point in the history
… version to check now
  • Loading branch information
clr182 committed Nov 1, 2024
1 parent ae80681 commit 5fbaa21
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions bugsnag/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,29 +422,25 @@ def remove_query_from_url(url: AnyStr) -> Optional[AnyStr]:
# milliseconds precision
# Python can do this natively from version 3.6, but we need to include a
# fallback implementation for Python 3.5
try:
# this will raise if 'timespec' isn't supported
datetime.now(timezone.utc).isoformat(
timespec='milliseconds' # type: ignore
)

if sys.version_info >= (3, 6):
# Python 3.6+ has a built-in method for this
def to_rfc3339(dt: datetime) -> str:
return dt.isoformat(timespec='milliseconds') # type: ignore

except Exception:
else:
# Python 3.5 fallback implementation
def _get_timezone_offset(dt: datetime) -> str:
if dt.tzinfo is None:
return ''

utc_offset = dt.tzinfo.utcoffset(dt)

if utc_offset is None:
return ''

sign = '+'

if utc_offset.days < 0:
sign = '-'
sign == '-'
utc_offset = -utc_offset

hours_offset, minutes = divmod(utc_offset, timedelta(hours=1))
Expand Down

0 comments on commit 5fbaa21

Please sign in to comment.