Exemple #1
0
    def __init__(self, socket_map, addr, passwd):
        """Constructor."""
        # python 2.4 does not have the 'map' parameter
        _map = asyncore.socket_map
        asyncore.socket_map = socket_map
        asynchat.async_chat.__init__(self)
        asyncore.socket_map = _map

        self._fileno = None
        self.addr = addr
        self.passwd = passwd

        self._bset = vimbuffer.BufferSet(self)
        self.last_buf = None
        self.console = None
        self.dbgvarbuf = None
        self.reply_fifo = asynchat.fifo()
        self.owner_thread = 0
        self.ready = False
        self.detached = False
        self.debugger = None
        self.nbversion = 'unknown'
        self.ibuff = []
        self.seqno = 0
        self.last_seqno = 0
        self.set_terminator('\n')
        self.lock = None
        self.sernum = Sernum()
        self.frame_annotation = vimbuffer.FrameAnnotation(self)
Exemple #2
0
 def test_given_list(self):
     f = asynchat.fifo(['x', 17, 3])
     self.assertEqual(len(f), 3)
     self.assertEqual(f.pop(), (1, 'x'))
     self.assertEqual(f.pop(), (1, 17))
     self.assertEqual(f.pop(), (1, 3))
     self.assertEqual(f.pop(), (0, None))
  def __init__(self, host, port=23, timeout=1, softStart=False, logger=None):
    """Initialize the class, open the socket"""
    asynchat.async_chat.__init__(self)

    self.STATES = [ "READY", "DISCONNECTED", "MV_WAIT", "ERROR", "EMPTY" ]
    self.state = self.STATES[1]

    self.logger = logger or logging.getLogger(__name__)

    self.__dict__['motorTypes'] = [0,0,0,0]
    self.__dict__['positions'] = [0,0,0,0]
    self.__dict__['velocities'] = [0,0,0,0]
    self.__dict__['accelerations'] = [0,0,0,0]

    
    self.ibuffer = [] # input buffer
    self.obuffer = '' # output buffer
    self.set_terminator('\r\n') # command and response termination protocol

    # store commands in a buffer that we only pop off after getting a response 
    # from the previous command
    self.cmdFIFO = asynchat.fifo()
    self.cmdCount = 0 # total commands sent to command buffer
    self.cmdID = -1 # ID number of last command sent to 8742
    # can be used to block the main thread until after a specfic command has been executed
    self.lastCmd = ''

    # connection info
    self.host = host # ip address
    self.port = port # port num (defaults to telnet port 23)
    self.timeout = timeout # time to wait for the listening thread after close

    self.connect(softStart)
Exemple #4
0
 def test_given_list(self):
     f = asynchat.fifo([b'x', 17, 3])
     self.assertEqual(len(f), 3)
     self.assertEqual(f.pop(), (1, b'x'))
     self.assertEqual(f.pop(), (1, 17))
     self.assertEqual(f.pop(), (1, 3))
     self.assertEqual(f.pop(), (0, None))
Exemple #5
0
    def __init__(self):
        """Constructor."""
        asynchat.async_chat.__init__(self)

        self._bset = vimbuffer.BufferSet(self)
        self.__last_sernum = 0
        self.last_buf = None
        self.console = None
        self.dbgvarbuf = None
        self.reply_fifo = asynchat.fifo()
        self.addr = None
        self.ready = False
        self.debugger = None
        self.passwd = None
        self.nbversion = None
        self.ibuff = []
        self.seqno = 0
        self.last_seqno = 0
        self.remove_fix = '0'
        self.getLength_fix = '0'
        self.max_lines = CONSOLE_MAXLINES
        self.bg_colors = ('Cyan', 'Green', 'Magenta')

        self.server = Server(self)
        self.set_terminator('\n')
 def test_given_list(self):
     with warnings.catch_warnings(record=True) as w:
         f = asynchat.fifo([b'x', 17, 3])
         if w:
             assert issubclass(w[0].category, DeprecationWarning)
     self.assertEqual(len(f), 3)
     self.assertEqual(f.pop(), (1, b'x'))
     self.assertEqual(f.pop(), (1, 17))
     self.assertEqual(f.pop(), (1, 3))
     self.assertEqual(f.pop(), (0, None))
 def test_given_list(self):
     with self.assertWarns(DeprecationWarning) as cm:
         f = asynchat.fifo([b'x', 17, 3])
     self.assertEqual(str(cm.warning),
                      "fifo class will be removed in Python 3.6")
     self.assertEqual(len(f), 3)
     self.assertEqual(f.pop(), (1, b'x'))
     self.assertEqual(f.pop(), (1, 17))
     self.assertEqual(f.pop(), (1, 3))
     self.assertEqual(f.pop(), (0, None))
