本文整理汇总了Python中webdav.urn.Urn.is_dir方法的典型用法代码示例。如果您正苦于以下问题:Python Urn.is_dir方法的具体用法?Python Urn.is_dir怎么用?Python Urn.is_dir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类webdav.urn.Urn
的用法示例。
在下文中一共展示了Urn.is_dir方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_from
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import is_dir [as 别名]
def upload_from(self, buff, remote_path):
try:
urn = Urn(remote_path)
if urn.is_dir():
raise OptionNotValid(name="remote_path", value=remote_path)
if not self.check(urn.parent()):
raise RemoteParentNotFound(urn.path())
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'HTTPHEADER': self.get_header('upload_from'),
'UPLOAD': 1,
'READFUNCTION': buff.read,
}
request = self.Request(options=options)
request.perform()
code = request.getinfo(pycurl.HTTP_CODE)
if code == "507":
raise NotEnoughSpace()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例2: upload_file
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import is_dir [as 别名]
def upload_file(self, remote_path, local_path, progress=None):
try:
if not os.path.exists(local_path):
raise LocalResourceNotFound(local_path)
urn = Urn(remote_path)
if urn.is_dir():
raise OptionNotValid(name="remote_path", value=remote_path)
if os.path.isdir(local_path):
raise OptionNotValid(name="local_path", value=local_path)
if not os.path.exists(local_path):
raise LocalResourceNotFound(local_path)
if not self.check(urn.parent()):
raise RemoteParentNotFound(urn.path())
with open(local_path, "rb") as local_file:
url = {'hostname': self.webdav.hostname, 'root': self.webdav.root, 'path': urn.quote()}
options = {
'URL': "{hostname}{root}{path}".format(**url),
'HTTPHEADER': self.get_header('upload_file'),
'UPLOAD': 1,
'READFUNCTION': local_file.read,
'NOPROGRESS': 0 if progress else 1
}
if progress:
options["PROGRESSFUNCTION"] = progress
file_size = os.path.getsize(local_path)
if file_size > self.large_size:
options['INFILESIZE_LARGE'] = file_size
else:
options['INFILESIZE'] = file_size
request = self.Request(options=options)
request.perform()
code = request.getinfo(pycurl.HTTP_CODE)
if code == "507":
raise NotEnoughSpace()
request.close()
except pycurl.error:
raise NotConnection(self.webdav.hostname)
示例3: upload_directory
# 需要导入模块: from webdav.urn import Urn [as 别名]
# 或者: from webdav.urn.Urn import is_dir [as 别名]
def upload_directory(self, remote_path, local_path, progress=None):
urn = Urn(remote_path, directory=True)
if not urn.is_dir():
raise OptionNotValid(name="remote_path", value=remote_path)
if not os.path.isdir(local_path):
raise OptionNotValid(name="local_path", value=local_path)
if not os.path.exists(local_path):
raise LocalResourceNotFound(local_path)
if self.check(urn.path()):
self.clean(urn.path())
self.mkdir(remote_path)
for resource_name in listdir(local_path):
_remote_path = "{parent}{name}".format(parent=urn.path(), name=resource_name)
_local_path = os.path.join(local_path, resource_name)
self.upload(local_path=_local_path, remote_path=_remote_path, progress=progress)