http-content-parser 0.0.21__tar.gz → 0.0.22__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/PKG-INFO +1 -1
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/pyproject.toml +1 -1
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/curl_parser.py +80 -2
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/tests/test_api_model_parser.py +2 -1
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/.gitignore +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/LICENSE +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/README.md +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/requirements.txt +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/__init__.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/api_parser.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/generate_api_file.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/openapi_parser.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/param_util.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/postman_parser.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/req_data.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/swagger2_parser.py +0 -0
- {http_content_parser-0.0.21 → http_content_parser-0.0.22}/tests/test_curl.py +0 -0
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/curl_parser.py
RENAMED
|
@@ -64,7 +64,7 @@ class CurlParser(object):
|
|
|
64
64
|
line_num_array.append([start_num, num])
|
|
65
65
|
return line_num_array
|
|
66
66
|
|
|
67
|
-
def
|
|
67
|
+
def split_curl_to_struct_old(self, lines, s, e, url_filter=None) -> dict:
|
|
68
68
|
req_data = {}
|
|
69
69
|
header = {}
|
|
70
70
|
reduced_lines = self.reduce_curl_data_part(lines=lines, s=s, e=e)
|
|
@@ -109,7 +109,6 @@ class CurlParser(object):
|
|
|
109
109
|
else:
|
|
110
110
|
curl_data = line_i_list[0]
|
|
111
111
|
body = re.sub(r"\n\s*", "", curl_data.replace(" \\\n", ""))
|
|
112
|
-
# body = re.sub(r"\s*", "", curl_data.replace(" \\\n", ""))
|
|
113
112
|
req_data["body"] = body[:-1]
|
|
114
113
|
|
|
115
114
|
if not req_data.get("method"):
|
|
@@ -120,3 +119,82 @@ class CurlParser(object):
|
|
|
120
119
|
req_data["method"] = "get"
|
|
121
120
|
|
|
122
121
|
return req_data
|
|
122
|
+
|
|
123
|
+
def split_curl_to_struct(self, lines, s, e, url_filter=None) -> dict:
|
|
124
|
+
req_data = {}
|
|
125
|
+
header = {}
|
|
126
|
+
|
|
127
|
+
reduced_lines = self.reduce_curl_data_part(lines=lines, s=s, e=e)
|
|
128
|
+
|
|
129
|
+
for line in reduced_lines:
|
|
130
|
+
line = str(line).strip()
|
|
131
|
+
|
|
132
|
+
# ---------------------------
|
|
133
|
+
# 解析 method 和 URL
|
|
134
|
+
# ---------------------------
|
|
135
|
+
if line.startswith("curl"):
|
|
136
|
+
parts = line.split()
|
|
137
|
+
|
|
138
|
+
for part in parts:
|
|
139
|
+
p = part.strip("'\"")
|
|
140
|
+
|
|
141
|
+
# method
|
|
142
|
+
if p.lower() in ["get", "post", "put", "delete"]:
|
|
143
|
+
req_data["method"] = p.lower()
|
|
144
|
+
|
|
145
|
+
# URL
|
|
146
|
+
elif p.startswith("http"):
|
|
147
|
+
req_data["original_url"] = p
|
|
148
|
+
elif "/" in p and "://" not in p: # Postman 样式
|
|
149
|
+
req_data["original_url"] = p
|
|
150
|
+
|
|
151
|
+
# url_filter
|
|
152
|
+
if url_filter and url_filter not in line:
|
|
153
|
+
continue
|
|
154
|
+
|
|
155
|
+
# ---------------------------
|
|
156
|
+
# -X METHOD
|
|
157
|
+
# ---------------------------
|
|
158
|
+
elif line.startswith("-X") or " -X " in line:
|
|
159
|
+
# 例如:-X POST
|
|
160
|
+
parts = line.replace("\\", "").split()
|
|
161
|
+
if len(parts) >= 2:
|
|
162
|
+
req_data["method"] = parts[1].strip("'\"").lower()
|
|
163
|
+
|
|
164
|
+
# ---------------------------
|
|
165
|
+
# Header 解析
|
|
166
|
+
# ---------------------------
|
|
167
|
+
elif line.startswith("-H") or "--header" in line:
|
|
168
|
+
# 支持各种写法
|
|
169
|
+
m = re.search(r"'(.+?):\s*(.+?)'", line)
|
|
170
|
+
if m:
|
|
171
|
+
key = m.group(1)
|
|
172
|
+
val = m.group(2)
|
|
173
|
+
header[key] = val
|
|
174
|
+
|
|
175
|
+
# ---------------------------
|
|
176
|
+
# Body 解析
|
|
177
|
+
# ---------------------------
|
|
178
|
+
elif "--data" in line or "--data-raw" in line:
|
|
179
|
+
# 去掉行尾的转义符
|
|
180
|
+
clean = line.replace("\\\n", "").strip()
|
|
181
|
+
|
|
182
|
+
# 提取单引号内容
|
|
183
|
+
m = re.search(r"'(.*)'$", clean)
|
|
184
|
+
if m:
|
|
185
|
+
req_data["body"] = m.group(1)
|
|
186
|
+
else:
|
|
187
|
+
# 兼容无引号情况
|
|
188
|
+
req_data["body"] = clean.split("--data")[-1].strip()
|
|
189
|
+
|
|
190
|
+
# 如果没有 method,则默认 POST
|
|
191
|
+
req_data.setdefault("method", "post")
|
|
192
|
+
|
|
193
|
+
# ---------------------------
|
|
194
|
+
# 最终补齐数据
|
|
195
|
+
# ---------------------------
|
|
196
|
+
req_data.setdefault("method", "get")
|
|
197
|
+
req_data["header"] = header
|
|
198
|
+
req_data.setdefault("original_url", "")
|
|
199
|
+
|
|
200
|
+
return req_data
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import json
|
|
1
2
|
from http_content_parser.api_parser import ApiModelParser
|
|
2
3
|
|
|
3
4
|
|
|
@@ -7,4 +8,4 @@ api_parser = ApiModelParser()
|
|
|
7
8
|
def test_curl_parser():
|
|
8
9
|
curl_file = "./tmp"
|
|
9
10
|
api_info = api_parser.get_api_list_for_curl(curl_file=curl_file)
|
|
10
|
-
print(api_info)
|
|
11
|
+
print(json.dumps(api_info, indent=4))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/__init__.py
RENAMED
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/api_parser.py
RENAMED
|
File without changes
|
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/openapi_parser.py
RENAMED
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/param_util.py
RENAMED
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/postman_parser.py
RENAMED
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/req_data.py
RENAMED
|
File without changes
|
{http_content_parser-0.0.21 → http_content_parser-0.0.22}/src/http_content_parser/swagger2_parser.py
RENAMED
|
File without changes
|
|
File without changes
|