File: //proc/self/root/usr/lib/python3/dist-packages/twisted/web/__pycache__/util.cpython-38.pyc
U
s�@g�0 � @ s@ d Z ddlmZmZ ddlZddlmZ ddlmZm Z m
Z
mZ ddlm
Z
ddlmZ ddlmZmZmZmZ dd lmZ d
d� Zdd
� ZG dd� dej�ZG dd� de�ZG dd� dej�ZG dd� dej�ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Z G dd� de�Z!d d!� Z"d
dddddd!gZ#dS )"z0
An assortment of web server-related utilities.
� )�division�absolute_importN)�urlpath)�_PY3�unicode�nativeString�escape)�fullyQualifiedName)�resource)� TagLoader� XMLString�Element�renderer)�
flattenStringc C s dt | �f S )aK
Wraps <pre> tags around some text and HTML-escape it.
This is here since once twisted.web.html was deprecated it was hard to
migrate the html.PRE from current code to twisted.web.template.
For new code consider using twisted.web.template.
@return: Escaped text wrapped in <pre> tags.
@rtype: C{str}
z
<pre>%s</pre>)r )�text� r �2/usr/lib/python3/dist-packages/twisted/web/util.py�_PRE s r c C sZ t | t�rtd��|�dd� |�| � ddtt| �d���d��i }t rV|�d�}|S )a�
Generate a redirect to the given location.
@param URL: A L{bytes} giving the location to which to redirect.
@type URL: L{bytes}
@param request: The request object to use to generate the redirect.
@type request: L{IRequest<twisted.web.iweb.IRequest>} provider
@raise TypeError: If the type of C{URL} a L{unicode} instead of L{bytes}.
@return: A C{bytes} containing HTML which tries to convince the client agent
to visit the new location even if it doesn't respect the I{FOUND}
response code. This is intended to be returned from a render method,
eg::
def render_GET(self, request):
return redirectTo(b"http://example.com/", request)
z!Unicode object not allowed as URLs Content-Types text/html; charset=utf-8z�
<html>
<head>
<meta http-equiv="refresh" content="0;URL=%(url)s">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<a href="%(url)s">click here</a>
</body>
</html>
�url�utf-8�utf8)
�
isinstancer � TypeErrorZ setHeaderZredirectr r �decode�encoder )ZURL�requestZcontentr r r �
redirectTo( s
�
r c @ s( e Zd ZdZdd� Zdd� Zdd� ZdS ) �RedirectTc C s t j�| � || _d S �N)r
�Resource�__init__r ��selfr r r r r R s zRedirect.__init__c C s t | j|�S r )r r �r"