From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 517AF9417F0 for ; Fri, 10 Nov 2023 15:41:58 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=bbNSCJazCEe6yZIJwjEfrc1BFltQZchInbc9sDmdiho=; c=relaxed/simple; d=groups.io; h=ARC-Seal:ARC-Message-Signature:ARC-Authentication-Results:From:To:CC:Subject:Thread-Topic:Thread-Index:Date:Message-ID:References:In-Reply-To:Accept-Language:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1699630916; v=1; b=Qh/Wm1hZLGzGIx2zGBk5LSuydSK/CYH5gqFgxuvvj6yxBtthdOe5nNLtEuv0W3HT/8sY6pqz IurIVzgPQ+y7IvWNoThL/e2tNhRz4JIfKfsY+DsN5yivxRp+Vm4mdGkzMwhqkojxf1fzWdu7wY4 eUx2kuSAJRRQNIQwbrcXiiVQ= X-Received: by 127.0.0.2 with SMTP id 9lEvYY7687511x8rSaaMWu5b; Fri, 10 Nov 2023 07:41:56 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web11.30702.1699630916141201218 for ; Fri, 10 Nov 2023 07:41:56 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10890"; a="393072464" X-IronPort-AV: E=Sophos;i="6.03,291,1694761200"; d="scan'208";a="393072464" X-Received: from fmviesa002.fm.intel.com ([10.60.135.142]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Nov 2023 07:41:55 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.03,291,1694761200"; d="scan'208";a="5080399" X-Received: from fmsmsx603.amr.corp.intel.com ([10.18.126.83]) by fmviesa002.fm.intel.com with ESMTP/TLS/AES256-GCM-SHA384; 10 Nov 2023 07:41:55 -0800 X-Received: from fmsmsx612.amr.corp.intel.com (10.18.126.92) by fmsmsx603.amr.corp.intel.com (10.18.126.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 10 Nov 2023 07:41:55 -0800 X-Received: from fmsmsx610.amr.corp.intel.com (10.18.126.90) by fmsmsx612.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34; Fri, 10 Nov 2023 07:41:54 -0800 X-Received: from fmsedg601.ED.cps.intel.com (10.1.192.135) by fmsmsx610.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.34 via Frontend Transport; Fri, 10 Nov 2023 07:41:54 -0800 X-Received: from NAM12-MW2-obe.outbound.protection.outlook.com (104.47.66.41) by edgegateway.intel.com (192.55.55.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.34; Fri, 10 Nov 2023 07:41:53 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oZhxPbac/ip+lWthNgqzi+XE9M/eL+ouTVwtx9eW1yg/5+HFy2tjXOSJIXisLiAwkSVafwaEf0lqSgdMFJjT40ucNKKqxmUZ9PMu3fnAGQnSqu/Lsi7OwTaDt8MV1MRcJvwDH37UottSfKCNehE1Z9baPGY6eZ1QVN4u5Se6glYYA1iVQR22Umx+nShDTXScLlIa0aBsc8D+sHvwo1tudMaz5dRDg6DyoGct6ZKsmfCG4lpPS0s6M+Ty/71i7KU3Pa/FeYazOHS/YWJu9gsLoWFu/9clc9wLAHIuE1qG7OzLycZ8NftCl0sPlg5Q5i6kdvDhyCEz9uCoVFC3aHJciQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Iyjgr/oJ7cLWuL+l+5fbV6hfZYgrTLvQ9dgka6+A5yk=; b=hhYBl0pa4of9gAfoTHqpg/kC9ahylXv1J8OFfmvoe91Dmhbw7aoFNoDGLxvDyO57/EUDHuSO2ehu7ORje7TOgirwGeakBsIBDOrG8xqWuOCSSnVZNr9F1LtIw+w9I/f8KGkv9wR2cFYabFsRrjOiFx2IA0n/6kijwjeC4jIvEdOd7dWaEbJuxbvB7k1QED27bCSHKjlDMP+7JF5tU5g0QBKrMPtJcGrpRIlVpj/WImsjOeTWSYqx7YZeByUE8Pf1f8INDDUoLVvDVPTKCnzRlt1TZXB441hS8/2xDsm+p/89jEdrWuekRu2m6IM/Yro7jF62PTpAwMNMr8n+PL9HCw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none X-Received: from PH7PR11MB5943.namprd11.prod.outlook.com (2603:10b6:510:13f::19) by BN9PR11MB5483.namprd11.prod.outlook.com (2603:10b6:408:104::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6977.19; Fri, 10 Nov 2023 15:41:51 +0000 X-Received: from PH7PR11MB5943.namprd11.prod.outlook.com ([fe80::5d95:6570:48f6:204c]) by PH7PR11MB5943.namprd11.prod.outlook.com ([fe80::5d95:6570:48f6:204c%4]) with mapi id 15.20.6954.028; Fri, 10 Nov 2023 15:41:51 +0000 From: "Jayaprakash, N" To: "devel@edk2.groups.io" , "Jayaprakash, N" CC: Rebecca Cran , "Kinney, Michael D" Subject: Re: [edk2-devel] [edk2-libc Patch 1/1] ek2-libc: Sample python scripts for socket client capabilities on UEFI shell Thread-Topic: [edk2-devel] [edk2-libc Patch 1/1] ek2-libc: Sample python scripts for socket client capabilities on UEFI shell Thread-Index: AQHaCPL2xLMx/gRtQUWH8PkoAJ6RwrBzxqqQ Date: Fri, 10 Nov 2023 15:41:51 +0000 Message-ID: References: <20231027162718.830-1-n.jayaprakash@intel.com> <179203AC4BBFEE91.3183@groups.io> In-Reply-To: <179203AC4BBFEE91.3183@groups.io> Accept-Language: en-IN, en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-publictraffictype: Email x-ms-traffictypediagnostic: PH7PR11MB5943:EE_|BN9PR11MB5483:EE_ x-ms-office365-filtering-correlation-id: 07751317-8127-494e-0bd2-08dbe2038ec2 x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam-message-info: dTebuT/HeaeGOarpNVb3++gh+s51vl4Lce0/HHtUEK3cclptM7mI79y6WVrqIWLEShKt+uj4/HHc8sanbaea4KIEPPXFAiLzFhDNjAlNV/jbwOTV/QLB3/Um8CWsDnm/G842gt9Q+sEu913LOeo59I0wVoB20SiNCUADghbRoD4K3juu+nWhCwWIjCl8rks4xxx4GFoPQHE0BsWiPX1Ugt4AoUIFRB1le58NPANQWNt+xkuESfBRgemT9AiIScCPTSuSrABfJloTg12GtyoRBnZ+KtLQAwlKMlZTeGWRZACps1Ij3pExR5mUmS6qlvdQbN8mxcB42joI0wvM/POctQRjfmVee8xzHUnDhvdZDYwGzOiML7dVx2t5kaf+mZGoWsH417k3i0ejGmbPh/ihxJ7ZYeVIyZwOXEaWsPedRf/WXag8ybmIGQr4kgGNhpCZGgQWdKDP+SX0aiJgiBmbGApSrm/VUTDStnYVDKF66Ss2vRM9lMI/lKGmoJO9d8wYqYE88DaVKt0k7L/5YAWciP1zmWSa+yOC8cW7nhkulD1o5aY+fjZ0s0CD71NPXF+wRS9+XBdixfz2SRtdiJegsGFpGQJ9pd5JHZmVJSGi/5Zkzl/Jesu8u/fMvEimkkq1CEupQ+PWp8cj22ZIKT8Tlg== x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?DyeJAGWvqgGEnBhWOpAtJr0UJo0xGsxtYKRz5wZa6Myk0h7/oMd78jdBQtTJ?= =?us-ascii?Q?Rm+8Tapmozxo9+y7eP99D9SUMWK2t4Am8qgWBAh/hvLv63jAj4W8WsRccgZ9?= =?us-ascii?Q?o7110LNdw8xhRVNwX2EWN5RG3Zhg4psgRdUIXl/OjCCGX5H5gMnuEnxyCvPn?= =?us-ascii?Q?rLGogxv5J2N/B04/cr/0Te+kNsissLWD3GvnJpygaVWHkN7xANO97RIJ4IT/?= =?us-ascii?Q?2rEOb/4V4SO9G2nszG1peLD+UfS815/BO1CEkQckZ6Jc1RjXrFAhaayCgiVM?= =?us-ascii?Q?xcZRoWjFfkBm7WY3a+0sM+xek69M3hOxg88s2SHKSzPyVItR1f7iSsECUlGn?= =?us-ascii?Q?njJiL1VTAKYlayPv9QCR5vHxKR9hF5K01tTOXawHMb9jKtVus7MgYS96PmAU?= =?us-ascii?Q?oVbxuKxTGVwmOLfMKIo2fUA/7f7dHGhZnCbEKQL3X5QbZVRtKok+bF7RV5J4?= =?us-ascii?Q?copa5ZGqp1rNmI4MXG2Ku3mzVtCWdf1Q1qu8cUmdTS3Zf37B0GiUP2kRhuLp?= =?us-ascii?Q?jBkMOHDQ1FAeEA4nEiVbZHNf46FMwj8XNCbfdyyByPs4rVQ+yOHOJUPJrCMY?= =?us-ascii?Q?npA7ZNhY5YSFZ8+xTV4LPMRUcCTD8LgOzrrt54NxeBNMfFAQRwMBStkqQI11?= =?us-ascii?Q?kInUqUYOBHaE52Lfz156c4fJaOH/feccKMmvXsPL6lFa6DdAwlXd7c8Wp6rx?= =?us-ascii?Q?YShASRuIbEpixBxe3DEOzYm9rfCl1JITfdNEjSudyHUb7dj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-Exchange-CrossTenant-AuthSource: PH7PR11MB5943.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 07751317-8127-494e-0bd2-08dbe2038ec2 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Nov 2023 15:41:51.0321 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: PkWtKAuYQirsEI4mhrcIooGz2gw7JEui7AYhcpUvTPPyEmafP7Wee1bNz9Z8nwNaF8yBgHaR6VP2xxNeu+fq9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN9PR11MB5483 X-OriginatorOrg: intel.com Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,n.jayaprakash@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: X5CEVfokgCp26fTSCppHmOsbx7686176AA= Content-Language: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b="Qh/Wm1hZ"; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io These are simple Python apps to demonstrate the usage of socket communicati= on using the HTTP library.=20 Reviewed-by : Jayaprakash N Regards, JP -----Original Message----- From: devel@edk2.groups.io On Behalf Of Jayaprakash,= N Sent: Friday, October 27, 2023 9:57 PM To: devel@edk2.groups.io Cc: Jayaprakash, N ; Rebecca Cran ; Kinney, Michael D Subject: [edk2-devel] [edk2-libc Patch 1/1] ek2-libc: Sample python scripts= for socket client capabilities on UEFI shell REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4580 This BZ has been created to provide the sample python scripts to demonstrat= e the socket client capabilities using http library on UEFI shell with the = help of Python UEFI interpreter. The http_echo_client.py and http_echo_server.py scripts are provided as sam= ple scripts to exercise the python http library from UEFI shell. Cc: Rebecca Cran Cc: Michael D Kinney Cc: Jayaprakash N Signed-off-by: Jayaprakash Nevara --- .../PyMod-3.6.8/Lib/http_echo_client.py | 81 +++++++++++++++++++ .../PyMod-3.6.8/Lib/http_echo_server.py | 61 ++++++++++++++ 2 files changed, 142 insertions(+) create mode 100644 AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib= /http_echo_client.py create mode 100644 AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib= /http_echo_server.py diff --git a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib/http_e= cho_client.py b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib/htt= p_echo_client.py new file mode 100644 index 0000000..ea0368d --- /dev/null +++ b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib/http_echo_ +++ client.py @@ -0,0 +1,81 @@ +""" +This is a sample HTTP echo client sends data to the server and gets=20 +echoed data from the server in response body and prints the same to the=20 +console. + +Note: This application needs to be run from UEFI shell using the Python=20 +UEFI interpreter. +""" + +import sys +import time +from http import client +from http.client import HTTPException +import traceback + +_max_retries =3D 10 +_retry_count =3D 0 + + +def _print_usage(): + print("Sample http echo client application") + print("Usage:") + print("python.efi http_echo_client.py ") + + +if len(sys.argv) !=3D 2: + _print_usage() + sys.exit(0) + +if sys.argv[1] =3D=3D "-h": + _print_usage() + sys.exit(0) + +http_server =3D sys.argv[1] +while True: + try: + name =3D input("Enter the parameter name:") + value =3D input("Enter parameter value:") + print("Connecting to server to send a get request with following p= arameter") + print("{}=3D{}".format(name, value)) + # replace space with %20 + value =3D value.replace(" ", "%20") + conn =3D client.HTTPConnection(http_server) + # Send GET request with some data + conn.request("GET", "/echo?{}=3D{}".format(name, value)) + rsp =3D conn.getresponse() + if rsp.status =3D=3D 204: + print("No content") + break + elif rsp.status =3D=3D 200: + data_received =3D rsp.read() + # replace %20 with space character before displaying to consol= e + data_received =3D data_received.replace(b"%20", b" ") + print("from server:{}".format(data_received)) + conn.close() + print("Closing the connection") + break + else: + print("Invalid response code {}".format(rsp.status)) + conn.close() + print("Closing the connection") + break + except HTTPException as exp: + print("Got exception while connecting to server : {}".format(exp)) + traceback.print_exc() + break + except ConnectionRefusedError as exp: + print("Got exception while connecting to server : {}".format(exp)) + print("Check & start the server, if it is not started") + print( + "Retrying connection after 10 seconds, retry count =3D {}".for= mat( + _retry_count + 1 + ) + ) + if _retry_count =3D=3D _max_retries: + print( + "Exceeded max retries {} exiting the application".format(_= max_retries) + ) + break + time.sleep(10) + _retry_count +=3D 1 diff --git a/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib/http_e= cho_server.py b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib/htt= p_echo_server.py new file mode 100644 index 0000000..eebdf33 --- /dev/null +++ b/AppPkg/Applications/Python/Python-3.6.8/PyMod-3.6.8/Lib/http_echo_ +++ server.py @@ -0,0 +1,61 @@ +""" +This is a sample HTTP echo server that echos the command / data coming=20 +from the client. +Here the data is received from client through GET request in the form=20 +of parameter of GET request. +The parameter is extracted and sent back to the client in the response=20 +body. + +Note that this server sample application needs to be run on a system=20 +booted to OS. +""" + +import os +import socket +import sys +from http.server import BaseHTTPRequestHandler, HTTPServer from=20 +http.client import parse_headers + + +class MyHTTPRequestHandler(BaseHTTPRequestHandler): + """HTTP request handler class""" + + # Handle GET command + def do_GET(self): + print("path {}".format(self.path)) + path =3D self.path.split("?")[0] + param_name =3D self.path.split("?")[1].split("=3D")[0] + param_value =3D self.path.split("?")[1].split("=3D")[1] + print("param name {} value =3D {}".format(param_name, param_value)= ) + if path =3D=3D "/echo": + self.send_response(200) + self.send_header("Content-type", "text/plain") + self.end_headers() + self.wfile.write( + bytes("{}=3D{}".format(param_name, param_value), encoding= =3D"utf-8") + ) + else: + print("invalid request") + self.send_response(204) + + +def run(): + try: + print("Starting the server...") + server_address =3D (socket.gethostbyname(socket.gethostname()), 80= ) + print("Server address :", server_address) + httpd =3D HTTPServer(server_address, MyHTTPRequestHandler) + print("\n\n\nPress CTRL+C to exit server application") + httpd.serve_forever() + except KeyboardInterrupt as exp: + print("KeyboardInterrupt") + sys.exit(0) + except Exception as exp: + print(str(exp)) + + +if __name__ =3D=3D "__main__": + if os.name =3D=3D "edk2": + print("HTTP echo server not supported on EDk2") + sys.exit(0) + run() -- 2.40.0.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#111039): https://edk2.groups.io/g/devel/message/111039 Mute This Topic: https://groups.io/mt/102508927/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-