summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/thandy/ServerCLI.py11
-rw-r--r--lib/thandy/SignerCLI.py21
-rw-r--r--lib/thandy/formats.py8
-rw-r--r--lib/thandy/keys.py10
-rw-r--r--lib/thandy/repository.py8
-rw-r--r--lib/thandy/util.py7
-rw-r--r--setup.py15
7 files changed, 54 insertions, 26 deletions
diff --git a/lib/thandy/ServerCLI.py b/lib/thandy/ServerCLI.py
index 2090ed9..794e119 100644
--- a/lib/thandy/ServerCLI.py
+++ b/lib/thandy/ServerCLI.py
@@ -5,7 +5,10 @@ import sys
import getopt
import time
-import simplejson
+try:
+ import json
+except:
+ import simplejson as json
import thandy.formats
import thandy.util
@@ -24,7 +27,7 @@ def snarf(fname):
def snarfObj(fname):
f = open(fname, 'r')
try:
- return simplejson.load(f)
+ return json.load(f)
finally:
f.close()
@@ -65,7 +68,7 @@ def insert(args):
continue
try:
- obj = simplejson.loads(content)
+ obj = json.loads(content)
except ValueError, e:
print "Couldn't decode %s: %s"%(fn, e)
continue
@@ -165,7 +168,7 @@ def timestamp(args):
for k in keydb.iterkeys():
thandy.formats.sign(signable, k)
- content = simplejson.dumps(signable, sort_keys=True)
+ content = json.dumps(signable, sort_keys=True)
thandy.util.replaceFile(tsFname, content)
def usage():
diff --git a/lib/thandy/SignerCLI.py b/lib/thandy/SignerCLI.py
index d002565..524981a 100644
--- a/lib/thandy/SignerCLI.py
+++ b/lib/thandy/SignerCLI.py
@@ -4,7 +4,10 @@ import os
import getopt
import sys
import logging
-import simplejson
+try:
+ import json
+except ImportError:
+ import simplejson as json
import thandy.keys
import thandy.formats
@@ -75,7 +78,7 @@ def makepackage(args):
location = os.path.split(package['location'])[-1]
print "Writing signed package to %s"%location
f = open(location, 'w')
- simplejson.dump(signable, f, indent=1)
+ json.dump(signable, f, indent=1)
f.close()
def makebundle(args):
@@ -93,7 +96,7 @@ def makebundle(args):
for pkgFile in args[1:]:
print "Loading", pkgFile
f = open(pkgFile, 'r')
- p = simplejson.load(f)
+ p = json.load(f)
f.close()
_, r, _ = thandy.formats.checkSignedObj(p)
if r != 'package':
@@ -115,7 +118,7 @@ def makebundle(args):
location = os.path.split(bundleObj['location'])[-1]
print "Writing signed bundle to %s"%location
f = open(location, 'w')
- simplejson.dump(signable, f, indent=1)
+ json.dump(signable, f, indent=1)
f.close()
# ------------------------------
@@ -143,14 +146,14 @@ def makekeylist(args):
print "writing signed keylist to keys.txt"
thandy.util.replaceFile("keys.txt",
- simplejson.dumps(signable, indent=1, sort_keys=True),
+ json.dumps(signable, indent=1, sort_keys=True),
textMode=True)
def signkeylist(args):
if len(args) != 1:
usage()
- keylist = simplejson.load(open(args[0], 'r'))
+ keylist = json.load(open(args[0], 'r'))
thandy.formats.SIGNED_SCHEMA.checkMatch(keylist)
thandy.formats.KEYLIST_SCHEMA.checkMatch(keylist['signed'])
@@ -162,7 +165,7 @@ def signkeylist(args):
print "writing signed keylist to keys.txt"
thandy.util.replaceFile("keys.txt",
- simplejson.dumps(keylist, indent=1, sort_keys=True),
+ json.dumps(keylist, indent=1, sort_keys=True),
textMode=True)
def makemirrorlist(args):
@@ -189,7 +192,7 @@ def makemirrorlist(args):
print "writing signed mirrorlist to mirrors.txt"
thandy.util.replaceFile("mirrors.txt",
- simplejson.dumps(signable, indent=1, sort_keys=True),
+ json.dumps(signable, indent=1, sort_keys=True),
textMode=True)
# ------------------------------
@@ -277,7 +280,7 @@ def dumpkey(args):
for k in keys:
data = k.format(private=includeSecret, includeRoles=True)
- print "Key(", simplejson.dumps(data, indent=2), ")"
+ print "Key(", json.dumps(data, indent=2), ")"
def usage():
print "Known commands:"
diff --git a/lib/thandy/formats.py b/lib/thandy/formats.py
index c44c9cf..42e3d79 100644
--- a/lib/thandy/formats.py
+++ b/lib/thandy/formats.py
@@ -1,6 +1,10 @@
# Copyright 2008 The Tor Project, Inc. See LICENSE for licensing information.
-import simplejson
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
import time
import re
import binascii
@@ -154,7 +158,7 @@ def checkSignatures(signed, keyDB, role=None, path=None):
return SignatureStatus(goodSigs, badSigs, unknownSigs, tangentialSigs)
def _encodeCanonical(obj, outf):
- # Helper for encodeCanonical. Older versions of simplejson.encoder don't
+ # Helper for encodeCanonical. Older versions of json.encoder don't
# even let us replace the separators.
def canonical_str_encoder(s):
diff --git a/lib/thandy/keys.py b/lib/thandy/keys.py
index f4bcac9..5442b26 100644
--- a/lib/thandy/keys.py
+++ b/lib/thandy/keys.py
@@ -11,9 +11,13 @@ import logging
import os
import struct
import sys
-import simplejson
import getpass
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
import thandy.formats
import thandy.util
@@ -380,7 +384,7 @@ class KeyStore(thandy.formats.KeyDB):
if self._encrypted:
contents = decryptSecret(contents, password)
- listOfKeys = simplejson.loads(contents)
+ listOfKeys = json.loads(contents)
self._passwd = password # It worked.
if not listOfKeys.has_key('keys'):
listOfKeys['keys'] = []
@@ -409,7 +413,7 @@ class KeyStore(thandy.formats.KeyDB):
[ key.format(private=True, includeRoles=True) for key in
self._keys.values() ]
}
- contents = simplejson.dumps(listOfKeys)
+ contents = json.dumps(listOfKeys)
if self._encrypted:
contents = encryptSecret(contents, password)
thandy.util.replaceFile(self._fname, contents)
diff --git a/lib/thandy/repository.py b/lib/thandy/repository.py
index 32108c0..1385dd6 100644
--- a/lib/thandy/repository.py
+++ b/lib/thandy/repository.py
@@ -3,7 +3,11 @@
import thandy.formats
import thandy.util
-import simplejson
+try:
+ import json
+except ImportError:
+ import simplejson as json
+
import logging
import os
import threading
@@ -70,7 +74,7 @@ class RepositoryFile:
def _checkContent(self, content):
try:
- obj = simplejson.loads(content)
+ obj = json.loads(content)
except ValueError, e:
raise thandy.FormatException("Couldn't decode content: %s"%e)
diff --git a/lib/thandy/util.py b/lib/thandy/util.py
index 2b1c572..b7281ae 100644
--- a/lib/thandy/util.py
+++ b/lib/thandy/util.py
@@ -4,7 +4,10 @@ import os
import sys
import tempfile
-import simplejson
+try:
+ import json
+except ImportError:
+ import simplejson as json
import thandy.formats
import thandy.keys
@@ -60,7 +63,7 @@ def getKeylist(keys_fname, checkKeys=True):
if keys_fname and os.path.exists(keys_fname):
f = open(keys_fname, 'r')
try:
- obj = simplejson.load(f)
+ obj = json.load(f)
finally:
f.close()
ss, role, path = thandy.formats.checkSignedObj(obj, keydb)
diff --git a/setup.py b/setup.py
index f8622b7..39df8ed 100644
--- a/setup.py
+++ b/setup.py
@@ -11,12 +11,19 @@ VERSION = '0.0.1-alpha'
# System: 0==alpha, 50==beta, 98=pre, 99==release candidate, 100==release
VERSION_INFO = (0,0,1)
-for name in [ "simplejson", "Crypto" ]:
+try:
+ import Crypto
+except ImportError:
+ print "Missing support for module Crypto"
+ sys.exit(1)
+
+try:
+ import json
+except ImportError:
try:
- __import__(name)
+ import simplejson
except ImportError:
- print "Missing support for module %s"%name
- sys.exit(1)
+ print "Missing support for module simplejson"
import os, re, shutil, string, struct, sys