Revision bf31e33e ncclient/content.py

b/ncclient/content.py
16 16

  
17 17
from xml.etree import cElementTree as ET
18 18

  
19

  
19 20
### Namespace-related ###
20 21

  
21 22
BASE_NS = 'urn:ietf:params:xml:ns:netconf:base:1.0'
......
34 35
# we'd like BASE_NS to be prefixed as "netconf"
35 36
register_namespace('netconf', BASE_NS)
36 37

  
37
qualify = lambda tag, ns: '{%s}%s' % (namespace, tag)
38
qualify = lambda tag, ns=BASE_NS: '{%s}%s' % (ns, tag)
39

  
40
# i would have written a def if lambdas weren't so much fun
41
multiqualify = lambda tag, nslist=(BASE_NS, CISCO_BS): [qualify(tag, ns) for ns in nslist]
38 42

  
39 43
unqualify = lambda tag: tag[tag.rfind('}')+1:]
40 44

  
45

  
41 46
### Build XML using Python data structures ###
42 47

  
43 48
class TreeBuilder:
......
67 72
    @staticmethod
68 73
    def build(spec):
69 74
        "TODO: docstring"
70
        if spec.has_key('tag'):
75
        if 'tag' in spec:
71 76
            ele = ET.Element(spec.get('tag'), spec.get('attributes', {}))
72 77
            ele.text = spec.get('text', '')
73 78
            children = spec.get('children', [])
......
76 81
            for child in children:
77 82
                ele.append(TreeBuilder.build(child))
78 83
            return ele
79
        elif spec.has_key('comment'):
84
        elif 'comment' in spec:
80 85
            return ET.Comment(spec.get('comment'))
81 86
        else:
82 87
            raise ValueError('Invalid tree spec')

Also available in: Unified diff