Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hand raw strings to re module #3

Merged
merged 1 commit into from
Nov 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions hocr_spec/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def __init__(self, name, type,
required_properties=None,
range=None,
required_capabilities=[],
split_pattern=["\s+"],
split_pattern=[r"\s+"],
list=False):
self.name = name
self.type = type
Expand Down Expand Up @@ -76,7 +76,7 @@ def __repr__(self):
'cuts',
int,
list=True,
split_pattern=['\s+', ','],
split_pattern=[r'\s+', ','],
required_properties=['bbox'])
nlp = HocrSpecProperty(
'nlp',
Expand Down Expand Up @@ -345,7 +345,7 @@ def __get_capabilities(self, root):
"""
try:
caps = root.xpath('//meta[@name="ocr-capabilities"]/@content')[0]
return re.split('\s+', caps)
return re.split(r'\s+', caps)
except IndexError as e: return []

def __has_capability(self, report, el, cap):
Expand Down Expand Up @@ -510,7 +510,7 @@ def list(cls, category):
elif category == 'checks':
return [k[len('check_'):] for k in dir(cls)]
elif category == 'capabilities':
return [k for k in dir(HocrSpecCapabilities) if re.match('^[a-z].*', k)]
return [k for k in dir(HocrSpecCapabilities) if re.match(r'^[a-z].*', k)]
else:
raise ValueError("Unknown category %s" % category)

Expand All @@ -529,9 +529,9 @@ def parse_properties(self, title):
if hasattr(title, 'attrib'):
title = title.attrib['title']
# Split on semicolon, optionally preceded and followed by whitespace
for kv in re.split('\s*;\s*', title):
for kv in re.split(r'\s*;\s*', title):
# Split key and value at first whitespace
(k, v) = re.split('\s+', kv, 1)
(k, v) = re.split(r'\s+', kv, 1)
# Make sure the property is from the list of known properties
try:
prop_spec = getattr(HocrSpecProperties, k)
Expand Down