本文整理汇总了Python中gio.File.resolve_relative_path方法的典型用法代码示例。如果您正苦于以下问题:Python File.resolve_relative_path方法的具体用法?Python File.resolve_relative_path怎么用?Python File.resolve_relative_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gio.File
的用法示例。
在下文中一共展示了File.resolve_relative_path方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Folder
# 需要导入模块: from gio import File [as 别名]
# 或者: from gio.File import resolve_relative_path [as 别名]
class Folder(object):
def __init__(self, obj=None):
if obj is None:
self._folder = None
elif type(obj) is str:
self._folder = File(obj)
elif isinstance(obj, File):
self._folder = obj
else:
raise ValueError, 'unexpected obj "%s"' % obj
############################
# Private API
############################
def _get_g_file(self, uri):
if type(uri) is not str:
raise TypeError, 'unexpected "%s"' % repr(uri)
# Resolve or not ?
# Your folder is None => new File
if self._folder is None:
g_file = File(uri)
else:
# Split the uri
scheme, authority, path, query, fragment = urlsplit(uri)
# A scheme or an authority => new File
# XXX This is not truly exact:
# we can have a scheme and a relative path.
if scheme or authority:
g_file = File(uri)
else:
# Else we resolve the path
g_file = self._folder.resolve_relative_path(uri)
# Automount a ftp server ?
if g_file.get_uri_scheme () == 'ftp':
# Mount the server
AnonymousConnection(g_file)
return g_file
def _get_xtime(self, uri, attribut):
g_file = self._get_g_file(uri)
info = g_file.query_info(attribut)
uint64 = info.get_attribute_uint64(attribut)
return datetime.fromtimestamp(uint64)
def _can_x(self, uri, attribut):
g_file = self._get_g_file(uri)
info = g_file.query_info(attribut)
return info.get_attribute_boolean(attribut)
############################
# Public API
############################
def exists(self, uri):
g_file = self._get_g_file(uri)
return g_file.query_exists()
def is_file(self, uri):
g_file = self._get_g_file(uri)
return _is_file(g_file)
def is_folder(self, uri):
g_file = self._get_g_file(uri)
return _is_folder(g_file)
def can_read(self, uri):
return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_READ)
def can_write(self, uri):
return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_WRITE)
def make_file(self, uri):
g_file = self._get_g_file(uri)
# Make the parent's directory
_make_directory_with_parents(g_file.get_parent())
return g_file.create()
def make_folder(self, uri):
g_file = self._get_g_file(uri)
# XXX g_file_make_directory_with_parents is not yet implemented!!
_make_directory_with_parents(g_file)
#.........这里部分代码省略.........
示例2: Folder
# 需要导入模块: from gio import File [as 别名]
# 或者: from gio.File import resolve_relative_path [as 别名]
class Folder(object):
def __init__(self, obj=None):
if obj is None:
self._folder = None
elif type(obj) is str:
self._folder = File(obj)
elif isinstance(obj, File):
self._folder = obj
else:
raise ValueError, 'unexpected obj "%s"' % obj
############################
# Private API
############################
def _get_g_file(self, uri):
if type(uri) is not str:
raise TypeError, 'unexpected "%s"' % repr(uri)
# Your folder is None => new File
if self._folder is None:
return File(uri)
# Your folder is not None, we must resolve the uri
scheme, authority, path, query, fragment = urlsplit(uri)
# A scheme or an authority => new File
# XXX This is not truly exact:
# we can have a scheme and a relative path.
if scheme or authority:
return File(uri)
# Else we resolve the path
return self._folder.resolve_relative_path(uri)
def _get_xtime(self, uri, attribut):
g_file = self._get_g_file(uri)
info = g_file.query_info(attribut)
uint64 = info.get_attribute_uint64(attribut)
return datetime.fromtimestamp(uint64)
def _can_x(self, uri, attribut):
g_file = self._get_g_file(uri)
info = g_file.query_info(attribut)
return info.get_attribute_boolean(attribut)
#######################################################################
# Public API
#######################################################################
def exists(self, uri):
g_file = self._get_g_file(uri)
return g_file.query_exists()
def is_file(self, uri):
g_file = self._get_g_file(uri)
return _is_file(g_file)
def is_folder(self, uri):
g_file = self._get_g_file(uri)
return _is_folder(g_file)
def can_read(self, uri):
return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_READ)
def can_write(self, uri):
return self._can_x(uri, FILE_ATTRIBUTE_ACCESS_CAN_WRITE)
def make_file(self, uri):
g_file = self._get_g_file(uri)
# Make the parent's directory
_make_directory_with_parents(g_file.get_parent())
return g_file.create()
def make_folder(self, uri):
g_file = self._get_g_file(uri)
_make_directory_with_parents(g_file)
def get_ctime(self, uri):
return self._get_xtime(uri, FILE_ATTRIBUTE_TIME_CHANGED)
def get_mtime(self, uri):
return self._get_xtime(uri, FILE_ATTRIBUTE_TIME_MODIFIED)
def get_atime(self, uri):
return self._get_xtime(uri, FILE_ATTRIBUTE_TIME_ACCESS)
#.........这里部分代码省略.........