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)
python类basejoin()的实例源码
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)
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)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
def staticuri(self, url):
base = self.config.get("static-baseurl", None)
if base:
return basejoin(base, url)
else:
return self.request.uri("/%s" % url)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
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)
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)
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)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
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.
#
def basejoin(base, url):
if url.startswith(token) is True:
return urllib.basejoin(base,url[2:])
return urllib.basejoin(base,url)
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)
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)
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)
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)
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)
checkNginxLatestVersionByParseHtmlOnline.py 文件源码
项目:LinuxBashShellScriptForOps
作者: DingGuodong
项目源码
文件源码
阅读 20
收藏 0
点赞 0
评论 0
def join_url(base, path):
import urllib
return urllib.basejoin(base, path)