# Path: coherence/upnp/core/utils.py
# def means_true(value):
# def generalise_boolean(value):
# def parse_xml(data, encoding="utf-8"):
# def parse_http_response(data):
# def get_ip_address(ifname):
# def get_host_address():
#             def result(r):
#             def fail(f):
# def de_chunk_payload(response):
#     def read_chunk_length():
#     def process(self):
#             def deferred_rendering(r):
#     def startFactory(self):
#     def __init__(self, command, rest, version, headers, data, father):
#     def handleStatus(self, version, code, message):
#     def handleHeader(self, key, value):
#     def handleResponsePart(self, buffer):
#     def __init__(self, host, port, path, reactor=reactor):
#     def getChild(self, path, request):
#     def render(self, request):
#     def resetTarget(self, host, port, path, qs=''):
#     def __init__(self, uri, reactor=reactor):
#     def resetUri (self, uri):
#     def buildProtocol(self, addr):
#     def page(self, page):
# def getPage(url, contextFactory=None, *args, **kwargs):
# def downloadPage(url, file, contextFactory=None, *args, **kwargs):
#     def __init__(self, path, target_size=0, *args):
#     def render(self, request):
#     def __init__(self, file, size, request):
#     def resumeProducing(self):
#     def pauseProducing(self):
#     def stopProducing(self):
#     def utcoffset(self, dt):
#     def tzname(self, dt):
#     def dst(self, dt):
# def datefaker():
#         SIOCGIFADDR = 0x8915
#         SIOCGIFADDR = 0xc0206921
# class Request(server.Request):
# class Site(server.Site):
# class ProxyClient(proxy.ProxyClient):
# class ProxyClientFactory(proxy.ProxyClientFactory):
# class ReverseProxyResource(proxy.ReverseProxyResource):
# class ReverseProxyUriResource(ReverseProxyResource):
# class myHTTPPageGetter(client.HTTPPageGetter):
# class HeaderAwareHTTPClientFactory(client.HTTPClientFactory):
# class BufferFile(static.File):
# class BufferFileTransfer(object):
# class _tz(tzinfo):
# class _CET(_tz):
# class _CEST(_tz):


import os
from twisted.trial import unittest
from twisted.python.filepath import FilePath
from twisted.internet import reactor
from twisted.web import static, server
from twisted.protocols import policies
from coherence.upnp.core import utils

class TestClient(unittest.TestCase):

    def _listen(self, site):
        return reactor.listenTCP(0, site, interface="127.0.0.1")

    def setUp(self):
        name = self.mktemp()
        os.mkdir(name)
        FilePath(name).child("file").setContent("0123456789")
        r = static.File(name)
        self.site = server.Site(r, timeout=None)
        self.wrapper = policies.WrappingFactory(self.site)
        self.port = self._listen(self.wrapper)
        self.portno = self.port.getHost().port

    def tearDown(self):
        return self.port.stopListening()

    def getURL(self, path):
        return "http://127.0.0.1:%d/%s" % (self.portno, path)

    def assertResponse(self, original, content, headers):
        self.assertIsInstance(original, tuple)
        self.assertEqual(original[0], content)
        originalHeaders = original[1]
        for header in headers:
            self.assertIn(header, originalHeaders)
            self.assertEqual(originalHeaders[header], headers[header])

    def test_parse_http_response(self):

# Path: coherence/upnp/core/utils.py
# def means_true(value):
# def generalise_boolean(value):
# def parse_xml(data, encoding="utf-8"):
# def parse_http_response(data):
# def get_ip_address(ifname):
# def get_host_address():
#             def result(r):
#             def fail(f):
# def de_chunk_payload(response):
#     def read_chunk_length():
#     def process(self):
#             def deferred_rendering(r):
#     def startFactory(self):
#     def __init__(self, command, rest, version, headers, data, father):
#     def handleStatus(self, version, code, message):
#     def handleHeader(self, key, value):
#     def handleResponsePart(self, buffer):
#     def __init__(self, host, port, path, reactor=reactor):
#     def getChild(self, path, request):
#     def render(self, request):
#     def resetTarget(self, host, port, path, qs=''):
#     def __init__(self, uri, reactor=reactor):
#     def resetUri (self, uri):
#     def buildProtocol(self, addr):
#     def page(self, page):
# def getPage(url, contextFactory=None, *args, **kwargs):
# def downloadPage(url, file, contextFactory=None, *args, **kwargs):
#     def __init__(self, path, target_size=0, *args):
#     def render(self, request):
#     def __init__(self, file, size, request):
#     def resumeProducing(self):
#     def pauseProducing(self):
#     def stopProducing(self):
#     def utcoffset(self, dt):
#     def tzname(self, dt):
#     def dst(self, dt):
# def datefaker():
#         SIOCGIFADDR = 0x8915
#         SIOCGIFADDR = 0xc0206921
# class Request(server.Request):
# class Site(server.Site):
# class ProxyClient(proxy.ProxyClient):
# class ProxyClientFactory(proxy.ProxyClientFactory):
# class ReverseProxyResource(proxy.ReverseProxyResource):
# class ReverseProxyUriResource(ReverseProxyResource):
# class myHTTPPageGetter(client.HTTPPageGetter):
# class HeaderAwareHTTPClientFactory(client.HTTPClientFactory):
# class BufferFile(static.File):
# class BufferFileTransfer(object):
# class _tz(tzinfo):
# class _CET(_tz):
# class _CEST(_tz):


# Path: coherence/upnp/core/test/test_utils.py
import os
from twisted.trial import unittest
from twisted.python.filepath import FilePath
from twisted.internet import reactor
from twisted.web import static, server
from twisted.protocols import policies
from coherence.upnp.core import utils

class TestClient(unittest.TestCase):

    def _listen(self, site):
        return reactor.listenTCP(0, site, interface="127.0.0.1")

    def setUp(self):
        name = self.mktemp()
        os.mkdir(name)
        FilePath(name).child("file").setContent("0123456789")
        r = static.File(name)
        self.site = server.Site(r, timeout=None)
        self.wrapper = policies.WrappingFactory(self.site)
        self.port = self._listen(self.wrapper)
        self.portno = self.port.getHost().port

    def tearDown(self):
        return self.port.stopListening()

    def getURL(self, path):
        return "http://127.0.0.1:%d/%s" % (self.portno, path)

    def assertResponse(self, original, content, headers):
        self.assertIsInstance(original, tuple)
        self.assertEqual(original[0], content)
        originalHeaders = original[1]
        for header in headers:
            self.assertIn(header, originalHeaders)
            self.assertEqual(originalHeaders[header], headers[header])

    def test_parse_http_response(self):

        cmd, headers, content = utils.parse_http_response(msearch_response1)
