comparison mercurial/httprepo.py @ 11370:db3f6f0e4e7d

pushkey: add http support pushkey requires the same permissions as push listitems requires the same permissions as pull
author Matt Mackall <mpm@selenic.com>
date Wed, 16 Jun 2010 16:05:19 -0500
parents 9936ed1d04f4
children 34cc8b84407f 65bd4b8e48bd
comparison
equal deleted inserted replaced
11369:02a4373ca5cd 11370:db3f6f0e4e7d
6 # This software may be used and distributed according to the terms of the 6 # This software may be used and distributed according to the terms of the
7 # GNU General Public License version 2 or any later version. 7 # GNU General Public License version 2 or any later version.
8 8
9 from node import bin, hex, nullid 9 from node import bin, hex, nullid
10 from i18n import _ 10 from i18n import _
11 import repo, changegroup, statichttprepo, error, url, util 11 import repo, changegroup, statichttprepo, error, url, util, pushkey
12 import os, urllib, urllib2, urlparse, zlib, httplib 12 import os, urllib, urllib2, urlparse, zlib, httplib
13 import errno, socket 13 import errno, socket
14 import encoding 14 import encoding
15 15
16 def zgenerator(f): 16 def zgenerator(f):
257 os.unlink(tempname) 257 os.unlink(tempname)
258 258
259 def stream_out(self): 259 def stream_out(self):
260 return self.do_cmd('stream_out') 260 return self.do_cmd('stream_out')
261 261
262 def pushkey(self, namespace, key, old, new):
263 if not self.capable('pushkey'):
264 return False
265 d = self.do_cmd("pushkey", data="", # force a POST
266 namespace=namespace, key=key, old=old, new=new).read()
267 code, output = d.split('\n', 1)
268 try:
269 ret = bool(int(code))
270 except ValueError, err:
271 raise error.ResponseError(
272 _('push failed (unexpected response):'), d)
273 for l in output.splitlines(True):
274 self.ui.status(_('remote: '), l)
275 return ret
276
277 def listkeys(self, namespace):
278 if not self.capable('pushkey'):
279 return {}
280 d = self.do_cmd("listkeys", namespace=namespace).read()
281 r = {}
282 for l in d.splitlines():
283 k, v = l.split('\t')
284 r[k.decode('string-escape')] = v.decode('string-escape')
285 return r
286
262 class httpsrepository(httprepository): 287 class httpsrepository(httprepository):
263 def __init__(self, ui, path): 288 def __init__(self, ui, path):
264 if not url.has_https: 289 if not url.has_https:
265 raise util.Abort(_('Python support for SSL and HTTPS ' 290 raise util.Abort(_('Python support for SSL and HTTPS '
266 'is not installed')) 291 'is not installed'))