本文整理汇总了Python中PyQt5.QtCore.QBuffer.seek方法的典型用法代码示例。如果您正苦于以下问题:Python QBuffer.seek方法的具体用法?Python QBuffer.seek怎么用?Python QBuffer.seek使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtCore.QBuffer
的用法示例。
在下文中一共展示了QBuffer.seek方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestStarted
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import seek [as 别名]
def requestStarted(self, job):
"""Handle a request for a qute: scheme.
This method must be reimplemented by all custom URL scheme handlers.
The request is asynchronous and does not need to be handled right away.
Args:
job: QWebEngineUrlRequestJob
"""
url = job.requestUrl()
if url.scheme() in ['chrome-error', 'chrome-extension']:
# WORKAROUND for https://bugreports.qt.io/browse/QTBUG-63378
job.fail(QWebEngineUrlRequestJob.UrlInvalid)
return
if not self._check_initiator(job):
return
if job.requestMethod() != b'GET':
job.fail(QWebEngineUrlRequestJob.RequestDenied)
return
assert url.scheme() == 'qute'
log.misc.debug("Got request for {}".format(url.toDisplayString()))
try:
mimetype, data = qutescheme.data_for_url(url)
except qutescheme.Error as e:
errors = {
qutescheme.NotFoundError:
QWebEngineUrlRequestJob.UrlNotFound,
qutescheme.UrlInvalidError:
QWebEngineUrlRequestJob.UrlInvalid,
qutescheme.RequestDeniedError:
QWebEngineUrlRequestJob.RequestDenied,
qutescheme.SchemeOSError:
QWebEngineUrlRequestJob.UrlNotFound,
qutescheme.Error:
QWebEngineUrlRequestJob.RequestFailed,
}
exctype = type(e)
log.misc.error("{} while handling qute://* URL".format(
exctype.__name__))
job.fail(errors[exctype])
except qutescheme.Redirect as e:
qtutils.ensure_valid(e.url)
job.redirect(e.url)
else:
log.misc.debug("Returning {} data".format(mimetype))
# We can't just use the QBuffer constructor taking a QByteArray,
# because that somehow segfaults...
# https://www.riverbankcomputing.com/pipermail/pyqt/2016-September/038075.html
buf = QBuffer(parent=self)
buf.open(QIODevice.WriteOnly)
buf.write(data)
buf.seek(0)
buf.close()
job.reply(mimetype.encode('ascii'), buf)
示例2: sendDeleteRequest
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import seek [as 别名]
def sendDeleteRequest(self, endpoint, data={}, params={}, headers={}):
buff = QBuffer()
buff.open(QBuffer.ReadWrite)
d = json.dumps(data).encode('utf-8')
buff.write(d)
buff.seek(0)
headers.update({"Content-Type":"application/json"})
content = self.sendRequest( endpoint, params,
'delete',
buff,
headers=headers
)
buff.close()
return content
示例3: requestStarted
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import seek [as 别名]
def requestStarted(self, job):
"""Handle a request for a qute: scheme.
This method must be reimplemented by all custom URL scheme handlers.
The request is asynchronous and does not need to be handled right away.
Args:
job: QWebEngineUrlRequestJob
"""
url = job.requestUrl()
assert job.requestMethod() == b'GET'
assert url.scheme() == 'qute'
log.misc.debug("Got request for {}".format(url.toDisplayString()))
try:
mimetype, data = qutescheme.data_for_url(url)
except qutescheme.NoHandlerFound:
log.misc.debug("No handler found for {}".format(
url.toDisplayString()))
job.fail(QWebEngineUrlRequestJob.UrlNotFound)
except qutescheme.QuteSchemeOSError:
# FIXME:qtwebengine how do we show a better error here?
log.misc.exception("OSError while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.UrlNotFound)
except qutescheme.QuteSchemeError:
# FIXME:qtwebengine how do we show a better error here?
log.misc.exception("Error while handling qute://* URL")
job.fail(QWebEngineUrlRequestJob.RequestFailed)
except qutescheme.Redirect as e:
qtutils.ensure_valid(e.url)
job.redirect(e.url)
else:
log.misc.debug("Returning {} data".format(mimetype))
# We can't just use the QBuffer constructor taking a QByteArray,
# because that somehow segfaults...
# https://www.riverbankcomputing.com/pipermail/pyqt/2016-September/038075.html
buf = QBuffer(parent=self)
buf.open(QIODevice.WriteOnly)
buf.write(data)
buf.seek(0)
buf.close()
job.reply(mimetype.encode('ascii'), buf)
示例4: HexEditChunks
# 需要导入模块: from PyQt5.QtCore import QBuffer [as 别名]
# 或者: from PyQt5.QtCore.QBuffer import seek [as 别名]
#.........这里部分代码省略.........
# In this section, we track changes before our required data
# and we take the edited data, if availible. ioDelta is a
# difference counter to justify the read pointer to the
# original data, if data in between was deleted or inserted.
chunk = self.__chunks[chunkIdx]
if chunk.absPos > pos:
chunksLoopOngoing = False
else:
chunkIdx += 1
chunkOfs = pos - chunk.absPos
if maxSize > (len(chunk.data) - chunkOfs):
count = len(chunk.data) - chunkOfs
ioDelta += self.CHUNK_SIZE - len(chunk.data)
else:
count = maxSize
if count > 0:
buffer += chunk.data[chunkOfs:chunkOfs + count]
maxSize -= count
pos += count
if highlighted is not None:
highlighted += \
chunk.dataChanged[chunkOfs:chunkOfs + count]
if maxSize > 0 and pos < chunk.absPos:
# In this section, we read data from the original source. This
# will only happen, when no copied data is available.
if chunk.absPos - pos > maxSize:
byteCount = maxSize
else:
byteCount = chunk.absPos - pos
maxSize -= byteCount
self.__ioDevice.seek(pos + ioDelta)
readBuffer = bytearray(self.__ioDevice.read(byteCount))
buffer += readBuffer
if highlighted is not None:
highlighted += bytearray(len(readBuffer))
pos += len(readBuffer)
self.__ioDevice.close()
return buffer
def write(self, ioDevice, pos=0, count=-1):
"""
Public method to write data to an io device.
@param ioDevice io device to write the data to
@type QIODevice
@param pos position to write bytes from
@type int
@param count amount of bytes to write
@type int
@return flag indicating success
@rtype bool
"""
if count == -1:
# write all data
count = self.__size
ok = ioDevice.open(QIODevice.WriteOnly)
if ok:
idx = pos
while idx < count:
data = self.data(idx, self.BUFFER_SIZE)
ioDevice.write(QByteArray(data))