Return True if a function for this endpoint likely exists in client.py.
(method, endpoint, file_name)
| 184 | |
| 185 | |
| 186 | def check_method_in_file(method, endpoint, file_name): |
| 187 | """ |
| 188 | Return True if a function for this endpoint likely exists in client.py. |
| 189 | """ |
| 190 | if not os.path.isfile(file_name): |
| 191 | print(f"{file_name} does not exist") |
| 192 | return False |
| 193 | |
| 194 | func_name, stripped_path, version = get_request_function_and_path(endpoint) |
| 195 | |
| 196 | # If no known request function is found, we consider it not found. |
| 197 | if not func_name or not stripped_path: |
| 198 | print(f"No known request function for endpoint: {endpoint}") |
| 199 | return False |
| 200 | |
| 201 | with open(file_name, "r", encoding="utf-8") as f: |
| 202 | content = f.read() |
| 203 | |
| 204 | # Remove any leftover version tokens from the path |
| 205 | stripped_path = re.sub(r"^v\d+/", "", stripped_path) |
| 206 | stripped_path = re.sub(r"/v\d+/", "/", stripped_path) |
| 207 | |
| 208 | patterns = [] |
| 209 | |
| 210 | if func_name == "_request_api": |
| 211 | if version == 3: |
| 212 | # v3 endpoints use PRIVATE_API_VERSION or "v3" |
| 213 | patterns.extend([ |
| 214 | # Direct request with PRIVATE_API_VERSION |
| 215 | rf'{re.escape(func_name)}\s*\(\s*"{re.escape(method.lower())}"\s*,\s*"{re.escape(stripped_path)}"[\s\S]*?version\s*=\s*self\.PRIVATE_API_VERSION[\s\S]*?\)', |
| 216 | # Direct request with "v3" |
| 217 | rf'{re.escape(func_name)}\s*\(\s*"{re.escape(method.lower())}"\s*,\s*"{re.escape(stripped_path)}"[\s\S]*?version\s*=\s*["\']v3["\'][\s\S]*?\)', |
| 218 | # Helper method with PRIVATE_API_VERSION |
| 219 | rf'_{method.lower()}\s*\(\s*"{re.escape(stripped_path)}"(?:\s*,\s*(?:True|False))?[\s\S]*?version\s*=\s*self\.PRIVATE_API_VERSION[\s\S]*?\)', |
| 220 | # Helper method with "v3" |
| 221 | rf'_{method.lower()}\s*\(\s*"{re.escape(stripped_path)}"(?:\s*,\s*(?:True|False))?[\s\S]*?version\s*=\s*["\']v3["\'][\s\S]*?\)', |
| 222 | ]) |
| 223 | elif version == 1: |
| 224 | # v1 endpoints can use either no version arg, PUBLIC_API_VERSION, or "v1" |
| 225 | patterns.extend([ |
| 226 | # Direct request with no version |
| 227 | rf'{re.escape(func_name)}\s*\(\s*"{re.escape(method.lower())}"\s*,\s*"{re.escape(stripped_path)}"[\s\S]*?\)', |
| 228 | # Direct request with PUBLIC_API_VERSION |
| 229 | rf'{re.escape(func_name)}\s*\(\s*"{re.escape(method.lower())}"\s*,\s*"{re.escape(stripped_path)}"[\s\S]*?version\s*=\s*self\.PUBLIC_API_VERSION[\s\S]*?\)', |
| 230 | # Direct request with "v1" |
| 231 | rf'{re.escape(func_name)}\s*\(\s*"{re.escape(method.lower())}"\s*,\s*"{re.escape(stripped_path)}"[\s\S]*?version\s*=\s*["\']v1["\'][\s\S]*?\)', |
| 232 | # Helper method with no version |
| 233 | rf'_{method.lower()}\s*\(\s*"{re.escape(stripped_path)}"(?:\s*,\s*(?:True|False))?[\s\S]*?\)', |
| 234 | # Helper method with PUBLIC_API_VERSION |
| 235 | rf'_{method.lower()}\s*\(\s*"{re.escape(stripped_path)}"(?:\s*,\s*(?:True|False))?[\s\S]*?version\s*=\s*self\.PUBLIC_API_VERSION[\s\S]*?\)', |
| 236 | # Helper method with "v1" |
| 237 | rf'_{method.lower()}\s*\(\s*"{re.escape(stripped_path)}"(?:\s*,\s*(?:True|False))?[\s\S]*?version\s*=\s*["\']v1["\'][\s\S]*?\)', |
| 238 | ]) |
| 239 | else: |
| 240 | # Non-API requests (margin, futures, etc.) |
| 241 | patterns.append( |
| 242 | rf'{re.escape(func_name)}\s*\(\s*"{re.escape(method.lower())}"\s*,\s*"{re.escape(stripped_path)}"' |
| 243 | ) |
no test coverage detected
searching dependent graphs…