Exemple #8
0
 def test_given_list(self):
     with self.assertWarns(DeprecationWarning) as cm:
         f = asynchat.fifo([b'x', 17, 3])
     self.assertEqual(str(cm.warning),
                      "fifo class will be removed in Python 3.6")
     self.assertEqual(len(f), 3)
     self.assertEqual(f.pop(), (1, b'x'))
     self.assertEqual(f.pop(), (1, 17))
     self.assertEqual(f.pop(), (1, 3))
     self.assertEqual(f.pop(), (0, None))
Exemple #9
0
 def __init__(self, channel, request, command, uri, version, headers):
     self.number = Request.singleton.request_counter.increment()
     self._channel = channel
     # Top line of the request, like GET /index.html HTTP/1.0 for example.
     self._request = request
     # Type of command, like GET for example.
     self._command = command
     # Requested resource, like /index.html for example.
     self._uri = uri
     # HTTP version, like 1.0 for example.
     self._version = version
     # String of headers exactly as recevied.  Headers included
     #   are all line after request and before double \r\n.
     self.request_header_lines = self._headers = headers
     self.request_headers = None
     self.response_headers = {
         'Server': 'WebServer/%s' % VERSION_STRING,
         'Date': _http_date.build_http_date(time.time())
     }
     self._split_uri = None
     self._query_dictionary = {}
     self.request_cookies = None
     self._outgoing = asynchat.fifo()
     self._outgoing_content_length = 0
     self._collector = None
     self._user_object = None
     self._authentication_scheme = None
     default = self.server.authentication.lower()
     self._default_scheme = default
     self._default_authentication = {
         'digest': self.digest_challenge,
         'basic': self.basic_challenge,
         'form': self.form_challenge
     }[default]
     self.out = None
     self.response_length = 0
     self.response_cookies = []
     self.response_producer = None
     self.outgoing_producers = asynchat.fifo()
Exemple #10
0
 def _build_outgoing_producer(self):
     if not self._outgoing_producer:
         outgoing_producers = [self._build_header_producer()]
         body_producer = self._build_body_producer()
         if body_producer is not None:
             outgoing_producers.append(body_producer)
         outgoing_fifo = asynchat.fifo(outgoing_producers)
         outgoing_producer = CompositeProducer(outgoing_fifo)
         if self.get_debuglevel() > 0:
             outgoing_producer = HookedProducer(outgoing_producer, self.log)
         outgoing_producer = GlobbingProducer(outgoing_producer)
         self._outgoing_producer = outgoing_producer
     return self._outgoing_producer
Exemple #11
0
 def _build_outgoing_producer(self):
     if not self._outgoing_producer:
         outgoing_producers = [self._build_header_producer()]
         body_producer = self._build_body_producer()
         if body_producer is not None:
             outgoing_producers.append(body_producer)
         outgoing_fifo = asynchat.fifo(outgoing_producers)
         outgoing_producer = CompositeProducer(outgoing_fifo)
         if self.get_debuglevel() > 0:
             outgoing_producer = HookedProducer(outgoing_producer, self.log)
         outgoing_producer = GlobbingProducer(outgoing_producer)
         self._outgoing_producer = outgoing_producer
     return self._outgoing_producer
Exemple #12
0
 def test_basic(self):
     f = asynchat.fifo()
     f.push(7)
     f.push(b'a')
     self.assertEqual(len(f), 2)
     self.assertEqual(f.first(), 7)
     self.assertEqual(f.pop(), (1, 7))
     self.assertEqual(len(f), 1)
     self.assertEqual(f.first(), b'a')
     self.assertEqual(f.is_empty(), False)
     self.assertEqual(f.pop(), (1, b'a'))
     self.assertEqual(len(f), 0)
     self.assertEqual(f.is_empty(), True)
     self.assertEqual(f.pop(), (0, None))
