pyobjc / pyobjc-framework-CFNetwork / PyObjCTest / test_cfhttpstream.py

from CFNetwork import *
from PyObjCTools.TestSupport import *
import os

class TestCFHTTPStream (TestCase):
    @min_os_level('10.5')
    def testConstants10_5(self):
        self.assertIsInstance(kCFStreamPropertyHTTPFinalRequest, unicode)

    def testConstants(self):
        self.assertIsInstance(kCFStreamErrorDomainHTTP, (int, long))

        self.assertEqual(kCFStreamErrorHTTPParseFailure, -1)
        self.assertEqual(kCFStreamErrorHTTPRedirectionLoop, -2)
        self.assertEqual(kCFStreamErrorHTTPBadURL, -3)

        self.assertIsInstance(kCFStreamPropertyHTTPResponseHeader, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPFinalURL, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPProxy, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPProxyHost, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPProxyPort, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPSProxyHost, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPSProxyPort, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPShouldAutoredirect, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPAttemptPersistentConnection, unicode)
        self.assertIsInstance(kCFStreamPropertyHTTPRequestBytesWrittenCount, unicode)

    def testFunctions(self):
       url = CFURLCreateWithString(None, "http://www.python.org/", None)
       self.assertIsInstance(url, CFURLRef)

       req = CFHTTPMessageCreateRequest(None, "GET", url, kCFHTTPVersion1_1)
       self.assertIsInstance(req, CFHTTPMessageRef)

       self.assertResultIsCFRetained(CFReadStreamCreateForHTTPRequest)
       v = CFReadStreamCreateForHTTPRequest(None, req)
       self.assertIsInstance(v, CFReadStreamRef)

       fp = open("/dev/null", "w")
       fd_2 = os.dup(2)
       os.dup2(fp.fileno(), 2)

       try:
           # Avoid deprecation messages from CFNetwork

           self.assertResultIsCFRetained(CFReadStreamCreateForStreamedHTTPRequest)
           v = CFReadStreamCreateForStreamedHTTPRequest(None, req, v)
           self.assertIsInstance(v, CFReadStreamRef)

           self.assertArgIsBOOL(CFHTTPReadStreamSetRedirectsAutomatically, 1)
           CFHTTPReadStreamSetRedirectsAutomatically(v, True)

           CFHTTPReadStreamSetProxy(v, u"localhost", 8080)

       finally:
           os.dup2(fd_2, 2)

if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.