Author: pjenvey
Date: 2008-10-03 16:55:20 -0600 (Fri, 03 Oct 2008)
New Revision: 3617
Modified:
FormEncode/trunk/formencode/foreach.py
FormEncode/trunk/formencode/validators.py
Log:
python 2.6 deprecations:
prefer hashlib over the sha module, special case sets
Modified: FormEncode/trunk/formencode/foreach.py
===================================================================
--- FormEncode/trunk/formencode/foreach.py 2008-10-03 18:54:23 UTC (rev
3616)
+++ FormEncode/trunk/formencode/foreach.py 2008-10-03 22:55:20 UTC (rev
3617)
@@ -1,14 +1,13 @@
"""
Validator for repeating items.
"""
+import warnings
+warnings.simplefilter('ignore', DeprecationWarning)
+from sets import Set
+warnings.resetwarnings()
from api import NoDefault, Invalid
from compound import CompoundValidator, to_python, from_python
-try:
- from sets import Set
-except ImportError:
- # We only use it for type information now:
- Set = None
__all__ = ['ForEach']
@@ -37,7 +36,7 @@
and a single Invalid exception will be raised at the end (with
error_list set).
- If the incoming value is a Set, then we return a Set.
+ If the incoming value is a set, then we return a set.
"""
convert_to_list = True
@@ -59,7 +58,7 @@
new_list = []
errors = []
all_good = True
- is_set = isinstance(value, Set)
+ is_set = isinstance(value, (set, Set))
if state is not None:
previous_index = getattr(state, 'index', NoDefault)
previous_full_list = getattr(state, 'full_list', NoDefault)
@@ -84,7 +83,7 @@
new_list.append(sub_value)
if all_good:
if is_set:
- new_list = Set(new_list)
+ new_list = set(new_list)
return new_list
else:
raise Invalid(
Modified: FormEncode/trunk/formencode/validators.py
===================================================================
--- FormEncode/trunk/formencode/validators.py 2008-10-03 18:54:23 UTC (rev
3616)
+++ FormEncode/trunk/formencode/validators.py 2008-10-03 22:55:20 UTC (rev
3617)
@@ -31,7 +31,7 @@
import socket
from interfaces import *
from api import *
-sha = random = None
+sha1 = random = None
try:
import sets
except ImportError:
@@ -2358,9 +2358,12 @@
nonce_length = 4
def _to_python(self, value, state):
- global sha
- if not sha:
- import sha
+ global sha1
+ if not sha1:
+ try:
+ from hashlib import sha1
+ except ImportError:
+ from sha import sha as sha1
assert self.secret is not None, (
"You must give a secret")
parts = value.split(None, 1)
@@ -2372,19 +2375,22 @@
rest = rest.decode('base64')
nonce = rest[:self.nonce_length]
rest = rest[self.nonce_length:]
- expected = sha.new(str(self.secret)+nonce+rest).digest()
+ expected = sha1(str(self.secret)+nonce+rest).digest()
if expected != sig:
raise Invalid(self.message('badsig', state),
value, state)
return rest
def _from_python(self, value, state):
- global sha
- if not sha:
- import sha
+ global sha1
+ if not sha1:
+ try:
+ from hashlib import sha1
+ except ImportError:
+ from sha import sha as sha1
nonce = self.make_nonce()
value = str(value)
- digest = sha.new(self.secret+nonce+value).digest()
+ digest = sha1(self.secret+nonce+value).digest()
return self.encode(digest)+' '+self.encode(nonce+value)
def encode(self, value):
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
FormEncode-CVS mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/formencode-cvs