Ejemplo n.º 1
0
    def initWithAdapter_(self, adapter):
        self = objc.super(NSURLSessionAdapterDelegate, self).init()

        if self is None:
            return None

        self.adapter = adapter
        self.bytesReceived = 0
        self.expectedLength = -1
        self.percentComplete = 0
        self.done = False
        self.error = None
        self.SSLError = None
        self.output = NSMutableData.dataWithCapacity_(1024)
        self.status = None
        self.headers = {}
        self.verify = True
        self.credential = None
        self.history = []

        return self
Ejemplo n.º 2
0
    def testFunctions(self):
        self.assertIsInstance(CGImageDestinationGetTypeID(), (int, long))

        self.assertResultIsCFRetained(CGImageDestinationCopyTypeIdentifiers)
        v = CGImageDestinationCopyTypeIdentifiers()
        self.assertIsInstance(v, CFArrayRef)
        if v:
            self.assertIsInstance(v[0], unicode)

        data = NSMutableData.dataWithCapacity_(1024 * 1024 * 50)
        self.assertResultIsCFRetained(CGImageDestinationCreateWithData)
        dest = CGImageDestinationCreateWithData(data, v[0], 1, None)
        self.assertIsInstance(dest, CGImageDestinationRef)

        url = CFURLCreateWithFileSystemPath(
            None, "/tmp/pyobjc.test.pdf", kCFURLPOSIXPathStyle, False
        )
        self.assertResultIsCFRetained(CGImageDestinationCreateWithURL)
        dest = CGImageDestinationCreateWithURL(url, "public.tiff", 2, None)
        self.assertIsInstance(dest, CGImageDestinationRef)

        CGImageDestinationSetProperties(
            dest, {b"key".decode("latin1"): b"value".decode("latin1")}
        )

        provider = CGDataProviderCreateWithCFData(buffer("1" * 4 * 100 * 80))
        img = CGImageCreate(
            100,
            80,
            8,
            32,
            400,
            CGColorSpaceCreateDeviceRGB(),
            kCGImageAlphaPremultipliedLast,
            provider,
            None,
            False,
            kCGRenderingIntentDefault,
        )
        self.assertIsInstance(img, CGImageRef)

        CGImageDestinationAddImage(dest, img, None)

        image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/bullet.tif"
        if not os.path.exists(image_path):
            image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.png"
        if not os.path.exists(image_path):
            image_path = "/System/Library/ColorSync/Calibrators/Display Calibrator.app/Contents/Resources/brightness.tiff"

        self.assertTrue(os.path.exists(image_path))

        url = CFURLCreateWithFileSystemPath(
            None, image_path, kCFURLPOSIXPathStyle, False
        )

        isrc = CGImageSourceCreateWithURL(url, None)
        CGImageDestinationAddImageFromSource(dest, isrc, 0, None)

        self.assertResultHasType(CGImageDestinationFinalize, objc._C_BOOL)
        v = CGImageDestinationFinalize(dest)
        self.assertIsInstance(v, bool)
        self.assertIs(v, True)

        dta = NSMutableData.alloc().init()
        cons = CGDataConsumerCreateWithCFData(dta)

        self.assertResultIsCFRetained(CGImageDestinationCreateWithDataConsumer)
        c = CGImageDestinationCreateWithDataConsumer(cons, "public.tiff", 1, None)
        self.assertIsInstance(c, CGImageDestinationRef)