def _parse_qs(qs): pairs = (s2 for s1 in qs.split('&') for s2 in s1.split(';')) retval = odict() for name_value in pairs: if name_value is None or len(name_value) == 0: continue nv = name_value.split('=', 1) if len(nv) != 2: # Handle case of a control-name with no equal sign nv.append(None) name = unquote(nv[0].replace('+', ' ')) value = None if nv[1] is not None: value = unquote(nv[1].replace('+', ' ')) l = retval.get(name, None) if l is None: l = retval[name] = [] l.append(value) return retval
def _parse_qs(qs): pairs = (s2 for s1 in qs.split('&') for s2 in s1.split(';')) retval = odict() for name_value in pairs: if name_value is None or len(name_value) == 0: continue nv = name_value.split('=', 1) if len(nv) != 2: # Handle case of a control-name with no equal sign nv.append(None) name = unquote(nv[0].replace('+', ' ')) value = None if nv[1] is not None: value = unquote(nv[1].replace('+', ' ')) l = retval.get(name, None) if l is None: l = retval[name] = [] l.append(value) return retval
def _join_attachment(href_id, envelope, payload, prefix=True): """Places the data from an attachment back into a SOAP message, replacing its xop:Include element or href. Returns a tuple of length 2 with the new message and the number of replacements made :param id: content-id or content-location of attachment :param prefix: Set this to true if id is content-id or false if it is content-location. It prefixes a "cid:" to the href value. :param envelope: soap envelope string to be operated on :param payload: attachment data """ def replacing(parent, node, payload_, numreplaces_): if node.tag == '{%s}Include' % _ns_xop: attr = node.attrib.get('href') if not attr is None: if unquote(attr) == href_id: parent.remove(node) parent.text = payload_ numreplaces_ += 1 else: for c in node: numreplaces_ = replacing(node, c, payload_, numreplaces_) return numreplaces_ # grab the XML element of the message in the SOAP body soaptree = etree.fromstring(envelope) soapbody = soaptree.find("{%s}Body" % _ns_soap_env) message = None for child in list(soapbody): if child.tag != "{%s}Fault" % _ns_soap_env: message = child break numreplaces = 0 idprefix = '' if prefix: idprefix = "cid:" href_id = "%s%s" % (idprefix, href_id, ) # Make replacement. for param in message: # Look for Include subelement. for sub in param: numreplaces = replacing(param, sub, payload, numreplaces) if numreplaces < 1: attrib = param.attrib.get('href') if not attrib is None: if unquote(attrib) == href_id: del param.attrib['href'] param.text = payload numreplaces += 1 return etree.tostring(soaptree), numreplaces
def decompose_incoming_envelope(self, prot, ctx, message): """This function is only called by the HttpRpc protocol to have the twisted web's Request object is parsed into ``ctx.in_body_doc`` and ``ctx.in_header_doc``. """ request = ctx.in_document assert isinstance(request, Request) ctx.in_header_doc = dict(request.requestHeaders.getAllRawHeaders()) fi = ctx.transport.file_info if fi is not None and len(request.args) == 1: key, = request.args.keys() if fi.field_name == key and fi.file_name is not None: ctx.in_body_doc = {key: [File.Value(name=fi.file_name, type=fi.file_type, data=request.args[key])]} else: ctx.in_body_doc = request.args else: ctx.in_body_doc = request.args # this is a huge hack because twisted seems to take the slashes in urls # too seriously. postpath = getattr(request, 'realpostpath', None) if postpath is None: postpath = request.path params = self.match_pattern(ctx, request.method, postpath, request.getHeader('Host')) if ctx.method_request_string is None: # no pattern match ctx.method_request_string = '{%s}%s' % (self.app.interface.get_tns(), request.path.rsplit('/', 1)[-1]) logger.debug("%sMethod name: %r%s" % (LIGHT_GREEN, ctx.method_request_string, END_COLOR)) for k, v in params.items(): val = ctx.in_body_doc.get(k, []) val.extend(v) ctx.in_body_doc[k] = val r = {} for k,v in ctx.in_body_doc.items(): l = [] for v2 in v: if isinstance(v2, string_types): l.append(unquote(v2)) else: l.append(v2) r[k] = l ctx.in_body_doc = r # This is consistent with what server.wsgi does. if request.method in ('POST', 'PUT', 'PATCH'): for k, v in ctx.in_body_doc.items(): if v == ['']: ctx.in_body_doc[k] = [None]
def replacing(parent, node, payload_, numreplaces_): if node.tag == '{%s}Include' % _ns_xop: attr = node.attrib.get('href') if not attr is None: if unquote(attr) == href_id: parent.remove(node) parent.text = payload_ numreplaces_ += 1 else: for c in node: numreplaces_ = replacing(node, c, payload_, numreplaces_) return numreplaces_
def replacing(parent, node, payload_, numreplaces_): if node.tag == '{%s}Include' % _ns_xop: attr = node.attrib.get('href') if not attr is None: if unquote(attr) == href_id: parent.remove(node) parent.text = payload_ numreplaces_ += 1 else: for c in node: numreplaces_ = replacing(node, c, payload_, numreplaces_) return numreplaces_
def _join_attachment(href_id, envelope, payload, prefix=True): """Places the data from an attachment back into a SOAP message, replacing its xop:Include element or href. Returns a tuple of length 2 with the new message and the number of replacements made :param id: content-id or content-location of attachment :param prefix: Set this to true if id is content-id or false if it is content-location. It prefixes a "cid:" to the href value. :param envelope: soap envelope string to be operated on :param payload: attachment data """ def replacing(parent, node, payload_, numreplaces_): if node.tag == '{%s}Include' % _ns_xop: attr = node.attrib.get('href') if not attr is None: if unquote(attr) == href_id: parent.remove(node) parent.text = payload_ numreplaces_ += 1 else: for c in node: numreplaces_ = replacing(node, c, payload_, numreplaces_) return numreplaces_ # grab the XML element of the message in the SOAP body soaptree = etree.fromstring(envelope) soapbody = soaptree.find("{%s}Body" % _ns_soap_env) message = None for child in list(soapbody): if child.tag != "{%s}Fault" % _ns_soap_env: message = child break numreplaces = 0 idprefix = '' if prefix: idprefix = "cid:" href_id = "%s%s" % ( idprefix, href_id, ) # Make replacement. for param in message: # Look for Include subelement. for sub in param: numreplaces = replacing(param, sub, payload, numreplaces) if numreplaces < 1: attrib = param.attrib.get('href') if not attrib is None: if unquote(attrib) == href_id: del param.attrib['href'] param.text = payload numreplaces += 1 return etree.tostring(soaptree), numreplaces
def _decode_path(fragment): if six.PY2: return unquote(fragment).decode('utf8') return unquote_to_bytes(fragment).decode('utf8')
def _decode_path(fragment): if six.PY2: return unquote(fragment).decode('utf8') return unquote_to_bytes(fragment).decode('utf8')