예제 #1
0
 def test_term_to_binary_atom(self):
     self.assertEqual(b'\x83s\0',
                      erlang.term_to_binary(erlang.OtpErlangAtom(b'')))
     self.assertEqual(
         b'\x83s\4test',
         erlang.term_to_binary(erlang.OtpErlangAtom(b'test'))
     )
예제 #2
0
 def test_term_to_binary_integer(self):
     self.assertEqual(b'\x83b\xff\xff\xff\xff', erlang.term_to_binary(-1))
     self.assertEqual(b'\x83b\x80\0\0\0',
                      erlang.term_to_binary(-2147483648))
     self.assertEqual(b'\x83b\0\0\1\0', erlang.term_to_binary(256))
     self.assertEqual(b'\x83b\x7f\xff\xff\xff',
                      erlang.term_to_binary(2147483647))
예제 #3
0
 def test_term_to_binary_integer(self):
     self.assertEqual(b'\x83b\xff\xff\xff\xff', erlang.term_to_binary(-1))
     self.assertEqual(b'\x83b\x80\0\0\0',
                      erlang.term_to_binary(-2147483648))
     self.assertEqual(b'\x83b\0\0\1\0', erlang.term_to_binary(256))
     self.assertEqual(b'\x83b\x7f\xff\xff\xff',
                      erlang.term_to_binary(2147483647))
예제 #4
0
 def test_term_to_binary_tuple(self):
     self.assertEqual(b'\x83h\0', erlang.term_to_binary(()))
     self.assertEqual(b'\x83h\2h\0h\0', erlang.term_to_binary(((), ())))
     self.assertEqual(b'\x83h\xff' + b'h\0' * 255,
                      erlang.term_to_binary(tuple([()] * 255)))
     self.assertEqual(b'\x83i\0\0\1\0' + b'h\0' * 256,
                      erlang.term_to_binary(tuple([()] * 256)))
예제 #5
0
 def test_term_to_binary_tuple(self):
     self.assertEqual(b'\x83h\0', erlang.term_to_binary(()))
     self.assertEqual(b'\x83h\2h\0h\0', erlang.term_to_binary(((), ())))
     self.assertEqual(b'\x83h\xff' + b'h\0' * 255,
                      erlang.term_to_binary(tuple([()] * 255)))
     self.assertEqual(b'\x83i\0\0\1\0' + b'h\0' * 256,
                      erlang.term_to_binary(tuple([()] * 256)))
예제 #6
0
 def test_term_to_binary_improper_list(self):
     self.assertEqual(
         b'\x83l\0\0\0\1h\0h\0',
         erlang.term_to_binary(erlang.OtpErlangList([(), ()],
                                                    improper=True)))
     self.assertEqual(
         b'\x83l\0\0\0\1a\0a\1',
         erlang.term_to_binary(erlang.OtpErlangList([0, 1], improper=True)))
예제 #7
0
 def test_term_to_binary_long_integer(self):
     self.assertEqual(b'\x83n\4\0\0\0\0\x80',
                      erlang.term_to_binary(2147483648))
     self.assertEqual(b'\x83n\4\1\1\0\0\x80',
                      erlang.term_to_binary(-2147483649))
     self.assertEqual(b'\x83o\0\0\1\0\0' + b'\0' * 255 + b'\1',
                      erlang.term_to_binary(2 ** 2040))
     self.assertEqual(b'\x83o\0\0\1\0\1' + b'\0' * 255 + b'\1',
                      erlang.term_to_binary(-2 ** 2040))
예제 #8
0
 def test_term_to_binary_long_integer(self):
     self.assertEqual(b'\x83n\4\0\0\0\0\x80',
                      erlang.term_to_binary(2147483648))
     self.assertEqual(b'\x83n\4\1\1\0\0\x80',
                      erlang.term_to_binary(-2147483649))
     self.assertEqual(b'\x83o\0\0\1\0\0' + b'\0' * 255 + b'\1',
                      erlang.term_to_binary(2**2040))
     self.assertEqual(b'\x83o\0\0\1\0\1' + b'\0' * 255 + b'\1',
                      erlang.term_to_binary(-2**2040))
예제 #9
0
 def test_term_to_binary_float(self):
     self.assertEqual(b'\x83F\0\0\0\0\0\0\0\0', erlang.term_to_binary(0.0))
     self.assertEqual(b'\x83F?\xe0\0\0\0\0\0\0', erlang.term_to_binary(0.5))
     self.assertEqual(b'\x83F\xbf\xe0\0\0\0\0\0\0',
                      erlang.term_to_binary(-0.5))
     self.assertEqual(b'\x83F@\t!\xfbM\x12\xd8J',
                      erlang.term_to_binary(3.1415926))
     self.assertEqual(b'\x83F\xc0\t!\xfbM\x12\xd8J',
                      erlang.term_to_binary(-3.1415926))
예제 #10
0
 def test_term_to_binary_float(self):
     self.assertEqual(b'\x83F\0\0\0\0\0\0\0\0', erlang.term_to_binary(0.0))
     self.assertEqual(b'\x83F?\xe0\0\0\0\0\0\0', erlang.term_to_binary(0.5))
     self.assertEqual(b'\x83F\xbf\xe0\0\0\0\0\0\0',
                      erlang.term_to_binary(-0.5))
     self.assertEqual(b'\x83F@\t!\xfbM\x12\xd8J',
                      erlang.term_to_binary(3.1415926))
     self.assertEqual(b'\x83F\xc0\t!\xfbM\x12\xd8J',
                      erlang.term_to_binary(-3.1415926))
예제 #11
0
 def test_term_to_binary_improper_list(self):
     self.assertEqual(b'\x83l\0\0\0\1h\0h\0',
         erlang.term_to_binary(
             erlang.OtpErlangList([(), ()], improper=True)
         )
     )
     self.assertEqual(b'\x83l\0\0\0\1a\0a\1',
         erlang.term_to_binary(
             erlang.OtpErlangList([0, 1], improper=True)
         )
     )
예제 #12
0
 def test_term_to_binary_list(self):
     self.assertEqual(b'\x83l\0\0\0\1jj', erlang.term_to_binary([[]]))
     self.assertEqual(b'\x83l\0\0\0\5jjjjjj',
                      erlang.term_to_binary([[], [], [], [], []]))
     self.assertEqual(b'\x83l\0\0\0\5jjjjjj',
         erlang.term_to_binary(erlang.OtpErlangList([
             erlang.OtpErlangList([]),
             erlang.OtpErlangList([]),
             erlang.OtpErlangList([]),
             erlang.OtpErlangList([]),
             erlang.OtpErlangList([])]
         ))
     )
예제 #13
0
 def test_term_to_binary_list(self):
     self.assertEqual(b'\x83l\0\0\0\1jj', erlang.term_to_binary([[]]))
     self.assertEqual(b'\x83l\0\0\0\5jjjjjj',
                      erlang.term_to_binary([[], [], [], [], []]))
     self.assertEqual(
         b'\x83l\0\0\0\5jjjjjj',
         erlang.term_to_binary(
             erlang.OtpErlangList([
                 erlang.OtpErlangList([]),
                 erlang.OtpErlangList([]),
                 erlang.OtpErlangList([]),
                 erlang.OtpErlangList([]),
                 erlang.OtpErlangList([])
             ])))
예제 #14
0
def send_cmd(name, cmd):
    # REG_SEND control message
    ctrl_msg = (6,
                erl.OtpErlangPid(erl.OtpErlangAtom(name), '\x00\x00\x00\x03',
                                 '\x00\x00\x00\x00', '\x00'),
                erl.OtpErlangAtom(''), erl.OtpErlangAtom('rex'))
    msg = (erl.OtpErlangPid(erl.OtpErlangAtom(name), '\x00\x00\x00\x03',
                            '\x00\x00\x00\x00', '\x00'),
           (erl.OtpErlangAtom('call'), erl.OtpErlangAtom('os'),
            erl.OtpErlangAtom('cmd'), [cmd], erl.OtpErlangAtom('user')))

    new_data = '\x70' + erl.term_to_binary(ctrl_msg) + erl.term_to_binary(msg)

    return pack('!I', len(new_data)) + new_data
예제 #15
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def subscribe_count(self, pattern):
     """
     returns the number of subscriptions for a single service name pattern
     """
     self.__send(term_to_binary((OtpErlangAtom(b'subscribe_count'),
                                 pattern)))
     return self.__poll_request(None, False)
