Python urllib.basejoin() Examples
The following are 18
code examples of urllib.basejoin().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
urllib
, or try the search function
.
Example #1
Source File: pimp.py From Computable with MIT License | 6 votes |
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)
Example #2
Source File: commands.py From Mxonline3 with Apache License 2.0 | 6 votes |
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 }
Example #3
Source File: pimp.py From Splunking-Crime with GNU Affero General Public License v3.0 | 6 votes |
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)
Example #4
Source File: commands.py From Dailyfresh-B2C with Apache License 2.0 | 6 votes |
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 }
Example #5
Source File: views.py From Dailyfresh-B2C with Apache License 2.0 | 6 votes |
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
Example #6
Source File: Uri.py From medicare-demo with Apache License 2.0 | 5 votes |
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:]
Example #7
Source File: Uri.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
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:]
Example #8
Source File: browser.py From cosa-nostra with GNU General Public License v3.0 | 5 votes |
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)
Example #9
Source File: Uri.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
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:]
Example #10
Source File: browser.py From bokken with GNU General Public License v2.0 | 5 votes |
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)
Example #11
Source File: customConversions.py From filmkodi with Apache License 2.0 | 5 votes |
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
Example #12
Source File: browser.py From nightmare with GNU General Public License v2.0 | 5 votes |
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)
Example #13
Source File: compiler.py From quark with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: Utility.py From p2pool-n with GNU General Public License v3.0 | 5 votes |
def basejoin(base, url): if url.startswith(token) is True: return urllib.basejoin(base,url[2:]) return urllib.basejoin(base,url)
Example #15
Source File: Utility.py From p2pool-n with GNU General Public License v3.0 | 5 votes |
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. #
Example #16
Source File: pimp.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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)
Example #17
Source File: pimp.py From Computable with MIT License | 5 votes |
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)
Example #18
Source File: views.py From Dailyfresh-B2C with Apache License 2.0 | 4 votes |
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")