Exemple #13
0
 def create_response(self, request):
     connection = request.get_header('connection')
     if connection:
         connection = connection.lower()
     if not request.has_key("Content-Length"):
         if request.response_length is not None:
             request['Content-Length'] = request.response_length
     close_it = 0
     wrap_in_chunking = 0
     if request._version == '1.0':
         if connection == 'keep-alive':
             if not request.has_key('Content-Length'):
                 close_it = 1
             else:
                 request['Connection'] = 'Keep-Alive'
         else:
             close_it = 1
     elif request._version == '1.1':
         if connection == 'close':
             close_it = 1
         elif not request.has_key('Content-Length'):
             if request.has_key('Transfer-Encoding'):
                 if not request['Transfer-Encoding'] == 'chunked':
                     close_it = 1
             elif request.use_chunked:
                 request['Transfer-Encoding'] = 'chunked'
                 wrap_in_chunking = 1
             else:
                 close_it = 1
     elif request._version is None:
         ##
         # Sometimes developers do not type a version when debugging
         # a server from telnet.  This is to support such requests.
         close_it = 1
     if close_it:
         request['Connection'] = 'close'
     header = self.build_header(request)
     header_producer = producers.SimpleProducer(header + "\r\n\r\n")
     body_producer = request.outgoing_producers
     request.outgoing_producers = None
     body_producer = producers.CompositeProducer(body_producer)
     if wrap_in_chunking:
         body_producer = producers.ChunkedProducer(body_producer)
     outgoing_fifo = asynchat.fifo([header_producer, body_producer])
     outgoing = producers.CompositeProducer(outgoing_fifo)
     outgoing = producers.HookedProducer(outgoing, request.log)
     outgoing = producers.GlobbingProducer(outgoing)
     if close_it:
         request._channel.close_when_done()
     return outgoing
Exemple #14
0
 def test_basic(self):
     f = asynchat.fifo()
     f.push(7)
     f.push('a')
     self.assertEqual(len(f), 2)
     self.assertEqual(f.first(), 7)
     self.assertEqual(f.pop(), (1, 7))
     self.assertEqual(len(f), 1)
     self.assertEqual(f.first(), 'a')
     self.assertEqual(f.is_empty(), False)
     self.assertEqual(f.pop(), (1, 'a'))
     self.assertEqual(len(f), 0)
     self.assertEqual(f.is_empty(), True)
     self.assertEqual(f.pop(), (0, None))
Exemple #15
0
 def create_response(self, request):
     connection = request.get_header('connection')
     if connection:
         connection = connection.lower()
     if not request.has_key("Content-Length"):
         if request.response_length is not None:
             request['Content-Length'] = request.response_length
     close_it = 0
     wrap_in_chunking = 0
     if request._version == '1.0':
         if connection == 'keep-alive':
             if not request.has_key('Content-Length'):
                 close_it = 1
             else:
                 request['Connection'] = 'Keep-Alive'
         else:
             close_it = 1
     elif request._version == '1.1':
         if connection == 'close':
             close_it = 1
         elif not request.has_key('Content-Length'):
             if request.has_key('Transfer-Encoding'):
                 if not request['Transfer-Encoding'] == 'chunked':
                     close_it = 1
             elif request.use_chunked:
                 request['Transfer-Encoding'] = 'chunked'
                 wrap_in_chunking = 1
             else:
                 close_it = 1
     elif request._version is None:
         ##
         # Sometimes developers do not type a version when debugging
         # a server from telnet.  This is to support such requests.
         close_it = 1
     if close_it:
         request['Connection'] = 'close'
     header = self.build_header(request)
     header_producer = producers.SimpleProducer(header + "\r\n\r\n")
     body_producer = request.outgoing_producers
     request.outgoing_producers = None
     body_producer = producers.CompositeProducer(body_producer)
     if wrap_in_chunking:    
         body_producer = producers.ChunkedProducer(body_producer)
     outgoing_fifo = asynchat.fifo([header_producer, body_producer])
     outgoing = producers.CompositeProducer(outgoing_fifo)
     outgoing = producers.HookedProducer(outgoing, request.log)
     outgoing = producers.GlobbingProducer(outgoing)
     if close_it:
         request._channel.close_when_done()
     return outgoing
Exemple #16
0
    def __init__(self, end_point_host, end_point_port, is_print_log=False):
        # set options
        self.be_init = 0
        self.is_print_log = is_print_log
        self.__notify_list = []

        # 已发送包的参数暂存区
        self.__sent_packge_info = {}
        # 接受到包的缓冲区
        # 存放格式为(seq, data)
        self.__rec_package = fifo()
        self.__lock = threading.Lock()

        # set receive data buffer size
        self.ac_in_buffer_size = 81920
        self.set_terminator(None)
        _monitor_methods_to_be_started = [
            self.__asyn_rec, self.__check_timeout, self.__asyn_fetch
        ]

        # set socket
        _socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        errcode = _socket.connect_ex((end_point_host, end_point_port))
        if errcode == 0:
            self.__print_log(
                "====================******socket 连接******===================="
            )
        else:
            self.__print_log("error_code:{0}".format(errcode))
        super(WechatClientTest, self).__init__(_socket)

        if not self.connected:
            logger.error(
                "==[F****d up]===WechatClientModify initiating failed. ======")
            self.close_when_done()
        else:
            # initial arg
            self.buffer_output = []
            self.rec_flag = False
            self.rec_len = 0
            self.total_len = 0
            self.seq = 0
            self.be_init = 1
            self.sent = False
            # start monitor methods
            for met in _monitor_methods_to_be_started:
                t = threading.Thread(target=met)
                t.setDaemon(True)
                t.start()
