MCPcopy Create free account
hub / github.com/Dispatcharr/Dispatcharr / regex_preview

Method regex_preview

apps/channels/api_views.py:298–445  ·  view source on GitHub ↗
(self, request, *args, **kwargs)

Source from the content-addressed store, hash-verified

296 )
297 @action(detail=False, methods=["get"], url_path="regex-preview")
298 def regex_preview(self, request, *args, **kwargs):
299 # `regex` (third-party) supports a per-call timeout that bounds
300 # catastrophic backtracking; paired with PATTERN_MAX_LEN to keep
301 # the endpoint safe under adversarial input.
302 import regex as re
303
304 SCAN_CAP = 5000
305 PATTERN_MAX_LEN = 512
306 REGEX_TIMEOUT = 0.1
307
308 group_name = request.query_params.get("channel_group")
309 if not group_name:
310 return Response(
311 {"detail": "channel_group is required"},
312 status=status.HTTP_400_BAD_REQUEST,
313 )
314
315 # Group names are not unique across M3U accounts (two providers
316 # can both publish a "Sports" group). Scope to the calling
317 # account so the sample reflects only the user's edits.
318 m3u_account_id = request.query_params.get("m3u_account_id")
319 if m3u_account_id is not None:
320 try:
321 m3u_account_id = int(m3u_account_id)
322 except (TypeError, ValueError):
323 return Response(
324 {"detail": "m3u_account_id must be an integer"},
325 status=status.HTTP_400_BAD_REQUEST,
326 )
327
328 find_pat = request.query_params.get("find") or None
329 replace_pat = request.query_params.get("replace") or ""
330 match_pat = request.query_params.get("match") or None
331 exclude_pat = request.query_params.get("exclude") or None
332 for label, value in (
333 ("find", find_pat),
334 ("replace", replace_pat),
335 ("match", match_pat),
336 ("exclude", exclude_pat),
337 ):
338 if value is not None and len(value) > PATTERN_MAX_LEN:
339 return Response(
340 {"detail": f"{label} exceeds {PATTERN_MAX_LEN} characters"},
341 status=status.HTTP_400_BAD_REQUEST,
342 )
343 try:
344 limit = int(request.query_params.get("limit", 10))
345 except (TypeError, ValueError):
346 limit = 10
347 limit = max(1, min(limit, 50))
348
349 find_re = None
350 match_re = None
351 exclude_re = None
352 find_error = None
353 match_error = None
354 exclude_error = None
355 if find_pat:

Callers

nothing calls this directly

Calls 3

searchMethod · 0.80
getMethod · 0.45
filterMethod · 0.45

Tested by

no test coverage detected