Skip to content

Instantly share code, notes, and snippets.

@kinow
Created December 10, 2018 04:13
Show Gist options
  • Save kinow/858d68c146d06795ba727156ee91905f to your computer and use it in GitHub Desktop.
Save kinow/858d68c146d06795ba727156ee91905f to your computer and use it in GitHub Desktop.
import re
s = re.sub(r"\db", r"\d_", "1bread")
print(s)
@kinow
Copy link
Author

kinow commented Dec 10, 2018

python 2.7.15rc1

kinow@kinow-VirtualBox:~/Development/python/workspace/isodatetime$ python test.py
\d_read

python 3.6.7

kinow@kinow-VirtualBox:~/Development/python/workspace/isodatetime$ python3 test.py
\d_read

python 3.7.0

kinow@kinow-VirtualBox:~/Development/python/workspace/isodatetime$ python test.py 
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test.py", line 3, in <module>
    s = re.sub(r"\db", r"\d_", "1bread")
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 0

@kinow
Copy link
Author

kinow commented Dec 11, 2018

kinow@kinow-VirtualBox:~/Development/python/workspace/isodatetime$ ./isodatetime/run_tests 
test_days_in_year_range (__main__.TestSuite)
Test the summing-over-days-in-year-range shortcut code. ... ok
test_duration_floordiv (__main__.TestSuite)
Test the existing dunder floordir, which will be removed when we ... ok
test_duration_in_weeks_floordiv (__main__.TestSuite)
Test the existing dunder floordir, which will be removed when we ... ok
test_duration_subtract (__main__.TestSuite)
Test subtracting a duration from a timepoint. ... ok
test_duration_to_weeks (__main__.TestSuite)
Test that the duration does not lose precision when converted ... ok
test_get_local_time_zone_format (__main__.TestSuite)
Test that the UTC offset string format is correct ... ok
test_get_local_time_zone_no_dst (__main__.TestSuite)
Test that the hour/minute returned is correct. ... ok
test_get_local_time_zone_with_dst (__main__.TestSuite)
Test that the hour/minute returned is correct ... ok
test_largest_truncated_property_name (__main__.TestSuite)
Test the largest truncated property name. ... ERROR
test_smallest_missing_property_name (__main__.TestSuite)
Test the smallest missing property name. ... ERROR
test_timeduration (__main__.TestSuite)
Test the duration class methods. ... ok
test_timeduration_add_week (__main__.TestSuite)
Test the duration not in weeks add duration in weeks. ... ok
test_timeduration_dumper (__main__.TestSuite)
Test the duration dumping. ... ok
test_timeduration_parser (__main__.TestSuite)
Test the duration parsing. ... ERROR
test_timepoint (__main__.TestSuite)
Test the time point data model (takes a while). ... ok
test_timepoint_add_duration (__main__.TestSuite)
Test adding a duration to a timepoint ... ok
test_timepoint_add_duration_without_minute (__main__.TestSuite)
Test adding a duration to a timepoint ... ok
test_timepoint_dumper (__main__.TestSuite)
Test the dumping of TimePoint instances. ... ERROR
test_timepoint_dumper_after_copy (__main__.TestSuite)
Test that printing the TimePoint attributes works after it has ... ok
test_timepoint_dumper_bounds_error_message (__main__.TestSuite)
Test the exception text contains the information expected ... ok
test_timepoint_dumper_get_time_zone (__main__.TestSuite)
Test the time zone returned by TimerPointDumper.get_time_zone ... ERROR
test_timepoint_parser (__main__.TestSuite)
Test the parsing of date/time expressions. ... ERROR
test_timepoint_plus_float_time_duration_day_of_month_type (__main__.TestSuite)
Test (TimePoint + Duration).day_of_month is an int. ... ok
test_timepoint_strftime_strptime (__main__.TestSuite)
Test the strftime/strptime for date/time expressions. ... ERROR
test_timepoint_subtract (__main__.TestSuite)
Test subtracting one time point from another. ... ok
test_timepoint_time_zone (__main__.TestSuite)
Test the time zone handling of timepoint instances. ... ok
test_timerecurrence (__main__.TestSuite)
Test the recurring date/time series data model. ... ERROR
test_timerecurrence_alt_calendars (__main__.TestSuite)
Test recurring date/time series for alternate calendars. ... ERROR
test_timerecurrence_parser (__main__.TestSuite)
Test the recurring date/time series parsing. ... ERROR
test_util_cache (__main__.TestSuite)
Test the cache provided in the util file ... ok

======================================================================
ERROR: test_largest_truncated_property_name (__main__.TestSuite)
Test the largest truncated property name.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1082, in test_largest_truncated_property_name
    allow_truncated=True)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_smallest_missing_property_name (__main__.TestSuite)
Test the smallest missing property name.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1102, in test_smallest_missing_property_name
    allow_truncated=True)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timeduration_parser (__main__.TestSuite)
Test the duration parsing.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1135, in test_timeduration_parser
    test_result = str(parser.parse(expression))
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 579, in parse
    assumed_time_zone=(0, 0)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 603, in parse_timepoint_expression
    parser = TimePointParser(**kwargs)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timepoint_dumper (__main__.TestSuite)
Test the dumping of TimePoint instances.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1256, in test_timepoint_dumper
    default_to_unknown_time_zone=True)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timepoint_dumper_get_time_zone (__main__.TestSuite)
Test the time zone returned by TimerPointDumper.get_time_zone
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1320, in test_timepoint_dumper_get_time_zone
    tz = dumper.get_time_zone(value)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/util.py", line 40, in _wrap_func
    results = func(*args, **kwargs)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/dumpers.py", line 221, in get_time_zone
    self._timepoint_parser = parsers.TimePointParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timepoint_parser (__main__.TestSuite)
Test the parsing of date/time expressions.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1337, in test_timepoint_parser
    default_to_unknown_time_zone=True)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timepoint_strftime_strptime (__main__.TestSuite)
Test the strftime/strptime for date/time expressions.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1422, in test_timepoint_strftime_strptime
    parser = parsers.TimePointParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timerecurrence (__main__.TestSuite)
Test the recurring date/time series data model.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1539, in test_timerecurrence
    parser = parsers.TimeRecurrenceParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 72, in __init__
    self.timepoint_parser = TimePointParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timerecurrence_alt_calendars (__main__.TestSuite)
Test recurring date/time series for alternate calendars.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1517, in test_timerecurrence_alt_calendars
    parser = parsers.TimeRecurrenceParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 72, in __init__
    self.timepoint_parser = TimePointParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

======================================================================
ERROR: test_timerecurrence_parser (__main__.TestSuite)
Test the recurring date/time series parsing.
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/tests.py", line 1593, in test_timerecurrence_parser
    parser = parsers.TimeRecurrenceParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 72, in __init__
    self.timepoint_parser = TimePointParser()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 158, in __init__
    self._generate_regexes()
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 181, in _generate_regexes
    date_expr)
  File "/home/kinow/Development/python/workspace/isodatetime/isodatetime/parsers.py", line 213, in parse_date_expression_to_regex
    expression = re.sub(expr_regex, substitute, expression)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 192, in sub
    return _compile(pattern, flags).sub(repl, string, count)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/home/kinow/Development/python/anaconda3/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 12

----------------------------------------------------------------------
Ran 30 tests in 253.385s

FAILED (errors=10)

@kinow
Copy link
Author

kinow commented Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment