zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
U
¡ý°dã@sÆddlmZGdd„deƒZGdd„deƒZGdd„deƒZeejdejd    <eejd
d d ejd <eejdejd<ed
dejd
<eejdejd    <eejdejd<eeejd
dƒejd
<d
S)é)ÚEntitySubstitutionc@s\eZdZdZiZiZdZdZee    ddgƒdZ
dd„Z dd d„Z dd„Z dd„Zdd„Zd    S)Ú    FormatteraDescribes a strategy to use when outputting a parse tree to a string.
 
    Some parts of this strategy come from the distinction between
    HTML4, HTML5, and XML. Others are configurable by the user.
 
    Formatters are passed in as the `formatter` argument to methods
    like `PageElement.encode`. Most people won't need to think about
    formatters, and most people who need to think about them can pass
    in one of these predefined strings as `formatter` rather than
    making a new Formatter object:
 
    For HTML documents:
     * 'html' - HTML entity substitution for generic HTML documents. (default)
     * 'html5' - HTML entity substitution for HTML5 documents, as
                 well as some optimizations in the way tags are rendered.
     * 'minimal' - Only make the substitutions necessary to guarantee
                   valid HTML.
     * None - Do not perform any substitution. This will be faster
              but may result in invalid markup.
 
    For XML documents:
     * 'html' - Entity substitution for XHTML documents.
     * 'minimal' - Only make the substitutions necessary to guarantee
                   valid XML. (default)
     * None - Do not perform any substitution. This will be faster
              but may result in invalid markup.
    ÚhtmlÚxmlÚscriptÚstyle)Úcdata_containing_tagscCs&|dk    r |S||jkrtƒS|j|S©N)ÚXMLÚsetÚ HTML_DEFAULTS)ÚselfÚlanguageÚvalueÚkwarg©rúDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\bs4/formatter.pyÚ_default*s
 
zFormatter._defaultNú/FécCsr||_||_||_| ||d¡|_||_|dkr4d}t|tƒrT|dkrJd}d|}nt|tƒrd|}nd}||_    dS)a)Constructor.
 
        :param language: This should be Formatter.XML if you are formatting
           XML markup and Formatter.HTML if you are formatting HTML markup.
 
        :param entity_substitution: A function to call to replace special
           characters with XML/HTML entities. For examples, see 
           bs4.dammit.EntitySubstitution.substitute_html and substitute_xml.
        :param void_element_close_prefix: By default, void elements
           are represented as <tag/> (XML rules) rather than <tag>
           (HTML rules). To get <tag>, pass in the empty string.
        :param cdata_containing_tags: The list of tags that are defined
           as containing CDATA in this dialect. For example, in HTML,
           <script> and <style> tags are defined as containing CDATA,
           and their contents should not be formatted.
        :param blank_attributes_are_booleans: Render attributes whose value
            is the empty string as HTML-style boolean attributes.
            (Attributes whose value is None are always rendered this way.)
 
        :param indent: If indent is a non-negative integer or string,
            then the contents of elements will be indented
            appropriately when pretty-printing. An indent level of 0,
            negative, or "" will only insert newlines. Using a
            positive integer indent indents that many spaces per
            level. If indent is a string (such as "    "), that string
            is used to indent each level. The default behavior to
            indent one space per level.
        rNrú )
rÚentity_substitutionÚvoid_element_close_prefixrrÚempty_attributes_are_booleansÚ
isinstanceÚintÚstrÚindent)r rrrrrrrrrÚ__init__1s&!ÿ
 
 
zFormatter.__init__cCsF|js
|Sddlm}t||ƒr<|jdk    r<|jj|jkr<|S| |¡S)aProcess a string that needs to undergo entity substitution.
        This may be a string encountered in an attribute value or as
        text.
 
        :param ns: A string.
        :return: A string with certain characters replaced by named
           or numeric entities.
        r)ÚNavigableStringN)rÚelementrrÚparentÚnamer)r ÚnsrrrrÚ
substitutees     
ÿ þzFormatter.substitutecCs
| |¡S)z­Process the value of an attribute.
 
        :param ns: A string.
        :return: A string with certain characters replaced by named
           or numeric entities.
        )r$)r rrrrÚattribute_valueyszFormatter.attribute_valuecs.|jdkrgSt‡fdd„t|j ¡ƒDƒƒS)a³Reorder a tag's attributes however you want.
        
        By default, attributes are sorted alphabetically. This makes
        behavior consistent between Python 2 and Python 3, and preserves
        backwards compatibility with older versions of Beautiful Soup.
 
        If `empty_boolean_attributes` is True, then attributes whose
        values are set to the empty string will be treated as boolean
        attributes.
        Nc3s,|]$\}}|ˆjr|dkrdn|fVqdS)ÚN)r)Ú.0ÚkÚv©r rrÚ    <genexpr>sÿz'Formatter.attributes.<locals>.<genexpr>)ÚattrsÚsortedÚlistÚitems)r Útagrr*rÚ
attributes‚s
 
  þzFormatter.attributes)NNrNFr)Ú__name__Ú
__module__Ú __qualname__Ú__doc__ZXML_FORMATTERSZHTML_FORMATTERSÚHTMLr
Údictr r rrr$r%r1rrrrrs&
ÿý
4    rcs$eZdZdZiZ‡fdd„Z‡ZS)Ú HTMLFormatterzA generic Formatter for HTML.cstt|ƒj|jf|ž|ŽdSr    )Úsuperr8rr6©r ÚargsÚkwargs©Ú    __class__rrr—szHTMLFormatter.__init__©r2r3r4r5ÚREGISTRYrÚ __classcell__rrr=rr8”sr8cs$eZdZdZiZ‡fdd„Z‡ZS)Ú XMLFormatterzA generic Formatter for XML.cstt|ƒj|jf|ž|ŽdSr    )r9rBrr
r:r=rrržszXMLFormatter.__init__r?rrr=rrB›srB)rrNT)rrrÚhtml5Zminimal)    Z
bs4.dammitrrr8rBZsubstitute_htmlr@Zsubstitute_xmlr
rrrrÚ<module>s6 ÿ ý ÿ ÿ ÿ ÿ  ÿ