Skip to content

Commit

Permalink
Cope with more characters when normalizing (hyphens, apostrophes, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
kfsone committed Aug 15, 2014
1 parent 01f3a4a commit 1665dbb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tradedb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# Imports

import sys
import re
import pypyodbc
from queue import Queue

Expand Down Expand Up @@ -124,6 +125,8 @@ def __repr__(self):


class TradeDB(object):
normalizeRe = re.compile(r'[ \t\'\"\.\-_]')

def __init__(self, path=r'.\TradeDangerous.accdb', debug=0):
self.path = "Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + path
self.debug = debug
Expand Down Expand Up @@ -275,6 +278,7 @@ def list_search(self, listType, lookup, values):
raise LookupError("Error: '%s' doesn't match any %s" % (lookup, listType))
return match


def normalized_str(self, str):
return str.replace(" ", "").casefold()
# Remove spaces, tabs, apostrophes, periods, hyphens and underscores,
# then convert to casefolded so that caseless matches will work.
return self.normalizeRe.sub('', str).casefold()

0 comments on commit 1665dbb

Please sign in to comment.