Skip to content

Commit

Permalink
Raise ShapefileException for runtime errors rather than using assert()
Browse files Browse the repository at this point in the history
  • Loading branch information
riggsd committed Dec 3, 2014
1 parent 202143c commit 66e1802
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions shapefile.py
Expand Up @@ -453,7 +453,8 @@ def __dbfHeader(self):
fieldDesc[1] = u(fieldDesc[1])
self.fields.append(fieldDesc)
terminator = dbf.read(1)
assert terminator == b("\r")
if terminator != b("\r"):
raise ShapefileException("Shapefile dbf header lacks expected terminator. (likely corrupt?)")
self.fields.insert(0, ('DeletionFlag', 'C', 1, 0))

def __recordFmt(self):
Expand Down Expand Up @@ -888,7 +889,10 @@ def __dbfRecords(self):
value = str(value)[0].upper()
else:
value = str(value)[:size].ljust(size)
assert len(value) == size
if len(value) != size:
raise ShapefileException(
"Shapefile Writer unable to pack incorrect sized value"
" (size %d) into field '%s' (size %d)." % (len(value), fieldName, size))
value = b(value)
f.write(value)

Expand Down

0 comments on commit 66e1802

Please sign in to comment.