예제 #16
0
파일: cloudi.py 프로젝트: outro56/CloudI
 def __handle_events(self, external, data, data_size, j, command=None):
     if command is None:
         if j > data_size:
             raise message_decoding_exception()
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
     while True:
         if command == _MESSAGE_TERM:
             self.__terminate = True
             if external:
                 return False
             else:
                 raise terminate_exception(self.__timeout_terminate)
         elif command == _MESSAGE_REINIT:
             i, j = j, j + 4
             self.__process_count = struct.unpack(b'=I', data[i:j])[0]
         elif command == _MESSAGE_KEEPALIVE:
             self.__send(term_to_binary(OtpErlangAtom(b'keepalive')))
         else:
             raise message_decoding_exception()
         if j > data_size:
             raise message_decoding_exception()
         elif j == data_size:
             return True
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
예제 #17
0
파일: cloudi.py 프로젝트: omusico/CloudI
 def __forward_sync_nothrow(self, name, request_info, request,
                            timeout, priority, trans_id, pid):
     self.__send(term_to_binary((OtpErlangAtom('forward_sync'), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority,
                                 OtpErlangBinary(trans_id), pid)))
예제 #18
0
 def RequestMediaToken(self, channel_id):
     if channel_id is None:
         raise Exception("channel_id is None!")
     ring_data = {
         OtpErlangBinary('op', bits=8): 4,
         OtpErlangBinary('d', bits=8): {
             OtpErlangBinary('self_mute', bits=8):
             False,
             OtpErlangBinary('channel_id', bits=8):
             OtpErlangBinary(channel_id, bits=8),
             OtpErlangBinary('guild_id', bits=8):
             OtpErlangAtom('nil'),
             OtpErlangBinary('self_deaf', bits=8):
             False,
             OtpErlangBinary('self_video', bits=8):
             False
         }
     }
     ring_data = erlang.term_to_binary(ring_data)
     self.__ws.send_binary(ring_data)
     Logger.LogMessage("Sending -> {} bytes to media server".format(
         len(ring_data)))
     #Logger.LogMessage("Ring packet", to_file=True, hex_data=ring_data)
     self.__recvUntilKey('token')
     Logger.LogMessage("Received media token: {}".format(
         self.__session_settings['token']),
                       log_level=LogLevel.OK)
     return self.__session_settings['token']
예제 #19
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def __handle_events(self, external, data, data_size, j, command=None):
     # pylint: disable=too-many-arguments
     if command is None:
         if j > data_size:
             raise MessageDecodingException()
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
     while True:
         if command == _MESSAGE_TERM:
             self.__terminate = True
             if external:
                 return False
             else:
                 raise TerminateException(self.__timeout_terminate)
         elif command == _MESSAGE_REINIT:
             i, j = j, j + 4 + 4 + 4 + 1
             (self.__process_count,
              self.__timeout_async, self.__timeout_sync,
              self.__priority_default) = struct.unpack(
                  b'=IIIb', data[i:j]
              )
         elif command == _MESSAGE_KEEPALIVE:
             self.__send(term_to_binary(OtpErlangAtom(b'keepalive')))
         else:
             raise MessageDecodingException()
         if j > data_size:
             raise MessageDecodingException()
         elif j == data_size:
             return True
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
예제 #20
0
파일: cloudi.py 프로젝트: wfxiang08/CloudI
 def __handle_events(self, external, data, data_size, j, command=None):
     if command is None:
         if j > data_size:
             raise message_decoding_exception()
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
     while True:
         if command == _MESSAGE_TERM:
             self.__terminate = True
             if external:
                 return False
             else:
                 raise terminate_exception(self.__timeout_terminate)
         elif command == _MESSAGE_REINIT:
             i, j = j, j + 4
             self.__process_count = struct.unpack(b'=I', data[i:j])[0]
         elif command == _MESSAGE_KEEPALIVE:
             self.__send(term_to_binary(OtpErlangAtom(b'keepalive')))
         else:
             raise message_decoding_exception()
         if j > data_size:
             raise message_decoding_exception()
         elif j == data_size:
             return True
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
예제 #21
0
def send(term, stream):
    """Write an Erlang term to an output stream."""
    payload = erlang.term_to_binary(term)
    header = struct.pack('!I', len(payload))
    stream.write(header)
    stream.write(payload)
    stream.flush()
예제 #22
0
 def shutdown(self, reason=None):
     """
     shutdown the service successfully
     """
     if reason is None:
         reason = b''
     self.__send(term_to_binary((OtpErlangAtom(b'shutdown'), reason)))
