Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def read_items(q: Dict[str, Item] = Query(None)):
pass # pragma: no cover
async def sparql_get(
request: Request,
query: str = Query(..., description="The SPARQL query to execute."),
default_graph_uri: str = Query(..., alias="default-graph-uri", description="The URI of the default RDF graph queried."),
next_link: str = Query(None, alias="next", description="(Optional) A next link used to resume query execution from a saved state.")
):
"""Execute a SPARQL query using the Web Preemption model"""
try:
mimetypes = request.headers['accept'].split(",")
server_url = urlunparse(request.url.components[0:3] + (None, None, None))
bindings, next_page, stats = await execute_query(query, default_graph_uri, next_link, dataset, server_url)
return create_response(mimetypes, bindings, next_page, stats, server_url)
except HTTPException as err:
raise err
except Exception as err:
logging.error(err)
raise HTTPException(status_code=500, detail=str(err))
async def read_items(
*,
item_id: int = Path(..., title="The ID of the item to get", ge=0, le=1000),
q: str,
size: float = Query(..., gt=0, lt=10.5)
):
results = {"item_id": item_id}
if q:
results.update({"q": q})
return results
async def search(
request: Request,
query: str = Query(None, max_length=50),
page: int = Query(1, gt=0),
):
if not query:
return RedirectResponse("/")
torrents, count = Torrent.search_by_name(
query,
limit=project_settings.PAGE_SIZE,
offset=project_settings.PAGE_SIZE * (page - 1),
)
return templates.TemplateResponse(
"search.html",
{
"request": request,
"query": query,
"torrents": torrents,
async def read_items(
q: str = Query(None, min_length=3, max_length=50, regex="^fixedquery$")
):
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
if q:
results.update({"q": q})
return results
async def get_places_bbox(
bbox: str = Query(
...,
title="Bounding box to search",
description="Format: left_lon,bottom_lat,right_lon,top_lat",
example="-4.56,48.35,-4.42,48.46",
),
category: Optional[List[str]] = Query(None),
raw_filter: Optional[List[str]] = Query(None),
source: Optional[str] = Query(None),
q: Optional[str] = Query(None, title="Query", description="Full text query"),
size: Optional[int] = Query(None),
lang: Optional[str] = Query(None),
verbosity: Optional[str] = Query(None),
extend_bbox: bool = Query(False),
) -> PlacesBboxResponse:
params = PlacesQueryParam(**locals())
source = params.source
if source is None:
if (
params.q or (params.category and all(c.get("pj_filters") for c in params.category))
) and pj_source.bbox_is_covered(params.bbox):
params.source = PoiSource.PAGESJAUNES
else:
params.source = PoiSource.OSM
async def read_items(q: str = Query("fixedquery", min_length=3)):
results = {"items": [{"item_id": "Foo"}, {"item_id": "Bar"}]}
if q:
results.update({"q": q})
return results
def get_directions(
# Query parameters
origin: str = Query(..., description="Origin place id"),
destination: str = Query(..., description="Destination place id"),
type: str = Query(..., description="Transport mode"),
language: str = Query("en", description="User language"),
# Request
request: Request = Depends(directions_request),
):
rate_limiter.check_limit_per_client(request)
try:
from_place = place_from_id(origin)
to_place = place_from_id(destination)
except InvalidPlaceId as exc:
raise HTTPException(status_code=404, detail=exc.message)
return directions_client.get_directions(
from_place, to_place, type, language, params=request.query_params
)
async def show(
user_id: int,
user_repo: UserRepo = Depends(UserRepo()),
token: TokenPayload = Depends(ScopedTo("user:show", "super")),
includes: List[str] = Query(None),
):
includes = only(includes, [], values=True)
item = user_repo.loads(includes).get_or_fail(user_id).includes(includes).data()
return UserResponse(user=item)
async def show(
dns_server: str,
dns_server_repo: DnsServerRepo = Depends(DnsServerRepo()),
token: TokenPayload = Depends(ScopedTo("dns-server:show")),
includes: List[str] = Query(None),
):
includes = only(includes, ["zones"], values=True)
dns_server_id_label = dns_server_repo.label("id")
try:
dns_server = int(dns_server)
label = dns_server_id_label
except ValueError:
label = dns_server_repo.label("name")
# TODO: is this vulnerable to sql injection?
item = (
dns_server_repo.loads(includes)
.filter(label == dns_server)
.first_or_fail()