servelog: use simplejson and the % operator for python versions < 2.6
authorDale Wijnand <dale.wijnand@gmail.com>
Thu, 20 Jan 2011 21:18:29 +0100
changeset 295 9741d82e5b1e
parent 292 022d2e6bcdde
child 296 6feeef02c057
servelog: use simplejson and the % operator for python versions < 2.6 Both the json module and str format operator are new in version 2.6, so replace them with the simplejson module and the % operator, respectively.
src/mercurialserver/servelog.py
--- a/src/mercurialserver/servelog.py	Sat Dec 18 17:05:36 2010 +0000
+++ b/src/mercurialserver/servelog.py	Thu Jan 20 21:18:29 2011 +0100
@@ -9,7 +9,8 @@
 import os
 import time
 import fcntl
-import json
+try: import simplejson as json
+except ImportError: import json
 from mercurialserver import ruleset, changes
 
 def hook(ui, repo, hooktype, node=None, source=None, **kwargs):
@@ -25,13 +26,13 @@
         fcntl.flock(log.fileno(), fcntl.LOCK_EX)
         log.seek(0, os.SEEK_END)
         # YAML log file format
-        log.write("- {0}\n".format(json.dumps(dict(
+        log.write("- %s\n" % json.dumps(dict(
             timestamp=time.strftime("%Y-%m-%d_%H:%M:%S Z", time.gmtime()),
             op=op,
             key=ruleset.rules.get('user'),
             ssh_connection=os.environ['SSH_CONNECTION'],
             nodes=[mercurial.node.hex(ctx.node())
                 for ctx in changes.changes(repo, node)],
-         ))))
+         )))
     finally:
         log.close()