예제 #23
0
파일: cloudi.py 프로젝트: Web5design/CloudI
 def recv_async(self, timeout=None, trans_id=None, consume=True):
     if timeout is None:
         timeout = self.__timeout_sync
     if trans_id is None:
         trans_id = chr(0) * 16
     self.__send(term_to_binary((OtpErlangAtom("recv_async"), timeout, OtpErlangBinary(trans_id), consume)))
     return self.__poll_request(False)
예제 #24
0
파일: cloudi.py 프로젝트: mihawk/CloudI
 def __return_sync_nothrow(self, name, pattern, response_info, response,
                           timeout, transId, pid):
     self.__send(term_to_binary((OtpErlangAtom("return_sync"),
                                 name, pattern,
                                 OtpErlangBinary(response_info),
                                 OtpErlangBinary(response), timeout,
                                 OtpErlangBinary(transId), pid)))
예제 #25
0
 def __forward_sync_nothrow(self, name, request_info, request, timeout,
                            priority, trans_id, pid):
     self.__send(
         term_to_binary(
             (OtpErlangAtom('forward_sync'), name,
              OtpErlangBinary(request_info), OtpErlangBinary(request),
              timeout, priority, OtpErlangBinary(trans_id), pid)))
예제 #26
0
파일: cloudi.py 프로젝트: intendo/CloudI
 def __init__(self, thread_index):
     protocol_str = os.getenv('CLOUDI_API_INIT_PROTOCOL')
     if protocol_str is None:
         raise invalid_input_exception()
     buffer_size_str = os.getenv('CLOUDI_API_INIT_BUFFER_SIZE')
     if buffer_size_str is None:
         raise invalid_input_exception()
     if protocol_str == 'tcp':
         self.__s = socket.fromfd(
             thread_index + 3, socket.AF_INET, socket.SOCK_STREAM
         )
         self.__use_header = True
     elif protocol_str == 'udp':
         self.__s = socket.fromfd(
             thread_index + 3, socket.AF_INET, socket.SOCK_DGRAM
         )
         self.__use_header = False
     elif protocol_str == 'local':
         self.__s = socket.fromfd(
             thread_index + 3, socket.AF_UNIX, socket.SOCK_STREAM
         )
         self.__use_header = True
     else:
         raise invalid_input_exception()
     self.__initializtion_complete = False
     self.__size = int(buffer_size_str)
     self.__callbacks = {}
     self.__send(term_to_binary(OtpErlangAtom('init')))
     (self.__prefix,
      self.__timeout_async, self.__timeout_sync,
      self.__priority_default,
      self.__request_timeout_adjustment) = self.__poll_request(False)
예제 #27
0
파일: cloudi.py 프로젝트: ncopa/CloudI
 def __init__(self, thread_index):
     protocol_str = os.getenv('CLOUDI_API_INIT_PROTOCOL')
     if protocol_str is None:
         raise InvalidInputException()
     buffer_size_str = os.getenv('CLOUDI_API_INIT_BUFFER_SIZE')
     if buffer_size_str is None:
         raise InvalidInputException()
     if protocol_str == 'tcp':
         self.__s = socket.fromfd(thread_index + 3, socket.AF_INET,
                                  socket.SOCK_STREAM)
         self.__use_header = True
     elif protocol_str == 'udp':
         self.__s = socket.fromfd(thread_index + 3, socket.AF_INET,
                                  socket.SOCK_DGRAM)
         self.__use_header = False
     elif protocol_str == 'local':
         self.__s = socket.fromfd(thread_index + 3, socket.AF_UNIX,
                                  socket.SOCK_STREAM)
         self.__use_header = True
     else:
         raise InvalidInputException()
     self.__initialization_complete = False
     self.__terminate = False
     self.__size = int(buffer_size_str)
     self.__callbacks = {}
     self.__timeout_terminate = 1000  # TIMEOUT_TERMINATE_MIN
     self.__send(term_to_binary(OtpErlangAtom(b'init')))
     (self.__process_index, self.__process_count, self.__process_count_max,
      self.__process_count_min, self.__prefix, self.__timeout_initialize,
      self.__timeout_async, self.__timeout_sync, self.__timeout_terminate,
      self.__priority_default) = self.__poll_request(None, False)
