ó ByòYc@slddlZddlZddlZddlZy*ddlmZmZddlmZWn-e k r‰ddl mZmZmZnXddl m Z ddl mZejeƒZejeƒee_ejejƒdZdZd Zd Zd Zd Zd „Zdefd„ƒYZej ddddgƒZ!ej dddgƒZ"ddd„ƒYZ#dS(iÿÿÿÿN(turlopentRequest(tURLError(RRR(t AUTH_TOKEN(tlocal_cloudwatch_handlersX-Amz-InvocationIdsX-Amz-Client-Contextt AuthorizationsX-Amz-Invocation-TypesX-Amz-Function-Errors 2016-11-01cs"tjˆƒ‡fd†ƒ}|S(NcsJyˆ||ŽSWn2tk rE}tj|ƒtt|ƒƒ‚nXdS(N(Rtruntime_loggert exceptiont IPCExceptiontstr(targstkwargste(tfunc(sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pytwrapped's  (t functoolstwraps(R R((R sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pytwrap_urllib_exceptions&sRcBseZRS((t__name__t __module__(((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyR2stWorkItemt invocation_idtpayloadtclient_contexttGetWorkResultOutputtfunc_errt IPCClientcBs}eZdZddd„Zedd„ƒZed„ƒZed„ƒZed„ƒZed „ƒZ d „Z d „Z RS( sŠ Client for IPC that provides methods for getting/posting work for functions, as well as getting/posting results of the work. t localhosti@cCs||_||_t|_dS(sÔ :param endpoint: Endpoint used to connect to IPC. Generally, IPC and functions always run on the same box, so endpoint should always be 'localhost' in production. You can override it for testing purposes. :type endpoint: str :param port: Port number used to connect to the :code:`endpoint`. Similarly to :code:`endpoint`, can be overridden for testing purposes. :type port: int N(tendpointtportRt auth_token(tselfRR((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyt__init__@s  tRequestResponsec Cs«|j|ƒ}tjdj||ƒƒt||p7dƒ}|jt|ƒ|jt|jƒ|jt |ƒt |ƒ}|jƒj t ƒ}tjdj|ƒƒ|S(sH Send work item to specified :code:`function_arn`. :param function_arn: Arn of the Lambda function intended to receive the work for processing. :type function_arn: string :param input_bytes: The data making up the work being posted. :type input_bytes: bytes :param client_context: The base64 encoded client context byte string that will be provided to the Lambda function being invoked. :type client_context: bytes :returns: Invocation ID for obtaining result of the work. :type returns: str s$Posting work for function [{}] to {}ts#Work posted with invocation id [{}]( t_get_urlRtinfotformatRt add_headertHEADER_CLIENT_CONTEXTtHEADER_AUTH_TOKENRtHEADER_INVOCATION_TYPERtgettHEADER_INVOCATION_ID( Rt function_arnt input_bytesRtinvocation_typeturltrequesttresponseR((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyt post_workPs cCs²|j|ƒ}tjdj||ƒƒt|ƒ}|jt|jƒt|ƒ}|jƒj t ƒ}|jƒj t ƒ}tjdj|ƒƒt d|d|j ƒd|ƒS(s= Retrieve the next work item for specified :code:`function_arn`. :param function_arn: Arn of the Lambda function intended to receive the work for processing. :type function_arn: string :returns: Next work item to be processed by the function. :type returns: WorkItem s&Getting work for function [{}] from {}s%Got work item with invocation id [{}]RRR(t _get_work_urlRR$R%RR&R(RRR*R+R'Rtread(RR,R/R0R1RR((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pytget_workps    cCs|j|ƒ}tjdj|j|ƒƒt||jp=dƒ}|jt|jƒ|jt |j ƒt |ƒtjdj|jƒƒdS(sk Post the result of processing work item by :code:`function_arn`. :param function_arn: Arn of the Lambda function intended to receive the work for processing. :type function_arn: string :param work_item: The WorkItem holding the results of the work being posted. :type work_item: WorkItem :returns: None s0Posting work result for invocation id [{}] to {}R"s)Posted work result for invocation id [{}]N( R3RR$R%RRRR&R+R(RR(RR,t work_itemR/R0((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pytpost_work_resultŒs  cCs­|j|ƒ}tjdj||ƒƒtji|d6ƒjdƒ}t||ƒ}|jt |ƒ|jt dƒ|jt |j ƒt |ƒtjdj|ƒƒdS(sí Post the error message from executing the function handler for :code:`function_arn` with specifid :code:`invocation_id` :param function_arn: Arn of the Lambda function which has the handler error message. :type function_arn: string :param invocation_id: Invocation ID of the work that is being requested :type invocation_id: string :param handler_err: the error message caught from handler :type handler_err: string s2Posting handler error for invocation id [{}] to {}t errorMessagesutf-8tHandleds+Posted handler error for invocation id [{}]N(R3RR$R%tjsontdumpstencodeRR&R+tHEADER_FUNCTION_ERR_TYPER(RR(RR,Rt handler_errR/RR0((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pytpost_handler_err¥s    cCs­|j|ƒ}tjdj||ƒƒt|ƒ}|jt|ƒ|jt|jƒt |ƒ}tjdj|ƒƒ|j ƒ}|jƒj t ƒ}t d|d|ƒS(s# Retrieve the result of the work processed by :code:`function_arn` with specified :code:`invocation_id`. :param function_arn: Arn of the Lambda function intended to receive the work for processing. :type function_arn: string :param invocation_id: Invocation ID of the work that is being requested :type invocation_id: string :returns: The get work result output contains result payload and function error type if the invoking is failed. :type returns: GetWorkResultOutput s2Getting work result for invocation id [{}] from {}s!Got result for invocation id [{}]RR(R#RR$R%RR&R+R(RRR4R*R=R(RR,RR/R0R1RR((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pytget_work_resultÆs   c Cs(djd|jd|jdtd|ƒS(Ns;http://{endpoint}:{port}/{version}/functions/{function_arn}RRtversionR,(R%RRtIPC_API_VERSION(RR,((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyR#ès cCsdjd|j|ƒƒS(Ns{base_url}/worktbase_url(R%R#(RR,((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyR3ís( RRt__doc__R RR2R5R7R?R@R#R3(((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyR:s!" (($t collectionsRtloggingR:turllib.requestRRt urllib.errorRt ImportErrorturllib2tgreengrass_common.env_varsRt%greengrass_common.common_log_appenderRt getLoggerRRt addHandlertFalset propagatetsetLeveltDEBUGR+R'R(R)R=RBRt ExceptionRt namedtupleRRR(((sš/rhel5pdi/workplace/yunusko/lambda-blueprints/src/LambdaConsoleResources/blueprints/greengrass-hello-world/test/../greengrass_ipc_python_sdk/ipc_client.pyts2