Skip to content

Commit

Permalink
some tricks to try compiling bootstrap code with PyPy
Browse files Browse the repository at this point in the history
  • Loading branch information
rfk committed Aug 10, 2010
1 parent cec32b5 commit 55b7ade
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions signedimp/bootstrap.py
Expand Up @@ -314,6 +314,10 @@ def _check_hash(self,type,hash,data):
return _signedimp_util.md5(data).hexdigest() == hash
raise ValueError("unknown hash type: %s" % (type,))

def _strip(self,s):
"""Compatability wrapper for compiling string.strip() under pypy."""
return s.strip("\n").strip("\r").strip(" ")

def parse_hash_data(self,hashdata):
"""Load hash data from the given string.
Expand All @@ -338,35 +342,39 @@ def parse_hash_data(self,hashdata):
# Find all valid keys that have provided a signature.
for ln in lines:
offset += len(ln)+1
ln = ln.strip()
ln = self._strip(ln)
if not ln:
break
try:
fingerprint,signature = ln.split()
fingerprint,signature = ln.split(" ")
signature = _signedimp_util.b64decode(signature)
except (ValueError,TypeError):
return
for k in self.valid_keys:
if k.fingerprint() == fingerprint:
signatures.append((k,signature))
else:
for k in self.valid_keys:
if k.fingerprint() == fingerprint:
signatures.append((k,signature))
# If there weren't any usable signatures, we can't use this data.
if not signatures:
return
# Check the signature for each key
signeddata = hashdata[offset:]
for (k,sig) in signatures:
if not k.verify(signeddata,sig):
err = "bad signature from " + fingerprint
err = "bad signature from " + k.fingerprint()
raise IntegrityCheckFailed(err)
# Next line is the hash type identifier
try:
htyp = lines.next().strip()
htyp = self._strip(lines.next())
except StopIteration:
return
# Now we can load each hash line into the database
for ln in lines:
try:
typ,hval,name = ln.strip().split(None,2)
comps = self._strip(ln).split(" ")
typ = comps[0]
hval = comps[1]
name = " ".join(comps[2:])
except ValueError:
continue
try:
Expand Down

0 comments on commit 55b7ade

Please sign in to comment.