|
3 | 3 | from __future__ import annotations |
4 | 4 |
|
5 | 5 | import os |
6 | | -from typing import TYPE_CHECKING, Any, Dict, Mapping, cast |
7 | | -from typing_extensions import Self, Literal, override |
| 6 | +from typing import TYPE_CHECKING, Any, Mapping |
| 7 | +from typing_extensions import Self, override |
8 | 8 |
|
9 | 9 | import httpx |
10 | 10 |
|
|
59 | 59 | from .resources.inbound_email import InboundEmailResource, AsyncInboundEmailResource |
60 | 60 |
|
61 | 61 | __all__ = [ |
62 | | - "ENVIRONMENTS", |
63 | 62 | "Timeout", |
64 | 63 | "Transport", |
65 | 64 | "ProxiesTypes", |
|
70 | 69 | "AsyncClient", |
71 | 70 | ] |
72 | 71 |
|
73 | | -ENVIRONMENTS: Dict[str, str] = { |
74 | | - "production": "https://portfolio-parser.api.casparser.in", |
75 | | - "environment_1": "https://client-apis.casparser.in", |
76 | | - "environment_2": "http://localhost:5000", |
77 | | -} |
78 | | - |
79 | 72 |
|
80 | 73 | class CasParser(SyncAPIClient): |
81 | 74 | # client options |
82 | 75 | api_key: str |
83 | 76 |
|
84 | | - _environment: Literal["production", "environment_1", "environment_2"] | NotGiven |
85 | | - |
86 | 77 | def __init__( |
87 | 78 | self, |
88 | 79 | *, |
89 | 80 | api_key: str | None = None, |
90 | | - environment: Literal["production", "environment_1", "environment_2"] | NotGiven = not_given, |
91 | | - base_url: str | httpx.URL | None | NotGiven = not_given, |
| 81 | + base_url: str | httpx.URL | None = None, |
92 | 82 | timeout: float | Timeout | None | NotGiven = not_given, |
93 | 83 | max_retries: int = DEFAULT_MAX_RETRIES, |
94 | 84 | default_headers: Mapping[str, str] | None = None, |
@@ -119,31 +109,10 @@ def __init__( |
119 | 109 | ) |
120 | 110 | self.api_key = api_key |
121 | 111 |
|
122 | | - self._environment = environment |
123 | | - |
124 | | - base_url_env = os.environ.get("CAS_PARSER_BASE_URL") |
125 | | - if is_given(base_url) and base_url is not None: |
126 | | - # cast required because mypy doesn't understand the type narrowing |
127 | | - base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast] |
128 | | - elif is_given(environment): |
129 | | - if base_url_env and base_url is not None: |
130 | | - raise ValueError( |
131 | | - "Ambiguous URL; The `CAS_PARSER_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None", |
132 | | - ) |
133 | | - |
134 | | - try: |
135 | | - base_url = ENVIRONMENTS[environment] |
136 | | - except KeyError as exc: |
137 | | - raise ValueError(f"Unknown environment: {environment}") from exc |
138 | | - elif base_url_env is not None: |
139 | | - base_url = base_url_env |
140 | | - else: |
141 | | - self._environment = environment = "production" |
142 | | - |
143 | | - try: |
144 | | - base_url = ENVIRONMENTS[environment] |
145 | | - except KeyError as exc: |
146 | | - raise ValueError(f"Unknown environment: {environment}") from exc |
| 112 | + if base_url is None: |
| 113 | + base_url = os.environ.get("CAS_PARSER_BASE_URL") |
| 114 | + if base_url is None: |
| 115 | + base_url = f"https://api.casparser.in" |
147 | 116 |
|
148 | 117 | super().__init__( |
149 | 118 | version=__version__, |
@@ -260,7 +229,6 @@ def copy( |
260 | 229 | self, |
261 | 230 | *, |
262 | 231 | api_key: str | None = None, |
263 | | - environment: Literal["production", "environment_1", "environment_2"] | None = None, |
264 | 232 | base_url: str | httpx.URL | None = None, |
265 | 233 | timeout: float | Timeout | None | NotGiven = not_given, |
266 | 234 | http_client: httpx.Client | None = None, |
@@ -296,7 +264,6 @@ def copy( |
296 | 264 | return self.__class__( |
297 | 265 | api_key=api_key or self.api_key, |
298 | 266 | base_url=base_url or self.base_url, |
299 | | - environment=environment or self._environment, |
300 | 267 | timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, |
301 | 268 | http_client=http_client, |
302 | 269 | max_retries=max_retries if is_given(max_retries) else self.max_retries, |
@@ -347,14 +314,11 @@ class AsyncCasParser(AsyncAPIClient): |
347 | 314 | # client options |
348 | 315 | api_key: str |
349 | 316 |
|
350 | | - _environment: Literal["production", "environment_1", "environment_2"] | NotGiven |
351 | | - |
352 | 317 | def __init__( |
353 | 318 | self, |
354 | 319 | *, |
355 | 320 | api_key: str | None = None, |
356 | | - environment: Literal["production", "environment_1", "environment_2"] | NotGiven = not_given, |
357 | | - base_url: str | httpx.URL | None | NotGiven = not_given, |
| 321 | + base_url: str | httpx.URL | None = None, |
358 | 322 | timeout: float | Timeout | None | NotGiven = not_given, |
359 | 323 | max_retries: int = DEFAULT_MAX_RETRIES, |
360 | 324 | default_headers: Mapping[str, str] | None = None, |
@@ -385,31 +349,10 @@ def __init__( |
385 | 349 | ) |
386 | 350 | self.api_key = api_key |
387 | 351 |
|
388 | | - self._environment = environment |
389 | | - |
390 | | - base_url_env = os.environ.get("CAS_PARSER_BASE_URL") |
391 | | - if is_given(base_url) and base_url is not None: |
392 | | - # cast required because mypy doesn't understand the type narrowing |
393 | | - base_url = cast("str | httpx.URL", base_url) # pyright: ignore[reportUnnecessaryCast] |
394 | | - elif is_given(environment): |
395 | | - if base_url_env and base_url is not None: |
396 | | - raise ValueError( |
397 | | - "Ambiguous URL; The `CAS_PARSER_BASE_URL` env var and the `environment` argument are given. If you want to use the environment, you must pass base_url=None", |
398 | | - ) |
399 | | - |
400 | | - try: |
401 | | - base_url = ENVIRONMENTS[environment] |
402 | | - except KeyError as exc: |
403 | | - raise ValueError(f"Unknown environment: {environment}") from exc |
404 | | - elif base_url_env is not None: |
405 | | - base_url = base_url_env |
406 | | - else: |
407 | | - self._environment = environment = "production" |
408 | | - |
409 | | - try: |
410 | | - base_url = ENVIRONMENTS[environment] |
411 | | - except KeyError as exc: |
412 | | - raise ValueError(f"Unknown environment: {environment}") from exc |
| 352 | + if base_url is None: |
| 353 | + base_url = os.environ.get("CAS_PARSER_BASE_URL") |
| 354 | + if base_url is None: |
| 355 | + base_url = f"https://api.casparser.in" |
413 | 356 |
|
414 | 357 | super().__init__( |
415 | 358 | version=__version__, |
@@ -526,7 +469,6 @@ def copy( |
526 | 469 | self, |
527 | 470 | *, |
528 | 471 | api_key: str | None = None, |
529 | | - environment: Literal["production", "environment_1", "environment_2"] | None = None, |
530 | 472 | base_url: str | httpx.URL | None = None, |
531 | 473 | timeout: float | Timeout | None | NotGiven = not_given, |
532 | 474 | http_client: httpx.AsyncClient | None = None, |
@@ -562,7 +504,6 @@ def copy( |
562 | 504 | return self.__class__( |
563 | 505 | api_key=api_key or self.api_key, |
564 | 506 | base_url=base_url or self.base_url, |
565 | | - environment=environment or self._environment, |
566 | 507 | timeout=self.timeout if isinstance(timeout, NotGiven) else timeout, |
567 | 508 | http_client=http_client, |
568 | 509 | max_retries=max_retries if is_given(max_retries) else self.max_retries, |
|
0 commit comments