Exemple #17
0
 def __init__(self,channel,request,command,uri,version,headers):
     self.number = Request.singleton.request_counter.increment()
     self._channel = channel
     # Top line of the request, like GET /index.html HTTP/1.0 for example.
     self._request = request
     # Type of command, like GET for example.
     self._command = command
     # Requested resource, like /index.html for example.
     self._uri = uri
     # HTTP version, like 1.0 for example.
     self._version = version
     # String of headers exactly as recevied.  Headers included
     #   are all line after request and before double \r\n.
     self.request_header_lines = self._headers = headers
     self.request_headers = None
     self.response_headers = {
         'Server': 'WebServer/%s' % VERSION_STRING,
         'Date': _http_date.build_http_date(time.time())}
     self._split_uri = None
     self._query_dictionary = {}
     self.request_cookies = None
     self._outgoing = asynchat.fifo()
     self._outgoing_content_length = 0
     self._collector = None
     self._user_object = None
     self._authentication_scheme = None
     default = self.server.authentication.lower()
     self._default_scheme = default
     self._default_authentication = {'digest':self.digest_challenge,
                                     'basic':self.basic_challenge, 
                                     'form': self.form_challenge}[default]
     self.out = None
     self.response_length = 0
     self.response_cookies = []
     self.response_producer = None
     self.outgoing_producers = asynchat.fifo()
Exemple #18
0
 def __init__ (self, conn=None, map=None):
     # if python version < 2.6:
     if sys.version_info[0:2] < (2, 6):
         # python 2.4 and 2.5 need to do this:
         try:
             self.ac_in_buffer = bytes('')
             self.ac_out_buffer = bytes('')
         except:
             self.ac_in_buffer = ''
             self.ac_out_buffer = ''
         self.producer_fifo = asynchat.fifo()
         # and here is the fix, I'm including 'map' to the superclass constructor here:
         asyncore.dispatcher.__init__ (self, conn, map)
     else:
         # otherwise, we defer 100% to the parent class, since it works fine
         asynchat.async_chat.__init__(self, conn, map)
Exemple #19
0
 def __init__(self, conn=None, map=None):
     # if python version < 2.6:
     if sys.version_info[0:2] < (2, 6):
         # python 2.4 and 2.5 need to do this:
         try:
             self.ac_in_buffer = bytes('')
             self.ac_out_buffer = bytes('')
         except:
             self.ac_in_buffer = ''
             self.ac_out_buffer = ''
         self.producer_fifo = asynchat.fifo()
         # and here is the fix, I'm including 'map' to the superclass constructor here:
         asyncore.dispatcher.__init__(self, conn, map)
     else:
         # otherwise, we defer 100% to the parent class, since it works fine
         asynchat.async_chat.__init__(self, conn, map)
 def test_basic(self):
     with self.assertWarns(DeprecationWarning) as cm:
         f = asynchat.fifo()
     self.assertEqual(str(cm.warning),
                      "fifo class will be removed in Python 3.6")
     f.push(7)
     f.push(b'a')
     self.assertEqual(len(f), 2)
     self.assertEqual(f.first(), 7)
     self.assertEqual(f.pop(), (1, 7))
     self.assertEqual(len(f), 1)
     self.assertEqual(f.first(), b'a')
     self.assertEqual(f.is_empty(), False)
     self.assertEqual(f.pop(), (1, b'a'))
     self.assertEqual(len(f), 0)
     self.assertEqual(f.is_empty(), True)
     self.assertEqual(f.pop(), (0, None))
 def test_basic(self):
     with warnings.catch_warnings(record=True) as w:
         f = asynchat.fifo()
         if w:
             assert issubclass(w[0].category, DeprecationWarning)
     f.push(7)
     f.push(b'a')
     self.assertEqual(len(f), 2)
     self.assertEqual(f.first(), 7)
     self.assertEqual(f.pop(), (1, 7))
     self.assertEqual(len(f), 1)
     self.assertEqual(f.first(), b'a')
     self.assertEqual(f.is_empty(), False)
     self.assertEqual(f.pop(), (1, b'a'))
     self.assertEqual(len(f), 0)
     self.assertEqual(f.is_empty(), True)
     self.assertEqual(f.pop(), (0, None))
