本文整理汇总了Python中twisted.python.compat.intToBytes函数的典型用法代码示例。如果您正苦于以下问题:Python intToBytes函数的具体用法?Python intToBytes怎么用?Python intToBytes使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了intToBytes函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: n
def n(self, proto, handler, buf):
if buf == b'6':
x, y = handler.reportCursorPosition()
proto.transport.write(b'\x1b['
+ intToBytes(x+1)
+ b';'
+ intToBytes(y+1)
+ b'R')
else:
handler.unhandledControlSequence(b'\x1b[' + buf + b'n')
示例2: setScrollRegion
def setScrollRegion(self, first=None, last=None):
if first is not None:
first = intToBytes(first)
else:
first = b''
if last is not None:
last = intToBytes(last)
else:
last = b''
self.write(b'\x1b[' + first + b';' + last + b'r')
示例3: test_selectGraphicRendition
def test_selectGraphicRendition(self):
"""
L{ServerProtocol.selectGraphicRendition} writes a control
sequence containing the requested attributes and ending with
L{CSFinalByte.SGR}
"""
self.protocol.selectGraphicRendition(str(BLINK), str(UNDERLINE))
self.assertEqual(self.transport.value(),
self.CSI +
intToBytes(BLINK) + b';' + intToBytes(UNDERLINE) +
CSFinalByte.SGR.value)
示例4: cbStarted
def cbStarted(ignored):
connectionRefused = client.startedDeferred = defer.Deferred()
client.transport.connect("127.0.0.1", 80)
for i in range(10):
client.transport.write(intToBytes(i))
server.transport.write(intToBytes(i), ("127.0.0.1", 80))
return self.assertFailure(
connectionRefused,
error.ConnectionRefusedError)
示例5: __bytes__
def __bytes__(self):
"""
Return a byte string representation of the channel
"""
name = self.name
if not name:
name = b'None'
return (b'<SSHChannel ' + name +
b' (lw ' + intToBytes(self.localWindowLeft) +
b' rw ' + intToBytes(self.remoteWindowLeft) +
b')>')
示例6: testSimpleCardinals
def testSimpleCardinals(self):
self.parser.dataReceived(
b''.join(
[b''.join([b'\x1b[' + n + ch
for n in (b'', intToBytes(2), intToBytes(20), intToBytes(200))]
) for ch in iterbytes(b'BACD')
]))
occs = occurrences(self.proto)
for meth in ("Down", "Up", "Forward", "Backward"):
for count in (1, 2, 20, 200):
result = self.assertCall(occs.pop(0), "cursor" + meth, (count,))
self.assertFalse(occurrences(result))
self.assertFalse(occs)
示例7: __init__
def __init__(self, code, message=None, response=None):
"""
Initializes a basic exception.
@type code: L{bytes} or L{int}
@param code: Refers to an HTTP status code (for example, 200) either as
an integer or a bytestring representing such. If no C{message} is
given, C{code} is mapped to a descriptive bytestring that is used
instead.
@type message: L{bytes}
@param message: A short error message, for example "NOT FOUND".
@type response: L{bytes}
@param response: A complete HTML document for an error page.
"""
message = message or _codeToMessage(code)
Exception.__init__(self, code, message, response)
if isinstance(code, int):
# If we're given an int, convert it to a bytestring
# downloadPage gives a bytes, Agent gives an int, and it worked by
# accident previously, so just make it keep working.
code = intToBytes(code)
self.status = code
self.message = message
self.response = response
示例8: test_blksize
def test_blksize(self):
self.s = MockSession()
opts = self.proto.processOptions(OrderedDict({b'blksize':b'8'}))
self.proto.applyOptions(self.s, opts)
self.assertEqual(self.s.block_size, 8)
self.assertEqual(opts, OrderedDict({b'blksize':b'8'}))
self.s = MockSession()
opts = self.proto.processOptions(OrderedDict({b'blksize':b'foo'}))
self.proto.applyOptions(self.s, opts)
self.assertEqual(self.s.block_size, 512)
self.assertEqual(opts, OrderedDict())
self.s = MockSession()
opts = self.proto.processOptions(OrderedDict({b'blksize':b'65464'}))
self.proto.applyOptions(self.s, opts)
self.assertEqual(self.s.block_size, MAX_BLOCK_SIZE)
self.assertEqual(opts, OrderedDict({b'blksize':intToBytes(MAX_BLOCK_SIZE)}))
self.s = MockSession()
opts = self.proto.processOptions(OrderedDict({b'blksize':b'65465'}))
self.proto.applyOptions(self.s, opts)
self.assertEqual(self.s.block_size, 512)
self.assertEqual(opts, OrderedDict())
self.s = MockSession()
opts = self.proto.processOptions(OrderedDict({b'blksize':b'7'}))
self.proto.applyOptions(self.s, opts)
self.assertEqual(self.s.block_size, 512)
self.assertEqual(opts, OrderedDict())
示例9: render_GET
def render_GET(self, request):
data = json.dumps(request.args)
request.setHeader(b"content-type", networkString("application/json"))
request.setHeader(b"content-length", intToBytes(len(data)))
if request.method == b"HEAD":
return b""
return data
示例10: _spawn
def _spawn(script, outputFD):
"""
Start a script that is a peer of this test as a subprocess.
@param script: the module name of the script in this directory (no
package prefix, no '.py')
@type script: C{str}
@rtype: L{StartStopProcessProtocol}
"""
pyExe = FilePath(sys.executable).asBytesMode().path
env = bytesEnviron()
env[b"PYTHONPATH"] = FilePath(
pathsep.join(sys.path)).asBytesMode().path
sspp = StartStopProcessProtocol()
reactor.spawnProcess(
sspp, pyExe, [
pyExe,
FilePath(__file__).sibling(script + ".py").asBytesMode().path,
intToBytes(outputFD),
],
env=env,
childFDs={0: "w", 1: "r", 2: "r", outputFD: outputFD}
)
return sspp
示例11: render_GET
def render_GET(self, request):
data = json.dumps(request.args)
request.setHeader(b'content-type', networkString('application/json'))
request.setHeader(b'content-length', intToBytes(len(data)))
if request.method == b'HEAD':
return b''
return data
示例12: render_GET
def render_GET(self, request):
def decode(x):
if isinstance(x, bytes):
return bytes2unicode(x)
elif isinstance(x, (list, tuple)):
return [bytes2unicode(y) for y in x]
elif isinstance(x, dict):
newArgs = {}
for a, b in x.items():
newArgs[decode(a)] = decode(b)
return newArgs
return x
args = decode(request.args)
content_type = request.getHeader(b'content-type')
if content_type == b"application/json":
jsonBytes = request.content.read()
jsonStr = bytes2unicode(jsonBytes)
args['json_received'] = json.loads(jsonStr)
data = json.dumps(args)
data = unicode2bytes(data)
request.setHeader(b'content-type', b'application/json')
request.setHeader(b'content-length', intToBytes(len(data)))
if request.method == b'HEAD':
return b''
return data
示例13: _cbRender
def _cbRender(self, result, request, responseFailed=None):
if responseFailed:
return
if isinstance(result, Handler):
result = result.result
if not isinstance(result, Fault):
result = (result,)
try:
try:
content = xmlrpclib.dumps(
result, methodresponse=True,
allow_none=self.allowNone)
except Exception as e:
f = Fault(self.FAILURE, "Can't serialize output: %s" % (e,))
content = xmlrpclib.dumps(f, methodresponse=True,
allow_none=self.allowNone)
if isinstance(content, unicode):
content = content.encode('utf8')
request.setHeader(
b"content-length", intToBytes(len(content)))
request.write(content)
except:
log.err()
request.finish()
示例14: spin
def spin():
for value in count:
if value == howMany:
connection.loseConnection()
return
connection.write(intToBytes(value))
break
reactor.callLater(0, spin)
示例15: contentFinish
def contentFinish(self, content):
if self.obj.client_supports_gzip:
self.setHeader(b'content-encoding', b'gzip')
content = self.zip(content, True)
self.setHeader(b'content-length', intToBytes(len(content)))
self.write(content)
self.finish()