def callconduit(ui, name, params): """call Conduit API, params is a dict. return json.loads result, or None""" host, token = readurltoken(ui) url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() ui.debug(b'Conduit Call: %s %s\n' % (url, pycompat.byterepr(params))) params = params.copy() params[b'api.token'] = token data = urlencodenested(params) curlcmd = ui.config(b'phabricator', b'curlcmd') if curlcmd: sin, sout = procutil.popen2(b'%s -d @- %s' % (curlcmd, procutil.shellquote(url))) sin.write(data) sin.close() body = sout.read() else: urlopener = urlmod.opener(ui, authinfo) request = util.urlreq.request(pycompat.strurl(url), data=data) with contextlib.closing(urlopener.open(request)) as rsp: body = rsp.read() ui.debug(b'Conduit Response: %s\n' % body) parsed = pycompat.rapply( lambda x: encoding.unitolocal(x) if isinstance(x, pycompat.unicode) else x, json.loads(body)) if parsed.get(b'error_code'): msg = (_(b'Conduit Error (%s): %s') % (parsed[b'error_code'], parsed[b'error_info'])) raise error.Abort(msg) return parsed[b'result']
def callconduit(repo, name, params): """call Conduit API, params is a dict. return json.loads result, or None""" host, token = readurltoken(repo) url, authinfo = util.url(b'/'.join([host, b'api', name])).authinfo() repo.ui.debug(b'Conduit Call: %s %s\n' % (url, params)) params = params.copy() params[b'api.token'] = token data = urlencodenested(params) curlcmd = repo.ui.config(b'phabricator', b'curlcmd') if curlcmd: sin, sout = procutil.popen2(b'%s -d @- %s' % (curlcmd, procutil.shellquote(url))) sin.write(data) sin.close() body = sout.read() else: urlopener = urlmod.opener(repo.ui, authinfo) request = util.urlreq.request(url, data=data) body = urlopener.open(request).read() repo.ui.debug(b'Conduit Response: %s\n' % body) parsed = json.loads(body) if parsed.get(r'error_code'): msg = (_(b'Conduit Error (%s): %s') % (parsed[r'error_code'], parsed[r'error_info'])) raise error.Abort(msg) return parsed[r'result']
def __init__(self, repo, url): ui = repo.ui self.ui = ui baseurl, authinfo = url.authinfo() self.baseurl = baseurl.rstrip('/') useragent = repo.ui.config('experimental', 'lfs.user-agent') if not useragent: useragent = 'git-lfs/2.3.4 (Mercurial %s)' % util.version() self.urlopener = urlmod.opener(ui, authinfo, useragent) self.retry = ui.configint('lfs', 'retry')
def __init__(self, ui, repo, remote): self.baseurl = bfutil.urljoin(remote.url(), 'bfile') try: # Mercurial >= 1.9 self.baseurl, authinfo = util.url(self.baseurl).authinfo() except AttributeError: # Mercurial <= 1.8 self.baseurl, authinfo = url_.getauthinfo(self.baseurl) self.opener = url_.opener(repo.ui, authinfo) super(kilnstore, self).__init__(ui, repo, remote.url())
def _submit(self, burl, data, method='POST'): data = json.dumps(data) if method == 'PUT': class putrequest(util.urlreq.request): def get_method(self): return 'PUT' request_type = putrequest else: request_type = util.urlreq.request req = request_type(burl, data, {'Content-Type': 'application/json'}) try: resp = url.opener(self.ui).open(req) return json.loads(resp.read()) except util.urlerr.httperror as inst: if inst.code == 401: raise error.Abort(_('authorization failed')) if inst.code == 404: raise NotFound() else: raise
def __init__(self, ui, repo, url): self.ui = ui self.repo = repo (self.baseurl, authinfo) = spliturl(url) self.opener = url_.opener(self.ui, authinfo)
def __init__(self, ui, repo, url): url = bfutil.urljoin(url, 'bfile') super(httpstore, self).__init__(ui, repo, url) self.rawurl, self.path = urlparse.urlsplit(self.url)[1:3] (baseurl, authinfo) = url_.getauthinfo(self.url) self.opener = url_.opener(self.ui, authinfo)