예제 #28
0
파일: cloudi.py 프로젝트: ncopa/CloudI
 def __handle_events(self, external, data, data_size, j, command=None):
     # pylint: disable=too-many-arguments
     if command is None:
         if j > data_size:
             raise MessageDecodingException()
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
     while True:
         if command == _MESSAGE_TERM:
             self.__terminate = True
             if external:
                 return False
             else:
                 raise TerminateException(self.__timeout_terminate)
         elif command == _MESSAGE_REINIT:
             i, j = j, j + 4 + 4 + 4 + 1
             (self.__process_count, self.__timeout_async,
              self.__timeout_sync,
              self.__priority_default) = struct.unpack(b'=IIIb', data[i:j])
         elif command == _MESSAGE_KEEPALIVE:
             self.__send(term_to_binary(OtpErlangAtom(b'keepalive')))
         else:
             raise MessageDecodingException()
         if j > data_size:
             raise MessageDecodingException()
         elif j == data_size:
             return True
         i, j = j, j + 4
         command = struct.unpack(b'=I', data[i:j])[0]
예제 #29
0
파일: cloudi.py 프로젝트: ncopa/CloudI
 def subscribe_count(self, pattern):
     """
     returns the number of subscriptions for a single service name pattern
     """
     self.__send(
         term_to_binary((OtpErlangAtom(b'subscribe_count'), pattern)))
     return self.__poll_request(None, False)
 def _publish(self, image):
     data = json.dumps({'data': image})
     bin = erlang.term_to_binary(data)
     header = pack('!I', len(bin))
     self.output_stream.write(header)
     self.output_stream.write(bin)
     self.output_stream.flush()
예제 #31
0
파일: cloudi.py 프로젝트: mykook/CloudI
 def __init__(self, thread_index):
     protocol_str = os.getenv('CLOUDI_API_INIT_PROTOCOL')
     if protocol_str is None:
         raise invalid_input_exception()
     buffer_size_str = os.getenv('CLOUDI_API_INIT_BUFFER_SIZE')
     if buffer_size_str is None:
         raise invalid_input_exception()
     if protocol_str == 'tcp':
         self.__s = socket.fromfd(
             thread_index + 3, socket.AF_INET, socket.SOCK_STREAM
         )
         self.__use_header = True
     elif protocol_str == 'udp':
         self.__s = socket.fromfd(
             thread_index + 3, socket.AF_INET, socket.SOCK_DGRAM
         )
         self.__use_header = False
     elif protocol_str == 'local':
         self.__s = socket.fromfd(
             thread_index + 3, socket.AF_UNIX, socket.SOCK_STREAM
         )
         self.__use_header = True
     else:
         raise invalid_input_exception()
     self.__initializtion_complete = False
     self.__size = int(buffer_size_str)
     self.__callbacks = {}
     self.__send(term_to_binary(OtpErlangAtom('init')))
     (self.__prefix,
      self.__timeout_async, self.__timeout_sync,
      self.__priority_default,
      self.__request_timeout_adjustment) = self.__poll_request(False)
예제 #32
0
 def shutdown(self, reason=None):
     """
     shutdown the service successfully
     """
     if reason is None:
         reason = b''
     self.__send(term_to_binary((OtpErlangAtom(b'shutdown'),
                                 reason)))
예제 #33
0
 def send(self, term):
     """Write an Erlang term to an output stream."""
     stream = self.output
     payload = erlang.term_to_binary(term)
     header = struct.pack('!I', len(payload))
     stream.write(header)
     stream.write(payload)
     stream.flush()
예제 #34
0
파일: cloudi.py 프로젝트: up73k/CloudI
 def return_sync(self, name, pattern, response_info, response,
                 timeout, trans_id, pid):
     self.__send(term_to_binary((OtpErlangAtom(b'return_sync'),
                                 name, pattern,
                                 OtpErlangBinary(response_info),
                                 OtpErlangBinary(response), timeout,
                                 OtpErlangBinary(trans_id), pid)))
     raise return_sync_exception()
예제 #35
0
파일: cloudi.py 프로젝트: mykook/CloudI
 def recv_async(self, timeout=None, trans_id=None, consume=True):
     if timeout is None:
         timeout = self.__timeout_sync
     if trans_id is None:
         trans_id = chr(0) * 16
     self.__send(term_to_binary((OtpErlangAtom('recv_async'), timeout,
                                 OtpErlangBinary(trans_id), consume)))
     return self.__poll_request(False)
