Permalink
Browse files

Added error traps

  • Loading branch information...
1 parent d15e37c commit 665e271b197811f10bece02dacbc0b78d44dd198 @yamatt committed May 4, 2012
Showing with 10 additions and 4 deletions.
  1. +10 −4 qrmodels.py
View
14 qrmodels.py
@@ -63,10 +63,13 @@ class QRStore(db.Model):
raw_qr_image = QRImageProperty()
def __init__(self, value):
- hash_value = sha512(value).hexdigest()
- raw_qr_image = MakeQR(value).modules
- raw_qr_image = self.__clean_modules(raw_qr_image)
- super(QRStore, self).__init__(key_name=hash_value, raw_qr_image=raw_qr_image)
+ if len(value) > 6:
+ hash_value = sha512(value).hexdigest()
+ raw_qr_image = MakeQR(value).modules
+ raw_qr_image = self.__clean_modules(raw_qr_image)
+ super(QRStore, self).__init__(key_name=hash_value, raw_qr_image=raw_qr_image)
+ else:
+ raise QRValueError("QR value too short.")
def __clean_modules(self, modules):
return map(lambda row: map(lambda data: False if data else True, row), modules)
@@ -98,3 +101,6 @@ def get_image(self, scale=10, fg_colour=(0,0,0,255), bg_colour=(255,255,255,255)
raw_qr_image = self.scale_image(raw_qr_image, scale)
qr_image = self.render_image(raw_qr_image, fg_colour, bg_colour)
return qr_image
+
+class QRValueError(Exception):
+ pass

0 comments on commit 665e271

Please sign in to comment.