Send an offer to a user for content to be downloaded.
        User authentication required with the following scope: 'content/write'
340985
def send_file_offer(self, file_id, user_id, auto_open=False, scope='content/send'):
        

        params = {
            'UserId': user_id,
            'autoOpen': 'true' if auto_open else 'false'
        }

        return _post(
            token=self.oauth.get_app_token(scope),
            uri='/user/media/file/send/' + urllib.quote(file_id) + '?' + urllib.urlencode(params)
        )
283167
def send(self):
        
        scheme, location, path, query, _ = urlparse.urlsplit(self.url)
        assert scheme in ("http", "https"), "Unsupported scheme %r" % scheme

        content_type, body = self._encode_multipart_formdata()
        handle = getattr(httplib, scheme.upper() + "Connection")(location)
        if self.mock_http:
            # Don't actually send anything, print to stdout instead
            handle.sock = parts.Bunch(
                sendall=lambda x: sys.stdout.write(fmt.to_utf8(
                    ''.join((c if 32 <= ord(c) < 127 or ord(c) in (8, 10) else u'\u27ea%02X\u27eb' % ord(c)) for c in x)
                )),
                makefile=lambda dummy, _: StringIO.StringIO("\r\n".join((
                    "HTTP/1.0 204 NO CONTENT",
                    "Content-Length: 0",
                    "",
                ))),
                close=lambda: None,
            )

        handle.putrequest('POST', urlparse.urlunsplit(('', '', path, query, '')))
        handle.putheader('Content-Type', content_type)
        handle.putheader('Content-Length', str(len(body)))
        for key, val in self.headers.items():
            handle.putheader(key, val)
        handle.endheaders()
        handle.send(body)
        #print handle.__dict__

        return handle.getresponse()
1373800
def download_file_proxy(p_url, p_op_file, p_username, p_password, proxies):
    
    chunk_size=4096
    import requests
    r = requests.get(p_url, auth=(p_username, p_password), proxies=proxies)
    #print(r.status_code)
    with open(p_op_file, 'wb') as fd:
        for chunk in r.iter_content(chunk_size):
            fd.write(chunk)  
    return r.status_code
1174891
def pub_download(args, location=None, prefix=""):
    
    download(location, remotes=args, prefix=prefix)
635133
function downloadFromUrl(page, ph, url, callback) {
    async.waterfall([
        function (callback) {
            page.getCookies(function (cookie) {
                callback(null, page, ph, cookie);
            });
        },
        function (page, ph, cookies, callback) {
            var cookieString = helpers.cookieToHeader(cookies);
            var headers = { Cookie: cookieString };
            request.get({
                url: url,
                headers: headers,
                encoding: null
            }, function (error, response, downloadedBytes) {
                callback(error, page, ph, downloadedBytes);
            });
        }
    ], callback);
}
945265
def download_file_insecure_to_io(url, target_file=None, headers={}):
    

    src = None
    try:
        req = Request(
            url,
            data=None,
            headers=headers
        )

        src = urlopen(req)

        # Read/write all in one block, so we don't create a corrupt file
        # if the download is interrupted.
        data = src.read()
        target_file.write(data)
    finally:
        if src:
            src.close()
456984
def write(self, auth, resource, value, options={}, defer=False):
        
        return self._call('write', auth, [resource, value, options], defer)
534050
def request_transfer(subject, recipient, comment):
    ''''''
    TransferPermission(subject).test()
    if recipient == (subject.organization or subject.owner):
        raise ValueError(
            'Recipient should be different than the current owner')
    transfer = Transfer.objects.create(
        owner=subject.organization or subject.owner,
        recipient=recipient,
        subject=subject,
        comment=comment
    )
    return transfer
478207
def download(url, encoding='utf-8'):
    """"""
    import requests
    response = requests.get(url)
    response.encoding = encoding
    return response.text
841960
def _send_content(self, content, content_type, code=200):
    """"""
    assert isinstance(content, bytes)
    self.send_response(code)
    self.send_header('Content-Type', content_type)
    self.send_header('Content-Length', str(len(content)))
    self.end_headers()
    self.wfile.write(content)
881268
def send_message(self, author, content):
        
        if isinstance(author, Author) is False:
            raise ValueError('argument answer need to be Zhihu.Author object.')
        if not content:
            raise ValueError('answer content cannot be empty')
        if author.url == self.url:
                return False
        data = {
            'member_id': author.hash_id,
            'content': content,
            'token': '',
            '_xsrf': author.xsrf
        }
        res = self._session.post(Send_Message_Url,
                                 data=data)
        return res.json()['r'] == 0
74265
def send_user_to_user_message(self, from_user_id, target_user_ids, message='', contains_markup=True,
                                  scope='message/user'):
        
        return _post(
            token=self.oauth.get_user_token(scope),
            uri='/message/send',
            data={
                'From': from_user_id,
                'To': ",".join(target_user_ids),
                'Body': message,
                'ContainsMarkup': contains_markup
            }
        )
1368402
function sendDirectToUser(content, username) {
    return getDirectMessageRoomId(username)
        .then((rid) => sendToRoomId(content, rid));
}
660058
def _request(method, url, content_type=None, _data=None, user=None, passwd=None):
    '''
    
    '''
    opener = _build_opener(_HTTPHandler)
    request = _Request(url, data=_data)
    if content_type:
        request.add_header('Content-Type', content_type)
    if user and passwd:
        auth_encode = '{0}:{1}'.format(user, passwd).encode('base64')[:-1]
        auth_basic = "Basic {0}".format(auth_encode)
        request.add_header('Authorization', auth_basic)
        request.add_header('Accept', 'application/json')
    request.get_method = lambda: method
    try:
        handler = opener.open(request)
    except HTTPError as exc:
        return {'error': '{0}'.format(exc)}
    return salt.utils.json.loads(handler.read())
131031
def exec_api_download(json_req, download_path)
      begin
        req = sign_request(json_req)
        File.open(download_path, "w") do |io|
          return HttpChannel.new(api_uri).execute_download(req) { |d| io << d; d.length }
        end
      rescue Curl::Err::CurlError => ex
        return JsonResponse.new("fail", ex.message)
      end
    end
585758
function download(input, output) {
	if (!output) output = input.split("/").pop();
	var file = fs.createWriteStream(output);
	var request = http.get(input, response => { response.pipe(file); });
}
421636
function downloadString(url, {userAgent}) {
	let deferred  = Q.defer()
	let startTime = Date.now()
	let data = ''
	request({
		method: 'GET',
		url: url,
		headers: {
			'User-Agent': userAgent
		}
	}, function(error, response, body) {
		if(error) {
			deferred.reject(new Error(error))
			return;
		}
		deferred.resolve({
			time: Date.now() - startTime,
			result: body,
			statusCode: response.statusCode
		})
	})
	return deferred.promise
}