本文整理汇总了Python中urllib.basejoin方法的典型用法代码示例。如果您正苦于以下问题:Python urllib.basejoin方法的具体用法?Python urllib.basejoin怎么用?Python urllib.basejoin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类urllib
的用法示例。
在下文中一共展示了urllib.basejoin方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _appendPackages
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def _appendPackages(self, packages, url):
"""Given a list of dictionaries containing package
descriptions create the PimpPackage objects and append them
to our internal storage."""
for p in packages:
p = dict(p)
if 'Download-URL' in p:
p['Download-URL'] = urllib.basejoin(url, p['Download-URL'])
flavor = p.get('Flavor')
if flavor == 'source':
pkg = PimpPackage_source(self, p)
elif flavor == 'binary':
pkg = PimpPackage_binary(self, p)
elif flavor == 'installer':
pkg = PimpPackage_installer(self, p)
elif flavor == 'hidden':
pkg = PimpPackage_installer(self, p)
else:
pkg = PimpPackage(self, dict(p))
self._packages.append(pkg)
示例2: render_ui
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def render_ui(self, editorID):
""" 创建button的js代码: """
return """
var btn = new UE.ui.Button({
name: uiName,
title: "%(title)s",
cssRules: "background-image:url('%(icon)s')!important;",
onclick: function() {
%(onclick)s
}
});
return btn
""" % {
"icon": urljoin(USettings.gSettings.MEDIA_URL, self.icon),
"onclick": self.onClick(),
"title": self.title
}
示例3: get_files
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def get_files(root_path, cur_path, allow_types=[]):
files = []
items = os.listdir(cur_path)
for item in items:
item = unicode(item)
item_fullname = os.path.join(root_path, cur_path, item).replace("\\", "/")
if os.path.isdir(item_fullname):
files.extend(get_files(root_path, item_fullname, allow_types))
else:
ext = os.path.splitext(item_fullname)[1]
is_allow_list = (len(allow_types) == 0) or (ext in allow_types)
if is_allow_list:
files.append({
"url": urljoin(USettings.gSettings.MEDIA_URL, os.path.join(os.path.relpath(cur_path, root_path), item).replace("\\", "/")),
"mtime": os.path.getmtime(item_fullname)
})
return files
示例4: open
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def open(self, url, data=None, headers={}):
"""Opens the specified url."""
url = urllib.basejoin(self.url, url)
req = urllib2.Request(url, data, headers)
return self.do_request(req)
示例5: appendURL
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def appendURL(self, url, included=0):
"""Append packages from the database with the given URL.
Only the first database should specify included=0, so the
global information (maintainer, description) get stored."""
if url in self._urllist:
return
self._urllist.append(url)
fp = urllib2.urlopen(url).fp
plistdata = plistlib.Plist.fromFile(fp)
# Test here for Pimp version, etc
if included:
version = plistdata.get('Version')
if version and version > self._version:
sys.stderr.write("Warning: included database %s is for pimp version %s\n" %
(url, version))
else:
self._version = plistdata.get('Version')
if not self._version:
sys.stderr.write("Warning: database has no Version information\n")
elif self._version > PIMP_VERSION:
sys.stderr.write("Warning: database version %s newer than pimp version %s\n"
% (self._version, PIMP_VERSION))
self._maintainer = plistdata.get('Maintainer', '')
self._description = plistdata.get('Description', '').strip()
self._url = url
self._appendPackages(plistdata['Packages'], url)
others = plistdata.get('Include', [])
for o in others:
o = urllib.basejoin(url, o)
self.appendURL(o, included=1)
示例6: SplitQName
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def SplitQName(qname):
'''SplitQName(qname) -> (string, string)
Split Qualified Name into a tuple of len 2, consisting
of the prefix and the local name.
(prefix, localName)
Special Cases:
xmlns -- (localName, 'xmlns')
None -- (None, localName)
'''
l = qname.split(':')
if len(l) == 1:
l.insert(0, None)
elif len(l) == 2:
if l[0] == 'xmlns':
l.reverse()
else:
return
return tuple(l)
#
# python2.3 urllib.basejoin does not remove current directory ./
# from path and this causes problems on subsequent basejoins.
#
示例7: basejoin
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
示例8: join
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def join(base, rel):
if rel == BUILTIN_FILE:
return os.path.join(os.path.dirname(__file__), "lib", BUILTIN_FILE)
else:
return urllib.basejoin(base, rel)
示例9: BaseJoin
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def BaseJoin(base, uriRef):
"""
Merges a base URI reference with another URI reference, returning a
new URI reference.
It behaves exactly the same as Absolutize(), except the arguments
are reversed, and it accepts any URI reference (even a relative URI)
as the base URI. If the base has no scheme component, it is
evaluated as if it did, and then the scheme component of the result
is removed from the result, unless the uriRef had a scheme. Thus, if
neither argument has a scheme component, the result won't have one.
This function is named BaseJoin because it is very much like
urllib.basejoin(), but it follows the current rfc3986 algorithms
for path merging, dot segment elimination, and inheritance of query
and fragment components.
WARNING: This function exists for 2 reasons: (1) because of a need
within the 4Suite repository to perform URI reference absolutization
using base URIs that are stored (inappropriately) as absolute paths
in the subjects of statements in the RDF model, and (2) because of
a similar need to interpret relative repo paths in a 4Suite product
setup.xml file as being relative to a path that can be set outside
the document. When these needs go away, this function probably will,
too, so it is not advisable to use it.
"""
if IsAbsolute(base):
return Absolutize(uriRef, base)
else:
dummyscheme = 'basejoin'
res = Absolutize(uriRef, '%s:%s' % (dummyscheme, base))
if IsAbsolute(uriRef):
# scheme will be inherited from uriRef
return res
else:
# no scheme in, no scheme out
return res[len(dummyscheme)+1:]
示例10: urlMerge
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def urlMerge(params, src):
paramArr = __parseParams(params)
paramTrunk = paramArr[0].replace('%s', src).replace("\t","")
paramFile= paramArr[1].replace('%s', src).replace("\t","")
if not paramFile.startswith('http'):
up = urlparse.urlparse(urllib.unquote(paramTrunk))
if paramFile.startswith('/'):
return urllib.basejoin(up[0] + '://' + up[1], paramFile)
else:
return urllib.basejoin(up[0] + '://' + up[1] + '/' + up[2],paramFile)
return src
示例11: catcher_remote_image
# 需要导入模块: import urllib [as 别名]
# 或者: from urllib import basejoin [as 别名]
def catcher_remote_image(request):
"""远程抓图,当catchRemoteImageEnable:true时,
如果前端插入图片地址与当前web不在同一个域,则由本函数从远程下载图片到本地
"""
if not request.method == "POST":
return HttpResponse(json.dumps(u"{'state:'ERROR'}"), content_type="application/javascript")
state = "SUCCESS"
allow_type = list(request.GET.get("catcherAllowFiles", USettings.UEditorUploadSettings.get("catcherAllowFiles", "")))
max_size = int(request.GET.get("catcherMaxSize", USettings.UEditorUploadSettings.get("catcherMaxSize", 0)))
remote_urls = request.POST.getlist("source[]", [])
catcher_infos = []
path_format_var = get_path_format_vars()
for remote_url in remote_urls:
# 取得上传的文件的原始名称
remote_file_name = os.path.basename(remote_url)
remote_original_name, remote_original_ext = os.path.splitext(remote_file_name)
# 文件类型检验
if remote_original_ext in allow_type:
path_format_var.update({
"basename": remote_original_name,
"extname": remote_original_ext[1:],
"filename": remote_original_name
})
# 计算保存的文件名
o_path_format, o_path, o_file = get_output_path(request, "catcherPathFormat", path_format_var)
o_filename = os.path.join(o_path, o_file).replace("\\", "/")
# 读取远程图片文件
try:
remote_image = urllib.urlopen(remote_url)
# 将抓取到的文件写入文件
try:
f = open(o_filename, 'wb')
f.write(remote_image.read())
f.close()
state = "SUCCESS"
except Exception as e:
state = u"写入抓取图片文件错误:%s" % e
except Exception as e:
state = u"抓取图片错误:%s" % e
catcher_infos.append({
"state": state,
"url": urljoin(USettings.gSettings.MEDIA_URL, o_path_format),
"size": os.path.getsize(o_filename),
"title": os.path.basename(o_file),
"original": remote_file_name,
"source": remote_url
})
return_info = {
"state": "SUCCESS" if len(catcher_infos) > 0 else "ERROR",
"list": catcher_infos
}
return HttpResponse(json.dumps(return_info, ensure_ascii=False), content_type="application/javascript")