check_key

Philip Neustrom philipn at gmail.com
Tue Aug 28 16:13:14 UTC 2007


>>> c = 'hi there'
>>> space = c[2]
>>> ord(space)
32

The memcached protocol spec says no control chars.  ord(c) < 33 does that.

That is the latest version of the client.  You can grab new releases
here: http://www.tummy.com/Community/software/python-memcached/

--Philip Neustrom

On 8/28/07, jacques.ales at bnpparibas.com <jacques.ales at bnpparibas.com> wrote:
>
> hello
>
> I'm using the python wrapper for memcached in it's version
> __author__    = "Evan Martin <martine at danga.com>"
> __version__ = "1.36"
> __copyright__ = "Copyright (C) 2003 Danga Interactive"
> __license__   = "Python"
>
> I can't figure out if this is the latest since the verion available in the
> svn repository is
> http://code.sixapart.com/svn/memcached/trunk/api/python/memcache.py
> __author__    = "Evan Martin <martine at danga.com>"
>  __version__   = "1.2"
>  __copyright__ = "Copyright (C) 2003 Danga Interactive"
>  __license__   = "Python"
>
>
> anyway, my concern is that version 1.36 checks key validity with the
> followinf function, that excludes spaces char (ascii32)
> as being 'control characters'.
>
> I was wondering is this is correct.
> and also wondering why other chars as DEL(ascii127) are not excluded
>
> thanks for your clues
>
> jacques
>
>
>
> def check_key(key, key_extra_len=0):
>     """Checks sanity of key.  Fails if:
>         Key length is > SERVER_MAX_KEY_LENGTH (Raises MemcachedKeyLength).
>         Contains control characters  (Raises MemcachedKeyCharacterError).
>         Is not a string (Raises MemcachedStringEncodingError)
>     """
>     if not isinstance(key, str):
>         raise Client.MemcachedStringEncodingError, ("Keys
> must be str()'s, not"
>                 "unicode.  Convert your unicode strings using "
>                 "mystring.encode(charset)!")
>
>     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) < 33:
>             raise Client.MemcachedKeyCharacterError,
> "Control characters not allowed"
>
>
>
>
>
>
> This message and any attachments (the "message") is intended solely for the
> addressees and is confidential.
> If you receive this message in error, please delete it and immediately
> notify the sender. Any use not in accord with
> its purpose, any dissemination or disclosure, either whole or partial, is
> prohibited except formal approval.
> The internet can not guarantee the integrity of this message.
> BNP PARIBAS (and its subsidiaries) shall (will) not therefore be liable for
> the message if modified.
> Do not print this message unless it is necessary, consider the environment.
>  ---------------------------------------------
> Ce message et toutes les pieces jointes (ci-apres le "message") sont etablis
> a l'intention exclusive de ses destinataires et sont confidentiels. Si vous
> recevez ce
> message par erreur, merci de le detruire et d'en avertir immediatement
> l'expediteur.
> Toute utilisation de ce message non conforme a sa destination, toute
> diffusion ou toute publication, totale ou partielle, est interdite, sauf
> autorisation expresse.
> L'internet ne permettant pas d'assurer l'integrite de ce message, BNP
> PARIBAS (et ses filiales) decline(nt) toute responsabilite au titre de ce
> message, dans l'hypothese ou il aurait ete modifie.
> N'imprimez ce message que si necessaire, pensez a l'environnement.
>
>


More information about the memcached mailing list