本文整理汇总了Python中posixpath.dirname方法的典型用法代码示例。如果您正苦于以下问题:Python posixpath.dirname方法的具体用法?Python posixpath.dirname怎么用?Python posixpath.dirname使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类posixpath
的用法示例。
在下文中一共展示了posixpath.dirname方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resolveEntity
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def resolveEntity(self, publicId, systemId):
assert systemId is not None
source = DOMInputSource()
source.publicId = publicId
source.systemId = systemId
source.byteStream = self._get_opener().open(systemId)
# determine the encoding if the transport provided it
source.encoding = self._guess_media_encoding(source)
# determine the base URI is we can
import posixpath, urllib.parse
parts = urllib.parse.urlparse(systemId)
scheme, netloc, path, params, query, fragment = parts
# XXX should we check the scheme here as well?
if path and not path.endswith("/"):
path = posixpath.dirname(path) + "/"
parts = scheme, netloc, path, params, query, fragment
source.baseURI = urllib.parse.urlunparse(parts)
return source
示例2: adjust_uri
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def adjust_uri(self, uri, relativeto):
"""Adjust the given ``uri`` based on the given relative URI."""
key = (uri, relativeto)
if key in self._uri_cache:
return self._uri_cache[key]
if uri[0] != "/":
if relativeto is not None:
v = self._uri_cache[key] = posixpath.join(
posixpath.dirname(relativeto), uri
)
else:
v = self._uri_cache[key] = "/" + uri
else:
v = self._uri_cache[key] = uri
return v
示例3: _refuri2http
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def _refuri2http(self, node):
# Replace 'refuri' in reference with HTTP address, if possible
# None for no possible address
url = node.get('refuri')
if not node.get('internal'):
return url
# If HTTP page build URL known, make link relative to that.
if not self.markdown_http_base:
return None
this_doc = self.builder.current_docname
if url in (None, ''): # Reference to this doc
url = self.builder.get_target_uri(this_doc)
else: # URL is relative to the current docname.
this_dir = posixpath.dirname(this_doc)
if this_dir:
url = posixpath.normpath('{}/{}'.format(this_dir, url))
url = '{}/{}'.format(self.markdown_http_base, url)
if 'refid' in node:
url += '#' + node['refid']
return url
示例4: adjust_uri
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def adjust_uri(self, uri, relativeto):
"""Adjust the given ``uri`` based on the given relative URI."""
key = (uri, relativeto)
if key in self._uri_cache:
return self._uri_cache[key]
if uri[0] != '/':
if relativeto is not None:
v = self._uri_cache[key] = posixpath.join(
posixpath.dirname(relativeto), uri)
else:
v = self._uri_cache[key] = '/' + uri
else:
v = self._uri_cache[key] = uri
return v
示例5: resolveEntity
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def resolveEntity(self, publicId, systemId):
assert systemId is not None
source = DOMInputSource()
source.publicId = publicId
source.systemId = systemId
source.byteStream = self._get_opener().open(systemId)
# determine the encoding if the transport provided it
source.encoding = self._guess_media_encoding(source)
# determine the base URI is we can
import posixpath, urlparse
parts = urlparse.urlparse(systemId)
scheme, netloc, path, params, query, fragment = parts
# XXX should we check the scheme here as well?
if path and not path.endswith("/"):
path = posixpath.dirname(path) + "/"
parts = scheme, netloc, path, params, query, fragment
source.baseURI = urlparse.urlunparse(parts)
return source
示例6: test_realpath_resolve_first
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def test_realpath_resolve_first(self):
# Bug #1213894: The first component of the path, if not absolute,
# must be resolved too.
try:
os.mkdir(ABSTFN)
os.mkdir(ABSTFN + "/k")
os.symlink(ABSTFN, ABSTFN + "link")
with support.change_cwd(dirname(ABSTFN)):
base = basename(ABSTFN)
self.assertEqual(realpath(base + "link"), ABSTFN)
self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
finally:
test_support.unlink(ABSTFN + "link")
safe_rmdir(ABSTFN + "/k")
safe_rmdir(ABSTFN)
示例7: get_dependents
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def get_dependents(archive, filename):
"""
Normalise dependency file paths to absolute ones
Relative paths are relative to parent object
"""
src = archive.read(filename)
node = fromstring(src)
rels = RelationshipList.from_tree(node)
folder = posixpath.dirname(filename)
parent = posixpath.split(folder)[0]
for r in rels.Relationship:
if r.TargetMode == "External":
continue
elif r.target.startswith("/"):
r.target = r.target[1:]
else:
pth = posixpath.join(parent, r.target)
r.target = posixpath.normpath(pth)
return rels
示例8: test_realpath_resolve_first
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def test_realpath_resolve_first(self):
# Bug #1213894: The first component of the path, if not absolute,
# must be resolved too.
try:
old_path = abspath('.')
os.mkdir(ABSTFN)
os.mkdir(ABSTFN + "/k")
os.symlink(ABSTFN, ABSTFN + "link")
os.chdir(dirname(ABSTFN))
base = basename(ABSTFN)
self.assertEqual(realpath(base + "link"), ABSTFN)
self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
finally:
os.chdir(old_path)
test_support.unlink(ABSTFN + "link")
safe_rmdir(ABSTFN + "/k")
safe_rmdir(ABSTFN)
示例9: run
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def run(self):
self.env = env = self.state.document.settings.env
self.genopt = Options()
self.warnings = []
self.result = ViewList()
names = [x.strip().split()[0] for x in self.content
if x.strip() and re.search(r'^[~a-zA-Z_]', x.strip()[0])]
#print "DEBUG: running for ",names
items = self.get_items(names)
nodes = self.get_table(items)
if 'toctree' in self.options:
dirname = posixpath.dirname(env.docname)
tree_prefix = self.options['toctree'].strip()
docnames = []
for name, sig, summary, real_name in items:
docname = posixpath.join(tree_prefix, real_name)
docname = posixpath.normpath(posixpath.join(dirname, docname))
if docname not in env.found_docs:
self.warn('toctree references unknown document %r'
% docname)
docnames.append(docname)
tocnode = addnodes.toctree()
tocnode['includefiles'] = docnames
tocnode['entries'] = [(None, docn) for docn in docnames]
tocnode['maxdepth'] = -1
tocnode['glob'] = None
tocnode = autosummary_toc('', '', tocnode)
#print "DEBUG: appending toc node:",tocnode
nodes.append(tocnode)
return self.warnings + nodes
示例10: autohandler
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def autohandler(template, context, name="autohandler"):
lookup = context.lookup
_template_uri = template.module._template_uri
if not lookup.filesystem_checks:
try:
return lookup._uri_cache[(autohandler, _template_uri, name)]
except KeyError:
pass
tokens = re.findall(r"([^/]+)", posixpath.dirname(_template_uri)) + [name]
while len(tokens):
path = "/" + "/".join(tokens)
if path != _template_uri and _file_exists(lookup, path):
if not lookup.filesystem_checks:
return lookup._uri_cache.setdefault(
(autohandler, _template_uri, name), path
)
else:
return path
if len(tokens) == 1:
break
tokens[-2:] = [name]
if not lookup.filesystem_checks:
return lookup._uri_cache.setdefault(
(autohandler, _template_uri, name), None
)
else:
return None
示例11: resolve_path
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def resolve_path(self, name, parent_path=None):
if parent_path and not parent_path.startswith("<") and \
not parent_path.startswith("/") and \
not name.startswith("/"):
current_path = os.path.join(self.root, parent_path)
file_dir = os.path.dirname(os.path.abspath(current_path))
relative_path = os.path.abspath(os.path.join(file_dir, name))
if relative_path.startswith(self.root):
name = relative_path[len(self.root) + 1:]
return name
示例12: autohandler
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def autohandler(template, context, name='autohandler'):
lookup = context.lookup
_template_uri = template.module._template_uri
if not lookup.filesystem_checks:
try:
return lookup._uri_cache[(autohandler, _template_uri, name)]
except KeyError:
pass
tokens = re.findall(r'([^/]+)', posixpath.dirname(_template_uri)) + [name]
while len(tokens):
path = '/' + '/'.join(tokens)
if path != _template_uri and _file_exists(lookup, path):
if not lookup.filesystem_checks:
return lookup._uri_cache.setdefault(
(autohandler, _template_uri, name), path)
else:
return path
if len(tokens) == 1:
break
tokens[-2:] = [name]
if not lookup.filesystem_checks:
return lookup._uri_cache.setdefault(
(autohandler, _template_uri, name), None)
else:
return None
示例13: _is_child
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def _is_child(self, path):
return posixpath.dirname(path.at.rstrip("/")) == self.at.rstrip("/")
示例14: _add_implied_dirs
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def _add_implied_dirs(names):
return names + [
name + "/"
for name in map(posixpath.dirname, names)
if name and name + "/" not in names
]
示例15: parent
# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import dirname [as 别名]
def parent(self):
parent_at = posixpath.dirname(self.at.rstrip('/'))
if parent_at:
parent_at += '/'
return self._next(parent_at)