Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added error traps

  • Loading branch information...
commit 665e271b197811f10bece02dacbc0b78d44dd198 1 parent d15e37c
Matthew Copperwaite authored May 04, 2012

Showing 1 changed file with 10 additions and 4 deletions. Show diff stats Hide diff stats

  1. 14  qrmodels.py
14  qrmodels.py
@@ -63,10 +63,13 @@ class QRStore(db.Model):
63 63
     raw_qr_image = QRImageProperty()
64 64
     
65 65
     def __init__(self, value):
66  
-        hash_value = sha512(value).hexdigest()
67  
-        raw_qr_image = MakeQR(value).modules
68  
-        raw_qr_image = self.__clean_modules(raw_qr_image)
69  
-        super(QRStore, self).__init__(key_name=hash_value, raw_qr_image=raw_qr_image)
  66
+        if len(value) > 6:
  67
+            hash_value = sha512(value).hexdigest()
  68
+            raw_qr_image = MakeQR(value).modules
  69
+            raw_qr_image = self.__clean_modules(raw_qr_image)
  70
+            super(QRStore, self).__init__(key_name=hash_value, raw_qr_image=raw_qr_image)
  71
+        else:
  72
+            raise QRValueError("QR value too short.")
70 73
         
71 74
     def __clean_modules(self, modules):
72 75
         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)
98 101
         raw_qr_image = self.scale_image(raw_qr_image, scale)
99 102
         qr_image = self.render_image(raw_qr_image, fg_colour, bg_colour)
100 103
         return qr_image
  104
+
  105
+class QRValueError(Exception):
  106
+    pass

0 notes on commit 665e271

Please sign in to comment.
Something went wrong with that request. Please try again.