summaryrefslogtreecommitdiff
path: root/memcache.py
diff options
context:
space:
mode:
authorSean Reifschneider <jafo@tummy.com>2009-04-02 13:35:25 -0600
committerSean Reifschneider <jafo@tummy.com>2009-04-02 13:35:25 -0600
commit06f80173d0134bb6f495a8f484ce64bb3a84915c (patch)
tree86274c526af05f296fcfd6b45a0e5504d09b1806 /memcache.py
parent106dcd68d30a6ac28388d81a787b4667f4eba7e4 (diff)
downloadpython-memcached-06f80173d0134bb6f495a8f484ce64bb3a84915c.tar.gz
Providing better error messages (patch provided by Johan Euphrosine).
Diffstat (limited to 'memcache.py')
-rw-r--r--memcache.py19
1 files changed, 15 insertions, 4 deletions
diff --git a/memcache.py b/memcache.py
index a96023a..3e0a789 100644
--- a/memcache.py
+++ b/memcache.py
@@ -129,6 +129,10 @@ class Client(local):
pass
class MemcachedKeyCharacterError(MemcachedKeyError):
pass
+ class MemcachedKeyNoneError(MemcachedKeyError):
+ pass
+ class MemcachedKeyTypeError(MemcachedKeyError):
+ pass
class MemcachedStringEncodingError(Exception):
pass
@@ -946,20 +950,27 @@ def check_key(key, key_extra_len=0):
Key length is > SERVER_MAX_KEY_LENGTH (Raises MemcachedKeyLength).
Contains control characters (Raises MemcachedKeyCharacterError).
Is not a string (Raises MemcachedStringEncodingError)
+ Is an unicode string (Raises MemcachedStringEncodingError)
+ Is not a string (Raises MemcachedKeyError)
+ Is None (Raises MemcachedKeyError)
"""
if type(key) == types.TupleType: key = key[1]
- if not isinstance(key, str):
- raise Client.MemcachedStringEncodingError, ("Keys must be str()'s, not"
+ if not key:
+ raise Client.MemcachedKeyNoneError, ("Key is None")
+ if isinstance(key, unicode):
+ raise Client.MemcachedStringEncodingError, ("Keys must be str()'s, not "
"unicode. Convert your unicode strings using "
"mystring.encode(charset)!")
+ if not isinstance(key, str):
+ raise Client.MemcachedKeyTypeError, ("Key must be str()'s")
if isinstance(key, basestring):
if len(key) + key_extra_len > SERVER_MAX_KEY_LENGTH:
raise Client.MemcachedKeyLengthError, ("Key length is > %s"
% SERVER_MAX_KEY_LENGTH)
for char in key:
- if ord(char) < 32 or ord(char) == 127:
- raise Client.MemcachedKeyCharacterError, "Control characters not allowed"
+ if ord(char) < 32 or ord(char) == 127:
+ raise Client.MemcachedKeyCharacterError, "Control characters not allowed"
def _doctest():
import doctest, memcache