def __init__(self, input, readerclass=None, keepdom=False,<EOL>trailers=False, resolver=None,  envelope=True, **kw):
self.readerclass = readerclass<EOL>self.keepdom = keepdom<EOL>if not self.readerclass:<EOL><INDENT>self.readerclass = self.defaultReaderClass<EOL><DEDENT>try:<EOL><INDENT>self.reader = self.readerclass()<EOL>if type(input) in _stringtypes:<EOL><INDENT>self.dom = self.reader.fromString(input)<EOL><DEDENT>else:<EOL><INDENT>self.dom = self.reader.fromStream(input)<EOL><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>raise<EOL><DEDENT>self.ns_cache = {<EOL>id(self.dom): {<EOL>'<STR_LIT>': XMLNS.XML,<EOL>'<STR_LIT>': XMLNS.BASE,<EOL>'<STR_LIT>': '<STR_LIT>'<EOL>}<EOL>}<EOL>self.trailers, self.resolver, self.id_cache = trailers, resolver, {}<EOL>c = [ E for E in _children(self.dom)<EOL>if E.nodeType == _Node.ELEMENT_NODE]<EOL>if len(c) == <NUM_LIT:0>:<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>if len(c) != <NUM_LIT:1>:<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>if envelope is False:<EOL><INDENT>self.body_root = c[<NUM_LIT:0>]<EOL>return<EOL><DEDENT>elt = c[<NUM_LIT:0>]<EOL>if elt.localName != "<STR_LIT>"or elt.namespaceURI != SOAP.ENV:<EOL><INDENT>raise ParseException('<STR_LIT>' + elt.localName +'<STR_LIT>', <NUM_LIT:0>)<EOL><DEDENT>self._check_for_legal_children("<STR_LIT>", elt)<EOL>for a in _attrs(elt):<EOL><INDENT>name = a.nodeName<EOL>if name.find("<STR_LIT::>") == -<NUM_LIT:1> and name not in [ "<STR_LIT>", "<STR_LIT:id>" ]:<EOL><INDENT>raise ParseException('<STR_LIT>' +name + '<STR_LIT>', <NUM_LIT:0>)<EOL><DEDENT><DEDENT>self.envelope = elt<EOL>if not _valid_encoding(self.envelope):<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>c = [ E for E in _children(self.envelope)<EOL>if E.nodeType == _Node.ELEMENT_NODE ]<EOL>if len(c) == <NUM_LIT:0>:<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>elt = c[<NUM_LIT:0>]<EOL>if elt.localName == "<STR_LIT>"and elt.namespaceURI == SOAP.ENV:<EOL><INDENT>self._check_for_legal_children("<STR_LIT>", elt)<EOL>self._check_for_pi_nodes(_children(elt), <NUM_LIT:1>)<EOL>self.header = c.pop(<NUM_LIT:0>)<EOL>self.header_elements = _child_elements(self.header)<EOL><DEDENT>else:<EOL><INDENT>self.header, self.header_elements = None, []<EOL><DEDENT>if len(c) == <NUM_LIT:0>:<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>elt = c.pop(<NUM_LIT:0>)<EOL>if elt.localName != "<STR_LIT>"or elt.namespaceURI != SOAP.ENV:<EOL><INDENT>if self.header:<EOL><INDENT>raise ParseException('<STR_LIT>' +elt.localName +'<STR_LIT>', <NUM_LIT:0>, elt, self.dom)<EOL><DEDENT>else:<EOL><INDENT>raise ParseException('<STR_LIT>' +elt.localName +'<STR_LIT>', <NUM_LIT:0>, elt, self.dom)<EOL><DEDENT><DEDENT>self._check_for_legal_children("<STR_LIT>", elt, <NUM_LIT:0>)<EOL>self._check_for_pi_nodes(_children(elt), <NUM_LIT:0>)<EOL>self.body = elt<EOL>if not _valid_encoding(self.body):<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>)<EOL><DEDENT>if not self.trailers:<EOL><INDENT>if len(c):<EOL><INDENT>raise ParseException("<STR_LIT>",<EOL><NUM_LIT:0>, elt, self.dom)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>self.trailer_elements = c<EOL>for elt in self.trailer_elements:<EOL><INDENT>if not elt.namespaceURI:<EOL><INDENT>raise ParseException('<STR_LIT>',<EOL><NUM_LIT:0>, elt, self.dom)<EOL><DEDENT><DEDENT><DEDENT>self.body_root, no, maybe = None, [], []<EOL>for elt in _child_elements(self.body):<EOL><INDENT>root = _find_root(elt)<EOL>if root == "<STR_LIT:1>":<EOL><INDENT>if self.body_root:<EOL><INDENT>raise ParseException("<STR_LIT>",<EOL><NUM_LIT:0>, elt, self.dom)<EOL><DEDENT>self.body_root = elt<EOL><DEDENT>elif root == "<STR_LIT:0>":<EOL><INDENT>no.append(elt)<EOL><DEDENT>elif not root:<EOL><INDENT>maybe.append(elt)<EOL><DEDENT>else:<EOL><INDENT>raise ParseException('<STR_LIT>',<EOL><NUM_LIT:0>, elt, self.dom)<EOL><DEDENT><DEDENT>if self.body_root is None:<EOL><INDENT>if len(maybe):<EOL><INDENT>self.body_root = maybe[<NUM_LIT:0>]<EOL><DEDENT>else:<EOL><INDENT>raise ParseException('<STR_LIT>',<EOL><NUM_LIT:0>, self.body, self.dom)<EOL><DEDENT><DEDENT>if not _valid_encoding(self.body_root):<EOL><INDENT>raise ParseException("<STR_LIT>", <NUM_LIT:0>,<EOL>elt, self.dom)<EOL><DEDENT>rootid = id(self.body_root)<EOL>self.data_elements = [ E for E in _child_elements(self.body)<EOL>if id(E) != rootid ]<EOL>self._check_for_pi_nodes(self.data_elements, <NUM_LIT:0>)<EOL>
Initialize.
        Keyword arguments:
            trailers -- allow trailer elments (default is zero)
            resolver -- function (bound method) to resolve URI's
            readerclass -- factory class to create a reader
            keepdom -- do not release the DOM
            envelope -- look for a SOAP envelope.