Skip to content

Commit

Permalink
fix: cleanup deprecation warnings for regular expression escapes
Browse files Browse the repository at this point in the history
  • Loading branch information
Cameron Hurst committed Feb 13, 2020
1 parent ba8d9e1 commit 447a391
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 59 deletions.
42 changes: 21 additions & 21 deletions pendulum/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,35 +11,35 @@
from pendulum.utils._compat import decode


_MATCH_1 = "\d"
_MATCH_2 = "\d\d"
_MATCH_3 = "\d{3}"
_MATCH_4 = "\d{4}"
_MATCH_6 = "[+-]?\d{6}"
_MATCH_1_TO_2 = "\d\d?"
_MATCH_1_TO_2_LEFT_PAD = "[0-9 ]\d?"
_MATCH_1_TO_3 = "\d{1,3}"
_MATCH_1_TO_4 = "\d{1,4}"
_MATCH_1_TO_6 = "[+-]?\d{1,6}"
_MATCH_3_TO_4 = "\d{3}\d?"
_MATCH_5_TO_6 = "\d{5}\d?"
_MATCH_UNSIGNED = "\d+"
_MATCH_SIGNED = "[+-]?\d+"
_MATCH_OFFSET = "[Zz]|[+-]\d\d:?\d\d"
_MATCH_SHORT_OFFSET = "[Zz]|[+-]\d\d(?::?\d\d)?"
_MATCH_TIMESTAMP = "[+-]?\d+(\.\d{1,6})?"
_MATCH_1 = r"\d"
_MATCH_2 = r"\d\d"
_MATCH_3 = r"\d{3}"
_MATCH_4 = r"\d{4}"
_MATCH_6 = r"[+-]?\d{6}"
_MATCH_1_TO_2 = r"\d\d?"
_MATCH_1_TO_2_LEFT_PAD = r"[0-9 ]\d?"
_MATCH_1_TO_3 = r"\d{1,3}"
_MATCH_1_TO_4 = r"\d{1,4}"
_MATCH_1_TO_6 = r"[+-]?\d{1,6}"
_MATCH_3_TO_4 = r"\d{3}\d?"
_MATCH_5_TO_6 = r"\d{5}\d?"
_MATCH_UNSIGNED = r"\d+"
_MATCH_SIGNED = r"[+-]?\d+"
_MATCH_OFFSET = r"[Zz]|[+-]\d\d:?\d\d"
_MATCH_SHORT_OFFSET = r"[Zz]|[+-]\d\d(?::?\d\d)?"
_MATCH_TIMESTAMP = r"[+-]?\d+(\.\d{1,6})?"
_MATCH_WORD = (
"(?i)[0-9]*"
"['a-z\u00A0-\u05FF\u0700-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+"
"|[\u0600-\u06FF\/]+(\s*?[\u0600-\u06FF]+){1,2}"
r"|[\u0600-\u06FF/]+(\s*?[\u0600-\u06FF]+){1,2}"
)
_MATCH_TIMEZONE = "[A-za-z0-9-+]+(/[A-Za-z0-9-+_]+)?"


class Formatter:

