本文整理汇总了Python中os.read方法的典型用法代码示例。如果您正苦于以下问题:Python os.read方法的具体用法?Python os.read怎么用?Python os.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os
的用法示例。
在下文中一共展示了os.read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _get
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def _get(self):
if not self._getMode:
return
buf = os.read(self._rt, _MAXLINE).decode()
if not buf:
raise CosimulationError(_error.SimulationEnd)
e = buf.split()
for i in range(1, len(e), 2):
s, v = self._toSigDict[e[i]], e[i + 1]
if v in 'zZ':
next = None
elif v in 'xX':
next = s._init
else:
try:
next = int(v, 16)
if s._nrbits and s._min is not None and s._min < 0:
if next >= (1 << (s._nrbits - 1)):
next |= (-1 << s._nrbits)
except ValueError:
next = intbv(0)
s.next = next
self._getMode = 0
示例2: copyfileobj
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def copyfileobj(src, dst, length=None):
"""Copy length bytes from fileobj src to fileobj dst.
If length is None, copy the entire content.
"""
if length == 0:
return
if length is None:
shutil.copyfileobj(src, dst)
return
BUFSIZE = 16 * 1024
blocks, remainder = divmod(length, BUFSIZE)
for b in range(blocks):
buf = src.read(BUFSIZE)
if len(buf) < BUFSIZE:
raise IOError("end of file reached")
dst.write(buf)
if remainder != 0:
buf = src.read(remainder)
if len(buf) < remainder:
raise IOError("end of file reached")
dst.write(buf)
return
示例3: read
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def read(self, size=None):
"""Return the next size number of bytes from the stream.
If size is not defined, return all bytes of the stream
up to EOF.
"""
if size is None:
t = []
while True:
buf = self._read(self.bufsize)
if not buf:
break
t.append(buf)
buf = "".join(t)
else:
buf = self._read(size)
self.pos += len(buf)
return buf
示例4: fromtarfile
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def fromtarfile(cls, tarfile):
"""Return the next TarInfo object from TarFile object
tarfile.
"""
buf = tarfile.fileobj.read(BLOCKSIZE)
obj = cls.frombuf(buf, tarfile.encoding, tarfile.errors)
obj.offset = tarfile.fileobj.tell() - BLOCKSIZE
return obj._proc_member(tarfile)
#--------------------------------------------------------------------------
# The following are methods that are called depending on the type of a
# member. The entry point is _proc_member() which can be overridden in a
# subclass to add custom _proc_*() methods. A _proc_*() method MUST
# implement the following
# operations:
# 1. Set self.offset_data to the position where the data blocks begin,
# if there is data that follows.
# 2. Set tarfile.offset to the position where the next member's header will
# begin.
# 3. Return self or another valid TarInfo object.
示例5: addfile
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def addfile(self, tarinfo, fileobj=None):
"""Add the TarInfo object `tarinfo' to the archive. If `fileobj' is
given, tarinfo.size bytes are read from it and added to the archive.
You can create TarInfo objects using gettarinfo().
On Windows platforms, `fileobj' should always be opened with mode
'rb' to avoid irritation about the file size.
"""
self._check("aw")
tarinfo = copy.copy(tarinfo)
buf = tarinfo.tobuf(self.format, self.encoding, self.errors)
self.fileobj.write(buf)
self.offset += len(buf)
# If there's data to follow, append it.
if fileobj is not None:
copyfileobj(fileobj, self.fileobj, tarinfo.size)
blocks, remainder = divmod(tarinfo.size, BLOCKSIZE)
if remainder > 0:
self.fileobj.write(NUL * (BLOCKSIZE - remainder))
blocks += 1
self.offset += blocks * BLOCKSIZE
self.members.append(tarinfo)
示例6: __next__
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def __next__(self):
"""Return the next item using TarFile's next() method.
When all members have been read, set TarFile as _loaded.
"""
# Fix for SF #1100429: Under rare circumstances it can
# happen that getmembers() is called during iteration,
# which will cause TarIter to stop prematurely.
if self.index == 0 and self.tarfile.firstmember is not None:
tarinfo = self.tarfile.next()
elif self.index < len(self.tarfile.members):
tarinfo = self.tarfile.members[self.index]
elif not self.tarfile._loaded:
tarinfo = self.tarfile.next()
if not tarinfo:
self.tarfile._loaded = True
raise StopIteration
else:
raise StopIteration
self.index += 1
return tarinfo
#--------------------
# exported functions
#--------------------
示例7: read_from_fd
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def read_from_fd(self):
try:
chunk = os.read(self.fd, self.read_chunk_size)
except (IOError, OSError) as e:
if errno_from_exception(e) in _ERRNO_WOULDBLOCK:
return None
elif errno_from_exception(e) == errno.EBADF:
# If the writing half of a pipe is closed, select will
# report it as readable but reads will fail with EBADF.
self.close(exc_info=True)
return None
else:
raise
if not chunk:
self.close()
return None
return chunk
示例8: test_dupfile
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def test_dupfile(tmpfile):
flist = []
for i in range(5):
nf = py.io.dupfile(tmpfile, encoding="utf-8")
assert nf != tmpfile
assert nf.fileno() != tmpfile.fileno()
assert nf not in flist
print_(i, end="", file=nf)
flist.append(nf)
for i in range(5):
f = flist[i]
f.close()
tmpfile.seek(0)
s = tmpfile.read()
assert "01234" in repr(s)
tmpfile.close()
示例9: init_faulthandler
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def init_faulthandler(self):
"""Handle a segfault from a previous run and set up faulthandler."""
logname = os.path.join(standarddir.data(), 'crash.log')
try:
# First check if an old logfile exists.
if os.path.exists(logname):
with open(logname, 'r', encoding='ascii') as f:
self._crash_log_data = f.read()
os.remove(logname)
self._init_crashlogfile()
else:
# There's no log file, so we can use this to display crashes to
# the user on the next start.
self._init_crashlogfile()
except OSError:
log.init.exception("Error while handling crash log file!")
self._init_crashlogfile()
示例10: handle_signal_wakeup
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def handle_signal_wakeup(self):
"""Handle a newly arrived signal.
This gets called via self._notifier when there's a signal.
Python will get control here, so the signal will get handled.
"""
assert self._notifier is not None
log.destroy.debug("Handling signal wakeup!")
self._notifier.setEnabled(False)
read_fd = self._notifier.socket()
try:
os.read(int(read_fd), 1)
except OSError:
log.destroy.exception("Failed to read wakeup fd.")
self._notifier.setEnabled(True)
示例11: packet_reader_mac
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def packet_reader_mac(self, tunnel, first_read, serverorclient):
packet = os.read(tunnel, 4096)
if first_read and not serverorclient:
packet = packet[4:]
return packet
# for Linux and other unices
# Windows is handled from the communication() unfortunately
示例12: packet_reader_default
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def packet_reader_default(self, tunnel, first_read, serverorclient):
packet = os.read(tunnel, 4096)
return packet
# function to transform packets back and forth.
# encryption, encodings anything that should be done on the packet and
# should be easily variable based on the config
示例13: post_authentication_client
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def post_authentication_client(self, control_message, additional_data):
self.authenticated = True
return
# server side
# if the client was initiated (first step was not skipped), then set
# the authenticated flag to True, add to packetselector and allow access
# the read only pipe (packets selected for the client)
示例14: packet_reader_default
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def packet_reader_default(self, tunnel, first_read, serverorclient):
packet = os.read(tunnel, 4096)
return packet
# encryption, encodings anything that should be done on the packet and
# should be easily variable based on the config
示例15: delete_client
# 需要导入模块: import os [as 别名]
# 或者: from os import read [as 别名]
def delete_client(self, client):
if client in self.clients:
if self.os_type == common.OS_WINDOWS:
import win32file
try:
win32file.CloseHandle(client.get_pipe_r())
win32file.CloseHandle(client.get_pipe_w())
except Exception as e:
common.internal_print("Remove authenticated client: CloseHandle exception: {0}".format(e), -1)
else:
try:
client.get_pipe_r_fd().close()
client.get_pipe_w_fd().close()
except Exception as e:
common.internal_print("Remove authenticated client: os.close exception: {0}".format(e), -1)
client.call_stopfp()
self.clients.remove(client)
return
# This function should run from the point when the framework was started.
# It runs as an infinite loop to read the packets off the tunnel.
# When an IPv4 packet was found that will be selected and checked whether
# it addresses a client in the client list. If a client was found, then the
# packet will be written on that pipe.