Mercurial > hg
comparison mercurial/pushkey.py @ 21659:a319842539f5
pushkey: add a ``decode`` function
This function is just a shorthand for ``decoding.fromlocal``. It will help
hiding the encoding business from other code exchanging pushkey data over the
wire.
author | Pierre-Yves David <pierre-yves.david@fb.com> |
---|---|
date | Thu, 29 May 2014 15:23:25 -0700 |
parents | ed6e61eaebc0 |
children | 2f52a16f2bee |
comparison
equal
deleted
inserted
replaced
21658:0696ca0a685b | 21659:a319842539f5 |
---|---|
35 def list(repo, namespace): | 35 def list(repo, namespace): |
36 '''return a dict''' | 36 '''return a dict''' |
37 lk = _get(namespace)[1] | 37 lk = _get(namespace)[1] |
38 return lk(repo) | 38 return lk(repo) |
39 | 39 |
40 decode = encoding.tolocal | |
41 | |
40 def encodekeys(keys): | 42 def encodekeys(keys): |
41 """encode the content of a pushkey namespace for exchange over the wire""" | 43 """encode the content of a pushkey namespace for exchange over the wire""" |
42 enc = encoding.fromlocal | 44 enc = encoding.fromlocal |
43 return '\n'.join(['%s\t%s' % (enc(k), enc(v)) for k, v in keys]) | 45 return '\n'.join(['%s\t%s' % (enc(k), enc(v)) for k, v in keys]) |
44 | 46 |
45 def decodekeys(data): | 47 def decodekeys(data): |
46 """decode the content of a pushkey namespace from exchange over the wire""" | 48 """decode the content of a pushkey namespace from exchange over the wire""" |
47 result = {} | 49 result = {} |
48 for l in data.splitlines(): | 50 for l in data.splitlines(): |
49 k, v = l.split('\t') | 51 k, v = l.split('\t') |
50 result[encoding.tolocal(k)] = encoding.tolocal(v) | 52 result[decode(k)] = decode(v) |
51 return result | 53 return result |