id int32 0 252k | repo stringlengths 7 55 | path stringlengths 4 127 | func_name stringlengths 1 88 | original_string stringlengths 75 19.8k | language stringclasses 1
value | code stringlengths 75 19.8k | code_tokens list | docstring stringlengths 3 17.3k | docstring_tokens list | sha stringlengths 40 40 | url stringlengths 87 242 |
|---|---|---|---|---|---|---|---|---|---|---|---|
26,600 | huge-success/sanic | sanic/blueprints.py | Blueprint.group | def group(*blueprints, url_prefix=""):
"""
Create a list of blueprints, optionally grouping them under a
general URL prefix.
:param blueprints: blueprints to be registered as a group
:param url_prefix: URL route to be prepended to all sub-prefixes
"""
def chain(... | python | def group(*blueprints, url_prefix=""):
"""
Create a list of blueprints, optionally grouping them under a
general URL prefix.
:param blueprints: blueprints to be registered as a group
:param url_prefix: URL route to be prepended to all sub-prefixes
"""
def chain(... | [
"def",
"group",
"(",
"*",
"blueprints",
",",
"url_prefix",
"=",
"\"\"",
")",
":",
"def",
"chain",
"(",
"nested",
")",
":",
"\"\"\"itertools.chain() but leaves strings untouched\"\"\"",
"for",
"i",
"in",
"nested",
":",
"if",
"isinstance",
"(",
"i",
",",
"(",
... | Create a list of blueprints, optionally grouping them under a
general URL prefix.
:param blueprints: blueprints to be registered as a group
:param url_prefix: URL route to be prepended to all sub-prefixes | [
"Create",
"a",
"list",
"of",
"blueprints",
"optionally",
"grouping",
"them",
"under",
"a",
"general",
"URL",
"prefix",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L68-L93 |
26,601 | huge-success/sanic | sanic/blueprints.py | Blueprint.register | def register(self, app, options):
"""
Register the blueprint to the sanic app.
:param app: Instance of :class:`sanic.app.Sanic` class
:param options: Options to be used while registering the
blueprint into the app.
*url_prefix* - URL Prefix to override the bluepr... | python | def register(self, app, options):
"""
Register the blueprint to the sanic app.
:param app: Instance of :class:`sanic.app.Sanic` class
:param options: Options to be used while registering the
blueprint into the app.
*url_prefix* - URL Prefix to override the bluepr... | [
"def",
"register",
"(",
"self",
",",
"app",
",",
"options",
")",
":",
"url_prefix",
"=",
"options",
".",
"get",
"(",
"\"url_prefix\"",
",",
"self",
".",
"url_prefix",
")",
"# Routes",
"for",
"future",
"in",
"self",
".",
"routes",
":",
"# attach the bluepri... | Register the blueprint to the sanic app.
:param app: Instance of :class:`sanic.app.Sanic` class
:param options: Options to be used while registering the
blueprint into the app.
*url_prefix* - URL Prefix to override the blueprint prefix | [
"Register",
"the",
"blueprint",
"to",
"the",
"sanic",
"app",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L95-L164 |
26,602 | huge-success/sanic | sanic/blueprints.py | Blueprint.route | def route(
self,
uri,
methods=frozenset({"GET"}),
host=None,
strict_slashes=None,
stream=False,
version=None,
name=None,
):
"""Create a blueprint route from a decorated function.
:param uri: endpoint at which the route will be accessib... | python | def route(
self,
uri,
methods=frozenset({"GET"}),
host=None,
strict_slashes=None,
stream=False,
version=None,
name=None,
):
"""Create a blueprint route from a decorated function.
:param uri: endpoint at which the route will be accessib... | [
"def",
"route",
"(",
"self",
",",
"uri",
",",
"methods",
"=",
"frozenset",
"(",
"{",
"\"GET\"",
"}",
")",
",",
"host",
"=",
"None",
",",
"strict_slashes",
"=",
"None",
",",
"stream",
"=",
"False",
",",
"version",
"=",
"None",
",",
"name",
"=",
"Non... | Create a blueprint route from a decorated function.
:param uri: endpoint at which the route will be accessible.
:param methods: list of acceptable HTTP methods.
:param host: IP Address of FQDN for the sanic server to use.
:param strict_slashes: Enforce the API urls are requested with a
... | [
"Create",
"a",
"blueprint",
"route",
"from",
"a",
"decorated",
"function",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L166-L207 |
26,603 | huge-success/sanic | sanic/blueprints.py | Blueprint.websocket | def websocket(
self, uri, host=None, strict_slashes=None, version=None, name=None
):
"""Create a blueprint websocket route from a decorated function.
:param uri: endpoint at which the route will be accessible.
:param host: IP Address of FQDN for the sanic server to use.
:par... | python | def websocket(
self, uri, host=None, strict_slashes=None, version=None, name=None
):
"""Create a blueprint websocket route from a decorated function.
:param uri: endpoint at which the route will be accessible.
:param host: IP Address of FQDN for the sanic server to use.
:par... | [
"def",
"websocket",
"(",
"self",
",",
"uri",
",",
"host",
"=",
"None",
",",
"strict_slashes",
"=",
"None",
",",
"version",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"if",
"strict_slashes",
"is",
"None",
":",
"strict_slashes",
"=",
"self",
".",
... | Create a blueprint websocket route from a decorated function.
:param uri: endpoint at which the route will be accessible.
:param host: IP Address of FQDN for the sanic server to use.
:param strict_slashes: Enforce the API urls are requested with a
training */*
:param version... | [
"Create",
"a",
"blueprint",
"websocket",
"route",
"from",
"a",
"decorated",
"function",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L260-L282 |
26,604 | huge-success/sanic | sanic/blueprints.py | Blueprint.add_websocket_route | def add_websocket_route(
self, handler, uri, host=None, version=None, name=None
):
"""Create a blueprint websocket route from a function.
:param handler: function for handling uri requests. Accepts function,
or class instance with a view_class method.
:param ... | python | def add_websocket_route(
self, handler, uri, host=None, version=None, name=None
):
"""Create a blueprint websocket route from a function.
:param handler: function for handling uri requests. Accepts function,
or class instance with a view_class method.
:param ... | [
"def",
"add_websocket_route",
"(",
"self",
",",
"handler",
",",
"uri",
",",
"host",
"=",
"None",
",",
"version",
"=",
"None",
",",
"name",
"=",
"None",
")",
":",
"self",
".",
"websocket",
"(",
"uri",
"=",
"uri",
",",
"host",
"=",
"host",
",",
"vers... | Create a blueprint websocket route from a function.
:param handler: function for handling uri requests. Accepts function,
or class instance with a view_class method.
:param uri: endpoint at which the route will be accessible.
:param host: IP Address of FQDN for the sanic... | [
"Create",
"a",
"blueprint",
"websocket",
"route",
"from",
"a",
"function",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L284-L298 |
26,605 | huge-success/sanic | sanic/blueprints.py | Blueprint.listener | def listener(self, event):
"""Create a listener from a decorated function.
:param event: Event to listen to.
"""
def decorator(listener):
self.listeners[event].append(listener)
return listener
return decorator | python | def listener(self, event):
"""Create a listener from a decorated function.
:param event: Event to listen to.
"""
def decorator(listener):
self.listeners[event].append(listener)
return listener
return decorator | [
"def",
"listener",
"(",
"self",
",",
"event",
")",
":",
"def",
"decorator",
"(",
"listener",
")",
":",
"self",
".",
"listeners",
"[",
"event",
"]",
".",
"append",
"(",
"listener",
")",
"return",
"listener",
"return",
"decorator"
] | Create a listener from a decorated function.
:param event: Event to listen to. | [
"Create",
"a",
"listener",
"from",
"a",
"decorated",
"function",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L300-L310 |
26,606 | huge-success/sanic | sanic/blueprints.py | Blueprint.middleware | def middleware(self, *args, **kwargs):
"""
Create a blueprint middleware from a decorated function.
:param args: Positional arguments to be used while invoking the
middleware
:param kwargs: optional keyword args that can be used with the
middleware.
"""
... | python | def middleware(self, *args, **kwargs):
"""
Create a blueprint middleware from a decorated function.
:param args: Positional arguments to be used while invoking the
middleware
:param kwargs: optional keyword args that can be used with the
middleware.
"""
... | [
"def",
"middleware",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"register_middleware",
"(",
"_middleware",
")",
":",
"future_middleware",
"=",
"FutureMiddleware",
"(",
"_middleware",
",",
"args",
",",
"kwargs",
")",
"self",
".... | Create a blueprint middleware from a decorated function.
:param args: Positional arguments to be used while invoking the
middleware
:param kwargs: optional keyword args that can be used with the
middleware. | [
"Create",
"a",
"blueprint",
"middleware",
"from",
"a",
"decorated",
"function",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L312-L339 |
26,607 | huge-success/sanic | sanic/blueprints.py | Blueprint.exception | def exception(self, *args, **kwargs):
"""
This method enables the process of creating a global exception
handler for the current blueprint under question.
:param args: List of Python exceptions to be caught by the handler
:param kwargs: Additional optional arguments to be passed... | python | def exception(self, *args, **kwargs):
"""
This method enables the process of creating a global exception
handler for the current blueprint under question.
:param args: List of Python exceptions to be caught by the handler
:param kwargs: Additional optional arguments to be passed... | [
"def",
"exception",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"def",
"decorator",
"(",
"handler",
")",
":",
"exception",
"=",
"FutureException",
"(",
"handler",
",",
"args",
",",
"kwargs",
")",
"self",
".",
"exceptions",
".",
... | This method enables the process of creating a global exception
handler for the current blueprint under question.
:param args: List of Python exceptions to be caught by the handler
:param kwargs: Additional optional arguments to be passed to the
exception handler
:return a d... | [
"This",
"method",
"enables",
"the",
"process",
"of",
"creating",
"a",
"global",
"exception",
"handler",
"for",
"the",
"current",
"blueprint",
"under",
"question",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprints.py#L341-L359 |
26,608 | huge-success/sanic | sanic/exceptions.py | abort | def abort(status_code, message=None):
"""
Raise an exception based on SanicException. Returns the HTTP response
message appropriate for the given status code, unless provided.
:param status_code: The HTTP status code to return.
:param message: The HTTP response body. Defaults to the messages
... | python | def abort(status_code, message=None):
"""
Raise an exception based on SanicException. Returns the HTTP response
message appropriate for the given status code, unless provided.
:param status_code: The HTTP status code to return.
:param message: The HTTP response body. Defaults to the messages
... | [
"def",
"abort",
"(",
"status_code",
",",
"message",
"=",
"None",
")",
":",
"if",
"message",
"is",
"None",
":",
"message",
"=",
"STATUS_CODES",
".",
"get",
"(",
"status_code",
")",
"# These are stored as bytes in the STATUS_CODES dict",
"message",
"=",
"message",
... | Raise an exception based on SanicException. Returns the HTTP response
message appropriate for the given status code, unless provided.
:param status_code: The HTTP status code to return.
:param message: The HTTP response body. Defaults to the messages
in response.py for the given status ... | [
"Raise",
"an",
"exception",
"based",
"on",
"SanicException",
".",
"Returns",
"the",
"HTTP",
"response",
"message",
"appropriate",
"for",
"the",
"given",
"status",
"code",
"unless",
"provided",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/exceptions.py#L284-L298 |
26,609 | huge-success/sanic | sanic/app.py | Sanic.add_task | def add_task(self, task):
"""Schedule a task to run later, after the loop has started.
Different from asyncio.ensure_future in that it does not
also return a future, and the actual ensure_future call
is delayed until before server start.
:param task: future, couroutine or awaita... | python | def add_task(self, task):
"""Schedule a task to run later, after the loop has started.
Different from asyncio.ensure_future in that it does not
also return a future, and the actual ensure_future call
is delayed until before server start.
:param task: future, couroutine or awaita... | [
"def",
"add_task",
"(",
"self",
",",
"task",
")",
":",
"try",
":",
"if",
"callable",
"(",
"task",
")",
":",
"try",
":",
"self",
".",
"loop",
".",
"create_task",
"(",
"task",
"(",
"self",
")",
")",
"except",
"TypeError",
":",
"self",
".",
"loop",
... | Schedule a task to run later, after the loop has started.
Different from asyncio.ensure_future in that it does not
also return a future, and the actual ensure_future call
is delayed until before server start.
:param task: future, couroutine or awaitable | [
"Schedule",
"a",
"task",
"to",
"run",
"later",
"after",
"the",
"loop",
"has",
"started",
".",
"Different",
"from",
"asyncio",
".",
"ensure_future",
"in",
"that",
"it",
"does",
"not",
"also",
"return",
"a",
"future",
"and",
"the",
"actual",
"ensure_future",
... | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L94-L120 |
26,610 | huge-success/sanic | sanic/app.py | Sanic.add_websocket_route | def add_websocket_route(
self,
handler,
uri,
host=None,
strict_slashes=None,
subprotocols=None,
name=None,
):
"""
A helper method to register a function as a websocket route.
:param handler: a callable function or instance of a class
... | python | def add_websocket_route(
self,
handler,
uri,
host=None,
strict_slashes=None,
subprotocols=None,
name=None,
):
"""
A helper method to register a function as a websocket route.
:param handler: a callable function or instance of a class
... | [
"def",
"add_websocket_route",
"(",
"self",
",",
"handler",
",",
"uri",
",",
"host",
"=",
"None",
",",
"strict_slashes",
"=",
"None",
",",
"subprotocols",
"=",
"None",
",",
"name",
"=",
"None",
",",
")",
":",
"if",
"strict_slashes",
"is",
"None",
":",
"... | A helper method to register a function as a websocket route.
:param handler: a callable function or instance of a class
that can handle the websocket request
:param host: Host IP or FQDN details
:param uri: URL path that will be mapped to the websocket
... | [
"A",
"helper",
"method",
"to",
"register",
"a",
"function",
"as",
"a",
"websocket",
"route",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L501-L535 |
26,611 | huge-success/sanic | sanic/app.py | Sanic.enable_websocket | def enable_websocket(self, enable=True):
"""Enable or disable the support for websocket.
Websocket is enabled automatically if websocket routes are
added to the application.
"""
if not self.websocket_enabled:
# if the server is stopped, we want to cancel any ongoing
... | python | def enable_websocket(self, enable=True):
"""Enable or disable the support for websocket.
Websocket is enabled automatically if websocket routes are
added to the application.
"""
if not self.websocket_enabled:
# if the server is stopped, we want to cancel any ongoing
... | [
"def",
"enable_websocket",
"(",
"self",
",",
"enable",
"=",
"True",
")",
":",
"if",
"not",
"self",
".",
"websocket_enabled",
":",
"# if the server is stopped, we want to cancel any ongoing",
"# websocket tasks, to allow the server to exit promptly",
"@",
"self",
".",
"liste... | Enable or disable the support for websocket.
Websocket is enabled automatically if websocket routes are
added to the application. | [
"Enable",
"or",
"disable",
"the",
"support",
"for",
"websocket",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L537-L551 |
26,612 | huge-success/sanic | sanic/app.py | Sanic.exception | def exception(self, *exceptions):
"""Decorate a function to be registered as a handler for exceptions
:param exceptions: exceptions
:return: decorated function
"""
def response(handler):
for exception in exceptions:
if isinstance(exception, (tuple, l... | python | def exception(self, *exceptions):
"""Decorate a function to be registered as a handler for exceptions
:param exceptions: exceptions
:return: decorated function
"""
def response(handler):
for exception in exceptions:
if isinstance(exception, (tuple, l... | [
"def",
"exception",
"(",
"self",
",",
"*",
"exceptions",
")",
":",
"def",
"response",
"(",
"handler",
")",
":",
"for",
"exception",
"in",
"exceptions",
":",
"if",
"isinstance",
"(",
"exception",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"for",
"... | Decorate a function to be registered as a handler for exceptions
:param exceptions: exceptions
:return: decorated function | [
"Decorate",
"a",
"function",
"to",
"be",
"registered",
"as",
"a",
"handler",
"for",
"exceptions"
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L567-L583 |
26,613 | huge-success/sanic | sanic/app.py | Sanic.register_middleware | def register_middleware(self, middleware, attach_to="request"):
"""
Register an application level middleware that will be attached
to all the API URLs registered under this application.
This method is internally invoked by the :func:`middleware`
decorator provided at the app lev... | python | def register_middleware(self, middleware, attach_to="request"):
"""
Register an application level middleware that will be attached
to all the API URLs registered under this application.
This method is internally invoked by the :func:`middleware`
decorator provided at the app lev... | [
"def",
"register_middleware",
"(",
"self",
",",
"middleware",
",",
"attach_to",
"=",
"\"request\"",
")",
":",
"if",
"attach_to",
"==",
"\"request\"",
":",
"if",
"middleware",
"not",
"in",
"self",
".",
"request_middleware",
":",
"self",
".",
"request_middleware",... | Register an application level middleware that will be attached
to all the API URLs registered under this application.
This method is internally invoked by the :func:`middleware`
decorator provided at the app level.
:param middleware: Callback method to be attached to the
mi... | [
"Register",
"an",
"application",
"level",
"middleware",
"that",
"will",
"be",
"attached",
"to",
"all",
"the",
"API",
"URLs",
"registered",
"under",
"this",
"application",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L585-L607 |
26,614 | huge-success/sanic | sanic/app.py | Sanic.handle_request | async def handle_request(self, request, write_callback, stream_callback):
"""Take a request from the HTTP Server and return a response object
to be sent back The HTTP Server only expects a response object, so
exception handling must be done here
:param request: HTTP Request object
... | python | async def handle_request(self, request, write_callback, stream_callback):
"""Take a request from the HTTP Server and return a response object
to be sent back The HTTP Server only expects a response object, so
exception handling must be done here
:param request: HTTP Request object
... | [
"async",
"def",
"handle_request",
"(",
"self",
",",
"request",
",",
"write_callback",
",",
"stream_callback",
")",
":",
"# Define `response` var here to remove warnings about",
"# allocation before assignment below.",
"response",
"=",
"None",
"cancelled",
"=",
"False",
"try... | Take a request from the HTTP Server and return a response object
to be sent back The HTTP Server only expects a response object, so
exception handling must be done here
:param request: HTTP Request object
:param write_callback: Synchronous response function to be
called with... | [
"Take",
"a",
"request",
"from",
"the",
"HTTP",
"Server",
"and",
"return",
"a",
"response",
"object",
"to",
"be",
"sent",
"back",
"The",
"HTTP",
"Server",
"only",
"expects",
"a",
"response",
"object",
"so",
"exception",
"handling",
"must",
"be",
"done",
"he... | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L863-L975 |
26,615 | huge-success/sanic | sanic/app.py | Sanic.run | def run(
self,
host: Optional[str] = None,
port: Optional[int] = None,
debug: bool = False,
ssl: Union[dict, SSLContext, None] = None,
sock: Optional[socket] = None,
workers: int = 1,
protocol: Type[Protocol] = None,
backlog: int = 100,
sto... | python | def run(
self,
host: Optional[str] = None,
port: Optional[int] = None,
debug: bool = False,
ssl: Union[dict, SSLContext, None] = None,
sock: Optional[socket] = None,
workers: int = 1,
protocol: Type[Protocol] = None,
backlog: int = 100,
sto... | [
"def",
"run",
"(",
"self",
",",
"host",
":",
"Optional",
"[",
"str",
"]",
"=",
"None",
",",
"port",
":",
"Optional",
"[",
"int",
"]",
"=",
"None",
",",
"debug",
":",
"bool",
"=",
"False",
",",
"ssl",
":",
"Union",
"[",
"dict",
",",
"SSLContext",
... | Run the HTTP Server and listen until keyboard interrupt or term
signal. On termination, drain connections before closing.
:param host: Address to host on
:type host: str
:param port: Port to host on
:type port: int
:param debug: Enables debug output (slows server)
... | [
"Run",
"the",
"HTTP",
"Server",
"and",
"listen",
"until",
"keyboard",
"interrupt",
"or",
"term",
"signal",
".",
"On",
"termination",
"drain",
"connections",
"before",
"closing",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/app.py#L989-L1105 |
26,616 | huge-success/sanic | sanic/response.py | json | def json(
body,
status=200,
headers=None,
content_type="application/json",
dumps=json_dumps,
**kwargs
):
"""
Returns response object with body in json format.
:param body: Response data to be serialized.
:param status: Response code.
:param headers: Custom Headers.
:para... | python | def json(
body,
status=200,
headers=None,
content_type="application/json",
dumps=json_dumps,
**kwargs
):
"""
Returns response object with body in json format.
:param body: Response data to be serialized.
:param status: Response code.
:param headers: Custom Headers.
:para... | [
"def",
"json",
"(",
"body",
",",
"status",
"=",
"200",
",",
"headers",
"=",
"None",
",",
"content_type",
"=",
"\"application/json\"",
",",
"dumps",
"=",
"json_dumps",
",",
"*",
"*",
"kwargs",
")",
":",
"return",
"HTTPResponse",
"(",
"dumps",
"(",
"body",... | Returns response object with body in json format.
:param body: Response data to be serialized.
:param status: Response code.
:param headers: Custom Headers.
:param kwargs: Remaining arguments that are passed to the json encoder. | [
"Returns",
"response",
"object",
"with",
"body",
"in",
"json",
"format",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/response.py#L203-L224 |
26,617 | huge-success/sanic | sanic/response.py | text | def text(
body, status=200, headers=None, content_type="text/plain; charset=utf-8"
):
"""
Returns response object with body in text format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.
:param content_type: the content type (string) ... | python | def text(
body, status=200, headers=None, content_type="text/plain; charset=utf-8"
):
"""
Returns response object with body in text format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.
:param content_type: the content type (string) ... | [
"def",
"text",
"(",
"body",
",",
"status",
"=",
"200",
",",
"headers",
"=",
"None",
",",
"content_type",
"=",
"\"text/plain; charset=utf-8\"",
")",
":",
"return",
"HTTPResponse",
"(",
"body",
",",
"status",
"=",
"status",
",",
"headers",
"=",
"headers",
",... | Returns response object with body in text format.
:param body: Response data to be encoded.
:param status: Response code.
:param headers: Custom Headers.
:param content_type: the content type (string) of the response | [
"Returns",
"response",
"object",
"with",
"body",
"in",
"text",
"format",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/response.py#L227-L240 |
26,618 | huge-success/sanic | sanic/response.py | file_stream | async def file_stream(
location,
status=200,
chunk_size=4096,
mime_type=None,
headers=None,
filename=None,
_range=None,
):
"""Return a streaming response object with file data.
:param location: Location of file on system.
:param chunk_size: The size of each chunk in the stream (... | python | async def file_stream(
location,
status=200,
chunk_size=4096,
mime_type=None,
headers=None,
filename=None,
_range=None,
):
"""Return a streaming response object with file data.
:param location: Location of file on system.
:param chunk_size: The size of each chunk in the stream (... | [
"async",
"def",
"file_stream",
"(",
"location",
",",
"status",
"=",
"200",
",",
"chunk_size",
"=",
"4096",
",",
"mime_type",
"=",
"None",
",",
"headers",
"=",
"None",
",",
"filename",
"=",
"None",
",",
"_range",
"=",
"None",
",",
")",
":",
"headers",
... | Return a streaming response object with file data.
:param location: Location of file on system.
:param chunk_size: The size of each chunk in the stream (in bytes)
:param mime_type: Specific mime_type.
:param headers: Custom Headers.
:param filename: Override filename.
:param _range: | [
"Return",
"a",
"streaming",
"response",
"object",
"with",
"file",
"data",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/response.py#L323-L386 |
26,619 | huge-success/sanic | sanic/response.py | stream | def stream(
streaming_fn,
status=200,
headers=None,
content_type="text/plain; charset=utf-8",
):
"""Accepts an coroutine `streaming_fn` which can be used to
write chunks to a streaming response. Returns a `StreamingHTTPResponse`.
Example usage::
@app.route("/")
async def in... | python | def stream(
streaming_fn,
status=200,
headers=None,
content_type="text/plain; charset=utf-8",
):
"""Accepts an coroutine `streaming_fn` which can be used to
write chunks to a streaming response. Returns a `StreamingHTTPResponse`.
Example usage::
@app.route("/")
async def in... | [
"def",
"stream",
"(",
"streaming_fn",
",",
"status",
"=",
"200",
",",
"headers",
"=",
"None",
",",
"content_type",
"=",
"\"text/plain; charset=utf-8\"",
",",
")",
":",
"return",
"StreamingHTTPResponse",
"(",
"streaming_fn",
",",
"headers",
"=",
"headers",
",",
... | Accepts an coroutine `streaming_fn` which can be used to
write chunks to a streaming response. Returns a `StreamingHTTPResponse`.
Example usage::
@app.route("/")
async def index(request):
async def streaming_fn(response):
await response.write('foo')
... | [
"Accepts",
"an",
"coroutine",
"streaming_fn",
"which",
"can",
"be",
"used",
"to",
"write",
"chunks",
"to",
"a",
"streaming",
"response",
".",
"Returns",
"a",
"StreamingHTTPResponse",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/response.py#L389-L415 |
26,620 | huge-success/sanic | sanic/response.py | StreamingHTTPResponse.write | async def write(self, data):
"""Writes a chunk of data to the streaming response.
:param data: bytes-ish data to be written.
"""
if type(data) != bytes:
data = self._encode_body(data)
self.protocol.push_data(b"%x\r\n%b\r\n" % (len(data), data))
await self.pr... | python | async def write(self, data):
"""Writes a chunk of data to the streaming response.
:param data: bytes-ish data to be written.
"""
if type(data) != bytes:
data = self._encode_body(data)
self.protocol.push_data(b"%x\r\n%b\r\n" % (len(data), data))
await self.pr... | [
"async",
"def",
"write",
"(",
"self",
",",
"data",
")",
":",
"if",
"type",
"(",
"data",
")",
"!=",
"bytes",
":",
"data",
"=",
"self",
".",
"_encode_body",
"(",
"data",
")",
"self",
".",
"protocol",
".",
"push_data",
"(",
"b\"%x\\r\\n%b\\r\\n\"",
"%",
... | Writes a chunk of data to the streaming response.
:param data: bytes-ish data to be written. | [
"Writes",
"a",
"chunk",
"of",
"data",
"to",
"the",
"streaming",
"response",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/response.py#L74-L83 |
26,621 | huge-success/sanic | sanic/response.py | StreamingHTTPResponse.stream | async def stream(
self, version="1.1", keep_alive=False, keep_alive_timeout=None
):
"""Streams headers, runs the `streaming_fn` callback that writes
content to the response body, then finalizes the response body.
"""
headers = self.get_headers(
version,
... | python | async def stream(
self, version="1.1", keep_alive=False, keep_alive_timeout=None
):
"""Streams headers, runs the `streaming_fn` callback that writes
content to the response body, then finalizes the response body.
"""
headers = self.get_headers(
version,
... | [
"async",
"def",
"stream",
"(",
"self",
",",
"version",
"=",
"\"1.1\"",
",",
"keep_alive",
"=",
"False",
",",
"keep_alive_timeout",
"=",
"None",
")",
":",
"headers",
"=",
"self",
".",
"get_headers",
"(",
"version",
",",
"keep_alive",
"=",
"keep_alive",
",",... | Streams headers, runs the `streaming_fn` callback that writes
content to the response body, then finalizes the response body. | [
"Streams",
"headers",
"runs",
"the",
"streaming_fn",
"callback",
"that",
"writes",
"content",
"to",
"the",
"response",
"body",
"then",
"finalizes",
"the",
"response",
"body",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/response.py#L85-L99 |
26,622 | huge-success/sanic | sanic/blueprint_group.py | BlueprintGroup.insert | def insert(self, index: int, item: object) -> None:
"""
The Abstract class `MutableSequence` leverages this insert method to
perform the `BlueprintGroup.append` operation.
:param index: Index to use for removing a new Blueprint item
:param item: New `Blueprint` object.
:... | python | def insert(self, index: int, item: object) -> None:
"""
The Abstract class `MutableSequence` leverages this insert method to
perform the `BlueprintGroup.append` operation.
:param index: Index to use for removing a new Blueprint item
:param item: New `Blueprint` object.
:... | [
"def",
"insert",
"(",
"self",
",",
"index",
":",
"int",
",",
"item",
":",
"object",
")",
"->",
"None",
":",
"self",
".",
"_blueprints",
".",
"insert",
"(",
"index",
",",
"item",
")"
] | The Abstract class `MutableSequence` leverages this insert method to
perform the `BlueprintGroup.append` operation.
:param index: Index to use for removing a new Blueprint item
:param item: New `Blueprint` object.
:return: None | [
"The",
"Abstract",
"class",
"MutableSequence",
"leverages",
"this",
"insert",
"method",
"to",
"perform",
"the",
"BlueprintGroup",
".",
"append",
"operation",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprint_group.py#L91-L100 |
26,623 | huge-success/sanic | sanic/blueprint_group.py | BlueprintGroup.middleware | def middleware(self, *args, **kwargs):
"""
A decorator that can be used to implement a Middleware plugin to
all of the Blueprints that belongs to this specific Blueprint Group.
In case of nested Blueprint Groups, the same middleware is applied
across each of the Blueprints recur... | python | def middleware(self, *args, **kwargs):
"""
A decorator that can be used to implement a Middleware plugin to
all of the Blueprints that belongs to this specific Blueprint Group.
In case of nested Blueprint Groups, the same middleware is applied
across each of the Blueprints recur... | [
"def",
"middleware",
"(",
"self",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"kwargs",
"[",
"\"bp_group\"",
"]",
"=",
"True",
"def",
"register_middleware_for_blueprints",
"(",
"fn",
")",
":",
"for",
"blueprint",
"in",
"self",
".",
"blueprints",
... | A decorator that can be used to implement a Middleware plugin to
all of the Blueprints that belongs to this specific Blueprint Group.
In case of nested Blueprint Groups, the same middleware is applied
across each of the Blueprints recursively.
:param args: Optional positional Parameter... | [
"A",
"decorator",
"that",
"can",
"be",
"used",
"to",
"implement",
"a",
"Middleware",
"plugin",
"to",
"all",
"of",
"the",
"Blueprints",
"that",
"belongs",
"to",
"this",
"specific",
"Blueprint",
"Group",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/blueprint_group.py#L102-L120 |
26,624 | huge-success/sanic | sanic/server.py | HttpProtocol.keep_alive_timeout_callback | def keep_alive_timeout_callback(self):
"""
Check if elapsed time since last response exceeds our configured
maximum keep alive timeout value and if so, close the transport
pipe and let the response writer handle the error.
:return: None
"""
time_elapsed = time() ... | python | def keep_alive_timeout_callback(self):
"""
Check if elapsed time since last response exceeds our configured
maximum keep alive timeout value and if so, close the transport
pipe and let the response writer handle the error.
:return: None
"""
time_elapsed = time() ... | [
"def",
"keep_alive_timeout_callback",
"(",
"self",
")",
":",
"time_elapsed",
"=",
"time",
"(",
")",
"-",
"self",
".",
"_last_response_time",
"if",
"time_elapsed",
"<",
"self",
".",
"keep_alive_timeout",
":",
"time_left",
"=",
"self",
".",
"keep_alive_timeout",
"... | Check if elapsed time since last response exceeds our configured
maximum keep alive timeout value and if so, close the transport
pipe and let the response writer handle the error.
:return: None | [
"Check",
"if",
"elapsed",
"time",
"since",
"last",
"response",
"exceeds",
"our",
"configured",
"maximum",
"keep",
"alive",
"timeout",
"value",
"and",
"if",
"so",
"close",
"the",
"transport",
"pipe",
"and",
"let",
"the",
"response",
"writer",
"handle",
"the",
... | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/server.py#L230-L247 |
26,625 | huge-success/sanic | sanic/server.py | HttpProtocol.write_response | def write_response(self, response):
"""
Writes response content synchronously to the transport.
"""
if self._response_timeout_handler:
self._response_timeout_handler.cancel()
self._response_timeout_handler = None
try:
keep_alive = self.keep_ali... | python | def write_response(self, response):
"""
Writes response content synchronously to the transport.
"""
if self._response_timeout_handler:
self._response_timeout_handler.cancel()
self._response_timeout_handler = None
try:
keep_alive = self.keep_ali... | [
"def",
"write_response",
"(",
"self",
",",
"response",
")",
":",
"if",
"self",
".",
"_response_timeout_handler",
":",
"self",
".",
"_response_timeout_handler",
".",
"cancel",
"(",
")",
"self",
".",
"_response_timeout_handler",
"=",
"None",
"try",
":",
"keep_aliv... | Writes response content synchronously to the transport. | [
"Writes",
"response",
"content",
"synchronously",
"to",
"the",
"transport",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/server.py#L412-L455 |
26,626 | huge-success/sanic | sanic/server.py | HttpProtocol.bail_out | def bail_out(self, message, from_error=False):
"""
In case if the transport pipes are closed and the sanic app encounters
an error while writing data to the transport pipe, we log the error
with proper details.
:param message: Error message to display
:param from_error: ... | python | def bail_out(self, message, from_error=False):
"""
In case if the transport pipes are closed and the sanic app encounters
an error while writing data to the transport pipe, we log the error
with proper details.
:param message: Error message to display
:param from_error: ... | [
"def",
"bail_out",
"(",
"self",
",",
"message",
",",
"from_error",
"=",
"False",
")",
":",
"if",
"from_error",
"or",
"self",
".",
"transport",
"is",
"None",
"or",
"self",
".",
"transport",
".",
"is_closing",
"(",
")",
":",
"logger",
".",
"error",
"(",
... | In case if the transport pipes are closed and the sanic app encounters
an error while writing data to the transport pipe, we log the error
with proper details.
:param message: Error message to display
:param from_error: If the bail out was invoked while handling an
exception... | [
"In",
"case",
"if",
"the",
"transport",
"pipes",
"are",
"closed",
"and",
"the",
"sanic",
"app",
"encounters",
"an",
"error",
"while",
"writing",
"data",
"to",
"the",
"transport",
"pipe",
"we",
"log",
"the",
"error",
"with",
"proper",
"details",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/server.py#L542-L570 |
26,627 | huge-success/sanic | sanic/server.py | HttpProtocol.cleanup | def cleanup(self):
"""This is called when KeepAlive feature is used,
it resets the connection in order for it to be able
to handle receiving another request on the same connection."""
self.parser = None
self.request = None
self.url = None
self.headers = None
... | python | def cleanup(self):
"""This is called when KeepAlive feature is used,
it resets the connection in order for it to be able
to handle receiving another request on the same connection."""
self.parser = None
self.request = None
self.url = None
self.headers = None
... | [
"def",
"cleanup",
"(",
"self",
")",
":",
"self",
".",
"parser",
"=",
"None",
"self",
".",
"request",
"=",
"None",
"self",
".",
"url",
"=",
"None",
"self",
".",
"headers",
"=",
"None",
"self",
".",
"_request_handler_task",
"=",
"None",
"self",
".",
"_... | This is called when KeepAlive feature is used,
it resets the connection in order for it to be able
to handle receiving another request on the same connection. | [
"This",
"is",
"called",
"when",
"KeepAlive",
"feature",
"is",
"used",
"it",
"resets",
"the",
"connection",
"in",
"order",
"for",
"it",
"to",
"be",
"able",
"to",
"handle",
"receiving",
"another",
"request",
"on",
"the",
"same",
"connection",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/server.py#L572-L583 |
26,628 | huge-success/sanic | sanic/request.py | StreamBuffer.read | async def read(self):
""" Stop reading when gets None """
payload = await self._queue.get()
self._queue.task_done()
return payload | python | async def read(self):
""" Stop reading when gets None """
payload = await self._queue.get()
self._queue.task_done()
return payload | [
"async",
"def",
"read",
"(",
"self",
")",
":",
"payload",
"=",
"await",
"self",
".",
"_queue",
".",
"get",
"(",
")",
"self",
".",
"_queue",
".",
"task_done",
"(",
")",
"return",
"payload"
] | Stop reading when gets None | [
"Stop",
"reading",
"when",
"gets",
"None"
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/request.py#L57-L61 |
26,629 | huge-success/sanic | sanic/request.py | Request.remote_addr | def remote_addr(self):
"""Attempt to return the original client ip based on X-Forwarded-For
or X-Real-IP. If HTTP headers are unavailable or untrusted, returns
an empty string.
:return: original client ip.
"""
if not hasattr(self, "_remote_addr"):
if self.app... | python | def remote_addr(self):
"""Attempt to return the original client ip based on X-Forwarded-For
or X-Real-IP. If HTTP headers are unavailable or untrusted, returns
an empty string.
:return: original client ip.
"""
if not hasattr(self, "_remote_addr"):
if self.app... | [
"def",
"remote_addr",
"(",
"self",
")",
":",
"if",
"not",
"hasattr",
"(",
"self",
",",
"\"_remote_addr\"",
")",
":",
"if",
"self",
".",
"app",
".",
"config",
".",
"PROXIES_COUNT",
"==",
"0",
":",
"self",
".",
"_remote_addr",
"=",
"\"\"",
"elif",
"self"... | Attempt to return the original client ip based on X-Forwarded-For
or X-Real-IP. If HTTP headers are unavailable or untrusted, returns
an empty string.
:return: original client ip. | [
"Attempt",
"to",
"return",
"the",
"original",
"client",
"ip",
"based",
"on",
"X",
"-",
"Forwarded",
"-",
"For",
"or",
"X",
"-",
"Real",
"-",
"IP",
".",
"If",
"HTTP",
"headers",
"are",
"unavailable",
"or",
"untrusted",
"returns",
"an",
"empty",
"string",
... | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/request.py#L357-L392 |
26,630 | huge-success/sanic | sanic/config.py | strtobool | def strtobool(val):
"""
This function was borrowed from distutils.utils. While distutils
is part of stdlib, it feels odd to use distutils in main application code.
The function was modified to walk its talk and actually return bool
and not int.
"""
val = val.lower()
if val in ("y", "yes... | python | def strtobool(val):
"""
This function was borrowed from distutils.utils. While distutils
is part of stdlib, it feels odd to use distutils in main application code.
The function was modified to walk its talk and actually return bool
and not int.
"""
val = val.lower()
if val in ("y", "yes... | [
"def",
"strtobool",
"(",
"val",
")",
":",
"val",
"=",
"val",
".",
"lower",
"(",
")",
"if",
"val",
"in",
"(",
"\"y\"",
",",
"\"yes\"",
",",
"\"t\"",
",",
"\"true\"",
",",
"\"on\"",
",",
"\"1\"",
")",
":",
"return",
"True",
"elif",
"val",
"in",
"("... | This function was borrowed from distutils.utils. While distutils
is part of stdlib, it feels odd to use distutils in main application code.
The function was modified to walk its talk and actually return bool
and not int. | [
"This",
"function",
"was",
"borrowed",
"from",
"distutils",
".",
"utils",
".",
"While",
"distutils",
"is",
"part",
"of",
"stdlib",
"it",
"feels",
"odd",
"to",
"use",
"distutils",
"in",
"main",
"application",
"code",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/config.py#L136-L150 |
26,631 | huge-success/sanic | sanic/config.py | Config.from_envvar | def from_envvar(self, variable_name):
"""Load a configuration from an environment variable pointing to
a configuration file.
:param variable_name: name of the environment variable
:return: bool. ``True`` if able to load config, ``False`` otherwise.
"""
config_file = os.e... | python | def from_envvar(self, variable_name):
"""Load a configuration from an environment variable pointing to
a configuration file.
:param variable_name: name of the environment variable
:return: bool. ``True`` if able to load config, ``False`` otherwise.
"""
config_file = os.e... | [
"def",
"from_envvar",
"(",
"self",
",",
"variable_name",
")",
":",
"config_file",
"=",
"os",
".",
"environ",
".",
"get",
"(",
"variable_name",
")",
"if",
"not",
"config_file",
":",
"raise",
"RuntimeError",
"(",
"\"The environment variable %r is not set and \"",
"\... | Load a configuration from an environment variable pointing to
a configuration file.
:param variable_name: name of the environment variable
:return: bool. ``True`` if able to load config, ``False`` otherwise. | [
"Load",
"a",
"configuration",
"from",
"an",
"environment",
"variable",
"pointing",
"to",
"a",
"configuration",
"file",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/config.py#L57-L70 |
26,632 | huge-success/sanic | sanic/config.py | Config.from_object | def from_object(self, obj):
"""Update the values from the given object.
Objects are usually either modules or classes.
Just the uppercase variables in that object are stored in the config.
Example usage::
from yourapplication import default_config
app.config.fro... | python | def from_object(self, obj):
"""Update the values from the given object.
Objects are usually either modules or classes.
Just the uppercase variables in that object are stored in the config.
Example usage::
from yourapplication import default_config
app.config.fro... | [
"def",
"from_object",
"(",
"self",
",",
"obj",
")",
":",
"for",
"key",
"in",
"dir",
"(",
"obj",
")",
":",
"if",
"key",
".",
"isupper",
"(",
")",
":",
"self",
"[",
"key",
"]",
"=",
"getattr",
"(",
"obj",
",",
"key",
")"
] | Update the values from the given object.
Objects are usually either modules or classes.
Just the uppercase variables in that object are stored in the config.
Example usage::
from yourapplication import default_config
app.config.from_object(default_config)
You s... | [
"Update",
"the",
"values",
"from",
"the",
"given",
"object",
".",
"Objects",
"are",
"usually",
"either",
"modules",
"or",
"classes",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/config.py#L95-L114 |
26,633 | huge-success/sanic | sanic/config.py | Config.load_environment_vars | def load_environment_vars(self, prefix=SANIC_PREFIX):
"""
Looks for prefixed environment variables and applies
them to the configuration if present.
"""
for k, v in os.environ.items():
if k.startswith(prefix):
_, config_key = k.split(prefix, 1)
... | python | def load_environment_vars(self, prefix=SANIC_PREFIX):
"""
Looks for prefixed environment variables and applies
them to the configuration if present.
"""
for k, v in os.environ.items():
if k.startswith(prefix):
_, config_key = k.split(prefix, 1)
... | [
"def",
"load_environment_vars",
"(",
"self",
",",
"prefix",
"=",
"SANIC_PREFIX",
")",
":",
"for",
"k",
",",
"v",
"in",
"os",
".",
"environ",
".",
"items",
"(",
")",
":",
"if",
"k",
".",
"startswith",
"(",
"prefix",
")",
":",
"_",
",",
"config_key",
... | Looks for prefixed environment variables and applies
them to the configuration if present. | [
"Looks",
"for",
"prefixed",
"environment",
"variables",
"and",
"applies",
"them",
"to",
"the",
"configuration",
"if",
"present",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/config.py#L116-L133 |
26,634 | huge-success/sanic | sanic/router.py | Router.parse_parameter_string | def parse_parameter_string(cls, parameter_string):
"""Parse a parameter string into its constituent name, type, and
pattern
For example::
parse_parameter_string('<param_one:[A-z]>')` ->
('param_one', str, '[A-z]')
:param parameter_string: String to parse
... | python | def parse_parameter_string(cls, parameter_string):
"""Parse a parameter string into its constituent name, type, and
pattern
For example::
parse_parameter_string('<param_one:[A-z]>')` ->
('param_one', str, '[A-z]')
:param parameter_string: String to parse
... | [
"def",
"parse_parameter_string",
"(",
"cls",
",",
"parameter_string",
")",
":",
"# We could receive NAME or NAME:PATTERN",
"name",
"=",
"parameter_string",
"pattern",
"=",
"\"string\"",
"if",
"\":\"",
"in",
"parameter_string",
":",
"name",
",",
"pattern",
"=",
"parame... | Parse a parameter string into its constituent name, type, and
pattern
For example::
parse_parameter_string('<param_one:[A-z]>')` ->
('param_one', str, '[A-z]')
:param parameter_string: String to parse
:return: tuple containing
(parameter_name, p... | [
"Parse",
"a",
"parameter",
"string",
"into",
"its",
"constituent",
"name",
"type",
"and",
"pattern"
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/router.py#L92-L119 |
26,635 | huge-success/sanic | sanic/router.py | Router.check_dynamic_route_exists | def check_dynamic_route_exists(pattern, routes_to_check, parameters):
"""
Check if a URL pattern exists in a list of routes provided based on
the comparison of URL pattern and the parameters.
:param pattern: URL parameter pattern
:param routes_to_check: list of dynamic routes ei... | python | def check_dynamic_route_exists(pattern, routes_to_check, parameters):
"""
Check if a URL pattern exists in a list of routes provided based on
the comparison of URL pattern and the parameters.
:param pattern: URL parameter pattern
:param routes_to_check: list of dynamic routes ei... | [
"def",
"check_dynamic_route_exists",
"(",
"pattern",
",",
"routes_to_check",
",",
"parameters",
")",
":",
"for",
"ndx",
",",
"route",
"in",
"enumerate",
"(",
"routes_to_check",
")",
":",
"if",
"route",
".",
"pattern",
"==",
"pattern",
"and",
"route",
".",
"p... | Check if a URL pattern exists in a list of routes provided based on
the comparison of URL pattern and the parameters.
:param pattern: URL parameter pattern
:param routes_to_check: list of dynamic routes either hashable or
unhashable routes.
:param parameters: List of :class:... | [
"Check",
"if",
"a",
"URL",
"pattern",
"exists",
"in",
"a",
"list",
"of",
"routes",
"provided",
"based",
"on",
"the",
"comparison",
"of",
"URL",
"pattern",
"and",
"the",
"parameters",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/router.py#L333-L349 |
26,636 | huge-success/sanic | sanic/router.py | Router.get | def get(self, request):
"""Get a request handler based on the URL of the request, or raises an
error
:param request: Request object
:return: handler, arguments, keyword arguments
"""
# No virtual hosts specified; default behavior
if not self.hosts:
re... | python | def get(self, request):
"""Get a request handler based on the URL of the request, or raises an
error
:param request: Request object
:return: handler, arguments, keyword arguments
"""
# No virtual hosts specified; default behavior
if not self.hosts:
re... | [
"def",
"get",
"(",
"self",
",",
"request",
")",
":",
"# No virtual hosts specified; default behavior",
"if",
"not",
"self",
".",
"hosts",
":",
"return",
"self",
".",
"_get",
"(",
"request",
".",
"path",
",",
"request",
".",
"method",
",",
"\"\"",
")",
"# v... | Get a request handler based on the URL of the request, or raises an
error
:param request: Request object
:return: handler, arguments, keyword arguments | [
"Get",
"a",
"request",
"handler",
"based",
"on",
"the",
"URL",
"of",
"the",
"request",
"or",
"raises",
"an",
"error"
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/router.py#L398-L415 |
26,637 | huge-success/sanic | sanic/router.py | Router.get_supported_methods | def get_supported_methods(self, url):
"""Get a list of supported methods for a url and optional host.
:param url: URL string (including host)
:return: frozenset of supported methods
"""
route = self.routes_all.get(url)
# if methods are None then this logic will prevent a... | python | def get_supported_methods(self, url):
"""Get a list of supported methods for a url and optional host.
:param url: URL string (including host)
:return: frozenset of supported methods
"""
route = self.routes_all.get(url)
# if methods are None then this logic will prevent a... | [
"def",
"get_supported_methods",
"(",
"self",
",",
"url",
")",
":",
"route",
"=",
"self",
".",
"routes_all",
".",
"get",
"(",
"url",
")",
"# if methods are None then this logic will prevent an error",
"return",
"getattr",
"(",
"route",
",",
"\"methods\"",
",",
"Non... | Get a list of supported methods for a url and optional host.
:param url: URL string (including host)
:return: frozenset of supported methods | [
"Get",
"a",
"list",
"of",
"supported",
"methods",
"for",
"a",
"url",
"and",
"optional",
"host",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/router.py#L417-L425 |
26,638 | huge-success/sanic | sanic/reloader_helpers.py | _get_args_for_reloading | def _get_args_for_reloading():
"""Returns the executable."""
rv = [sys.executable]
main_module = sys.modules["__main__"]
mod_spec = getattr(main_module, "__spec__", None)
if mod_spec:
# Parent exe was launched as a module rather than a script
rv.extend(["-m", mod_spec.name])
... | python | def _get_args_for_reloading():
"""Returns the executable."""
rv = [sys.executable]
main_module = sys.modules["__main__"]
mod_spec = getattr(main_module, "__spec__", None)
if mod_spec:
# Parent exe was launched as a module rather than a script
rv.extend(["-m", mod_spec.name])
... | [
"def",
"_get_args_for_reloading",
"(",
")",
":",
"rv",
"=",
"[",
"sys",
".",
"executable",
"]",
"main_module",
"=",
"sys",
".",
"modules",
"[",
"\"__main__\"",
"]",
"mod_spec",
"=",
"getattr",
"(",
"main_module",
",",
"\"__spec__\"",
",",
"None",
")",
"if"... | Returns the executable. | [
"Returns",
"the",
"executable",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/reloader_helpers.py#L36-L48 |
26,639 | huge-success/sanic | sanic/reloader_helpers.py | restart_with_reloader | def restart_with_reloader():
"""Create a new process and a subprocess in it with the same arguments as
this one.
"""
cwd = os.getcwd()
args = _get_args_for_reloading()
new_environ = os.environ.copy()
new_environ["SANIC_SERVER_RUNNING"] = "true"
cmd = " ".join(args)
worker_process = P... | python | def restart_with_reloader():
"""Create a new process and a subprocess in it with the same arguments as
this one.
"""
cwd = os.getcwd()
args = _get_args_for_reloading()
new_environ = os.environ.copy()
new_environ["SANIC_SERVER_RUNNING"] = "true"
cmd = " ".join(args)
worker_process = P... | [
"def",
"restart_with_reloader",
"(",
")",
":",
"cwd",
"=",
"os",
".",
"getcwd",
"(",
")",
"args",
"=",
"_get_args_for_reloading",
"(",
")",
"new_environ",
"=",
"os",
".",
"environ",
".",
"copy",
"(",
")",
"new_environ",
"[",
"\"SANIC_SERVER_RUNNING\"",
"]",
... | Create a new process and a subprocess in it with the same arguments as
this one. | [
"Create",
"a",
"new",
"process",
"and",
"a",
"subprocess",
"in",
"it",
"with",
"the",
"same",
"arguments",
"as",
"this",
"one",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/reloader_helpers.py#L51-L66 |
26,640 | huge-success/sanic | sanic/reloader_helpers.py | kill_process_children | def kill_process_children(pid):
"""Find and kill child processes of a process.
:param pid: PID of parent process (process ID)
:return: Nothing
"""
if sys.platform == "darwin":
kill_process_children_osx(pid)
elif sys.platform == "linux":
kill_process_children_unix(pid)
else:
... | python | def kill_process_children(pid):
"""Find and kill child processes of a process.
:param pid: PID of parent process (process ID)
:return: Nothing
"""
if sys.platform == "darwin":
kill_process_children_osx(pid)
elif sys.platform == "linux":
kill_process_children_unix(pid)
else:
... | [
"def",
"kill_process_children",
"(",
"pid",
")",
":",
"if",
"sys",
".",
"platform",
"==",
"\"darwin\"",
":",
"kill_process_children_osx",
"(",
"pid",
")",
"elif",
"sys",
".",
"platform",
"==",
"\"linux\"",
":",
"kill_process_children_unix",
"(",
"pid",
")",
"e... | Find and kill child processes of a process.
:param pid: PID of parent process (process ID)
:return: Nothing | [
"Find",
"and",
"kill",
"child",
"processes",
"of",
"a",
"process",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/reloader_helpers.py#L110-L121 |
26,641 | huge-success/sanic | sanic/reloader_helpers.py | watchdog | def watchdog(sleep_interval):
"""Watch project files, restart worker process if a change happened.
:param sleep_interval: interval in second.
:return: Nothing
"""
mtimes = {}
worker_process = restart_with_reloader()
signal.signal(
signal.SIGTERM, lambda *args: kill_program_completly... | python | def watchdog(sleep_interval):
"""Watch project files, restart worker process if a change happened.
:param sleep_interval: interval in second.
:return: Nothing
"""
mtimes = {}
worker_process = restart_with_reloader()
signal.signal(
signal.SIGTERM, lambda *args: kill_program_completly... | [
"def",
"watchdog",
"(",
"sleep_interval",
")",
":",
"mtimes",
"=",
"{",
"}",
"worker_process",
"=",
"restart_with_reloader",
"(",
")",
"signal",
".",
"signal",
"(",
"signal",
".",
"SIGTERM",
",",
"lambda",
"*",
"args",
":",
"kill_program_completly",
"(",
"wo... | Watch project files, restart worker process if a change happened.
:param sleep_interval: interval in second.
:return: Nothing | [
"Watch",
"project",
"files",
"restart",
"worker",
"process",
"if",
"a",
"change",
"happened",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/reloader_helpers.py#L135-L167 |
26,642 | huge-success/sanic | sanic/views.py | HTTPMethodView.as_view | def as_view(cls, *class_args, **class_kwargs):
"""Return view function for use with the routing system, that
dispatches request to appropriate handler method.
"""
def view(*args, **kwargs):
self = view.view_class(*class_args, **class_kwargs)
return self.dispatch_... | python | def as_view(cls, *class_args, **class_kwargs):
"""Return view function for use with the routing system, that
dispatches request to appropriate handler method.
"""
def view(*args, **kwargs):
self = view.view_class(*class_args, **class_kwargs)
return self.dispatch_... | [
"def",
"as_view",
"(",
"cls",
",",
"*",
"class_args",
",",
"*",
"*",
"class_kwargs",
")",
":",
"def",
"view",
"(",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"self",
"=",
"view",
".",
"view_class",
"(",
"*",
"class_args",
",",
"*",
"*",
"cla... | Return view function for use with the routing system, that
dispatches request to appropriate handler method. | [
"Return",
"view",
"function",
"for",
"use",
"with",
"the",
"routing",
"system",
"that",
"dispatches",
"request",
"to",
"appropriate",
"handler",
"method",
"."
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/sanic/views.py#L47-L65 |
26,643 | huge-success/sanic | examples/limit_concurrency.py | bounded_fetch | async def bounded_fetch(session, url):
"""
Use session object to perform 'get' request on url
"""
async with sem, session.get(url) as response:
return await response.json() | python | async def bounded_fetch(session, url):
"""
Use session object to perform 'get' request on url
"""
async with sem, session.get(url) as response:
return await response.json() | [
"async",
"def",
"bounded_fetch",
"(",
"session",
",",
"url",
")",
":",
"async",
"with",
"sem",
",",
"session",
".",
"get",
"(",
"url",
")",
"as",
"response",
":",
"return",
"await",
"response",
".",
"json",
"(",
")"
] | Use session object to perform 'get' request on url | [
"Use",
"session",
"object",
"to",
"perform",
"get",
"request",
"on",
"url"
] | 6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd | https://github.com/huge-success/sanic/blob/6a4a3f617fdbe1d3ee8bdc9d1b12ad2d0b34acdd/examples/limit_concurrency.py#L18-L23 |
26,644 | albu/albumentations | albumentations/augmentations/functional.py | preserve_shape | def preserve_shape(func):
"""Preserve shape of the image."""
@wraps(func)
def wrapped_function(img, *args, **kwargs):
shape = img.shape
result = func(img, *args, **kwargs)
result = result.reshape(shape)
return result
return wrapped_function | python | def preserve_shape(func):
"""Preserve shape of the image."""
@wraps(func)
def wrapped_function(img, *args, **kwargs):
shape = img.shape
result = func(img, *args, **kwargs)
result = result.reshape(shape)
return result
return wrapped_function | [
"def",
"preserve_shape",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapped_function",
"(",
"img",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"shape",
"=",
"img",
".",
"shape",
"result",
"=",
"func",
"(",
"img",
",",
... | Preserve shape of the image. | [
"Preserve",
"shape",
"of",
"the",
"image",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L35-L44 |
26,645 | albu/albumentations | albumentations/augmentations/functional.py | preserve_channel_dim | def preserve_channel_dim(func):
"""Preserve dummy channel dim."""
@wraps(func)
def wrapped_function(img, *args, **kwargs):
shape = img.shape
result = func(img, *args, **kwargs)
if len(shape) == 3 and shape[-1] == 1 and len(result.shape) == 2:
result = np.expand_dims(resul... | python | def preserve_channel_dim(func):
"""Preserve dummy channel dim."""
@wraps(func)
def wrapped_function(img, *args, **kwargs):
shape = img.shape
result = func(img, *args, **kwargs)
if len(shape) == 3 and shape[-1] == 1 and len(result.shape) == 2:
result = np.expand_dims(resul... | [
"def",
"preserve_channel_dim",
"(",
"func",
")",
":",
"@",
"wraps",
"(",
"func",
")",
"def",
"wrapped_function",
"(",
"img",
",",
"*",
"args",
",",
"*",
"*",
"kwargs",
")",
":",
"shape",
"=",
"img",
".",
"shape",
"result",
"=",
"func",
"(",
"img",
... | Preserve dummy channel dim. | [
"Preserve",
"dummy",
"channel",
"dim",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L47-L57 |
26,646 | albu/albumentations | albumentations/augmentations/functional.py | add_snow | def add_snow(img, snow_point, brightness_coeff):
"""Bleaches out pixels, mitation snow.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img:
snow_point:
brightness_coeff:
Returns:
"""
non_rgb_warning(img)
input_dtype = img.dtype
... | python | def add_snow(img, snow_point, brightness_coeff):
"""Bleaches out pixels, mitation snow.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img:
snow_point:
brightness_coeff:
Returns:
"""
non_rgb_warning(img)
input_dtype = img.dtype
... | [
"def",
"add_snow",
"(",
"img",
",",
"snow_point",
",",
"brightness_coeff",
")",
":",
"non_rgb_warning",
"(",
"img",
")",
"input_dtype",
"=",
"img",
".",
"dtype",
"needs_float",
"=",
"False",
"snow_point",
"*=",
"127.5",
"# = 255 / 2",
"snow_point",
"+=",
"85",... | Bleaches out pixels, mitation snow.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img:
snow_point:
brightness_coeff:
Returns: | [
"Bleaches",
"out",
"pixels",
"mitation",
"snow",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L438-L479 |
26,647 | albu/albumentations | albumentations/augmentations/functional.py | add_fog | def add_fog(img, fog_coef, alpha_coef, haze_list):
"""Add fog to the image.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
fog_coef (float):
alpha_coef (float):
haze_list (list):
Returns:
"""
non_rgb_warning(img)
... | python | def add_fog(img, fog_coef, alpha_coef, haze_list):
"""Add fog to the image.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
fog_coef (float):
alpha_coef (float):
haze_list (list):
Returns:
"""
non_rgb_warning(img)
... | [
"def",
"add_fog",
"(",
"img",
",",
"fog_coef",
",",
"alpha_coef",
",",
"haze_list",
")",
":",
"non_rgb_warning",
"(",
"img",
")",
"input_dtype",
"=",
"img",
".",
"dtype",
"needs_float",
"=",
"False",
"if",
"input_dtype",
"==",
"np",
".",
"float32",
":",
... | Add fog to the image.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
fog_coef (float):
alpha_coef (float):
haze_list (list):
Returns: | [
"Add",
"fog",
"to",
"the",
"image",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L533-L578 |
26,648 | albu/albumentations | albumentations/augmentations/functional.py | add_sun_flare | def add_sun_flare(img, flare_center_x, flare_center_y, src_radius, src_color, circles):
"""Add sun flare.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
flare_center_x (float):
flare_center_y (float):
src_radius:
src_c... | python | def add_sun_flare(img, flare_center_x, flare_center_y, src_radius, src_color, circles):
"""Add sun flare.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
flare_center_x (float):
flare_center_y (float):
src_radius:
src_c... | [
"def",
"add_sun_flare",
"(",
"img",
",",
"flare_center_x",
",",
"flare_center_y",
",",
"src_radius",
",",
"src_color",
",",
"circles",
")",
":",
"non_rgb_warning",
"(",
"img",
")",
"input_dtype",
"=",
"img",
".",
"dtype",
"needs_float",
"=",
"False",
"if",
"... | Add sun flare.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
flare_center_x (float):
flare_center_y (float):
src_radius:
src_color (int, int, int):
circles (list):
Returns: | [
"Add",
"sun",
"flare",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L582-L633 |
26,649 | albu/albumentations | albumentations/augmentations/functional.py | add_shadow | def add_shadow(img, vertices_list):
"""Add shadows to the image.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
vertices_list (list):
Returns:
"""
non_rgb_warning(img)
input_dtype = img.dtype
needs_float = False
if ... | python | def add_shadow(img, vertices_list):
"""Add shadows to the image.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
vertices_list (list):
Returns:
"""
non_rgb_warning(img)
input_dtype = img.dtype
needs_float = False
if ... | [
"def",
"add_shadow",
"(",
"img",
",",
"vertices_list",
")",
":",
"non_rgb_warning",
"(",
"img",
")",
"input_dtype",
"=",
"img",
".",
"dtype",
"needs_float",
"=",
"False",
"if",
"input_dtype",
"==",
"np",
".",
"float32",
":",
"img",
"=",
"from_float",
"(",
... | Add shadows to the image.
From https://github.com/UjjwalSaxena/Automold--Road-Augmentation-Library
Args:
img (np.array):
vertices_list (list):
Returns: | [
"Add",
"shadows",
"to",
"the",
"image",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L637-L675 |
26,650 | albu/albumentations | albumentations/augmentations/functional.py | bbox_vflip | def bbox_vflip(bbox, rows, cols):
"""Flip a bounding box vertically around the x-axis."""
x_min, y_min, x_max, y_max = bbox
return [x_min, 1 - y_max, x_max, 1 - y_min] | python | def bbox_vflip(bbox, rows, cols):
"""Flip a bounding box vertically around the x-axis."""
x_min, y_min, x_max, y_max = bbox
return [x_min, 1 - y_max, x_max, 1 - y_min] | [
"def",
"bbox_vflip",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
":",
"x_min",
",",
"y_min",
",",
"x_max",
",",
"y_max",
"=",
"bbox",
"return",
"[",
"x_min",
",",
"1",
"-",
"y_max",
",",
"x_max",
",",
"1",
"-",
"y_min",
"]"
] | Flip a bounding box vertically around the x-axis. | [
"Flip",
"a",
"bounding",
"box",
"vertically",
"around",
"the",
"x",
"-",
"axis",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L918-L921 |
26,651 | albu/albumentations | albumentations/augmentations/functional.py | bbox_hflip | def bbox_hflip(bbox, rows, cols):
"""Flip a bounding box horizontally around the y-axis."""
x_min, y_min, x_max, y_max = bbox
return [1 - x_max, y_min, 1 - x_min, y_max] | python | def bbox_hflip(bbox, rows, cols):
"""Flip a bounding box horizontally around the y-axis."""
x_min, y_min, x_max, y_max = bbox
return [1 - x_max, y_min, 1 - x_min, y_max] | [
"def",
"bbox_hflip",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
":",
"x_min",
",",
"y_min",
",",
"x_max",
",",
"y_max",
"=",
"bbox",
"return",
"[",
"1",
"-",
"x_max",
",",
"y_min",
",",
"1",
"-",
"x_min",
",",
"y_max",
"]"
] | Flip a bounding box horizontally around the y-axis. | [
"Flip",
"a",
"bounding",
"box",
"horizontally",
"around",
"the",
"y",
"-",
"axis",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L924-L927 |
26,652 | albu/albumentations | albumentations/augmentations/functional.py | bbox_flip | def bbox_flip(bbox, d, rows, cols):
"""Flip a bounding box either vertically, horizontally or both depending on the value of `d`.
Raises:
ValueError: if value of `d` is not -1, 0 or 1.
"""
if d == 0:
bbox = bbox_vflip(bbox, rows, cols)
elif d == 1:
bbox = bbox_hflip(bbox, r... | python | def bbox_flip(bbox, d, rows, cols):
"""Flip a bounding box either vertically, horizontally or both depending on the value of `d`.
Raises:
ValueError: if value of `d` is not -1, 0 or 1.
"""
if d == 0:
bbox = bbox_vflip(bbox, rows, cols)
elif d == 1:
bbox = bbox_hflip(bbox, r... | [
"def",
"bbox_flip",
"(",
"bbox",
",",
"d",
",",
"rows",
",",
"cols",
")",
":",
"if",
"d",
"==",
"0",
":",
"bbox",
"=",
"bbox_vflip",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
"elif",
"d",
"==",
"1",
":",
"bbox",
"=",
"bbox_hflip",
"(",
"bbox"... | Flip a bounding box either vertically, horizontally or both depending on the value of `d`.
Raises:
ValueError: if value of `d` is not -1, 0 or 1. | [
"Flip",
"a",
"bounding",
"box",
"either",
"vertically",
"horizontally",
"or",
"both",
"depending",
"on",
"the",
"value",
"of",
"d",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L930-L946 |
26,653 | albu/albumentations | albumentations/augmentations/functional.py | crop_bbox_by_coords | def crop_bbox_by_coords(bbox, crop_coords, crop_height, crop_width, rows, cols):
"""Crop a bounding box using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop.
"""
bbox = denormalize_bbox(bbox, rows, cols)
x_min, y_min, x_max, y_ma... | python | def crop_bbox_by_coords(bbox, crop_coords, crop_height, crop_width, rows, cols):
"""Crop a bounding box using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop.
"""
bbox = denormalize_bbox(bbox, rows, cols)
x_min, y_min, x_max, y_ma... | [
"def",
"crop_bbox_by_coords",
"(",
"bbox",
",",
"crop_coords",
",",
"crop_height",
",",
"crop_width",
",",
"rows",
",",
"cols",
")",
":",
"bbox",
"=",
"denormalize_bbox",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
"x_min",
",",
"y_min",
",",
"x_max",
",... | Crop a bounding box using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop. | [
"Crop",
"a",
"bounding",
"box",
"using",
"the",
"provided",
"coordinates",
"of",
"bottom",
"-",
"left",
"and",
"top",
"-",
"right",
"corners",
"in",
"pixels",
"and",
"the",
"required",
"height",
"and",
"width",
"of",
"the",
"crop",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L949-L957 |
26,654 | albu/albumentations | albumentations/augmentations/functional.py | bbox_rotate | def bbox_rotate(bbox, angle, rows, cols, interpolation):
"""Rotates a bounding box by angle degrees
Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
angle (int): Angle of rotation in degrees
rows (int): Image rows.
cols (int): Image cols.
interpolation (int): in... | python | def bbox_rotate(bbox, angle, rows, cols, interpolation):
"""Rotates a bounding box by angle degrees
Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
angle (int): Angle of rotation in degrees
rows (int): Image rows.
cols (int): Image cols.
interpolation (int): in... | [
"def",
"bbox_rotate",
"(",
"bbox",
",",
"angle",
",",
"rows",
",",
"cols",
",",
"interpolation",
")",
":",
"scale",
"=",
"cols",
"/",
"float",
"(",
"rows",
")",
"x",
"=",
"np",
".",
"array",
"(",
"[",
"bbox",
"[",
"0",
"]",
",",
"bbox",
"[",
"2... | Rotates a bounding box by angle degrees
Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
angle (int): Angle of rotation in degrees
rows (int): Image rows.
cols (int): Image cols.
interpolation (int): interpolation method.
return a tuple (x_min, y_min, x_max... | [
"Rotates",
"a",
"bounding",
"box",
"by",
"angle",
"degrees"
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L998-L1020 |
26,655 | albu/albumentations | albumentations/augmentations/functional.py | bbox_transpose | def bbox_transpose(bbox, axis, rows, cols):
"""Transposes a bounding box along given axis.
Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
axis (int): 0 - main axis, 1 - secondary axis.
rows (int): Image rows.
cols (int): Image cols.
"""
x_min, y_min, x_max, y_... | python | def bbox_transpose(bbox, axis, rows, cols):
"""Transposes a bounding box along given axis.
Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
axis (int): 0 - main axis, 1 - secondary axis.
rows (int): Image rows.
cols (int): Image cols.
"""
x_min, y_min, x_max, y_... | [
"def",
"bbox_transpose",
"(",
"bbox",
",",
"axis",
",",
"rows",
",",
"cols",
")",
":",
"x_min",
",",
"y_min",
",",
"x_max",
",",
"y_max",
"=",
"bbox",
"if",
"axis",
"!=",
"0",
"and",
"axis",
"!=",
"1",
":",
"raise",
"ValueError",
"(",
"'Axis must be ... | Transposes a bounding box along given axis.
Args:
bbox (tuple): A tuple (x_min, y_min, x_max, y_max).
axis (int): 0 - main axis, 1 - secondary axis.
rows (int): Image rows.
cols (int): Image cols. | [
"Transposes",
"a",
"bounding",
"box",
"along",
"given",
"axis",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L1023-L1039 |
26,656 | albu/albumentations | albumentations/augmentations/functional.py | keypoint_vflip | def keypoint_vflip(kp, rows, cols):
"""Flip a keypoint vertically around the x-axis."""
x, y, angle, scale = kp
c = math.cos(angle)
s = math.sin(angle)
angle = math.atan2(-s, c)
return [x, (rows - 1) - y, angle, scale] | python | def keypoint_vflip(kp, rows, cols):
"""Flip a keypoint vertically around the x-axis."""
x, y, angle, scale = kp
c = math.cos(angle)
s = math.sin(angle)
angle = math.atan2(-s, c)
return [x, (rows - 1) - y, angle, scale] | [
"def",
"keypoint_vflip",
"(",
"kp",
",",
"rows",
",",
"cols",
")",
":",
"x",
",",
"y",
",",
"angle",
",",
"scale",
"=",
"kp",
"c",
"=",
"math",
".",
"cos",
"(",
"angle",
")",
"s",
"=",
"math",
".",
"sin",
"(",
"angle",
")",
"angle",
"=",
"mat... | Flip a keypoint vertically around the x-axis. | [
"Flip",
"a",
"keypoint",
"vertically",
"around",
"the",
"x",
"-",
"axis",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L1042-L1048 |
26,657 | albu/albumentations | albumentations/augmentations/functional.py | keypoint_flip | def keypoint_flip(bbox, d, rows, cols):
"""Flip a keypoint either vertically, horizontally or both depending on the value of `d`.
Raises:
ValueError: if value of `d` is not -1, 0 or 1.
"""
if d == 0:
bbox = keypoint_vflip(bbox, rows, cols)
elif d == 1:
bbox = keypoint_hflip... | python | def keypoint_flip(bbox, d, rows, cols):
"""Flip a keypoint either vertically, horizontally or both depending on the value of `d`.
Raises:
ValueError: if value of `d` is not -1, 0 or 1.
"""
if d == 0:
bbox = keypoint_vflip(bbox, rows, cols)
elif d == 1:
bbox = keypoint_hflip... | [
"def",
"keypoint_flip",
"(",
"bbox",
",",
"d",
",",
"rows",
",",
"cols",
")",
":",
"if",
"d",
"==",
"0",
":",
"bbox",
"=",
"keypoint_vflip",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
"elif",
"d",
"==",
"1",
":",
"bbox",
"=",
"keypoint_hflip",
"... | Flip a keypoint either vertically, horizontally or both depending on the value of `d`.
Raises:
ValueError: if value of `d` is not -1, 0 or 1. | [
"Flip",
"a",
"keypoint",
"either",
"vertically",
"horizontally",
"or",
"both",
"depending",
"on",
"the",
"value",
"of",
"d",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L1060-L1076 |
26,658 | albu/albumentations | albumentations/augmentations/functional.py | keypoint_scale | def keypoint_scale(keypoint, scale_x, scale_y, **params):
"""Scales a keypoint by scale_x and scale_y."""
x, y, a, s = keypoint
return [x * scale_x, y * scale_y, a, s * max(scale_x, scale_y)] | python | def keypoint_scale(keypoint, scale_x, scale_y, **params):
"""Scales a keypoint by scale_x and scale_y."""
x, y, a, s = keypoint
return [x * scale_x, y * scale_y, a, s * max(scale_x, scale_y)] | [
"def",
"keypoint_scale",
"(",
"keypoint",
",",
"scale_x",
",",
"scale_y",
",",
"*",
"*",
"params",
")",
":",
"x",
",",
"y",
",",
"a",
",",
"s",
"=",
"keypoint",
"return",
"[",
"x",
"*",
"scale_x",
",",
"y",
"*",
"scale_y",
",",
"a",
",",
"s",
"... | Scales a keypoint by scale_x and scale_y. | [
"Scales",
"a",
"keypoint",
"by",
"scale_x",
"and",
"scale_y",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L1107-L1110 |
26,659 | albu/albumentations | albumentations/augmentations/functional.py | crop_keypoint_by_coords | def crop_keypoint_by_coords(keypoint, crop_coords, crop_height, crop_width, rows, cols):
"""Crop a keypoint using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop.
"""
x, y, a, s = keypoint
x1, y1, x2, y2 = crop_coords
cropped_... | python | def crop_keypoint_by_coords(keypoint, crop_coords, crop_height, crop_width, rows, cols):
"""Crop a keypoint using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop.
"""
x, y, a, s = keypoint
x1, y1, x2, y2 = crop_coords
cropped_... | [
"def",
"crop_keypoint_by_coords",
"(",
"keypoint",
",",
"crop_coords",
",",
"crop_height",
",",
"crop_width",
",",
"rows",
",",
"cols",
")",
":",
"x",
",",
"y",
",",
"a",
",",
"s",
"=",
"keypoint",
"x1",
",",
"y1",
",",
"x2",
",",
"y2",
"=",
"crop_co... | Crop a keypoint using the provided coordinates of bottom-left and top-right corners in pixels and the
required height and width of the crop. | [
"Crop",
"a",
"keypoint",
"using",
"the",
"provided",
"coordinates",
"of",
"bottom",
"-",
"left",
"and",
"top",
"-",
"right",
"corners",
"in",
"pixels",
"and",
"the",
"required",
"height",
"and",
"width",
"of",
"the",
"crop",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L1113-L1120 |
26,660 | albu/albumentations | albumentations/augmentations/functional.py | py3round | def py3round(number):
"""Unified rounding in all python versions."""
if abs(round(number) - number) == 0.5:
return int(2.0 * round(number / 2.0))
return int(round(number)) | python | def py3round(number):
"""Unified rounding in all python versions."""
if abs(round(number) - number) == 0.5:
return int(2.0 * round(number / 2.0))
return int(round(number)) | [
"def",
"py3round",
"(",
"number",
")",
":",
"if",
"abs",
"(",
"round",
"(",
"number",
")",
"-",
"number",
")",
"==",
"0.5",
":",
"return",
"int",
"(",
"2.0",
"*",
"round",
"(",
"number",
"/",
"2.0",
")",
")",
"return",
"int",
"(",
"round",
"(",
... | Unified rounding in all python versions. | [
"Unified",
"rounding",
"in",
"all",
"python",
"versions",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/functional.py#L1133-L1138 |
26,661 | albu/albumentations | albumentations/augmentations/bbox_utils.py | normalize_bbox | def normalize_bbox(bbox, rows, cols):
"""Normalize coordinates of a bounding box. Divide x-coordinates by image width and y-coordinates
by image height.
"""
if rows == 0:
raise ValueError('Argument rows cannot be zero')
if cols == 0:
raise ValueError('Argument cols cannot be zero')
... | python | def normalize_bbox(bbox, rows, cols):
"""Normalize coordinates of a bounding box. Divide x-coordinates by image width and y-coordinates
by image height.
"""
if rows == 0:
raise ValueError('Argument rows cannot be zero')
if cols == 0:
raise ValueError('Argument cols cannot be zero')
... | [
"def",
"normalize_bbox",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
":",
"if",
"rows",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'Argument rows cannot be zero'",
")",
"if",
"cols",
"==",
"0",
":",
"raise",
"ValueError",
"(",
"'Argument cols cannot be zero'... | Normalize coordinates of a bounding box. Divide x-coordinates by image width and y-coordinates
by image height. | [
"Normalize",
"coordinates",
"of",
"a",
"bounding",
"box",
".",
"Divide",
"x",
"-",
"coordinates",
"by",
"image",
"width",
"and",
"y",
"-",
"coordinates",
"by",
"image",
"height",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L10-L20 |
26,662 | albu/albumentations | albumentations/augmentations/bbox_utils.py | normalize_bboxes | def normalize_bboxes(bboxes, rows, cols):
"""Normalize a list of bounding boxes."""
return [normalize_bbox(bbox, rows, cols) for bbox in bboxes] | python | def normalize_bboxes(bboxes, rows, cols):
"""Normalize a list of bounding boxes."""
return [normalize_bbox(bbox, rows, cols) for bbox in bboxes] | [
"def",
"normalize_bboxes",
"(",
"bboxes",
",",
"rows",
",",
"cols",
")",
":",
"return",
"[",
"normalize_bbox",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
"for",
"bbox",
"in",
"bboxes",
"]"
] | Normalize a list of bounding boxes. | [
"Normalize",
"a",
"list",
"of",
"bounding",
"boxes",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L37-L39 |
26,663 | albu/albumentations | albumentations/augmentations/bbox_utils.py | denormalize_bboxes | def denormalize_bboxes(bboxes, rows, cols):
"""Denormalize a list of bounding boxes."""
return [denormalize_bbox(bbox, rows, cols) for bbox in bboxes] | python | def denormalize_bboxes(bboxes, rows, cols):
"""Denormalize a list of bounding boxes."""
return [denormalize_bbox(bbox, rows, cols) for bbox in bboxes] | [
"def",
"denormalize_bboxes",
"(",
"bboxes",
",",
"rows",
",",
"cols",
")",
":",
"return",
"[",
"denormalize_bbox",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
"for",
"bbox",
"in",
"bboxes",
"]"
] | Denormalize a list of bounding boxes. | [
"Denormalize",
"a",
"list",
"of",
"bounding",
"boxes",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L42-L44 |
26,664 | albu/albumentations | albumentations/augmentations/bbox_utils.py | calculate_bbox_area | def calculate_bbox_area(bbox, rows, cols):
"""Calculate the area of a bounding box in pixels."""
bbox = denormalize_bbox(bbox, rows, cols)
x_min, y_min, x_max, y_max = bbox[:4]
area = (x_max - x_min) * (y_max - y_min)
return area | python | def calculate_bbox_area(bbox, rows, cols):
"""Calculate the area of a bounding box in pixels."""
bbox = denormalize_bbox(bbox, rows, cols)
x_min, y_min, x_max, y_max = bbox[:4]
area = (x_max - x_min) * (y_max - y_min)
return area | [
"def",
"calculate_bbox_area",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
":",
"bbox",
"=",
"denormalize_bbox",
"(",
"bbox",
",",
"rows",
",",
"cols",
")",
"x_min",
",",
"y_min",
",",
"x_max",
",",
"y_max",
"=",
"bbox",
"[",
":",
"4",
"]",
"area",
... | Calculate the area of a bounding box in pixels. | [
"Calculate",
"the",
"area",
"of",
"a",
"bounding",
"box",
"in",
"pixels",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L47-L52 |
26,665 | albu/albumentations | albumentations/augmentations/bbox_utils.py | filter_bboxes_by_visibility | def filter_bboxes_by_visibility(original_shape, bboxes, transformed_shape, transformed_bboxes,
threshold=0., min_area=0.):
"""Filter bounding boxes and return only those boxes whose visibility after transformation is above
the threshold and minimal area of bounding box in pixels ... | python | def filter_bboxes_by_visibility(original_shape, bboxes, transformed_shape, transformed_bboxes,
threshold=0., min_area=0.):
"""Filter bounding boxes and return only those boxes whose visibility after transformation is above
the threshold and minimal area of bounding box in pixels ... | [
"def",
"filter_bboxes_by_visibility",
"(",
"original_shape",
",",
"bboxes",
",",
"transformed_shape",
",",
"transformed_bboxes",
",",
"threshold",
"=",
"0.",
",",
"min_area",
"=",
"0.",
")",
":",
"img_height",
",",
"img_width",
"=",
"original_shape",
"[",
":",
"... | Filter bounding boxes and return only those boxes whose visibility after transformation is above
the threshold and minimal area of bounding box in pixels is more then min_area.
Args:
original_shape (tuple): original image shape
bboxes (list): original bounding boxes
transformed_shape(tu... | [
"Filter",
"bounding",
"boxes",
"and",
"return",
"only",
"those",
"boxes",
"whose",
"visibility",
"after",
"transformation",
"is",
"above",
"the",
"threshold",
"and",
"minimal",
"area",
"of",
"bounding",
"box",
"in",
"pixels",
"is",
"more",
"then",
"min_area",
... | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L55-L82 |
26,666 | albu/albumentations | albumentations/augmentations/bbox_utils.py | convert_bbox_from_albumentations | def convert_bbox_from_albumentations(bbox, target_format, rows, cols, check_validity=False):
"""Convert a bounding box from the format used by albumentations to a format, specified in `target_format`.
Args:
bbox (list): bounding box with coordinates in the format used by albumentations
target_f... | python | def convert_bbox_from_albumentations(bbox, target_format, rows, cols, check_validity=False):
"""Convert a bounding box from the format used by albumentations to a format, specified in `target_format`.
Args:
bbox (list): bounding box with coordinates in the format used by albumentations
target_f... | [
"def",
"convert_bbox_from_albumentations",
"(",
"bbox",
",",
"target_format",
",",
"rows",
",",
"cols",
",",
"check_validity",
"=",
"False",
")",
":",
"if",
"target_format",
"not",
"in",
"{",
"'coco'",
",",
"'pascal_voc'",
"}",
":",
"raise",
"ValueError",
"(",... | Convert a bounding box from the format used by albumentations to a format, specified in `target_format`.
Args:
bbox (list): bounding box with coordinates in the format used by albumentations
target_format (str): required format of the output bounding box. Should be 'coco' or 'pascal_voc'.
r... | [
"Convert",
"a",
"bounding",
"box",
"from",
"the",
"format",
"used",
"by",
"albumentations",
"to",
"a",
"format",
"specified",
"in",
"target_format",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L122-L152 |
26,667 | albu/albumentations | albumentations/augmentations/bbox_utils.py | convert_bboxes_to_albumentations | def convert_bboxes_to_albumentations(bboxes, source_format, rows, cols, check_validity=False):
"""Convert a list bounding boxes from a format specified in `source_format` to the format used by albumentations
"""
return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox... | python | def convert_bboxes_to_albumentations(bboxes, source_format, rows, cols, check_validity=False):
"""Convert a list bounding boxes from a format specified in `source_format` to the format used by albumentations
"""
return [convert_bbox_to_albumentations(bbox, source_format, rows, cols, check_validity) for bbox... | [
"def",
"convert_bboxes_to_albumentations",
"(",
"bboxes",
",",
"source_format",
",",
"rows",
",",
"cols",
",",
"check_validity",
"=",
"False",
")",
":",
"return",
"[",
"convert_bbox_to_albumentations",
"(",
"bbox",
",",
"source_format",
",",
"rows",
",",
"cols",
... | Convert a list bounding boxes from a format specified in `source_format` to the format used by albumentations | [
"Convert",
"a",
"list",
"bounding",
"boxes",
"from",
"a",
"format",
"specified",
"in",
"source_format",
"to",
"the",
"format",
"used",
"by",
"albumentations"
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L155-L158 |
26,668 | albu/albumentations | albumentations/augmentations/bbox_utils.py | convert_bboxes_from_albumentations | def convert_bboxes_from_albumentations(bboxes, target_format, rows, cols, check_validity=False):
"""Convert a list of bounding boxes from the format used by albumentations to a format, specified
in `target_format`.
Args:
bboxes (list): List of bounding box with coordinates in the format used by alb... | python | def convert_bboxes_from_albumentations(bboxes, target_format, rows, cols, check_validity=False):
"""Convert a list of bounding boxes from the format used by albumentations to a format, specified
in `target_format`.
Args:
bboxes (list): List of bounding box with coordinates in the format used by alb... | [
"def",
"convert_bboxes_from_albumentations",
"(",
"bboxes",
",",
"target_format",
",",
"rows",
",",
"cols",
",",
"check_validity",
"=",
"False",
")",
":",
"return",
"[",
"convert_bbox_from_albumentations",
"(",
"bbox",
",",
"target_format",
",",
"rows",
",",
"cols... | Convert a list of bounding boxes from the format used by albumentations to a format, specified
in `target_format`.
Args:
bboxes (list): List of bounding box with coordinates in the format used by albumentations
target_format (str): required format of the output bounding box. Should be 'coco' or... | [
"Convert",
"a",
"list",
"of",
"bounding",
"boxes",
"from",
"the",
"format",
"used",
"by",
"albumentations",
"to",
"a",
"format",
"specified",
"in",
"target_format",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L161-L172 |
26,669 | albu/albumentations | albumentations/augmentations/bbox_utils.py | check_bbox | def check_bbox(bbox):
"""Check if bbox boundaries are in range 0, 1 and minimums are lesser then maximums"""
for name, value in zip(['x_min', 'y_min', 'x_max', 'y_max'], bbox[:4]):
if not 0 <= value <= 1:
raise ValueError(
'Expected {name} for bbox {bbox} '
't... | python | def check_bbox(bbox):
"""Check if bbox boundaries are in range 0, 1 and minimums are lesser then maximums"""
for name, value in zip(['x_min', 'y_min', 'x_max', 'y_max'], bbox[:4]):
if not 0 <= value <= 1:
raise ValueError(
'Expected {name} for bbox {bbox} '
't... | [
"def",
"check_bbox",
"(",
"bbox",
")",
":",
"for",
"name",
",",
"value",
"in",
"zip",
"(",
"[",
"'x_min'",
",",
"'y_min'",
",",
"'x_max'",
",",
"'y_max'",
"]",
",",
"bbox",
"[",
":",
"4",
"]",
")",
":",
"if",
"not",
"0",
"<=",
"value",
"<=",
"1... | Check if bbox boundaries are in range 0, 1 and minimums are lesser then maximums | [
"Check",
"if",
"bbox",
"boundaries",
"are",
"in",
"range",
"0",
"1",
"and",
"minimums",
"are",
"lesser",
"then",
"maximums"
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L175-L195 |
26,670 | albu/albumentations | albumentations/augmentations/bbox_utils.py | filter_bboxes | def filter_bboxes(bboxes, rows, cols, min_area=0., min_visibility=0.):
"""Remove bounding boxes that either lie outside of the visible area by more then min_visibility
or whose area in pixels is under the threshold set by `min_area`. Also it crops boxes to final image size.
Args:
bboxes (list): Lis... | python | def filter_bboxes(bboxes, rows, cols, min_area=0., min_visibility=0.):
"""Remove bounding boxes that either lie outside of the visible area by more then min_visibility
or whose area in pixels is under the threshold set by `min_area`. Also it crops boxes to final image size.
Args:
bboxes (list): Lis... | [
"def",
"filter_bboxes",
"(",
"bboxes",
",",
"rows",
",",
"cols",
",",
"min_area",
"=",
"0.",
",",
"min_visibility",
"=",
"0.",
")",
":",
"resulting_boxes",
"=",
"[",
"]",
"for",
"bbox",
"in",
"bboxes",
":",
"transformed_box_area",
"=",
"calculate_bbox_area",... | Remove bounding boxes that either lie outside of the visible area by more then min_visibility
or whose area in pixels is under the threshold set by `min_area`. Also it crops boxes to final image size.
Args:
bboxes (list): List of bounding box with coordinates in the format used by albumentations
... | [
"Remove",
"bounding",
"boxes",
"that",
"either",
"lie",
"outside",
"of",
"the",
"visible",
"area",
"by",
"more",
"then",
"min_visibility",
"or",
"whose",
"area",
"in",
"pixels",
"is",
"under",
"the",
"threshold",
"set",
"by",
"min_area",
".",
"Also",
"it",
... | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L204-L228 |
26,671 | albu/albumentations | albumentations/augmentations/bbox_utils.py | union_of_bboxes | def union_of_bboxes(height, width, bboxes, erosion_rate=0.0, to_int=False):
"""Calculate union of bounding boxes.
Args:
height (float): Height of image or space.
width (float): Width of image or space.
bboxes (list): List like bounding boxes. Format is `[x_min, y_min, x_max, y_max]`.
... | python | def union_of_bboxes(height, width, bboxes, erosion_rate=0.0, to_int=False):
"""Calculate union of bounding boxes.
Args:
height (float): Height of image or space.
width (float): Width of image or space.
bboxes (list): List like bounding boxes. Format is `[x_min, y_min, x_max, y_max]`.
... | [
"def",
"union_of_bboxes",
"(",
"height",
",",
"width",
",",
"bboxes",
",",
"erosion_rate",
"=",
"0.0",
",",
"to_int",
"=",
"False",
")",
":",
"x1",
",",
"y1",
"=",
"width",
",",
"height",
"x2",
",",
"y2",
"=",
"0",
",",
"0",
"for",
"b",
"in",
"bb... | Calculate union of bounding boxes.
Args:
height (float): Height of image or space.
width (float): Width of image or space.
bboxes (list): List like bounding boxes. Format is `[x_min, y_min, x_max, y_max]`.
erosion_rate (float): How much each bounding box can be shrinked, useful for ... | [
"Calculate",
"union",
"of",
"bounding",
"boxes",
"."
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/bbox_utils.py#L231-L249 |
26,672 | albu/albumentations | albumentations/augmentations/keypoints_utils.py | check_keypoint | def check_keypoint(kp, rows, cols):
"""Check if keypoint coordinates are in range [0, 1)"""
for name, value, size in zip(['x', 'y'], kp[:2], [cols, rows]):
if not 0 <= value < size:
raise ValueError(
'Expected {name} for keypoint {kp} '
'to be in the range [0.... | python | def check_keypoint(kp, rows, cols):
"""Check if keypoint coordinates are in range [0, 1)"""
for name, value, size in zip(['x', 'y'], kp[:2], [cols, rows]):
if not 0 <= value < size:
raise ValueError(
'Expected {name} for keypoint {kp} '
'to be in the range [0.... | [
"def",
"check_keypoint",
"(",
"kp",
",",
"rows",
",",
"cols",
")",
":",
"for",
"name",
",",
"value",
",",
"size",
"in",
"zip",
"(",
"[",
"'x'",
",",
"'y'",
"]",
",",
"kp",
"[",
":",
"2",
"]",
",",
"[",
"cols",
",",
"rows",
"]",
")",
":",
"i... | Check if keypoint coordinates are in range [0, 1) | [
"Check",
"if",
"keypoint",
"coordinates",
"are",
"in",
"range",
"[",
"0",
"1",
")"
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/keypoints_utils.py#L5-L17 |
26,673 | albu/albumentations | albumentations/augmentations/keypoints_utils.py | check_keypoints | def check_keypoints(keypoints, rows, cols):
"""Check if keypoints boundaries are in range [0, 1)"""
for kp in keypoints:
check_keypoint(kp, rows, cols) | python | def check_keypoints(keypoints, rows, cols):
"""Check if keypoints boundaries are in range [0, 1)"""
for kp in keypoints:
check_keypoint(kp, rows, cols) | [
"def",
"check_keypoints",
"(",
"keypoints",
",",
"rows",
",",
"cols",
")",
":",
"for",
"kp",
"in",
"keypoints",
":",
"check_keypoint",
"(",
"kp",
",",
"rows",
",",
"cols",
")"
] | Check if keypoints boundaries are in range [0, 1) | [
"Check",
"if",
"keypoints",
"boundaries",
"are",
"in",
"range",
"[",
"0",
"1",
")"
] | b31393cd6126516d37a84e44c879bd92c68ffc93 | https://github.com/albu/albumentations/blob/b31393cd6126516d37a84e44c879bd92c68ffc93/albumentations/augmentations/keypoints_utils.py#L20-L23 |
26,674 | tornadoweb/tornado | tornado/autoreload.py | main | def main() -> None:
"""Command-line wrapper to re-run a script whenever its source changes.
Scripts may be specified by filename or module name::
python -m tornado.autoreload -m tornado.test.runtests
python -m tornado.autoreload tornado/test/runtests.py
Running a script with this wrapper ... | python | def main() -> None:
"""Command-line wrapper to re-run a script whenever its source changes.
Scripts may be specified by filename or module name::
python -m tornado.autoreload -m tornado.test.runtests
python -m tornado.autoreload tornado/test/runtests.py
Running a script with this wrapper ... | [
"def",
"main",
"(",
")",
"->",
"None",
":",
"# Remember that we were launched with autoreload as main.",
"# The main module can be tricky; set the variables both in our globals",
"# (which may be __main__) and the real importable version.",
"import",
"tornado",
".",
"autoreload",
"global... | Command-line wrapper to re-run a script whenever its source changes.
Scripts may be specified by filename or module name::
python -m tornado.autoreload -m tornado.test.runtests
python -m tornado.autoreload tornado/test/runtests.py
Running a script with this wrapper is similar to calling
`... | [
"Command",
"-",
"line",
"wrapper",
"to",
"re",
"-",
"run",
"a",
"script",
"whenever",
"its",
"source",
"changes",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/autoreload.py#L272-L358 |
26,675 | tornadoweb/tornado | tornado/tcpclient.py | _Connector.split | def split(
addrinfo: List[Tuple]
) -> Tuple[
List[Tuple[socket.AddressFamily, Tuple]],
List[Tuple[socket.AddressFamily, Tuple]],
]:
"""Partition the ``addrinfo`` list by address family.
Returns two lists. The first list contains the first entry from
``addrinfo``... | python | def split(
addrinfo: List[Tuple]
) -> Tuple[
List[Tuple[socket.AddressFamily, Tuple]],
List[Tuple[socket.AddressFamily, Tuple]],
]:
"""Partition the ``addrinfo`` list by address family.
Returns two lists. The first list contains the first entry from
``addrinfo``... | [
"def",
"split",
"(",
"addrinfo",
":",
"List",
"[",
"Tuple",
"]",
")",
"->",
"Tuple",
"[",
"List",
"[",
"Tuple",
"[",
"socket",
".",
"AddressFamily",
",",
"Tuple",
"]",
"]",
",",
"List",
"[",
"Tuple",
"[",
"socket",
".",
"AddressFamily",
",",
"Tuple",... | Partition the ``addrinfo`` list by address family.
Returns two lists. The first list contains the first entry from
``addrinfo`` and all others with the same family, and the
second list contains all other addresses (normally one list will
be AF_INET and the other AF_INET6, although non-... | [
"Partition",
"the",
"addrinfo",
"list",
"by",
"address",
"family",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/tcpclient.py#L81-L103 |
26,676 | tornadoweb/tornado | tornado/tcpclient.py | TCPClient.connect | async def connect(
self,
host: str,
port: int,
af: socket.AddressFamily = socket.AF_UNSPEC,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
max_buffer_size: int = None,
source_ip: str = None,
source_port: int = None,
timeout: Union[float... | python | async def connect(
self,
host: str,
port: int,
af: socket.AddressFamily = socket.AF_UNSPEC,
ssl_options: Union[Dict[str, Any], ssl.SSLContext] = None,
max_buffer_size: int = None,
source_ip: str = None,
source_port: int = None,
timeout: Union[float... | [
"async",
"def",
"connect",
"(",
"self",
",",
"host",
":",
"str",
",",
"port",
":",
"int",
",",
"af",
":",
"socket",
".",
"AddressFamily",
"=",
"socket",
".",
"AF_UNSPEC",
",",
"ssl_options",
":",
"Union",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"... | Connect to the given host and port.
Asynchronously returns an `.IOStream` (or `.SSLIOStream` if
``ssl_options`` is not None).
Using the ``source_ip`` kwarg, one can specify the source
IP address to use when establishing the connection.
In case the user needs to resolve and
... | [
"Connect",
"to",
"the",
"given",
"host",
"and",
"port",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/tcpclient.py#L222-L296 |
26,677 | tornadoweb/tornado | tornado/httpserver.py | HTTPServer.close_all_connections | async def close_all_connections(self) -> None:
"""Close all open connections and asynchronously wait for them to finish.
This method is used in combination with `~.TCPServer.stop` to
support clean shutdowns (especially for unittests). Typical
usage would call ``stop()`` first to stop ac... | python | async def close_all_connections(self) -> None:
"""Close all open connections and asynchronously wait for them to finish.
This method is used in combination with `~.TCPServer.stop` to
support clean shutdowns (especially for unittests). Typical
usage would call ``stop()`` first to stop ac... | [
"async",
"def",
"close_all_connections",
"(",
"self",
")",
"->",
"None",
":",
"while",
"self",
".",
"_connections",
":",
"# Peek at an arbitrary element of the set",
"conn",
"=",
"next",
"(",
"iter",
"(",
"self",
".",
"_connections",
")",
")",
"await",
"conn",
... | Close all open connections and asynchronously wait for them to finish.
This method is used in combination with `~.TCPServer.stop` to
support clean shutdowns (especially for unittests). Typical
usage would call ``stop()`` first to stop accepting new
connections, then ``await close_all_co... | [
"Close",
"all",
"open",
"connections",
"and",
"asynchronously",
"wait",
"for",
"them",
"to",
"finish",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/httpserver.py#L204-L221 |
26,678 | tornadoweb/tornado | tornado/httpserver.py | _HTTPRequestContext._apply_xheaders | def _apply_xheaders(self, headers: httputil.HTTPHeaders) -> None:
"""Rewrite the ``remote_ip`` and ``protocol`` fields."""
# Squid uses X-Forwarded-For, others use X-Real-Ip
ip = headers.get("X-Forwarded-For", self.remote_ip)
# Skip trusted downstream hosts in X-Forwarded-For list
... | python | def _apply_xheaders(self, headers: httputil.HTTPHeaders) -> None:
"""Rewrite the ``remote_ip`` and ``protocol`` fields."""
# Squid uses X-Forwarded-For, others use X-Real-Ip
ip = headers.get("X-Forwarded-For", self.remote_ip)
# Skip trusted downstream hosts in X-Forwarded-For list
... | [
"def",
"_apply_xheaders",
"(",
"self",
",",
"headers",
":",
"httputil",
".",
"HTTPHeaders",
")",
"->",
"None",
":",
"# Squid uses X-Forwarded-For, others use X-Real-Ip",
"ip",
"=",
"headers",
".",
"get",
"(",
"\"X-Forwarded-For\"",
",",
"self",
".",
"remote_ip",
"... | Rewrite the ``remote_ip`` and ``protocol`` fields. | [
"Rewrite",
"the",
"remote_ip",
"and",
"protocol",
"fields",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/httpserver.py#L332-L352 |
26,679 | tornadoweb/tornado | tornado/httpserver.py | _HTTPRequestContext._unapply_xheaders | def _unapply_xheaders(self) -> None:
"""Undo changes from `_apply_xheaders`.
Xheaders are per-request so they should not leak to the next
request on the same connection.
"""
self.remote_ip = self._orig_remote_ip
self.protocol = self._orig_protocol | python | def _unapply_xheaders(self) -> None:
"""Undo changes from `_apply_xheaders`.
Xheaders are per-request so they should not leak to the next
request on the same connection.
"""
self.remote_ip = self._orig_remote_ip
self.protocol = self._orig_protocol | [
"def",
"_unapply_xheaders",
"(",
"self",
")",
"->",
"None",
":",
"self",
".",
"remote_ip",
"=",
"self",
".",
"_orig_remote_ip",
"self",
".",
"protocol",
"=",
"self",
".",
"_orig_protocol"
] | Undo changes from `_apply_xheaders`.
Xheaders are per-request so they should not leak to the next
request on the same connection. | [
"Undo",
"changes",
"from",
"_apply_xheaders",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/httpserver.py#L354-L361 |
26,680 | tornadoweb/tornado | tornado/locale.py | set_default_locale | def set_default_locale(code: str) -> None:
"""Sets the default locale.
The default locale is assumed to be the language used for all strings
in the system. The translations loaded from disk are mappings from
the default locale to the destination locale. Consequently, you don't
need to create a tran... | python | def set_default_locale(code: str) -> None:
"""Sets the default locale.
The default locale is assumed to be the language used for all strings
in the system. The translations loaded from disk are mappings from
the default locale to the destination locale. Consequently, you don't
need to create a tran... | [
"def",
"set_default_locale",
"(",
"code",
":",
"str",
")",
"->",
"None",
":",
"global",
"_default_locale",
"global",
"_supported_locales",
"_default_locale",
"=",
"code",
"_supported_locales",
"=",
"frozenset",
"(",
"list",
"(",
"_translations",
".",
"keys",
"(",
... | Sets the default locale.
The default locale is assumed to be the language used for all strings
in the system. The translations loaded from disk are mappings from
the default locale to the destination locale. Consequently, you don't
need to create a translation file for the default locale. | [
"Sets",
"the",
"default",
"locale",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L77-L88 |
26,681 | tornadoweb/tornado | tornado/locale.py | load_translations | def load_translations(directory: str, encoding: str = None) -> None:
"""Loads translations from CSV files in a directory.
Translations are strings with optional Python-style named placeholders
(e.g., ``My name is %(name)s``) and their associated translations.
The directory should have translation file... | python | def load_translations(directory: str, encoding: str = None) -> None:
"""Loads translations from CSV files in a directory.
Translations are strings with optional Python-style named placeholders
(e.g., ``My name is %(name)s``) and their associated translations.
The directory should have translation file... | [
"def",
"load_translations",
"(",
"directory",
":",
"str",
",",
"encoding",
":",
"str",
"=",
"None",
")",
"->",
"None",
":",
"global",
"_translations",
"global",
"_supported_locales",
"_translations",
"=",
"{",
"}",
"for",
"path",
"in",
"os",
".",
"listdir",
... | Loads translations from CSV files in a directory.
Translations are strings with optional Python-style named placeholders
(e.g., ``My name is %(name)s``) and their associated translations.
The directory should have translation files of the form ``LOCALE.csv``,
e.g. ``es_GT.csv``. The CSV files should h... | [
"Loads",
"translations",
"from",
"CSV",
"files",
"in",
"a",
"directory",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L91-L175 |
26,682 | tornadoweb/tornado | tornado/locale.py | load_gettext_translations | def load_gettext_translations(directory: str, domain: str) -> None:
"""Loads translations from `gettext`'s locale tree
Locale tree is similar to system's ``/usr/share/locale``, like::
{directory}/{lang}/LC_MESSAGES/{domain}.mo
Three steps are required to have your app translated:
1. Generate... | python | def load_gettext_translations(directory: str, domain: str) -> None:
"""Loads translations from `gettext`'s locale tree
Locale tree is similar to system's ``/usr/share/locale``, like::
{directory}/{lang}/LC_MESSAGES/{domain}.mo
Three steps are required to have your app translated:
1. Generate... | [
"def",
"load_gettext_translations",
"(",
"directory",
":",
"str",
",",
"domain",
":",
"str",
")",
"->",
"None",
":",
"global",
"_translations",
"global",
"_supported_locales",
"global",
"_use_gettext",
"_translations",
"=",
"{",
"}",
"for",
"lang",
"in",
"os",
... | Loads translations from `gettext`'s locale tree
Locale tree is similar to system's ``/usr/share/locale``, like::
{directory}/{lang}/LC_MESSAGES/{domain}.mo
Three steps are required to have your app translated:
1. Generate POT translation file::
xgettext --language=Python --keyword=_:1,2... | [
"Loads",
"translations",
"from",
"gettext",
"s",
"locale",
"tree"
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L178-L218 |
26,683 | tornadoweb/tornado | tornado/locale.py | Locale.get_closest | def get_closest(cls, *locale_codes: str) -> "Locale":
"""Returns the closest match for the given locale code."""
for code in locale_codes:
if not code:
continue
code = code.replace("-", "_")
parts = code.split("_")
if len(parts) > 2:
... | python | def get_closest(cls, *locale_codes: str) -> "Locale":
"""Returns the closest match for the given locale code."""
for code in locale_codes:
if not code:
continue
code = code.replace("-", "_")
parts = code.split("_")
if len(parts) > 2:
... | [
"def",
"get_closest",
"(",
"cls",
",",
"*",
"locale_codes",
":",
"str",
")",
"->",
"\"Locale\"",
":",
"for",
"code",
"in",
"locale_codes",
":",
"if",
"not",
"code",
":",
"continue",
"code",
"=",
"code",
".",
"replace",
"(",
"\"-\"",
",",
"\"_\"",
")",
... | Returns the closest match for the given locale code. | [
"Returns",
"the",
"closest",
"match",
"for",
"the",
"given",
"locale",
"code",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L236-L251 |
26,684 | tornadoweb/tornado | tornado/locale.py | Locale.get | def get(cls, code: str) -> "Locale":
"""Returns the Locale for the given locale code.
If it is not supported, we raise an exception.
"""
if code not in cls._cache:
assert code in _supported_locales
translations = _translations.get(code, None)
if trans... | python | def get(cls, code: str) -> "Locale":
"""Returns the Locale for the given locale code.
If it is not supported, we raise an exception.
"""
if code not in cls._cache:
assert code in _supported_locales
translations = _translations.get(code, None)
if trans... | [
"def",
"get",
"(",
"cls",
",",
"code",
":",
"str",
")",
"->",
"\"Locale\"",
":",
"if",
"code",
"not",
"in",
"cls",
".",
"_cache",
":",
"assert",
"code",
"in",
"_supported_locales",
"translations",
"=",
"_translations",
".",
"get",
"(",
"code",
",",
"No... | Returns the Locale for the given locale code.
If it is not supported, we raise an exception. | [
"Returns",
"the",
"Locale",
"for",
"the",
"given",
"locale",
"code",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L254-L269 |
26,685 | tornadoweb/tornado | tornado/locale.py | Locale.translate | def translate(
self, message: str, plural_message: str = None, count: int = None
) -> str:
"""Returns the translation for the given message for this locale.
If ``plural_message`` is given, you must also provide
``count``. We return ``plural_message`` when ``count != 1``,
and... | python | def translate(
self, message: str, plural_message: str = None, count: int = None
) -> str:
"""Returns the translation for the given message for this locale.
If ``plural_message`` is given, you must also provide
``count``. We return ``plural_message`` when ``count != 1``,
and... | [
"def",
"translate",
"(",
"self",
",",
"message",
":",
"str",
",",
"plural_message",
":",
"str",
"=",
"None",
",",
"count",
":",
"int",
"=",
"None",
")",
"->",
"str",
":",
"raise",
"NotImplementedError",
"(",
")"
] | Returns the translation for the given message for this locale.
If ``plural_message`` is given, you must also provide
``count``. We return ``plural_message`` when ``count != 1``,
and we return the singular form for the given message when
``count == 1``. | [
"Returns",
"the",
"translation",
"for",
"the",
"given",
"message",
"for",
"this",
"locale",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L306-L316 |
26,686 | tornadoweb/tornado | tornado/locale.py | Locale.format_day | def format_day(
self, date: datetime.datetime, gmt_offset: int = 0, dow: bool = True
) -> bool:
"""Formats the given date as a day of week.
Example: "Monday, January 22". You can remove the day of week with
``dow=False``.
"""
local_date = date - datetime.timedelta(mi... | python | def format_day(
self, date: datetime.datetime, gmt_offset: int = 0, dow: bool = True
) -> bool:
"""Formats the given date as a day of week.
Example: "Monday, January 22". You can remove the day of week with
``dow=False``.
"""
local_date = date - datetime.timedelta(mi... | [
"def",
"format_day",
"(",
"self",
",",
"date",
":",
"datetime",
".",
"datetime",
",",
"gmt_offset",
":",
"int",
"=",
"0",
",",
"dow",
":",
"bool",
"=",
"True",
")",
"->",
"bool",
":",
"local_date",
"=",
"date",
"-",
"datetime",
".",
"timedelta",
"(",... | Formats the given date as a day of week.
Example: "Monday, January 22". You can remove the day of week with
``dow=False``. | [
"Formats",
"the",
"given",
"date",
"as",
"a",
"day",
"of",
"week",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L423-L443 |
26,687 | tornadoweb/tornado | tornado/locale.py | Locale.list | def list(self, parts: Any) -> str:
"""Returns a comma-separated list for the given list of parts.
The format is, e.g., "A, B and C", "A and B" or just "A" for lists
of size 1.
"""
_ = self.translate
if len(parts) == 0:
return ""
if len(parts) == 1:
... | python | def list(self, parts: Any) -> str:
"""Returns a comma-separated list for the given list of parts.
The format is, e.g., "A, B and C", "A and B" or just "A" for lists
of size 1.
"""
_ = self.translate
if len(parts) == 0:
return ""
if len(parts) == 1:
... | [
"def",
"list",
"(",
"self",
",",
"parts",
":",
"Any",
")",
"->",
"str",
":",
"_",
"=",
"self",
".",
"translate",
"if",
"len",
"(",
"parts",
")",
"==",
"0",
":",
"return",
"\"\"",
"if",
"len",
"(",
"parts",
")",
"==",
"1",
":",
"return",
"parts"... | Returns a comma-separated list for the given list of parts.
The format is, e.g., "A, B and C", "A and B" or just "A" for lists
of size 1. | [
"Returns",
"a",
"comma",
"-",
"separated",
"list",
"for",
"the",
"given",
"list",
"of",
"parts",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L445-L460 |
26,688 | tornadoweb/tornado | tornado/locale.py | Locale.friendly_number | def friendly_number(self, value: int) -> str:
"""Returns a comma-separated number for the given integer."""
if self.code not in ("en", "en_US"):
return str(value)
s = str(value)
parts = []
while s:
parts.append(s[-3:])
s = s[:-3]
return... | python | def friendly_number(self, value: int) -> str:
"""Returns a comma-separated number for the given integer."""
if self.code not in ("en", "en_US"):
return str(value)
s = str(value)
parts = []
while s:
parts.append(s[-3:])
s = s[:-3]
return... | [
"def",
"friendly_number",
"(",
"self",
",",
"value",
":",
"int",
")",
"->",
"str",
":",
"if",
"self",
".",
"code",
"not",
"in",
"(",
"\"en\"",
",",
"\"en_US\"",
")",
":",
"return",
"str",
"(",
"value",
")",
"s",
"=",
"str",
"(",
"value",
")",
"pa... | Returns a comma-separated number for the given integer. | [
"Returns",
"a",
"comma",
"-",
"separated",
"number",
"for",
"the",
"given",
"integer",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L462-L471 |
26,689 | tornadoweb/tornado | tornado/locale.py | GettextLocale.pgettext | def pgettext(
self, context: str, message: str, plural_message: str = None, count: int = None
) -> str:
"""Allows to set context for translation, accepts plural forms.
Usage example::
pgettext("law", "right")
pgettext("good", "right")
Plural message example... | python | def pgettext(
self, context: str, message: str, plural_message: str = None, count: int = None
) -> str:
"""Allows to set context for translation, accepts plural forms.
Usage example::
pgettext("law", "right")
pgettext("good", "right")
Plural message example... | [
"def",
"pgettext",
"(",
"self",
",",
"context",
":",
"str",
",",
"message",
":",
"str",
",",
"plural_message",
":",
"str",
"=",
"None",
",",
"count",
":",
"int",
"=",
"None",
")",
"->",
"str",
":",
"if",
"plural_message",
"is",
"not",
"None",
":",
... | Allows to set context for translation, accepts plural forms.
Usage example::
pgettext("law", "right")
pgettext("good", "right")
Plural message example::
pgettext("organization", "club", "clubs", len(clubs))
pgettext("stick", "club", "clubs", len(clubs)... | [
"Allows",
"to",
"set",
"context",
"for",
"translation",
"accepts",
"plural",
"forms",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/locale.py#L522-L562 |
26,690 | tornadoweb/tornado | tornado/routing.py | _unquote_or_none | def _unquote_or_none(s: Optional[str]) -> Optional[bytes]: # noqa: F811
"""None-safe wrapper around url_unescape to handle unmatched optional
groups correctly.
Note that args are passed as bytes so the handler can decide what
encoding to use.
"""
if s is None:
return s
return url_u... | python | def _unquote_or_none(s: Optional[str]) -> Optional[bytes]: # noqa: F811
"""None-safe wrapper around url_unescape to handle unmatched optional
groups correctly.
Note that args are passed as bytes so the handler can decide what
encoding to use.
"""
if s is None:
return s
return url_u... | [
"def",
"_unquote_or_none",
"(",
"s",
":",
"Optional",
"[",
"str",
"]",
")",
"->",
"Optional",
"[",
"bytes",
"]",
":",
"# noqa: F811",
"if",
"s",
"is",
"None",
":",
"return",
"s",
"return",
"url_unescape",
"(",
"s",
",",
"encoding",
"=",
"None",
",",
... | None-safe wrapper around url_unescape to handle unmatched optional
groups correctly.
Note that args are passed as bytes so the handler can decide what
encoding to use. | [
"None",
"-",
"safe",
"wrapper",
"around",
"url_unescape",
"to",
"handle",
"unmatched",
"optional",
"groups",
"correctly",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/routing.py#L702-L711 |
26,691 | tornadoweb/tornado | tornado/routing.py | Router.find_handler | def find_handler(
self, request: httputil.HTTPServerRequest, **kwargs: Any
) -> Optional[httputil.HTTPMessageDelegate]:
"""Must be implemented to return an appropriate instance of `~.httputil.HTTPMessageDelegate`
that can serve the request.
Routing implementations may pass additional... | python | def find_handler(
self, request: httputil.HTTPServerRequest, **kwargs: Any
) -> Optional[httputil.HTTPMessageDelegate]:
"""Must be implemented to return an appropriate instance of `~.httputil.HTTPMessageDelegate`
that can serve the request.
Routing implementations may pass additional... | [
"def",
"find_handler",
"(",
"self",
",",
"request",
":",
"httputil",
".",
"HTTPServerRequest",
",",
"*",
"*",
"kwargs",
":",
"Any",
")",
"->",
"Optional",
"[",
"httputil",
".",
"HTTPMessageDelegate",
"]",
":",
"raise",
"NotImplementedError",
"(",
")"
] | Must be implemented to return an appropriate instance of `~.httputil.HTTPMessageDelegate`
that can serve the request.
Routing implementations may pass additional kwargs to extend the routing logic.
:arg httputil.HTTPServerRequest request: current HTTP request.
:arg kwargs: additional ke... | [
"Must",
"be",
"implemented",
"to",
"return",
"an",
"appropriate",
"instance",
"of",
"~",
".",
"httputil",
".",
"HTTPMessageDelegate",
"that",
"can",
"serve",
"the",
"request",
".",
"Routing",
"implementations",
"may",
"pass",
"additional",
"kwargs",
"to",
"exten... | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/routing.py#L193-L205 |
26,692 | tornadoweb/tornado | tornado/routing.py | RuleRouter.add_rules | def add_rules(self, rules: _RuleList) -> None:
"""Appends new rules to the router.
:arg rules: a list of Rule instances (or tuples of arguments, which are
passed to Rule constructor).
"""
for rule in rules:
if isinstance(rule, (tuple, list)):
asse... | python | def add_rules(self, rules: _RuleList) -> None:
"""Appends new rules to the router.
:arg rules: a list of Rule instances (or tuples of arguments, which are
passed to Rule constructor).
"""
for rule in rules:
if isinstance(rule, (tuple, list)):
asse... | [
"def",
"add_rules",
"(",
"self",
",",
"rules",
":",
"_RuleList",
")",
"->",
"None",
":",
"for",
"rule",
"in",
"rules",
":",
"if",
"isinstance",
"(",
"rule",
",",
"(",
"tuple",
",",
"list",
")",
")",
":",
"assert",
"len",
"(",
"rule",
")",
"in",
"... | Appends new rules to the router.
:arg rules: a list of Rule instances (or tuples of arguments, which are
passed to Rule constructor). | [
"Appends",
"new",
"rules",
"to",
"the",
"router",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/routing.py#L334-L348 |
26,693 | tornadoweb/tornado | tornado/routing.py | RuleRouter.get_target_delegate | def get_target_delegate(
self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any
) -> Optional[httputil.HTTPMessageDelegate]:
"""Returns an instance of `~.httputil.HTTPMessageDelegate` for a
Rule's target. This method is called by `~.find_handler` and can be
exte... | python | def get_target_delegate(
self, target: Any, request: httputil.HTTPServerRequest, **target_params: Any
) -> Optional[httputil.HTTPMessageDelegate]:
"""Returns an instance of `~.httputil.HTTPMessageDelegate` for a
Rule's target. This method is called by `~.find_handler` and can be
exte... | [
"def",
"get_target_delegate",
"(",
"self",
",",
"target",
":",
"Any",
",",
"request",
":",
"httputil",
".",
"HTTPServerRequest",
",",
"*",
"*",
"target_params",
":",
"Any",
")",
"->",
"Optional",
"[",
"httputil",
".",
"HTTPMessageDelegate",
"]",
":",
"if",
... | Returns an instance of `~.httputil.HTTPMessageDelegate` for a
Rule's target. This method is called by `~.find_handler` and can be
extended to provide additional target types.
:arg target: a Rule's target.
:arg httputil.HTTPServerRequest request: current request.
:arg target_para... | [
"Returns",
"an",
"instance",
"of",
"~",
".",
"httputil",
".",
"HTTPMessageDelegate",
"for",
"a",
"Rule",
"s",
"target",
".",
"This",
"method",
"is",
"called",
"by",
"~",
".",
"find_handler",
"and",
"can",
"be",
"extended",
"to",
"provide",
"additional",
"t... | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/routing.py#L376-L401 |
26,694 | tornadoweb/tornado | tornado/routing.py | Matcher.match | def match(self, request: httputil.HTTPServerRequest) -> Optional[Dict[str, Any]]:
"""Matches current instance against the request.
:arg httputil.HTTPServerRequest request: current HTTP request
:returns: a dict of parameters to be passed to the target handler
(for example, ``handler_... | python | def match(self, request: httputil.HTTPServerRequest) -> Optional[Dict[str, Any]]:
"""Matches current instance against the request.
:arg httputil.HTTPServerRequest request: current HTTP request
:returns: a dict of parameters to be passed to the target handler
(for example, ``handler_... | [
"def",
"match",
"(",
"self",
",",
"request",
":",
"httputil",
".",
"HTTPServerRequest",
")",
"->",
"Optional",
"[",
"Dict",
"[",
"str",
",",
"Any",
"]",
"]",
":",
"raise",
"NotImplementedError",
"(",
")"
] | Matches current instance against the request.
:arg httputil.HTTPServerRequest request: current HTTP request
:returns: a dict of parameters to be passed to the target handler
(for example, ``handler_kwargs``, ``path_args``, ``path_kwargs``
can be passed for proper `~.web.RequestH... | [
"Matches",
"current",
"instance",
"against",
"the",
"request",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/routing.py#L493-L503 |
26,695 | tornadoweb/tornado | demos/webspider/webspider.py | get_links_from_url | async def get_links_from_url(url):
"""Download the page at `url` and parse it for links.
Returned links have had the fragment after `#` removed, and have been made
absolute so, e.g. the URL 'gen.html#tornado.gen.coroutine' becomes
'http://www.tornadoweb.org/en/stable/gen.html'.
"""
response = a... | python | async def get_links_from_url(url):
"""Download the page at `url` and parse it for links.
Returned links have had the fragment after `#` removed, and have been made
absolute so, e.g. the URL 'gen.html#tornado.gen.coroutine' becomes
'http://www.tornadoweb.org/en/stable/gen.html'.
"""
response = a... | [
"async",
"def",
"get_links_from_url",
"(",
"url",
")",
":",
"response",
"=",
"await",
"httpclient",
".",
"AsyncHTTPClient",
"(",
")",
".",
"fetch",
"(",
"url",
")",
"print",
"(",
"\"fetched %s\"",
"%",
"url",
")",
"html",
"=",
"response",
".",
"body",
".... | Download the page at `url` and parse it for links.
Returned links have had the fragment after `#` removed, and have been made
absolute so, e.g. the URL 'gen.html#tornado.gen.coroutine' becomes
'http://www.tornadoweb.org/en/stable/gen.html'. | [
"Download",
"the",
"page",
"at",
"url",
"and",
"parse",
"it",
"for",
"links",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/demos/webspider/webspider.py#L15-L26 |
26,696 | tornadoweb/tornado | demos/chat/chatdemo.py | MessageBuffer.get_messages_since | def get_messages_since(self, cursor):
"""Returns a list of messages newer than the given cursor.
``cursor`` should be the ``id`` of the last message received.
"""
results = []
for msg in reversed(self.cache):
if msg["id"] == cursor:
break
... | python | def get_messages_since(self, cursor):
"""Returns a list of messages newer than the given cursor.
``cursor`` should be the ``id`` of the last message received.
"""
results = []
for msg in reversed(self.cache):
if msg["id"] == cursor:
break
... | [
"def",
"get_messages_since",
"(",
"self",
",",
"cursor",
")",
":",
"results",
"=",
"[",
"]",
"for",
"msg",
"in",
"reversed",
"(",
"self",
".",
"cache",
")",
":",
"if",
"msg",
"[",
"\"id\"",
"]",
"==",
"cursor",
":",
"break",
"results",
".",
"append",... | Returns a list of messages newer than the given cursor.
``cursor`` should be the ``id`` of the last message received. | [
"Returns",
"a",
"list",
"of",
"messages",
"newer",
"than",
"the",
"given",
"cursor",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/demos/chat/chatdemo.py#L38-L49 |
26,697 | tornadoweb/tornado | tornado/util.py | import_object | def import_object(name: str) -> Any:
"""Imports an object by name.
``import_object('x')`` is equivalent to ``import x``.
``import_object('x.y.z')`` is equivalent to ``from x.y import z``.
>>> import tornado.escape
>>> import_object('tornado.escape') is tornado.escape
True
>>> import_object... | python | def import_object(name: str) -> Any:
"""Imports an object by name.
``import_object('x')`` is equivalent to ``import x``.
``import_object('x.y.z')`` is equivalent to ``from x.y import z``.
>>> import tornado.escape
>>> import_object('tornado.escape') is tornado.escape
True
>>> import_object... | [
"def",
"import_object",
"(",
"name",
":",
"str",
")",
"->",
"Any",
":",
"if",
"name",
".",
"count",
"(",
"\".\"",
")",
"==",
"0",
":",
"return",
"__import__",
"(",
"name",
")",
"parts",
"=",
"name",
".",
"split",
"(",
"\".\"",
")",
"obj",
"=",
"_... | Imports an object by name.
``import_object('x')`` is equivalent to ``import x``.
``import_object('x.y.z')`` is equivalent to ``from x.y import z``.
>>> import tornado.escape
>>> import_object('tornado.escape') is tornado.escape
True
>>> import_object('tornado.escape.utf8') is tornado.escape.ut... | [
"Imports",
"an",
"object",
"by",
"name",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/util.py#L131-L157 |
26,698 | tornadoweb/tornado | tornado/util.py | GzipDecompressor.decompress | def decompress(self, value: bytes, max_length: int = 0) -> bytes:
"""Decompress a chunk, returning newly-available data.
Some data may be buffered for later processing; `flush` must
be called when there is no more input data to ensure that
all data was processed.
If ``max_lengt... | python | def decompress(self, value: bytes, max_length: int = 0) -> bytes:
"""Decompress a chunk, returning newly-available data.
Some data may be buffered for later processing; `flush` must
be called when there is no more input data to ensure that
all data was processed.
If ``max_lengt... | [
"def",
"decompress",
"(",
"self",
",",
"value",
":",
"bytes",
",",
"max_length",
":",
"int",
"=",
"0",
")",
"->",
"bytes",
":",
"return",
"self",
".",
"decompressobj",
".",
"decompress",
"(",
"value",
",",
"max_length",
")"
] | Decompress a chunk, returning newly-available data.
Some data may be buffered for later processing; `flush` must
be called when there is no more input data to ensure that
all data was processed.
If ``max_length`` is given, some input data may be left over
in ``unconsumed_tail``... | [
"Decompress",
"a",
"chunk",
"returning",
"newly",
"-",
"available",
"data",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/util.py#L103-L114 |
26,699 | tornadoweb/tornado | tornado/wsgi.py | WSGIContainer.environ | def environ(request: httputil.HTTPServerRequest) -> Dict[Text, Any]:
"""Converts a `tornado.httputil.HTTPServerRequest` to a WSGI environment.
"""
hostport = request.host.split(":")
if len(hostport) == 2:
host = hostport[0]
port = int(hostport[1])
else:
... | python | def environ(request: httputil.HTTPServerRequest) -> Dict[Text, Any]:
"""Converts a `tornado.httputil.HTTPServerRequest` to a WSGI environment.
"""
hostport = request.host.split(":")
if len(hostport) == 2:
host = hostport[0]
port = int(hostport[1])
else:
... | [
"def",
"environ",
"(",
"request",
":",
"httputil",
".",
"HTTPServerRequest",
")",
"->",
"Dict",
"[",
"Text",
",",
"Any",
"]",
":",
"hostport",
"=",
"request",
".",
"host",
".",
"split",
"(",
"\":\"",
")",
"if",
"len",
"(",
"hostport",
")",
"==",
"2",... | Converts a `tornado.httputil.HTTPServerRequest` to a WSGI environment. | [
"Converts",
"a",
"tornado",
".",
"httputil",
".",
"HTTPServerRequest",
"to",
"a",
"WSGI",
"environment",
"."
] | b8b481770bcdb333a69afde5cce7eaa449128326 | https://github.com/tornadoweb/tornado/blob/b8b481770bcdb333a69afde5cce7eaa449128326/tornado/wsgi.py#L148-L183 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.