예제 #1
0
    def init(self, response_text):
        class FakeSocket:
            def __init__(self, response_str):
                self._file = StringIO(response_str)
            def makefile(self, *args, **kwargs):
                return self._file

        source = FakeSocket(response_text)
        HTTPResponse.__init__(self, source)
        self.begin()
예제 #2
0
  def __init__(self, response_str):
    source = FakeSocket(response_str)
    HTTPResponse.__init__(self, source)
    self.begin()



# Request
# error_code 
# command    GET/POST
# path       PATH
# request_version "HTTP/1.0"
# headers   "Headers"
# headers.keys() 
# headers['host']

# Response
# status    CODE
# getheader('Content-Length')
# read(len(response_str)) 
예제 #3
0
    def __init__(self, data):
        """Initialize a new object.

        :param data: a stream of data which contain a discovery response in the HTTP format.
        :type data: str or list[bytes] or list[int]
        :rtype: DiscoveryResponse
        """

        # create a fake socket which is needed by the base class to initialize.
        # initialize the base class
        HTTPResponse.__init__(self, DiscoveryResponse._FakeSocket(data), 1)

        # turn off any debugging in the base class
        self.debuglevel = 0

        # let the base class parse the input
        self.begin()

        # set dedicated properties from the discovery response headers
        self.__location = self.getheader("location")
        self.__usn = self.getheader("usn")
        self.__service = self.getheader("st")

        # parse the location URL
        urlParts = urlparse(self.location)

        self.__locationProtocol = urlParts.scheme.lower()

        self.__locationPath = urlParts.path
        self.__locationHost = urlParts.hostname

        # set the right port depending on if a port was given or the given protocol
        if urlParts.port:
            self.__locationPort = urlParts.port
        else:
            if self.__locationProtocol == "https":
                self.__locationPort = 443
            else:
                self.__locationPort = 80
예제 #4
0
    def __init__(self, data):
        """Initialize a new object.

        :param data: a stream of data which contain a discovery response in the HTTP format.
        :type data: str or list[bytes] or list[int]
        :rtype: DiscoveryResponse
        """

        # create a fake socket which is needed by the base class to initialize.
        # initialize the base class
        HTTPResponse.__init__(self, DiscoveryResponse._FakeSocket(data), 1)

        # turn off any debugging in the base class
        self.debuglevel = 0

        # let the base class parse the input
        self.begin()

        # set dedicated properties from the discovery response headers
        self.__location = self.getheader("location")
        self.__usn = self.getheader("usn")
        self.__service = self.getheader("st")

        # parse the location URL
        urlParts = urlparse(self.location)

        self.__locationProtocol = urlParts.scheme.lower()

        self.__locationPath = urlParts.path
        self.__locationHost = urlParts.hostname

        # set the right port depending on if a port was given or the given protocol
        if urlParts.port:
            self.__locationPort = urlParts.port
        else:
            if self.__locationProtocol == "https":
                self.__locationPort = 443
            else:
                self.__locationPort = 80