# HG changeset patch # User Pierre-Yves David # Date 1397711345 14400 # Node ID f469879d27ecfbe2fed9169731265f000b530271 # Parent 341a083603a545dfe06ce0934d8cf03cc6b98427 bundle2: extract capabilities decoding We'll need to reuse this in more places (at least pull and push). diff -r 341a083603a5 -r f469879d27ec mercurial/bundle2.py --- a/mercurial/bundle2.py Thu Apr 17 01:03:33 2014 -0400 +++ b/mercurial/bundle2.py Thu Apr 17 01:09:05 2014 -0400 @@ -333,6 +333,29 @@ raise return op +def decodecaps(blob): + """decode a bundle2 caps bytes blob into a dictionnary + + The blob is a list of capabilities (one per line) + Capabilities may have values using a line of the form:: + + capability=value1,value2,value3 + + The values are always a list.""" + caps = {} + for line in blob.splitlines(): + if not line: + continue + if '=' not in line: + key, vals = line, () + else: + key, vals = line.split('=', 1) + vals = vals.split(',') + key = urllib.unquote(key) + vals = [urllib.unquote(v) for v in vals] + caps[key] = vals + return caps + class bundle20(object): """represent an outgoing bundle2 container @@ -697,24 +720,8 @@ def handlereplycaps(op, inpart): """Notify that a reply bundle should be created - The part payload is a list of capabilities (one per line) - Capabilities may have values using a line of form:: - - capability=value1,value2,value3 - - The value are alway a list.""" - caps = {} - for line in inpart.read().splitlines(): - if not line: - continue - if '=' not in line: - key, vals = line, () - else: - key, vals = line.split('=', 1) - vals = vals.split(',') - key = urllib.unquote(key) - vals = [urllib.unquote(v) for v in vals] - caps[key] = vals + The payload contains the capabilities information for the reply""" + caps = decodecaps(inpart.read()) if op.reply is None: op.reply = bundle20(op.ui, caps)