← Back
Editing: resource.cpython-38.pyc
U W[43 � @ s d Z ddlmZmZ ddddddd gZdd lZddlmZmZm Z ddl mZmZ dd l mZ ddlmZ ddlmZmZ ddlmZ G dd� de�Zdd� Ze e�G dd� d��Zdd� ZG dd� de�ZG dd� de�ZG dd� de�ZG dd� de�Ze e�G dd � d ee���Zd S )z4 Implementation of the lowest-level Resource class. � )�division�absolute_import� IResource�getChildForRequest�Resource� ErrorPage� NoResource�ForbiddenResource�EncodingResourceWrapperN)� Attribute� Interface�implementer)�nativeString�unicode)�prefixedMethodNames)�proxyForInterface)� FORBIDDEN� NOT_FOUND)�UnsupportedMethodc @ s0 e Zd ZdZed�Zdd� Zdd� Zdd� Zd S ) r z A web resource. z� Signal if this IResource implementor is a "leaf node" or not. If True, getChildWithDefault will not be called on this Resource. c C s dS )a Return a child with the given name for the given request. This is the external interface used by the Resource publishing machinery. If implementing IResource without subclassing Resource, it must be provided. However, if subclassing Resource, getChild overridden instead. @param name: A single path component from a requested URL. For example, a request for I{http://example.com/foo/bar} will result in calls to this method with C{b"foo"} and C{b"bar"} as values for this argument. @type name: C{bytes} @param request: A representation of all of the information about the request that is being made for this child. @type request: L{twisted.web.server.Request} N� )�name�requestr r �6/usr/lib/python3/dist-packages/twisted/web/resource.py�getChildWithDefault) s zIResource.getChildWithDefaultc C s dS )a� Put a child IResource implementor at the given path. @param path: A single path component, to be interpreted relative to the path this resource is found at, at which to put the given child. For example, if resource A can be found at I{http://example.com/foo} then a call like C{A.putChild(b"bar", B)} will make resource B available at I{http://example.com/foo/bar}. @type path: C{bytes} Nr )�path�childr r r �putChild= s zIResource.putChildc C s dS )ap Render a request. This is called on the leaf resource for a request. @return: Either C{server.NOT_DONE_YET} to indicate an asynchronous or a C{bytes} instance to write as the response to the request. If C{NOT_DONE_YET} is returned, at some point later (for example, in a Deferred callback) call C{request.write(b"<html>")} to write data to the request, and C{request.finish()} to send the data to the browser. @raise twisted.web.error.UnsupportedMethod: If the HTTP verb requested is not supported by this resource. Nr �r r r r �renderJ s zIResource.renderN) �__name__� __module__�__qualname__�__doc__r �isLeafr r r r r r r r s � c C s6 |j r2| js2|j �d�}|j�|� | �||�} q | S )zE Traverse resource tree to find who will handle the request. r )Zpostpathr# �popZprepath�appendr )�resourcer ZpathElementr r r r [ s c @ s� e Zd ZdZeZdZdd� ZdZdd� Z dd � Z d d� Zdd � Zdd� Z d&dd�Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zdd� Zd d!� Zd"d#� Zd$d%� ZdS )'r z� Define a web-accessible resource. This serves 2 main purposes; one is to provide a standard representation for what HTTP specification calls an 'entity', and the other is to provide an abstract directory structure for URL retrieval. Nc C s i | _ dS )z Initialize. N��children��selfr r r �__init__t s zResource.__init__r c C s t | j�� �S �N)�listr( �keysr) r r r �listStaticNames~ s zResource.listStaticNamesc C s t | j�� �S r, )r- r( �itemsr) r r r �listStaticEntities� s zResource.listStaticEntitiesc C s t | �� �| �� S r, )r- r/ �listDynamicNamesr) r r r � listNames� s zResource.listNamesc C s t | �� �| �� S r, )r- r1 �listDynamicEntitiesr) r r r �listEntities� s zResource.listEntitiesc C s g S r, r r) r r r r2 � s zResource.listDynamicNamesc C s g S r, r �r* r r r r r4 � s zResource.listDynamicEntitiesc C s | j �|�S r, )r( �get�r* r r r r �getStaticEntity� s zResource.getStaticEntityc C s || j kr| �||�S d S d S r, �r( �getChild)r* r r r r r �getDynamicEntity� s zResource.getDynamicEntityc C s | j |= d S r, r'