Exemple #22
0
 def test_basic(self):
     with self.assertWarns(DeprecationWarning) as cm:
         f = asynchat.fifo()
     self.assertEqual(str(cm.warning),
                      "fifo class will be removed in Python 3.6")
     f.push(7)
     f.push(b'a')
     self.assertEqual(len(f), 2)
     self.assertEqual(f.first(), 7)
     self.assertEqual(f.pop(), (1, 7))
     self.assertEqual(len(f), 1)
     self.assertEqual(f.first(), b'a')
     self.assertEqual(f.is_empty(), False)
     self.assertEqual(f.pop(), (1, b'a'))
     self.assertEqual(len(f), 0)
     self.assertEqual(f.is_empty(), True)
     self.assertEqual(f.pop(), (0, None))
Exemple #23
0
    def __init__(self, addr, passwd):
        """Constructor."""
        asynchat.async_chat.__init__(self)
        self._fileno = None
        self.addr = addr
        self.passwd = passwd

        self._bset = vimbuffer.BufferSet(self)
        self.last_buf = None
        self.console = None
        self.dbgvarbuf = None
        self.reply_fifo = asynchat.fifo()
        self.ready = False
        self.debugger = None
        self.nbversion = None
        self.ibuff = []
        self.seqno = 0
        self.last_seqno = 0
        self.set_terminator('\n')
Exemple #24
0
    def __init__(self, addr, passwd):
        """Constructor."""
        asynchat.async_chat.__init__(self)
        self._fileno = None
        self.addr = addr
        self.passwd = passwd

        self._bset = vimbuffer.BufferSet(self)
        self.last_buf = None
        self.console = None
        self.dbgvarbuf = None
        self.reply_fifo = asynchat.fifo()
        self.ready = False
        self.debugger = None
        self.nbversion = None
        self.ibuff = []
        self.seqno = 0
        self.last_seqno = 0
        self.set_terminator('\n')
Exemple #25
0
 def __init__(self, server, conn, addr, map=None):
     """The constructor"""
     self.ac_in_buffer = ''
     self.ac_out_buffer = ''
     self.producer_fifo = fifo()
     self.map = map
     dispatcher.__init__ (self, conn, self.map)
     self.__server = server
     self.__conn = conn
     self.__addr = addr
     self.__line = []
     self.__state = self.COMMAND
     self.__greeting = 0
     self.__mailfrom = None
     self.__mail_options = []
     self.__rcpttos = []
     self.__rcptopts = []
     self.__data = ''
     self.__fqdn = gethostbyaddr(gethostbyname(gethostname()))[0]
     self.__peer = conn.getpeername()
     self.push('220 %s %s' % (self.__fqdn, server.banner))
     self.set_terminator('\r\n')
     self.__getaddr = getaddr
Exemple #26
0
 def __init__(self, server, conn, addr, map=None):
     """The constructor"""
     self.ac_in_buffer = ''
     self.ac_out_buffer = ''
     self.producer_fifo = fifo()
     self.map = map
     dispatcher.__init__(self, conn, self.map)
     self.__server = server
     self.__conn = conn
     self.__addr = addr
     self.__line = []
     self.__state = self.COMMAND
     self.__greeting = 0
     self.__mailfrom = None
     self.__mail_options = []
     self.__rcpttos = []
     self.__rcptopts = []
     self.__data = ''
     self.__fqdn = gethostbyaddr(gethostbyname(gethostname()))[0]
     self.__peer = conn.getpeername()
     self.push('220 %s %s' % (self.__fqdn, server.banner))
     self.set_terminator('\r\n')
     self.__getaddr = getaddr
 def asynchat_monkey_init(self, conn=None, map=None):
     self.ac_in_buffer = b''
     self.ac_out_buffer = b''
     self.producer_fifo = asynchat.fifo()
     asyncore.dispatcher.__init__(self, sock=conn, map=map)
Exemple #28
0
 def asynchat_monkey_init(self, conn=None, map=None):
     self.ac_in_buffer = ''
     self.ac_out_buffer = ''
     self.producer_fifo = asynchat.fifo()
     asyncore.dispatcher.__init__ (self, sock=conn, map=map)
Exemple #29
0
 def __init__(self, sock):
     self.ac_in_buffer = ''
     self.ac_out_buffer = ''
     self.producer_fifo = asynchat.fifo()
     UdpDispatcher.__init__(self, sock)
     return