本文整理汇总了Python中util.url函数的典型用法代码示例。如果您正苦于以下问题:Python url函数的具体用法?Python url怎么用?Python url使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了url函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: gets_all_available_sites_test
def gets_all_available_sites_test():
r = requests.get(url('instances'), headers=default_headers())
company_id = next(c['companyId'] for c in r.json() if c['mx'] == 'liferay.com')
r = requests.get(url('instances', company_id, 'sites'), headers=default_headers())
assert r.status_code == 200
assert len(r.json()) > 0
示例2: gets_the_detail_of_an_instance_test
def gets_the_detail_of_an_instance_test():
r = requests.get(url('instances'), headers=default_headers())
company_id = next(c['companyId'] for c in r.json() if c['mx'] == 'liferay.com')
r = requests.get(url('instances', company_id), headers=default_headers())
assert r.status_code == 200
assert r.json()['companyId'] == company_id
示例3: addResourceTarget
def addResourceTarget(module,type,name,kwargs):
pages.require("/admin/modules.edit")
#Create a permission
if type == 'permission':
with modulesLock:
if kwargs['name'] in ActiveModules[module]:
raise cherrypy.HTTPRedirect("/errors/alreadyexists")
else:
ActiveModules[module] [kwargs['name']]= {"resource-type":"permission","description":kwargs['description']}
#has its own lock
auth.importPermissionsFromModules() #sync auth's list of permissions
raise cherrypy.HTTPRedirect("/modules/module/" +util.url(module)+ '/resource/' + util.url(name) )
if type == 'event':
with modulesLock:
if kwargs['name'] not in ActiveModules[module]:
ActiveModules[module] [kwargs['name']]= {"resource-type":"event","trigger":"False","action":"pass",
"once":True}
#newevt maintains a cache of precompiled events that must be kept in sync with
#the modules
newevt.updateOneEvent(kwargs['name'],module)
raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name))
else:
raise cherrypy.HTTPRedirect("/errors/alreadyexists")
if type == 'page':
with modulesLock:
if kwargs['name'] not in ActiveModules[module]:
ActiveModules[module][kwargs['name']]= {"resource-type":"page","body":"Content here",'no-navheader':True}
#newevt maintains a cache of precompiled events that must be kept in sync with
#the modules
raise cherrypy.HTTPRedirect("/modules/module/"+util.url(module)+'/resource/'+util.url(name))
else:
raise cherrypy.HTTPRedirect("/errors/alreadyexists")
示例4: gets_a_site_detail_test
def gets_a_site_detail_test():
r = requests.get(url('instances'), headers=default_headers())
company_id = next(c['companyId'] for c in r.json() if c['mx'] == 'liferay.com')
r = requests.get(url('instances', company_id, 'sites'), headers=default_headers())
group_id = next(g['classPK'] for g in r.json() if g['friendlyURL'] == '/guest')
r = requests.get(url('instances', company_id, 'sites', group_id),
headers=default_headers())
assert r.status_code == 200
assert r.json()['classPK'] == group_id
示例5: returns_all_site_articles_test
def returns_all_site_articles_test():
r = requests.get(url('instances'), headers=default_headers())
company_id = next(c['companyId'] for c in r.json() if c['mx'] == 'liferay.com')
r = requests.get(url('instances', company_id, 'sites'),
headers=default_headers())
group_id = next(g['classPK'] for g in r.json() if g['friendlyURL'] == '/guest')
r = requests.get(url('instances', company_id, 'sites', group_id, 'articles'),
headers=default_headers())
assert r.status_code == 200
assert len(r.json()) >= 0
示例6: getModuleAsZip
def getModuleAsZip(module):
with modulesLock:
#We use a stringIO so we can avoid using a real file.
ram_file = StringIO()
z = zipfile.ZipFile(ram_file,'w')
#Dump each resource to JSON in the ZIP
for resource in ActiveModules[module]:
#AFAIK Zip files fake the directories with naming conventions
s = json.dumps(ActiveModules[module][resource],sort_keys=True,indent=4, separators=(',', ': '))
z.writestr(url(module)+'/'+url(resource)+".json",s)
z.close()
s = ram_file.getvalue()
ram_file.close()
return s
示例7: __init__
def __init__(self, ui, path, create=False):
self._url = path
self.ui = ui
u = util.url(path, parsequery=False, parsefragment=False)
if u.scheme != "ssh" or not u.host or u.path is None:
self._abort(error.RepoError(_("couldn't parse location %s") % path))
self.user = u.user
if u.passwd is not None:
self._abort(error.RepoError(_("password in URL not supported")))
self.host = u.host
self.port = u.port
self.path = u.path or "."
sshcmd = self.ui.config("ui", "ssh", "ssh")
remotecmd = self.ui.config("ui", "remotecmd", "hg")
args = util.sshargs(sshcmd, self.host, self.user, self.port)
if create:
cmd = '%s %s "%s init %s"'
cmd = cmd % (sshcmd, args, remotecmd, self.path)
ui.note(_("running %s\n") % cmd)
res = util.system(cmd)
if res != 0:
self._abort(error.RepoError(_("could not create remote repo")))
self.validate_repo(ui, sshcmd, args, remotecmd)
示例8: openpath
def openpath(ui, path):
"""open path with open if local, url.open if remote"""
pathurl = util.url(path, parsequery=False, parsefragment=False)
if pathurl.islocal():
return util.posixfile(pathurl.localpath(), "rb")
else:
return url.open(ui, path)
示例9: __init__
def __init__(self, ui, path, create=False):
self._url = path
self.ui = ui
self.pipeo = self.pipei = self.pipee = None
u = util.url(path, parsequery=False, parsefragment=False)
if u.scheme != 'ssh' or not u.host or u.path is None:
self._abort(error.RepoError(_("couldn't parse location %s") % path))
self.user = u.user
if u.passwd is not None:
self._abort(error.RepoError(_("password in URL not supported")))
self.host = u.host
self.port = u.port
self.path = u.path or "."
sshcmd = self.ui.config("ui", "ssh", "ssh")
remotecmd = self.ui.config("ui", "remotecmd", "hg")
args = util.sshargs(sshcmd, self.host, self.user, self.port)
if create:
cmd = '%s %s %s' % (sshcmd, args,
util.shellquote("%s init %s" %
(_serverquote(remotecmd), _serverquote(self.path))))
ui.debug('running %s\n' % cmd)
res = util.system(cmd, out=ui.fout)
if res != 0:
self._abort(error.RepoError(_("could not create remote repo")))
self._validaterepo(sshcmd, args, remotecmd)
示例10: instance
def instance(ui, path, create):
if create:
raise util.Abort(_('cannot create new bundle repository'))
parentpath = ui.config("bundle", "mainreporoot", "")
if not parentpath:
# try to find the correct path to the working directory repo
parentpath = cmdutil.findrepo(os.getcwd())
if parentpath is None:
parentpath = ''
if parentpath:
# Try to make the full path relative so we get a nice, short URL.
# In particular, we don't want temp dir names in test outputs.
cwd = os.getcwd()
if parentpath == cwd:
parentpath = ''
else:
cwd = os.path.join(cwd,'')
if parentpath.startswith(cwd):
parentpath = parentpath[len(cwd):]
u = util.url(path)
path = u.localpath()
if u.scheme == 'bundle':
s = path.split("+", 1)
if len(s) == 1:
repopath, bundlename = parentpath, s[0]
else:
repopath, bundlename = s
else:
repopath, bundlename = parentpath, path
return bundlerepository(ui, repopath, bundlename)
示例11: __init__
def __init__(self, ui, path):
self._url = path
self.ui = ui
self.root = path
u = util.url(path.rstrip("/") + "/.hg")
self.path, authinfo = u.authinfo()
opener = build_opener(ui, authinfo)
self.opener = opener(self.path)
self.vfs = self.opener
self._phasedefaults = []
try:
requirements = scmutil.readrequires(self.opener, self.supported)
except IOError, inst:
if inst.errno != errno.ENOENT:
raise
requirements = set()
# check if it is a non-empty old-style repository
try:
fp = self.opener("00changelog.i")
fp.read(1)
fp.close()
except IOError, inst:
if inst.errno != errno.ENOENT:
raise
# we do not care about empty old-style repositories here
msg = _("'%s' does not appear to be an hg repository") % path
raise error.RepoError(msg)
示例12: find_user_password
def find_user_password(self, realm, authuri):
authinfo = urllib2.HTTPPasswordMgrWithDefaultRealm.find_user_password(
self, realm, authuri)
user, passwd = authinfo
if user and passwd:
self._writedebug(user, passwd)
return (user, passwd)
if not user or not passwd:
res = httpconnectionmod.readauthforuri(self.ui, authuri, user)
if res:
group, auth = res
user, passwd = auth.get('username'), auth.get('password')
self.ui.debug("using auth.%s.* for authentication\n" % group)
if not user or not passwd:
u = util.url(authuri)
u.query = None
if not self.ui.interactive():
raise util.Abort(_('http authorization required for %s') %
util.hidepassword(str(u)))
self.ui.write(_("http authorization required for %s\n") %
util.hidepassword(str(u)))
self.ui.write(_("realm: %s\n") % realm)
if user:
self.ui.write(_("user: %s\n") % user)
else:
user = self.ui.prompt(_("user:"), default=None)
if not passwd:
passwd = self.ui.getpass()
self.add_password(realm, authuri, user, passwd)
self._writedebug(user, passwd)
return (user, passwd)
示例13: _peerlookup
def _peerlookup(path):
u = util.url(path)
scheme = u.scheme or 'file'
thing = schemes.get(scheme) or schemes['file']
try:
return thing(path)
except TypeError:
return thing
示例14: parseurl
def parseurl(path, branches=None):
'''parse url#branch, returning (url, (branch, branches))'''
u = util.url(path)
branch = None
if u.fragment:
branch = u.fragment
u.fragment = None
return str(u), (branch, branches or [])
示例15: open
def open(ui, url_, data=None):
u = util.url(url_)
if u.scheme:
u.scheme = u.scheme.lower()
url_, authinfo = u.authinfo()
else:
path = util.normpath(os.path.abspath(url_))
url_ = 'file://' + urllib.pathname2url(path)
authinfo = None
return opener(ui, authinfo).open(url_, data)