Skip to content
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ automatically by Travis-CI)
pip install pytest
python -m pytest

To run the full matrix of Python versions locally, use two commands:

# old Python versions (via Docker)
docker run --rm -v .:/src -w /src makukha/multipython:unsafe tox run -m old

# modern Python versions (via uv)
uvx --with tox-uv tox run -m new

Quick Start
-----------

Expand Down
10 changes: 5 additions & 5 deletions mf2util.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ def do_convert(match):
for tagname, attributes in URL_ATTRIBUTES.items():
for attribute in attributes:
pattern = re.compile(
'<%s[^>]*?%s\s*=\s*[\'"](.*?)[\'"]' % (tagname, attribute),
r'<%s[^>]*?%s\s*=\s*[\'"](.*?)[\'"]' % (tagname, attribute),
flags=re.DOTALL | re.MULTILINE | re.IGNORECASE)
html = pattern.sub(do_convert, html)

Expand Down Expand Up @@ -484,10 +484,10 @@ def parse_datetime(s):
if not s:
return None

s = re.sub('\s+', ' ', s)
date_re = "(?P<year>\d{4,})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
time_re = "(?P<hour>\d{1,2}):(?P<minute>\d{2})(:(?P<second>\d{2})(\.(?P<microsecond>\d+))?)?"
tz_re = "(?P<tzz>Z)|(?P<tzsign>[+-])(?P<tzhour>\d{1,2}):?(?P<tzminute>\d{2})"
s = re.sub(r'\s+', ' ', s)
date_re = r"(?P<year>\d{4,})-(?P<month>\d{1,2})-(?P<day>\d{1,2})"
time_re = r"(?P<hour>\d{1,2}):(?P<minute>\d{2})(:(?P<second>\d{2})(\.(?P<microsecond>\d+))?)?"
tz_re = r"(?P<tzz>Z)|(?P<tzsign>[+-])(?P<tzhour>\d{1,2}):?(?P<tzminute>\d{2})"
dt_re = "%s((T| )%s ?(%s)?)?$" % (date_re, time_re, tz_re)

m = re.match(dt_re, s)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def run_tests(self):


setup(name='mf2util',
version='0.5.2',
version='0.5.2+zegnat.1',
description='Python Microformats2 utilities, a companion to mf2py',
long_description="""
Microformats2 Utilities
Expand Down
3 changes: 2 additions & 1 deletion tests/test_interpret.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
"""
from __future__ import unicode_literals
from datetime import datetime, date, timedelta
import io
import mf2util
import json


def load_test(testname):
return json.load(open('tests/interpret/%s.json' % testname))
return json.load(io.open('tests/interpret/%s.json' % testname, encoding='utf-8'))


def test_event():
Expand Down
3 changes: 2 additions & 1 deletion tests/test_post_type_discovery.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for post_type_discovery
"""

import io
import json
import mf2util

Expand All @@ -21,7 +22,7 @@ def test_post_type_discovery():
('posttype/hcard_org', 'org'),
# TODO add more tests
]:
parsed = json.load(open('tests/' + test + '.json'))
parsed = json.load(io.open('tests/' + test + '.json', encoding='utf-8'))
types = (['h-card'] if implied_type in ('person', 'org')
else ['h-entry', 'h-event'])
entry = mf2util.find_first_entry(parsed, types)
Expand Down
11 changes: 11 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[tox]
envlist = py27,py35,py36,py37,py38,py39,py310,py311,py312,py313,py314
labels =
old = py27,py35,py36,py37
new = py38,py39,py310,py311,py312,py313,py314

[testenv]
deps =
pytest
mf2py
commands = pytest tests