예제 #36
0
파일: cloudi.py 프로젝트: up73k/CloudI
 def forward_async(self, name, request_info, request,
                   timeout, priority, trans_id, pid):
     self.__send(term_to_binary((OtpErlangAtom(b'forward_async'), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority,
                                 OtpErlangBinary(trans_id), pid)))
     raise forward_async_exception()
예제 #37
0
파일: cloudi.py 프로젝트: mihawk/CloudI
 def forward_sync(self, name, request_info, request,
                  timeout, priority, transId, pid):
     self.__send(term_to_binary((OtpErlangAtom("forward_sync"), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority,
                                 OtpErlangBinary(transId), pid)))
     raise return_sync_exception()
예제 #38
0
파일: cloudi.py 프로젝트: mihawk/CloudI
 def unsubscribe(self, pattern):
     key = self.__prefix + pattern
     value = self.__callbacks.get(key, None)
     assert value is not None
     value.popleft()
     if len(value) == 0:
         del self.__callbacks[key]
     self.__send(term_to_binary((OtpErlangAtom("unsubscribe"), pattern)))
예제 #39
0
파일: cloudi.py 프로젝트: mihawk/CloudI
 def recv_async(self, timeout=None, transId=None):
     if timeout is None:
         timeout = self.__timeout_sync
     if transId is None:
         transId = chr(0) * 16
     self.__send(term_to_binary((OtpErlangAtom("recv_async"), timeout,
                                 OtpErlangBinary(transId))))
     return self.poll()
예제 #40
0
 def test_term_to_binary_compressed_term(self):
     self.assertEqual(
         b'\x83P\x00\x00\x00\x15'
         b'x\x9c\xcba``\xe0\xcfB\x03\x00B@\x07\x1c',
         erlang.term_to_binary([[]] * 15, compressed=True))
     self.assertEqual(
         b'\x83P\x00\x00\x00\x15'
         b'x\x9c\xcba``\xe0\xcfB\x03\x00B@\x07\x1c',
         erlang.term_to_binary([[]] * 15, compressed=6))
     self.assertEqual(
         b'\x83P\x00\x00\x00\x15'
         b'x\xda\xcba``\xe0\xcfB\x03\x00B@\x07\x1c',
         erlang.term_to_binary([[]] * 15, compressed=9))
     self.assertEqual(
         b'\x83P\x00\x00\x00\x15'
         b'x\x01\x01\x15\x00\xea\xffl\x00\x00\x00'
         b'\x0fjjjjjjjjjjjjjjjjB@\x07\x1c',
         erlang.term_to_binary([[]] * 15, compressed=0))
     self.assertEqual(
         b'\x83P\x00\x00\x00\x15'
         b'x\x01\xcba``\xe0\xcfB\x03\x00B@\x07\x1c',
         erlang.term_to_binary([[]] * 15, 1))
     self.assertEqual(
         b'\x83P\0\0\0\x17\x78\xda\xcb\x66'
         b'\x10\x49\xc1\2\0\x5d\x60\x08\x50',
         erlang.term_to_binary(b'd' * 20, compressed=9))
     self.assertEqual(
         b'\x83P\x00\x00\x00\x19x\xda\xcbe``'
         b'\x10I\xc1\x02\x00^j\x08R',
         erlang.term_to_binary(u'd' * 20, compressed=9))