_TOKENS = (
"\[([^\[]*)\]|\\\(.)|"
r"\[([^\[]*)\]|\\(.)|"
"("
"Mo|MM?M?M?"
"|Do|DDDo|DD?D?D?|ddd?d?|do?"
Expand Down Expand Up @@ -67,7 +67,7 @@ class Formatter:
"Mo": None,
"DDDo": None,
"Do": lambda locale: tuple(
"\d+{}".format(o) for o in locale.get("custom.ordinal").values()
r"\d+{}".format(o) for o in locale.get("custom.ordinal").values()
),
"dddd": "days.wide",
"ddd": "days.abbreviated",
Expand Down Expand Up @@ -607,7 +607,7 @@ def _get_parsed_locale_value(
unit = "month"
match = "months.abbreviated"
elif token == "Do":
parsed["day"] = int(re.match("(\d+)", value).group(1))
parsed["day"] = int(re.match(r"(\d+)", value).group(1))

return
elif token == "dddd":
Expand Down
12 changes: 6 additions & 6 deletions pendulum/parsing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
"^"
"(?P<date>"
" (?P<classic>" # Classic date (YYYY-MM-DD)
" (?P<year>\d{4})" # Year
r" (?P<year>\d{4})" # Year
" (?P<monthday>"
" (?P<monthsep>[/:])?(?P<month>\d{2})" # Month (optional)
" ((?P<daysep>[/:])?(?P<day>\d{2}))" # Day (optional)
r" (?P<monthsep>[/:])?(?P<month>\d{2})" # Month (optional)
r" ((?P<daysep>[/:])?(?P<day>\d{2}))" # Day (optional)
" )?"
" )"
")?"
# Time (optional)
"(?P<time>"
" (?P<timesep>\ )?" # Separator (space)
" (?P<hour>\d{1,2}):(?P<minute>\d{1,2})?(?::(?P<second>\d{1,2}))?" # HH:mm:ss (optional mm and ss)
r" (?P<timesep>\ )?" # Separator (space)
r" (?P<hour>\d{1,2}):(?P<minute>\d{1,2})?(?::(?P<second>\d{1,2}))?" # HH:mm:ss (optional mm and ss)
# Subsecond part (optional)
" (?P<subsecondsection>"
" (?:[.|,])" # Subsecond separator (optional)
" (?P<subsecond>\d{1,9})" # Subsecond
r" (?P<subsecond>\d{1,9})" # Subsecond
" )?"
")?"
"$",
Expand Down
34 changes: 17 additions & 17 deletions pendulum/parsing/iso8601.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,34 @@
"^"
"(?P<date>"
" (?P<classic>" # Classic date (YYYY-MM-DD) or ordinal (YYYY-DDD)
" (?P<year>\d{4})" # Year
r" (?P<year>\d{4})" # Year
" (?P<monthday>"
" (?P<monthsep>-)?(?P<month>\d{2})" # Month (optional)
" ((?P<daysep>-)?(?P<day>\d{1,2}))?" # Day (optional)
r" (?P<monthsep>-)?(?P<month>\d{2})" # Month (optional)
r" ((?P<daysep>-)?(?P<day>\d{1,2}))?" # Day (optional)
" )?"
" )"
" |"
" (?P<isocalendar>" # Calendar date (2016-W05 or 2016-W05-5)
" (?P<isoyear>\d{4})" # Year
r" (?P<isoyear>\d{4})" # Year
" (?P<weeksep>-)?" # Separator (optional)
" W" # W separator
" (?P<isoweek>\d{2})" # Week number
r" (?P<isoweek>\d{2})" # Week number
" (?P<weekdaysep>-)?" # Separator (optional)
" (?P<isoweekday>\d)?" # Weekday (optional)
r" (?P<isoweekday>\d)?" # Weekday (optional)
" )"
")?"
# Time (optional)
"(?P<time>"
" (?P<timesep>[T\ ])?" # Separator (T or space)
" (?P<hour>\d{1,2})(?P<minsep>:)?(?P<minute>\d{1,2})?(?P<secsep>:)?(?P<second>\d{1,2})?" # HH:mm:ss (optional mm and ss)
r" (?P<timesep>[T\ ])?" # Separator (T or space)
r" (?P<hour>\d{1,2})(?P<minsep>:)?(?P<minute>\d{1,2})?(?P<secsep>:)?(?P<second>\d{1,2})?" # HH:mm:ss (optional mm and ss)
# Subsecond part (optional)
" (?P<subsecondsection>"
" (?:[.,])" # Subsecond separator (optional)
" (?P<subsecond>\d{1,9})" # Subsecond
r" (?P<subsecond>\d{1,9})" # Subsecond
" )?"
# Timezone offset
" (?P<tz>"
" (?:[-+])\d{2}:?(?:\d{2})?|Z" # Offset (+HH:mm or +HHmm or +HH or Z)
r" (?:[-+])\d{2}:?(?:\d{2})?|Z" # Offset (+HH:mm or +HHmm or +HH or Z)
" )?"
")?"
"$",
Expand All @@ -59,18 +59,18 @@
"^P" # Duration P indicator
# Years, months and days (optional)
"(?P<w>"
" (?P<weeks>\d+(?:[.,]\d+)?W)"
r" (?P<weeks>\d+(?:[.,]\d+)?W)"
")?"
"(?P<ymd>"
" (?P<years>\d+(?:[.,]\d+)?Y)?"
" (?P<months>\d+(?:[.,]\d+)?M)?"
" (?P<days>\d+(?:[.,]\d+)?D)?"
r" (?P<years>\d+(?:[.,]\d+)?Y)?"
r" (?P<months>\d+(?:[.,]\d+)?M)?"
r" (?P<days>\d+(?:[.,]\d+)?D)?"
")?"
"(?P<hms>"
" (?P<timesep>T)" # Separator (T)
" (?P<hours>\d+(?:[.,]\d+)?H)?"
" (?P<minutes>\d+(?:[.,]\d+)?M)?"
" (?P<seconds>\d+(?:[.,]\d+)?S)?"
r" (?P<hours>\d+(?:[.,]\d+)?H)?"
r" (?P<minutes>\d+(?:[.,]\d+)?M)?"
r" (?P<seconds>\d+(?:[.,]\d+)?S)?"
")?"
"$",
re.VERBOSE,
Expand Down
4 changes: 2 additions & 2 deletions pendulum/tz/local_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,8 @@ def _get_unix_timezone(_root="/"): # type: (str) -> Timezone
# OpenSUSE has a TIMEZONE setting in /etc/sysconfig/clock and
# Gentoo has a TIMEZONE setting in /etc/conf.d/clock
# We look through these files for a timezone:
zone_re = re.compile('\s*ZONE\s*=\s*"')
timezone_re = re.compile('\s*TIMEZONE\s*=\s*"')
zone_re = re.compile(r'\s*ZONE\s*=\s*"')
timezone_re = re.compile(r'\s*TIMEZONE\s*=\s*"')
end_re = re.compile('"')

for filename in ("etc/sysconfig/clock", "etc/conf.d/clock"):
Expand Down
26 changes: 13 additions & 13 deletions pendulum/tz/zoneinfo/posix_timezone.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@

_spec = re.compile(
"^"
"(?P<std_abbr><.*?>|[^-+,\d]{3,})"
"(?P<std_offset>([+-])?(\d{1,2})(:\d{2}(:\d{2})?)?)"
"(?P<dst_info>"
" (?P<dst_abbr><.*?>|[^-+,\d]{3,})"
" (?P<dst_offset>([+-])?(\d{1,2})(:\d{2}(:\d{2})?)?)?"
")?"
"(?:,(?P<rules>"
" (?P<dst_start>"
" (?:J\d+|\d+|M\d{1,2}.\d.[0-6])"
" (?:/(?P<dst_start_offset>([+-])?(\d+)(:\d{2}(:\d{2})?)?))?"
r"(?P<std_abbr><.*?>|[^-+,\d]{3,})"
r"(?P<std_offset>([+-])?(\d{1,2})(:\d{2}(:\d{2})?)?)"
r"(?P<dst_info>"
r" (?P<dst_abbr><.*?>|[^-+,\d]{3,})"
r" (?P<dst_offset>([+-])?(\d{1,2})(:\d{2}(:\d{2})?)?)?"
r")?"
r"(?:,(?P<rules>"
r" (?P<dst_start>"
r" (?:J\d+|\d+|M\d{1,2}.\d.[0-6])"
r" (?:/(?P<dst_start_offset>([+-])?(\d+)(:\d{2}(:\d{2})?)?))?"
" )"
" ,"
" (?P<dst_end>"
" (?:J\d+|\d+|M\d{1,2}.\d.[0-6])"
" (?:/(?P<dst_end_offset>([+-])?(\d+)(:\d{2}(:\d{2})?)?))?"
r" (?P<dst_end>"
r" (?:J\d+|\d+|M\d{1,2}.\d.[0-6])"
r" (?:/(?P<dst_end_offset>([+-])?(\d+)(:\d{2}(:\d{2})?)?))?"
" )"
"))?"
"$",
Expand Down

0 comments on commit 447a391

Please sign in to comment.