Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create BrowserSpec. #309

Closed
wants to merge 6 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions curl_cffi/requests/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,35 @@ def normalize(cls, item):
else:
return item


class BrowserSpec:
"""A more structured way of selecting browsers"""

# TODO
def __init__(
self,
browser_type: BrowserType,
version: Optional[str] = None,
platform: Optional[str] = None
):
self.browser_type = browser_type
self.version = version
self.platform = platform

@classmethod
def from_string(cls, spec_string: str) -> 'BrowserSpec':
parts = spec_string.split("_")
browser_type = BrowserType.normalize(parts[0])
version, platform = (parts[1], parts[2]) if len(parts) > 2 else (parts[1] if len(parts) > 1 else None, None)
return cls(browser_type, version, platform)

def __str__(self) -> str:
result = self.browser_type
if self.version:
result += "_" + self.version

if self.platform:
result += "_" + self.platform

return result


def _is_absolute_url(url: str) -> bool:
Expand Down
Loading