관리-도구
편집 파일: agent.cpython-37.pyc
B � df � @ sf d Z ddlZddlZddlmZmZ ddlmZ ddlm Z ddl mZ ddlm Z G d d � d �ZdS )zH This module contains contains classes implementing SSA Agent behaviour � N)�Thread�current_thread� )� agent_sock)�SSAError)� create_socket)�RequestProcessorc @ sF e Zd ZdZdd� Zdd�dd�Zddd �d d�Zded �dd�ZdS )�SimpleAgentz SSA Simple Agent class c C s t �d�| _t� | _| �� d S )N�agent)�loggingZ getLogger�loggerr �request_processor�listen)�self� r �:/opt/alt/python37/lib/python3.7/site-packages/ssa/agent.py�__init__ s zSimpleAgent.__init__N)�returnc C sF t t�}x8|�� \}}t| j|fd�}|�� | j�d|j� q W dS )z( Start listening socket )�target�argsz[%s] StartedN) r r Zacceptr �handle�startr �debug�name)r Z_socket� connectionZaddress�tr r r r s zSimpleAgent.listenz socket object)r r c C sn |j dd�}y| �|�}| j�|� W n: tk r` } z| j�dt� jt |�� W dd}~X Y nX |� � dS )z� Handle incoming connection :param connection: socket object usable to send and receive data on the connection �ignore)�errorszHandled exception in [%s]: %sN)Zmakefile� read_inputr r r r �errorr r �str�close)r r ZfileobjZ input_data�er r r r * s zSimpleAgent.handlezfile object)�fileior c C s8 |� � }| j�dt� jt|�� �|� tj|� � dd�S )zy Read input data and return decoded json :param fileio: a file-like object providing read method z[%s] I received %i bytes: %sF)�strict) �readr �infor r �len�encode�json�loads�strip)r r# �datar r r r : s zSimpleAgent.read_input) �__name__� __module__�__qualname__�__doc__r r r �dictr r r r r r s r )r0 r) r Z threadingr r Zinternal.constantsr Zinternal.exceptionsr Zinternal.utilsr Zmodules.processorr r r r r r �<module> s