From becf59db4255e4ce9577a9559c3c9b10d4ee64f0 Mon Sep 17 00:00:00 2001 From: Prasanth Date: Sat, 15 Jul 2023 17:09:57 +0000 Subject: [PATCH] support toml and yaml configuration files --- Pipfile | 2 + Pipfile.lock | 124 ++++++++++++++++++++++++++++++----------- dothttp/__init__.py | 36 +++++++++--- dothttp/__version__.py | 2 +- requirements.txt | 4 +- 5 files changed, 128 insertions(+), 40 deletions(-) diff --git a/Pipfile b/Pipfile index 8913762..2f4c341 100644 --- a/Pipfile +++ b/Pipfile @@ -16,6 +16,8 @@ requests_ntlm = "==1.1.0" RestrictedPython = "==6.1" Faker = "==13.11.1" requests-hawk = "==1.1.1" +toml = "0.10.2" +pyyaml = "6.0" [dev-packages] pyinstaller = "*" diff --git a/Pipfile.lock b/Pipfile.lock index ab49a18..d4c2934 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "d1bf9c8d3cdeac0ec718c619253ea7ab54608de179c0e8d1c8e27ee59b8a8985" + "sha256": "be314c15be1dd73e65ca57e16c62ad0aed84ddc84e56269855e7d61560c723b1" }, "pipfile-spec": 6, "requires": { @@ -28,7 +28,7 @@ "sha256:1f28b4522cdc2fb4256ac1a020c78acf9cba2c6b461ccd2c126f3aa8e8335d04", "sha256:6279836d581513a26f1bf235f9acd333bc9115683f14f7e8fae46c98fc50e015" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==23.1.0" }, "certifi": { @@ -215,7 +215,7 @@ "sha256:f14ad275364c8b4e525d018f6716537ae7b6d369c094805cae45300847e0894f", "sha256:f772610fe364372de33d76edcd313636a25684edb94cee53fd790195f5989d14" ], - "index": "pypi", + "markers": "python_version >= '3.7'", "version": "==41.0.2" }, "faker": { @@ -324,7 +324,7 @@ "sha256:f0774bf48631f3a20471dd7c5989657b639fd2d285b861237ea9e82c36a415a9", "sha256:f0e7c4b2f77593871e918be000b96c8107da48444d57005b6a6bc61fb4331b2c" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==0.19.3" }, "python-dateutil": { @@ -335,6 +335,52 @@ "markers": "python_version >= '2.7' and python_version not in '3.0, 3.1, 3.2, 3.3'", "version": "==2.8.2" }, + "pyyaml": { + "hashes": [ + "sha256:01b45c0191e6d66c470b6cf1b9531a771a83c1c4208272ead47a3ae4f2f603bf", + "sha256:0283c35a6a9fbf047493e3a0ce8d79ef5030852c51e9d911a27badfde0605293", + "sha256:055d937d65826939cb044fc8c9b08889e8c743fdc6a32b33e2390f66013e449b", + "sha256:07751360502caac1c067a8132d150cf3d61339af5691fe9e87803040dbc5db57", + "sha256:0b4624f379dab24d3725ffde76559cff63d9ec94e1736b556dacdfebe5ab6d4b", + "sha256:0ce82d761c532fe4ec3f87fc45688bdd3a4c1dc5e0b4a19814b9009a29baefd4", + "sha256:1e4747bc279b4f613a09eb64bba2ba602d8a6664c6ce6396a4d0cd413a50ce07", + "sha256:213c60cd50106436cc818accf5baa1aba61c0189ff610f64f4a3e8c6726218ba", + "sha256:231710d57adfd809ef5d34183b8ed1eeae3f76459c18fb4a0b373ad56bedcdd9", + "sha256:277a0ef2981ca40581a47093e9e2d13b3f1fbbeffae064c1d21bfceba2030287", + "sha256:2cd5df3de48857ed0544b34e2d40e9fac445930039f3cfe4bcc592a1f836d513", + "sha256:40527857252b61eacd1d9af500c3337ba8deb8fc298940291486c465c8b46ec0", + "sha256:432557aa2c09802be39460360ddffd48156e30721f5e8d917f01d31694216782", + "sha256:473f9edb243cb1935ab5a084eb238d842fb8f404ed2193a915d1784b5a6b5fc0", + "sha256:48c346915c114f5fdb3ead70312bd042a953a8ce5c7106d5bfb1a5254e47da92", + "sha256:50602afada6d6cbfad699b0c7bb50d5ccffa7e46a3d738092afddc1f9758427f", + "sha256:68fb519c14306fec9720a2a5b45bc9f0c8d1b9c72adf45c37baedfcd949c35a2", + "sha256:77f396e6ef4c73fdc33a9157446466f1cff553d979bd00ecb64385760c6babdc", + "sha256:81957921f441d50af23654aa6c5e5eaf9b06aba7f0a19c18a538dc7ef291c5a1", + "sha256:819b3830a1543db06c4d4b865e70ded25be52a2e0631ccd2f6a47a2822f2fd7c", + "sha256:897b80890765f037df3403d22bab41627ca8811ae55e9a722fd0392850ec4d86", + "sha256:98c4d36e99714e55cfbaaee6dd5badbc9a1ec339ebfc3b1f52e293aee6bb71a4", + "sha256:9df7ed3b3d2e0ecfe09e14741b857df43adb5a3ddadc919a2d94fbdf78fea53c", + "sha256:9fa600030013c4de8165339db93d182b9431076eb98eb40ee068700c9c813e34", + "sha256:a80a78046a72361de73f8f395f1f1e49f956c6be882eed58505a15f3e430962b", + "sha256:afa17f5bc4d1b10afd4466fd3a44dc0e245382deca5b3c353d8b757f9e3ecb8d", + "sha256:b3d267842bf12586ba6c734f89d1f5b871df0273157918b0ccefa29deb05c21c", + "sha256:b5b9eccad747aabaaffbc6064800670f0c297e52c12754eb1d976c57e4f74dcb", + "sha256:bfaef573a63ba8923503d27530362590ff4f576c626d86a9fed95822a8255fd7", + "sha256:c5687b8d43cf58545ade1fe3e055f70eac7a5a1a0bf42824308d868289a95737", + "sha256:cba8c411ef271aa037d7357a2bc8f9ee8b58b9965831d9e51baf703280dc73d3", + "sha256:d15a181d1ecd0d4270dc32edb46f7cb7733c7c508857278d3d378d14d606db2d", + "sha256:d4b0ba9512519522b118090257be113b9468d804b19d63c71dbcf4a48fa32358", + "sha256:d4db7c7aef085872ef65a8fd7d6d09a14ae91f691dec3e87ee5ee0539d516f53", + "sha256:d4eccecf9adf6fbcc6861a38015c2a64f38b9d94838ac1810a9023a0609e1b78", + "sha256:d67d839ede4ed1b28a4e8909735fc992a923cdb84e618544973d7dfc71540803", + "sha256:daf496c58a8c52083df09b80c860005194014c3698698d1a57cbcfa182142a3a", + "sha256:dbad0e9d368bb989f4515da330b88a057617d16b6a8245084f1b05400f24609f", + "sha256:e61ceaab6f49fb8bdfaa0f92c4b57bcfbea54c09277b1b4f7ac376bfb7a7c174", + "sha256:f84fbc98b019fef2ee9a1cb3ce93e3187a6df0b2538a651bfb890254ba9f90b5" + ], + "index": "pypi", + "version": "==6.0" + }, "requests": { "hashes": [ "sha256:58cd2187c01e70e6e26505bca751777aa9f2ee0b7f4300988b709f44e013003f", @@ -396,7 +442,7 @@ "sha256:11e52c67415a381d10d6b462ced9cfb97066179f0e871399e006c4ab101fc85f", "sha256:baf1fdb41c6da4cd2eae722e135500da913332ab3f2f5c7d33af9b492acb5235" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==68.0.0" }, "six": { @@ -415,12 +461,20 @@ "index": "pypi", "version": "==3.1.1" }, + "toml": { + "hashes": [ + "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b", + "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f" + ], + "index": "pypi", + "version": "==0.10.2" + }, "tzlocal": { "hashes": [ "sha256:46eb99ad4bdb71f3f72b7d24f4267753e240944ecfc16f25d2719ba89827a803", "sha256:f3596e180296aaf2dbd97d124fe76ae3a0e3d32b258447de7b939b3fd4be992f" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==5.0.1" }, "urllib3": { @@ -428,7 +482,7 @@ "sha256:48e7fafa40319d358848e1bc6809b208340fafe2096f1725d05d67443d0483d1", "sha256:bee28b5e56addb8226c96f7f13ac28cb4c301dd5ea8a6ca179c0b9835e032825" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==2.0.3" } }, @@ -462,6 +516,14 @@ ], "version": "==0.2.0" }, + "blinker": { + "hashes": [ + "sha256:4afd3de66ef3a9f8067559fb7a1cbe555c17dcbe15971b05d1b625c3e7abe213", + "sha256:c3d739772abb7bc2860abf5f2ec284223d9ad5c76da018234f6f50d6f31ab1f0" + ], + "markers": "python_version >= '3.7'", + "version": "==1.6.2" + }, "click": { "hashes": [ "sha256:4be4b1af8d665c6d942909916d31a213a106800c47d0eeba73d34da3cbc11367", @@ -487,11 +549,11 @@ }, "flask": { "hashes": [ - "sha256:7eb373984bf1c770023fce9db164ed0c3353cd0b53f130f4693da0ca756a2e6d", - "sha256:c0bec9477df1cb867e5a67c9e1ab758de9cb4a3e52dd70681f59fa40a62b3f2d" + "sha256:77fd4e1249d8c9923de34907236b747ced06e5467ecac1a7bb7115ae0e9670b0", + "sha256:8c2f9abd47a9e8df7f0c3f091ce9497d011dc3b31effcf4c85a6e2b50f4114ef" ], "index": "pypi", - "version": "==2.2.3" + "version": "==2.3.2" }, "iniconfig": { "hashes": [ @@ -503,11 +565,11 @@ }, "ipython": { "hashes": [ - "sha256:1c183bf61b148b00bcebfa5d9b39312733ae97f6dad90d7e9b4d86c8647f498c", - "sha256:a950236df04ad75b5bc7f816f9af3d74dc118fd42f2ff7e80e8e60ca1f182e2d" + "sha256:1d197b907b6ba441b692c48cf2a3a2de280dc0ac91a3405b39349a50272ca0a1", + "sha256:248aca623f5c99a6635bc3857677b7320b9b8039f99f070ee0d20a5ca5a8e6bf" ], "index": "pypi", - "version": "==8.12.0" + "version": "==8.14.0" }, "itsdangerous": { "hashes": [ @@ -641,7 +703,7 @@ "sha256:04505ade687dc26dc4284b1ad19a83be2f2afe83e7a828ace0c72f3a1df72aac", "sha256:9dffbe1d8acf91e3de75f3b544e4842382fc06c6babe903ac9acb74dc6e08d88" ], - "markers": "python_version >= '3.7'", + "markers": "python_full_version >= '3.7.0'", "version": "==3.0.39" }, "ptyprocess": { @@ -683,21 +745,21 @@ }, "pyinstaller": { "hashes": [ - "sha256:247b99c52dc3cf69eba905da30dbca0a8ea309e1058cab44658ac838d9b8f2f0", - "sha256:2d16641a495593d174504263b038a6d3d46b3b15a381ccb216cf6cce67723512", - "sha256:333b4ffda38d9c0a561c38429dd9848d37aa78f3b8ea8a6f2b2e69a60d523c02", - "sha256:6afc7aa4885ffd3e6121a8cf2138830099f874c18cb5869bed8c1a42db82d060", - "sha256:6ecc464bf56919bf2d6bff275f38d85ff08ae747b8ead3a0c26cf85573b3c723", - "sha256:7a1db833bb0302b66ae3ae337fbd5487699658ce869ca4d538b5359b8179e83a", - "sha256:85e39e36d03355423636907a26a9bfa06fdc93cb1086441b19d2d0ca448479fa", - "sha256:915a502802c751bafd92d568ac57468ec6cdf252b8308aa9a167bbc2c565ad2d", - "sha256:9e9a38f41f8280c8e29b294716992852281b41fbe64ba330ebab671efe27b26d", - "sha256:bb7de35cd209a0a0358aec761a273ae951d2161c03728f15d9a640d06a88e472", - "sha256:df97aaf1103a1c485aa3c9947792a86675e370f5ce9b436b4a84e34a4180c8d2", - "sha256:f677fbc151db1eb00ada94e86ed128e7b359cbd6bf3f6ea815afdde687692d46" + "sha256:0df43697c4914285ecd333be968d2cd042ab9b2670124879ee87931d2344eaf5", + "sha256:1fde4381155f21d6354dc450dcaa338cd8a40aaacf6bd22b987b0f3e1f96f3ee", + "sha256:24009eba63cfdbcde6d2634e9c87f545eb67249ddf3b514e0cd3b2cdaa595828", + "sha256:28d9742c37e9fb518444b12f8c8ab3cb4ba212d752693c34475c08009aa21ccf", + "sha256:2d03419904d1c25c8968b0ad21da0e0f33d8d65716e29481b5bd83f7f342b0c5", + "sha256:3a331951f9744bc2379ea5d65d36f3c828eaefe2785f15039592cdc08560b262", + "sha256:5e446df41255e815017d96318e39f65a3eb807e74a796c7e7ff7f13b6366a2e9", + "sha256:78975043edeb628e23a73fb3ef0a273cda50e765f1716f75212ea3e91b09dede", + "sha256:7fdd319828de679f9c5e381eff998ee9b4164bf4457e7fca56946701cf002c3f", + "sha256:9fc27c5a853b14a90d39c252707673c7a0efec921cd817169aff3af0fca8c127", + "sha256:cd7d5c06f2847195a23d72ede17c60857d6f495d6f0727dc6c9bc1235f2eb79c", + "sha256:e5fb17de6c325d3b2b4ceaeb55130ad7100a79096490e4c5b890224406fa42f4" ], "index": "pypi", - "version": "==5.10.1" + "version": "==5.13.0" }, "pyinstaller-hooks-contrib": { "hashes": [ @@ -741,18 +803,18 @@ }, "pywin32-ctypes": { "hashes": [ - "sha256:24ffc3b341d457d48e8922352130cf2644024a4ff09762a2261fd34c36ee5942", - "sha256:9dc2d991b3479cc2df15930958b674a48a227d5361d413827a4cfd0b5876fc98" + "sha256:3426e063bdd5fd4df74a14fa3cf80a0b42845a87e1d1e81f6549f9daec593a60", + "sha256:bf490a1a709baf35d688fe0ecf980ed4de11d2b3e37b51e5442587a75d9957e7" ], "markers": "os_name == 'nt'", - "version": "==0.2.0" + "version": "==0.2.2" }, "setuptools": { "hashes": [ "sha256:11e52c67415a381d10d6b462ced9cfb97066179f0e871399e006c4ab101fc85f", "sha256:baf1fdb41c6da4cd2eae722e135500da913332ab3f2f5c7d33af9b492acb5235" ], - "markers": "python_full_version >= '3.7.0'", + "markers": "python_version >= '3.7'", "version": "==68.0.0" }, "six": { diff --git a/dothttp/__init__.py b/dothttp/__init__.py index 98a26a7..7091514 100644 --- a/dothttp/__init__.py +++ b/dothttp/__init__.py @@ -36,7 +36,8 @@ except ImportError: import json validate = None - +import yaml +import toml from textx import TextXSyntaxError, metamodel_from_file from .dsl_jsonparser import json_or_array_to_json @@ -314,7 +315,6 @@ class Property: key: Union[str, None] = None value: Union[str, None] = None - class BaseModelProcessor: var_regex = re.compile(r'{{(?P.*?)}}') @@ -350,11 +350,26 @@ def load_properties_n_headers(self): """ if not self.property_file and self.file: base_logger.debug('property file not specified') - default = os.path.join(os.path.dirname(self.file), ".dothttp.json") - if os.path.exists(default): + default_json = os.path.join(os.path.dirname(self.file), ".dothttp.json") + default_yaml = os.path.join(os.path.dirname(self.file), ".dothttp.yaml") + default_yml = os.path.join(os.path.dirname(self.file), ".dothttp.yml") + default_toml = os.path.join(os.path.dirname(self.file), ".dothttp.toml") + if os.path.exists(default_json): + base_logger.debug( + f'file: {default_json} exists. it will be used for property reference') + self.property_file = default_json + elif os.path.exists(default_yaml): + base_logger.debug( + f'file: {default_yaml} exists. it will be used for property reference') + self.property_file = default_yaml + elif os.path.exists(default_yml): + base_logger.debug( + f'file: {default_yaml} exists. it will be used for property reference') + self.property_file = default_yml + elif os.path.exists(default_toml): base_logger.debug( - f'file: {default} exists. it will be used for property reference') - self.property_file = default + f'file: {default_yaml} exists. it will be used for property reference') + self.property_file = default_toml if self.property_file and not os.path.exists(self.property_file): base_logger.debug( f'file: {self.property_file} not found') @@ -363,7 +378,14 @@ def load_properties_n_headers(self): if self.property_file: with open(self.property_file, 'r') as f: try: - props = json.load(f) + if self.property_file.endswith('.json'): + props = json.load(f) + elif self.property_file.endswith('.yaml') or self.property_file.endswith('.yml') : + props = yaml.load(f, yaml.SafeLoader) + elif self.property_file.endswith('.toml'): + props = toml.load(f) + else: + raise Exception("unrecognized property file") base_logger.debug( f'file: {self.property_file} loaded successfully') except Exception as e: diff --git a/dothttp/__version__.py b/dothttp/__version__.py index 006d4c8..307f89b 100644 --- a/dothttp/__version__.py +++ b/dothttp/__version__.py @@ -1 +1 @@ -__version__ = '0.0.42.a9' +__version__ = '0.0.42.a10' diff --git a/requirements.txt b/requirements.txt index ff8a286..4fcba2d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -9,4 +9,6 @@ requests-aws4auth==1.1.1 requests_ntlm==1.1.0 RestrictedPython==6.0 Faker==13.11.1 -requests-hawk==1.1.1 \ No newline at end of file +requests-hawk==1.1.1 +PyYaml==6.0 +toml==0.10.2 \ No newline at end of file