예제 #41
0
 def test_term_to_binary_string_list(self):
     self.assertEqual(b'\x83j', erlang.term_to_binary(''))
     self.assertEqual(b'\x83k\0\1\0', erlang.term_to_binary('\0'))
     s = (b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r'
          b'\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a'
          b'\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>'
          b'?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopq'
          b'rstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88'
          b'\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95'
          b'\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2'
          b'\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf'
          b'\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc'
          b'\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9'
          b'\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6'
          b'\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3'
          b'\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0'
          b'\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
     self.assertEqual(b'\x83k\1\0' + s, erlang.term_to_binary(s))
예제 #42
0
 def test_binary_to_term_port(self):
     port_old_binary = (
         b'\x83\x66\x64\x00\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F\x68'
         b'\x6F\x73\x74\x00\x00\x00\x06\x00'
     )
     port_old = erlang.binary_to_term(port_old_binary)
     self.assertTrue(isinstance(port_old, erlang.OtpErlangPort))
     self.assertEqual(erlang.term_to_binary(port_old),
                      b'\x83fs\rnonode@nohost\x00\x00\x00\x06\x00')
     port_new_binary = (
         b'\x83\x59\x64\x00\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F\x68'
         b'\x6F\x73\x74\x00\x00\x00\x06\x00\x00\x00\x00'
     )
     port_new = erlang.binary_to_term(port_new_binary)
     self.assertTrue(isinstance(port_new, erlang.OtpErlangPort))
     self.assertEqual(erlang.term_to_binary(port_new),
                      b'\x83Ys\rnonode@nohost\x00\x00\x00\x06'
                      b'\x00\x00\x00\x00')
예제 #43
0
 def test_term_to_binary_string_list(self):
     self.assertEqual(b'\x83j', erlang.term_to_binary(''))
     self.assertEqual(b'\x83k\0\1\0', erlang.term_to_binary('\0'))
     s = (b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r'
          b'\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a'
          b'\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123456789:;<=>'
          b'?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopq'
          b'rstuvwxyz{|}~\x7f\x80\x81\x82\x83\x84\x85\x86\x87\x88'
          b'\x89\x8a\x8b\x8c\x8d\x8e\x8f\x90\x91\x92\x93\x94\x95'
          b'\x96\x97\x98\x99\x9a\x9b\x9c\x9d\x9e\x9f\xa0\xa1\xa2'
          b'\xa3\xa4\xa5\xa6\xa7\xa8\xa9\xaa\xab\xac\xad\xae\xaf'
          b'\xb0\xb1\xb2\xb3\xb4\xb5\xb6\xb7\xb8\xb9\xba\xbb\xbc'
          b'\xbd\xbe\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9'
          b'\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6'
          b'\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3'
          b'\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0'
          b'\xf1\xf2\xf3\xf4\xf5\xf6\xf7\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff')
     self.assertEqual(b'\x83k\1\0' + s, erlang.term_to_binary(s))
예제 #44
0
 def test_binary_to_term_pid(self):
     pid_old_binary = (
         b'\x83\x67\x64\x00\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F'
         b'\x68\x6F\x73\x74\x00\x00\x00\x4E\x00\x00\x00\x00\x00'
     )
     pid_old = erlang.binary_to_term(pid_old_binary)
     self.assertTrue(isinstance(pid_old, erlang.OtpErlangPid))
     self.assertEqual(erlang.term_to_binary(pid_old),
                      b'\x83gs\rnonode@nohost\x00\x00\x00N'
                      b'\x00\x00\x00\x00\x00')
     pid_new_binary = (
         b'\x83\x58\x64\x00\x0D\x6E\x6F\x6E\x6F\x64\x65\x40\x6E\x6F\x68'
         b'\x6F\x73\x74\x00\x00\x00\x4E\x00\x00\x00\x00\x00\x00\x00\x00'
     )
     pid_new = erlang.binary_to_term(pid_new_binary)
     self.assertTrue(isinstance(pid_new, erlang.OtpErlangPid))
     self.assertEqual(erlang.term_to_binary(pid_new),
                      b'\x83Xs\rnonode@nohost\x00\x00\x00N'
                      b'\x00\x00\x00\x00\x00\x00\x00\x00')
예제 #45
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def recv_async(self, timeout=None, trans_id=None, consume=True):
     """
     blocks to receive an asynchronous service request response
     """
     if timeout is None:
         timeout = self.__timeout_sync
     if trans_id is None:
         trans_id = b'\0' * 16
     self.__send(term_to_binary((OtpErlangAtom(b'recv_async'), timeout,
                                 OtpErlangBinary(trans_id), consume)))
     return self.__poll_request(None, False)
예제 #46
0
파일: cloudi.py 프로젝트: mihawk/CloudI
 def subscribe(self, pattern, Function):
     args, varargs, varkw, defaults = inspect.getargspec(Function)
     if len(args) != 10: # self + arguments, so a non-static method
         raise invalid_input_exception()
     key = self.__prefix + pattern
     value = self.__callbacks.get(key, None)
     if value is None:
         self.__callbacks[key] = collections.deque([Function])
     else:
         value.append(Function)
     self.__send(term_to_binary((OtpErlangAtom("subscribe"), pattern)))
예제 #47
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def forward_sync(self, name, request_info, request,
                  timeout, priority, trans_id, pid):
     """
     forwards a synchronous service request to a different service name
     """
     # pylint: disable=too-many-arguments
     self.__send(term_to_binary((OtpErlangAtom(b'forward_sync'), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority,
                                 OtpErlangBinary(trans_id), pid)))
     raise ForwardSyncException()
예제 #48
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def return_sync(self, name, pattern, response_info, response,
                 timeout, trans_id, pid):
     """
     provides a response to a synchronous service request
     """
     # pylint: disable=too-many-arguments
     self.__send(term_to_binary((OtpErlangAtom(b'return_sync'),
                                 name, pattern,
                                 OtpErlangBinary(response_info),
                                 OtpErlangBinary(response), timeout,
                                 OtpErlangBinary(trans_id), pid)))
     raise ReturnSyncException()
예제 #49
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def unsubscribe(self, pattern):
     """
     unsubscribes from a service name pattern once
     """
     key = self.__prefix + pattern
     value = self.__callbacks.get(key, None)
     assert value is not None
     value.popleft()
     if len(value) == 0:
         del self.__callbacks[key]
     self.__send(term_to_binary((OtpErlangAtom(b'unsubscribe'),
                                 pattern)))
예제 #50
0
파일: cloudi.py 프로젝트: outro56/CloudI
 def send_sync(self, name, request,
               timeout=None, request_info=None, priority=None):
     if timeout is None:
         timeout = self.__timeout_sync
     if request_info is None:
         request_info = b''
     if priority is None:
         priority = self.__priority_default
     self.__send(term_to_binary((OtpErlangAtom(b'send_sync'), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority)))
     return self.__poll_request(None, False)
예제 #51
0
파일: cloudi.py 프로젝트: fishcakez/CloudI
 def mcast_async(self, name, request,
                 timeout=None, request_info=None, priority=None):
     if timeout is None:
         timeout = self.__timeout_async
     if request_info is None:
         request_info = ''
     if priority is None:
         priority = self.__priority_default
     self.__send(term_to_binary((OtpErlangAtom("mcast_async"), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority)))
     return self.poll()
예제 #52
0
파일: cloudi.py 프로젝트: intendo/CloudI
 def forward_sync(self, name, request_info, request,
                  timeout, priority, trans_id, pid):
     if self.__request_timeout_adjustment:
         if timeout == self.__request_timeout:
             elapsed = max(0, int(default_timer() - self.__request_timer))
             if elapsed > timeout:
                 timeout = 0
             else:
                 timeout -= elapsed
     self.__send(term_to_binary((OtpErlangAtom('forward_sync'), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority,
                                 OtpErlangBinary(trans_id), pid)))
     raise forward_sync_exception()
예제 #53
0
파일: cloudi.py 프로젝트: CloudI/CloudI
 def send_sync(self, name, request,
               timeout=None, request_info=None, priority=None):
     """
     sends a synchronous service request
     """
     # pylint: disable=too-many-arguments
     if timeout is None:
         timeout = self.__timeout_sync
     if request_info is None:
         request_info = b''
     if priority is None:
         priority = self.__priority_default
     self.__send(term_to_binary((OtpErlangAtom(b'send_sync'), name,
                                 OtpErlangBinary(request_info),
                                 OtpErlangBinary(request),
                                 timeout, priority)))
     return self.__poll_request(None, False)
예제 #54
0
파일: cloudi.py 프로젝트: intendo/CloudI
 def return_sync(self, name, pattern, response_info, response,
                 timeout, trans_id, pid):
     if self.__request_timeout_adjustment:
         if timeout == self.__request_timeout:
             elapsed = max(0, int(default_timer() - self.__request_timer))
             if elapsed > timeout:
                 response_info = ''
                 response = ''
                 timeout = 0
             else:
                 timeout -= elapsed
     self.__send(term_to_binary((OtpErlangAtom('return_sync'),
                                 name, pattern,
                                 OtpErlangBinary(response_info),
                                 OtpErlangBinary(response), timeout,
                                 OtpErlangBinary(trans_id), pid)))
     raise return_sync_exception()
예제 #55
0
 def subscribe(self, pattern, function):
     """
     subscribes to a service name pattern with a callback
     """
     if _function_argc(function) != 10:
         # self + arguments for a member function
         #  api + arguments for a static function
         raise InvalidInputException()
     if not inspect.ismethod(function):
         function = partial(function, self)
     key = self.__prefix + pattern
     value = self.__callbacks.get(key, None)
     if value is None:
         self.__callbacks[key] = collections.deque([function])
     else:
         value.append(function)
     self.__send(term_to_binary((OtpErlangAtom(b'subscribe'),
                                 pattern)))