示例#1
0
    def _got_location(self, location):
        if self.controlURL is not None:
            return

        URLBase = location

        data = urlopen_custom(location, self.rawserver).read()
        bs = BeautifulSupe(data)

        URLBase_tag = bs.first("URLBase")
        if URLBase_tag and URLBase_tag.contents:
            URLBase = str(URLBase_tag.contents[0])

        wanservices = bs.fetch("service", dict(serviceType="urn:schemas-upnp-org:service:WANIPConnection:"))
        wanservices += bs.fetch("service", dict(serviceType="urn:schemas-upnp-org:service:WANPPPConnection:"))
        for service in wanservices:
            controlURL = service.get("controlURL")
            if controlURL:
                self.controlURL = urlparse.urljoin(URLBase, controlURL)
                break

        if self.controlURL is None:
            # resume init services, because we know we've failed
            self.traverser.resume_init_services()
            return

        # attach service, so the queue gets flushed
        self.traverser.attach_service(self)
示例#2
0
def VerifySOAPResponse(request, response):
    if response.code != 200:
        raise HTTPError(
            request.get_full_url(),
            response.code,
            str(response.msg) + " (unexpected SOAP response code)",
            response.info(),
            response,
        )

    data = response.read()
    bs = BeautifulSupe(data)
    soap_response = bs.scour("m:", "Response")
    if not soap_response:
        # maybe I should read the SOAP spec.
        soap_response = bs.scour("u:", "Response")
        if not soap_response:
            raise HTTPError(
                request.get_full_url(),
                response.code,
                str(response.msg) + " (incorrect SOAP response method)",
                response.info(),
                response,
            )
    return soap_response[0]
示例#3
0
def SOAPErrorToString(response):
    if not isinstance(response, Exception):
        data = response.read()
        bs = BeautifulSupe(data)
        error = bs.first('errorDescription')
        if error:
            return str(error.contents[0])
    return str(response)
示例#4
0
def SOAPErrorToString(response):
    if not isinstance(response, Exception):
        data = response.read()
        bs = BeautifulSupe(data)
        error = bs.first("errorDescription")
        if error:
            return str(error.contents[0])
    return str(response)
示例#5
0
    def _got_location(self, location):
        if self.controlURL is not None:
            return

        URLBase = location

        for i in xrange(5):  # retry
            try:
                data = urlopen_custom(location, self.rawserver).read()
            except IOError:
                nat_logger.warning("urlopen_custom timeout")
            except:
                nat_logger.warning("urlopen_custom error",
                                   exc_info=sys.exc_info())
            else:
                break
        else:
            nat_logger.warning("urlopen_custom error. giving up.")
            return

        try:
            bs = BeautifulSupe(data)
        except:  # xml.parsers.expat.ExpatError, maybe others
            #open("wtf.xml", 'wb').write(data)
            nat_logger.warning("XML parse error", exc_info=sys.exc_info())
            return

        URLBase_tag = bs.first('URLBase')
        if URLBase_tag and URLBase_tag.contents:
            URLBase = str(URLBase_tag.contents[0])

        wanservices = bs.fetch(
            'service',
            dict(serviceType='urn:schemas-upnp-org:service:WANIPConnection:'))
        wanservices += bs.fetch(
            'service',
            dict(serviceType='urn:schemas-upnp-org:service:WANPPPConnection:'))
        for service in wanservices:
            controlURL = service.get('controlURL')
            if controlURL:
                self.controlURL = urlparse.urljoin(URLBase, controlURL)
                break

        if self.controlURL is None:
            # resume init services, because we know we've failed
            self.traverser.resume_init_services()
            return

        # attach service, so the queue gets flushed
        self.traverser.attach_service(self)
示例#6
0
    def _got_location(self, location):
        if self.controlURL is not None:
            return

        URLBase = location

        for i in xrange(5): # retry
            try:
                data = urlopen_custom(location, self.rawserver).read()
            except IOError:
                nat_logger.warning("urlopen_custom timeout")
            except:
                nat_logger.warning("urlopen_custom error", exc_info=sys.exc_info())
            else:
                break
        else:
            nat_logger.warning("urlopen_custom error. giving up.")
            return

        try:
            bs = BeautifulSupe(data)
        except: # xml.parsers.expat.ExpatError, maybe others
            #open("wtf.xml", 'wb').write(data)
            nat_logger.warning("XML parse error", exc_info=sys.exc_info())
            return

        URLBase_tag = bs.first('URLBase')
        if URLBase_tag and URLBase_tag.contents:
            URLBase = str(URLBase_tag.contents[0])

        wanservices = bs.fetch('service',
                               dict(serviceType=
                                    'urn:schemas-upnp-org:service:WANIPConnection:'))
        wanservices += bs.fetch('service',
                                dict(serviceType=
                                     'urn:schemas-upnp-org:service:WANPPPConnection:'))
        for service in wanservices:
            controlURL = service.get('controlURL')
            if controlURL:
                self.controlURL = urlparse.urljoin(URLBase, controlURL)
                break

        if self.controlURL is None:
            # resume init services, because we know we've failed
            self.traverser.resume_init_services()
            return

        # attach service, so the queue gets flushed
        self.traverser.attach_service(self)
示例#7
0
def VerifySOAPResponse(request, response):
    if response.code != 200:
        raise HTTPError(request.get_full_url(), response.code,
                        str(response.msg) + " (unexpected SOAP response code)",
                        response.info(), response)

    data = response.read()
    bs = BeautifulSupe(data)
    # On Matt's Linksys WRT54G rev 4 v.1.0 I saw u: instead of m:
    # and ignoring that caused the router to crash
    soap_response = bs.scour("m:", "Response")
    if not soap_response:
        raise HTTPError(
            request.get_full_url(), response.code,
            str(response.msg) + " (incorrect SOAP response method)",
            response.info(), response)
    return soap_response[0]
示例#8
0
def VerifySOAPResponse(request, response):
    if response.code != 200:
        raise HTTPError(request.get_full_url(),
                        response.code, str(response.msg) + " (unexpected SOAP response code)",
                        response.info(), response)

    data = response.read()
    bs = BeautifulSupe(data)
    # On Matt's Linksys WRT54G rev 4 v.1.0 I saw u: instead of m:
    # and ignoring that caused the router to crash
    soap_response = bs.scour("m:", "Response")
    if not soap_response:
        raise HTTPError(request.get_full_url(),
                        response.code, str(response.msg) +
                        " (incorrect SOAP response method)",
                        response.info(), response)
    return soap_response[0]