Файловый менеджер - Редактировать - /usr/lib/python3.6/site-packages/bs4/builder/__pycache__/__init__.cpython-36.pyc
Назад
3 6]�/ � @ s, d dl mZ d dlZd dlZd dlmZmZmZmZ ddddgZ dZ d Zd ZdZ dZd ZG dd� de�Ze� ZG dd� de�ZG dd� de�ZG dd� de�Zdd� ZG dd� de�ZddlmZ ee� yddlmZ ee� W n ek r� Y nX yddlmZ ee� W n ek �r& Y nX dS )� )�defaultdictN)�CharsetMetaAttributeValue�ContentMetaAttributeValue�HTMLAwareEntitySubstitution� whitespace_re�HTMLTreeBuilder�SAXTreeBuilder�TreeBuilder�TreeBuilderRegistryZfastZ permissive�strictZxmlZhtmlZhtml5c @ s$ e Zd Zdd� Zdd� Zdd� ZdS )r c C s t t�| _g | _d S )N)r �list�builders_for_feature�builders)�self� r �/usr/lib/python3.6/__init__.py�__init__ s zTreeBuilderRegistry.__init__c C s4 x |j D ]}| j| jd|� qW | jjd|� dS )z8Register a treebuilder based on its advertised features.r N)�featuresr �insertr )r Ztreebuilder_class�featurer r r �register$ s zTreeBuilderRegistry.registerc G s� t | j�dkrd S t |�dkr(| jd S t|�}|j� d }d }xVt |�dkr�|j� }| jj|g �}t |�dkrB|d kr�|}t|�}qB|jt|��}qBW |d kr�d S x|D ]}||kr�|S q�W d S )Nr ) �lenr r �reverse�popr �get�set�intersection)r r Z candidatesZ candidate_setr Zwe_have_the_feature� candidater r r �lookup* s. zTreeBuilderRegistry.lookupN)�__name__� __module__�__qualname__r r r r r r r r s c @ st e Zd ZdZdZg Zg ZdZdZe � Z dZi Zdd� Z dd� Zd d � Zdd� Zdd d�Zdd� Zdd� Zdd� ZdS )r z2Turn a document into a Beautiful Soup object tree.z[Unknown tree builder]FNc C s d | _ d S )N)�soup)r r r r r f s zTreeBuilder.__init__c C s d S )Nr )r r r r �reseti s zTreeBuilder.resetc C s | j dkrdS || j kS )a� Might a tag with this name be an empty-element tag? The final markup may or may not actually present this tag as self-closing. For instance: an HTMLBuilder does not consider a <p> tag to be an empty-element tag (it's not in HTMLBuilder.empty_element_tags). This means an empty <p> tag will be presented as "<p></p>", not "<p />". The default implementation has no opinion about which tags are empty-element tags, so a tag will be presented as an empty-element tag if and only if it has no contents. "<foo></foo>" will become "<foo />", and "<foo>bar</foo>" will be left alone. NT)�empty_element_tags)r �tag_namer r r �can_be_empty_elementl s z TreeBuilder.can_be_empty_elementc C s t � �d S )N)�NotImplementedError)r �markupr r r �feed� s zTreeBuilder.feedc C s |d d dfS )NFr )r r( Zuser_specified_encodingZdocument_declared_encodingr r r �prepare_markup� s zTreeBuilder.prepare_markupc C s |S )a� Wrap an HTML fragment to make it look like a document. Different parsers do this differently. For instance, lxml introduces an empty <head> tag, and html5lib doesn't. Abstracting this away lets us write simple tests which run HTML fragments through the parser and compare the results against other HTML fragments. This method should not be used outside of tests. r )r Zfragmentr r r �test_fragment_to_document� s z%TreeBuilder.test_fragment_to_documentc C s dS )NFr )r �tagr r r �set_up_substitutions� s z TreeBuilder.set_up_substitutionsc C s� |s|S | j r�| j jdg �}| j j|j� d�}xRt|j� �D ]B}||ksT|r<||kr<|| }t|t�rrtj|�}n|}|||<