##// END OF EJS Templates
pushkey: add an ``encode`` function...
Pierre-Yves David -
r21661:2f52a16f default
parent child Browse files
Show More
@@ -1,53 +1,54
1 1 # pushkey.py - dispatching for pushing and pulling keys
2 2 #
3 3 # Copyright 2010 Matt Mackall <mpm@selenic.com>
4 4 #
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 8 import bookmarks, phases, obsolete, encoding
9 9
10 10 def _nslist(repo):
11 11 n = {}
12 12 for k in _namespaces:
13 13 n[k] = ""
14 14 if not obsolete._enabled:
15 15 n.pop('obsolete')
16 16 return n
17 17
18 18 _namespaces = {"namespaces": (lambda *x: False, _nslist),
19 19 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks),
20 20 "phases": (phases.pushphase, phases.listphases),
21 21 "obsolete": (obsolete.pushmarker, obsolete.listmarkers),
22 22 }
23 23
24 24 def register(namespace, pushkey, listkeys):
25 25 _namespaces[namespace] = (pushkey, listkeys)
26 26
27 27 def _get(namespace):
28 28 return _namespaces.get(namespace, (lambda *x: False, lambda *x: {}))
29 29
30 30 def push(repo, namespace, key, old, new):
31 31 '''should succeed iff value was old'''
32 32 pk = _get(namespace)[0]
33 33 return pk(repo, key, old, new)
34 34
35 35 def list(repo, namespace):
36 36 '''return a dict'''
37 37 lk = _get(namespace)[1]
38 38 return lk(repo)
39 39
40 encode = encoding.fromlocal
41
40 42 decode = encoding.tolocal
41 43
42 44 def encodekeys(keys):
43 45 """encode the content of a pushkey namespace for exchange over the wire"""
44 enc = encoding.fromlocal
45 return '\n'.join(['%s\t%s' % (enc(k), enc(v)) for k, v in keys])
46 return '\n'.join(['%s\t%s' % (encode(k), encode(v)) for k, v in keys])
46 47
47 48 def decodekeys(data):
48 49 """decode the content of a pushkey namespace from exchange over the wire"""
49 50 result = {}
50 51 for l in data.splitlines():
51 52 k, v = l.split('\t')
52 53 result[decode(k)] = decode(v)
53 54 return result
General Comments 0
You need to be logged in to leave comments. Login now