ci: add flake8
This commit is contained in:
parent
014596d271
commit
dd501a6e4e
32 changed files with 170 additions and 171 deletions
|
@ -4,7 +4,7 @@ from typing import List, Dict, Union
|
|||
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from app.models.mirrors import Origin
|
||||
from app.models.mirrors import Origin, Proxy, Mirror
|
||||
|
||||
|
||||
class BC2Alternative(BaseModel):
|
||||
|
@ -18,52 +18,48 @@ class BC2Alternative(BaseModel):
|
|||
class BC2Site(BaseModel):
|
||||
main_domain: str = Field(
|
||||
description="The main domain name of the website, excluding \"www.\" if present.",
|
||||
examples=["bbc.co.uk", "bbc.com", "guardianproject.info"]
|
||||
)
|
||||
examples=["bbc.co.uk", "bbc.com", "guardianproject.info"])
|
||||
available_alternatives: List[BC2Alternative]
|
||||
|
||||
|
||||
class BypassCensorship2(BaseModel):
|
||||
version: str = Field(
|
||||
description="Version number of the Bypass Censorship Extension schema in use",
|
||||
)
|
||||
version: str = Field(description="Version number of the Bypass Censorship Extension schema in use", )
|
||||
sites: List[BC2Site]
|
||||
|
||||
class Config:
|
||||
title = "Bypass Censorship Version 2"
|
||||
|
||||
|
||||
def mirror_sites(provider: str = "cloudfront") -> Dict[
|
||||
str, Union[str, List[Dict[str, Union[str, List[Dict[str, str]]]]]]]:
|
||||
def mirror_alternative(mirror: Mirror):
|
||||
return {
|
||||
"version": "2.0",
|
||||
"sites": [{
|
||||
"main_domain": x.description[len("proxy:"):].replace("www.", "") if x.description.startswith(
|
||||
"proxy:") else x.domain_name.replace("www.", ""),
|
||||
"available_alternatives": [
|
||||
{
|
||||
"proto": "tor" if ".onion" in a.url else "https",
|
||||
"type": "eotk" if ".onion" in a.url else "mirror",
|
||||
"created_at": str(a.added),
|
||||
"updated_at": str(a.updated),
|
||||
"url": a.url
|
||||
} for a in x.mirrors if not a.deprecated and not a.destroyed
|
||||
] + [
|
||||
{
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"created_at": str(a.added),
|
||||
"updated_at": str(a.updated),
|
||||
"url": a.url
|
||||
} for a in x.proxies if
|
||||
a.url is not None
|
||||
and not a.deprecated
|
||||
and not a.destroyed
|
||||
and a.provider == provider
|
||||
]} for x in Origin.query.order_by(Origin.domain_name).all() if x.destroyed is None
|
||||
]
|
||||
"proto": "tor" if ".onion" in mirror.url else "https",
|
||||
"type": "eotk" if ".onion" in mirror.url else "mirror",
|
||||
"created_at": str(mirror.added),
|
||||
"updated_at": str(mirror.updated),
|
||||
"url": mirror.url
|
||||
}
|
||||
|
||||
|
||||
def proxy_alternative(proxy: Proxy):
|
||||
return {
|
||||
"proto": "https",
|
||||
"type": "mirror",
|
||||
"created_at": str(proxy.added),
|
||||
"updated_at": str(proxy.updated),
|
||||
"url": proxy.url
|
||||
}
|
||||
|
||||
|
||||
def mirror_sites(provider: str = "cloudfront") -> Dict[str,
|
||||
Union[str, List[Dict[str, Union[str, List[Dict[str, str]]]]]]]:
|
||||
return {"version": "2.0", "sites": [{
|
||||
"main_domain": x.description[len("proxy:"):].replace("www.", "") if x.description.startswith(
|
||||
"proxy:") else x.domain_name.replace("www.", ""),
|
||||
"available_alternatives": [mirror_alternative(a) for a in x.mirrors if not a.deprecated and not a.destroyed] + [
|
||||
proxy_alternative(a) for a in x.proxies if
|
||||
a.url is not None and not a.deprecated and not a.destroyed and a.provider == provider]} for x in
|
||||
Origin.query.order_by(Origin.domain_name).all() if x.destroyed is None]}
|
||||
|
||||
|
||||
if getattr(builtins, "__sphinx_build__", False):
|
||||
schema = BypassCensorship2.schema_json()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue