devshell.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:xxNet 作者: drzorm 项目源码 文件源码
def _SendRecv():
  """Communicate with the Developer Shell server socket."""

  port = int(os.getenv(DEVSHELL_ENV, 0))
  if port == 0:
    raise NoDevshellServer()

  import socket

  sock = socket.socket()
  sock.connect(('localhost', port))

  data = CREDENTIAL_INFO_REQUEST_JSON
  msg = '%s\n%s' % (len(data), data)
  sock.sendall(msg.encode())

  header = sock.recv(6).decode()
  if '\n' not in header:
    raise CommunicationError('saw no newline in the first 6 bytes')
  len_str, json_str = header.split('\n', 1)
  to_read = int(len_str) - len(json_str)
  if to_read > 0:
    json_str += sock.recv(to_read, socket.MSG_WAITALL).decode()

  return CredentialInfoResponse(json_str)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号