def start()

in chef/cookbooks/cpe_nudge/files/nudge-python/resources/gurl.py [0:0]


    def start(self):
        '''Start the connection'''
        if not self.destination_path:
            self.log('No output file specified.')
            self.done = True
            return
        url = NSURL.URLWithString_(self.url)
        request = (
            NSMutableURLRequest.requestWithURL_cachePolicy_timeoutInterval_(
                url, NSURLRequestReloadIgnoringLocalCacheData,
                self.connection_timeout))
        if self.additional_headers:
            for header, value in self.additional_headers.items():
                request.setValue_forHTTPHeaderField_(value, header)
        # does the file already exist? See if we can resume a partial download
        if os.path.isfile(self.destination_path):
            stored_data = self.getStoredHeaders()
            if (self.can_resume and 'expected-length' in stored_data and
                    ('last-modified' in stored_data or 'etag' in stored_data)):
                # we have a partial file and we're allowed to resume
                self.resume = True
                local_filesize = os.path.getsize(self.destination_path)
                byte_range = 'bytes=%s-' % local_filesize
                request.setValue_forHTTPHeaderField_(byte_range, 'Range')
        if self.download_only_if_changed and not self.resume:
            stored_data = self.cache_data or self.getStoredHeaders()
            if 'last-modified' in stored_data:
                request.setValue_forHTTPHeaderField_(
                    stored_data['last-modified'], 'if-modified-since')
            if 'etag' in stored_data:
                request.setValue_forHTTPHeaderField_(
                    stored_data['etag'], 'if-none-match')
        if NSURLSESSION_AVAILABLE:
            configuration = (
                NSURLSessionConfiguration.defaultSessionConfiguration())

            # optional: ignore system http/https proxies (10.9+ only)
            if self.ignore_system_proxy is True:
                configuration.setConnectionProxyDictionary_(
                    {kCFNetworkProxiesHTTPEnable: False,
                     kCFNetworkProxiesHTTPSEnable: False})

            # set minimum supported TLS protocol (defaults to TLS1)
            configuration.setTLSMinimumSupportedProtocol_(
                self.minimum_tls_protocol)

            self.session = (
                NSURLSession.sessionWithConfiguration_delegate_delegateQueue_(
                    configuration, self, None))
            self.task = self.session.dataTaskWithRequest_(request)
            self.task.resume()
        else:
            self.connection = NSURLConnection.alloc().initWithRequest_delegate_(
                request, self)