Skip to content

Commit

Permalink
update validator for record id, fix reference bug in dbm adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
GreatYYX committed Apr 3, 2018
1 parent 5db3517 commit c4c61f3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rltk/io/adapter/dbm_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@


class DBMAdapter(KeyValueAdapter):
def __init__(self, filename, dbm_class=dbm.ndbm, serializer:Serializer=PickleSerializer()):
def __init__(self, filename, dbm_class=dbm.ndbm, serializer: Serializer = None):
"""
:dbm_class dbm, dbm.gnu, dbm.ndbm, dbm.dumb (same as dbm)
"""
if not serializer:
serializer = PickleSerializer()
self._db = dbm_class.open(filename, 'c')
self._serializer = serializer

Expand Down
8 changes: 8 additions & 0 deletions rltk/record.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
import re


re_record_id = re.compile(r'^[^*]{1,255}$')


class Record(object):
"""
Record representation. Properties should be defined for further usage.
Expand Down Expand Up @@ -80,3 +86,5 @@ def validate_record(obj):
"""
if not isinstance(obj.id, str):
raise TypeError('Id in {} should be an utf-8 encoded string.'.format(obj.__class__.__name__))
if not re_record_id.match(obj.id):
raise ValueError('Id is not valid')

0 comments on commit c4c61f3

Please sign in to comment.