本文整理汇总了Python中errno.ENODATA属性的典型用法代码示例。如果您正苦于以下问题:Python errno.ENODATA属性的具体用法?Python errno.ENODATA怎么用?Python errno.ENODATA使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类errno
的用法示例。
在下文中一共展示了errno.ENODATA属性的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _copyxattr
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def _copyxattr(src, dst, *, follow_symlinks=True):
"""Copy extended filesystem attributes from `src` to `dst`.
Overwrite existing attributes.
If `follow_symlinks` is false, symlinks won't be followed.
"""
try:
names = os.listxattr(src, follow_symlinks=follow_symlinks)
except OSError as e:
if e.errno not in (errno.ENOTSUP, errno.ENODATA):
raise
return
for name in names:
try:
value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
except OSError as e:
if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA):
raise
示例2: _copyxattr
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def _copyxattr(src, dst, *, follow_symlinks=True):
"""Copy extended filesystem attributes from `src` to `dst`.
Overwrite existing attributes.
If `follow_symlinks` is false, symlinks won't be followed.
"""
try:
names = os.listxattr(src, follow_symlinks=follow_symlinks)
except OSError as e:
if e.errno not in (errno.ENOTSUP, errno.ENODATA, errno.EINVAL):
raise
return
for name in names:
try:
value = os.getxattr(src, name, follow_symlinks=follow_symlinks)
os.setxattr(dst, name, value, follow_symlinks=follow_symlinks)
except OSError as e:
if e.errno not in (errno.EPERM, errno.ENOTSUP, errno.ENODATA,
errno.EINVAL):
raise
示例3: save
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def save(self, presenter, path=None, fileptr=None):
self.presenter = presenter
self.config = self.presenter.config
self.model = presenter.model
if path:
self.fileptr = get_fileptr(path, True)
elif fileptr:
self.fileptr = fileptr
else:
msg = _('There is no file for writting')
raise IOError(errno.ENODATA, msg, '')
self.presenter.update()
self.saving_msg(.01)
try:
self.do_save()
except Exception as e:
LOG.error('Error saving file content %s', e)
raise
self.saving_msg(.99)
self.fileptr.close()
self.fileptr = None
示例4: get_fileptr
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def get_fileptr(path, writable=False):
if not path:
msg = _('There is no file path')
raise IOError(errno.ENODATA, msg, '')
path = get_sys_path(path)
if writable:
try:
fileptr = open(path, 'wb')
except Exception:
msg = _('Cannot open %s file for writing') % path
events.emit(events.MESSAGES, msgconst.ERROR, msg)
LOG.exception(msg)
raise
else:
try:
fileptr = open(path, 'rb')
except Exception:
msg = _('Cannot open %s file for reading') % path
events.emit(events.MESSAGES, msgconst.ERROR, msg)
LOG.exception(msg)
raise
return fileptr
示例5: _check_xattrs_str
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def _check_xattrs_str(self, s, getxattr, setxattr, removexattr, listxattr, **kwargs):
fn = support.TESTFN
open(fn, "wb").close()
with self.assertRaises(OSError) as cm:
getxattr(fn, s("user.test"), **kwargs)
self.assertEqual(cm.exception.errno, errno.ENODATA)
init_xattr = listxattr(fn)
self.assertIsInstance(init_xattr, list)
setxattr(fn, s("user.test"), b"", **kwargs)
xattr = set(init_xattr)
xattr.add("user.test")
self.assertEqual(set(listxattr(fn)), xattr)
self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"")
setxattr(fn, s("user.test"), b"hello", os.XATTR_REPLACE, **kwargs)
self.assertEqual(getxattr(fn, b"user.test", **kwargs), b"hello")
with self.assertRaises(OSError) as cm:
setxattr(fn, s("user.test"), b"bye", os.XATTR_CREATE, **kwargs)
self.assertEqual(cm.exception.errno, errno.EEXIST)
with self.assertRaises(OSError) as cm:
setxattr(fn, s("user.test2"), b"bye", os.XATTR_REPLACE, **kwargs)
self.assertEqual(cm.exception.errno, errno.ENODATA)
setxattr(fn, s("user.test2"), b"foo", os.XATTR_CREATE, **kwargs)
xattr.add("user.test2")
self.assertEqual(set(listxattr(fn)), xattr)
removexattr(fn, s("user.test"), **kwargs)
with self.assertRaises(OSError) as cm:
getxattr(fn, s("user.test"), **kwargs)
self.assertEqual(cm.exception.errno, errno.ENODATA)
xattr.remove("user.test")
self.assertEqual(set(listxattr(fn)), xattr)
self.assertEqual(getxattr(fn, s("user.test2"), **kwargs), b"foo")
setxattr(fn, s("user.test"), b"a"*1024, **kwargs)
self.assertEqual(getxattr(fn, s("user.test"), **kwargs), b"a"*1024)
removexattr(fn, s("user.test"), **kwargs)
many = sorted("user.test{}".format(i) for i in range(100))
for thing in many:
setxattr(fn, thing, b"x", **kwargs)
self.assertEqual(set(listxattr(fn)), set(init_xattr) | set(many))
示例6: load
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def load(self, presenter, path=None, fileptr=None):
self.presenter = presenter
self.model = presenter.model
self.config = self.presenter.config
if path:
self.filepath = path
self.file_size = os.path.getsize(get_sys_path(path))
self.fileptr = get_fileptr(path)
elif fileptr:
self.fileptr = fileptr
self.fileptr.seek(-1, 1)
self.file_size = self.fileptr.tell()
self.fileptr.seek(0)
else:
msg = _('There is no file for reading')
raise IOError(errno.ENODATA, msg, '')
try:
self.init_load()
except Exception:
LOG.error('Error loading file content')
raise
self.fileptr.close()
self.position = 0
return self.model
示例7: fileStoreFromPath
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def fileStoreFromPath(cls, path):
"""
@param path: a path pointing at the document root, where the file-based
data-store is located.
@type path: L{CachingFilePath}
"""
# Legacy: old file store only ever used these two top-level paths
for homeType in ("calendars", "addressbooks"):
if path.child(homeType).exists():
if platform.isMacOSX():
appropriateStoreClass = XattrPropertyStore
else:
attrs = xattr.xattr(path.path)
try:
attrs.get('user.should-not-be-set')
except IOError, ioe:
if ioe.errno == errno.ENODATA:
# xattrs are supported and enabled on the filesystem
# where the calendar data lives. this takes some
# doing (you have to edit fstab), so this means
# we're trying to migrate some 2.x data from a
# previous linux installation.
appropriateStoreClass = XattrPropertyStore
elif ioe.errno == errno.EOPNOTSUPP:
# The operation wasn't supported. This is what will
# usually happen on a naively configured filesystem,
# so this means we're most likely trying to migrate
# some data from an untarred archive created on an
# OS X installation using xattrs.
appropriateStoreClass = AppleDoubleStore
else:
# No need to check for ENOENT and the like; we just
# checked above to make sure the parent exists.
# Other errors are not anticipated here, so fail
# fast.
raise
appropriateStoreClass = AppleDoubleStore
from txdav.common.datastore.file import CommonDataStore as FileStore
return FileStore(
path, None, None, True, True,
propertyStoreClass=appropriateStoreClass)
示例8: treesum
# 需要导入模块: import errno [as 别名]
# 或者: from errno import ENODATA [as 别名]
def treesum(m, dir_fd):
"""Compute a content hash of a filesystem tree
Parameters
----------
m : hash object
the hash object to append the treesum to
dir_fd : int
directory file descriptor number to operate on
The hash is stable between runs, and guarantees that two filesystem
trees with the same hash, are functionally equivalent from the OS
point of view.
The file, symlink and directory names and contents are recursively
hashed, together with security-relevant metadata."""
with os.scandir(f"/proc/self/fd/{dir_fd}") as it:
for dirent in sorted(it, key=(lambda d: d.name)):
stat_result = dirent.stat(follow_symlinks=False)
metadata = {}
metadata["name"] = os.fsdecode(dirent.name)
metadata["mode"] = stat_result.st_mode
metadata["uid"] = stat_result.st_uid
metadata["gid"] = stat_result.st_gid
# include the size of symlink target/file-contents so we don't have to delimit it
metadata["size"] = stat_result.st_size
# getxattr cannot operate on a dir_fd, so do a trick and rely on the entries in /proc
stable_file_path = os.path.join(f"/proc/self/fd/{dir_fd}", dirent.name)
try:
selinux_label = os.getxattr(stable_file_path, b"security.selinux", follow_symlinks=False)
except OSError as e:
# SELinux support is optional
if e.errno != errno.ENODATA:
raise
else:
metadata["selinux"] = os.fsdecode(selinux_label)
# hash the JSON representation of the metadata to stay unique/stable/well-defined
m.update(json.dumps(metadata, sort_keys=True).encode())
if dirent.is_symlink():
m.update(os.fsdecode(os.readlink(dirent.name, dir_fd=dir_fd)).encode())
else:
fd = os.open(dirent.name, flags=os.O_RDONLY, dir_fd=dir_fd)
try:
if dirent.is_dir(follow_symlinks=False):
treesum(m, fd)
elif dirent.is_file(follow_symlinks=False):
# hash a page at a time (using f with fd as default is a hack to please pylint)
for byte_block in iter(lambda f=fd: os.read(f, 4096), b""):
m.update(byte_block)
else:
raise ValueError("Found unexpected filetype on OS image")
finally:
os.close(fd)