File manager - Edit - /home/u478019808/domains/bestandroidphones.store/public_html/static/img/logo/wildcard_iterator.cpython-39.pyc.tar
Back
opt/gsutil/gslib/__pycache__/wildcard_iterator.cpython-39.pyc 0000644 00000057701 15025232166 0020334 0 ustar 00 a +(Wg� � @ s� d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl Z ddl Z ddlZddlZddl mZ ddl mZ dd l mZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl"m$Z$ ej%�r8e&Z'e �(d�Z)dZ*G dd� de+�Z,G dd� de,�Z-dd� Z.G dd � d e,�Z/G d!d"� d"e'�Z0d&d$d%�Z1dS )'z1Wildcard iterator class and supporting functions.� )�absolute_import)�print_function)�division)�unicode_literalsN)�BucketListingBucket)�BucketListingObject)�BucketListingPrefix)�AccessDeniedException)�CloudApi)�NotFoundException)�CommandException)�ContainsWildcard)�GenerationFromUrlAndString)�StorageUrlFromString)� StripOneSlash)�WILDCARD_REGEX)�storage_v1_messages)�UTF8)�FixWindowsEncodingIfNeeded)�PrintableStrz (?P<before>.*?)\*\*(?P<after>.*)a\ Invalid Unicode path encountered (%s). gsutil cannot proceed with such files present. Please remove or rename this file and try again. NOTE: the path printed above replaces the problematic characters with a hex-encoded printable representation. For more details (including how to convert to a gsutil-compatible encoding) see `gsutil help encoding`.c @ s e Zd ZdZdd� ZdS )�WildcardIteratora Class for iterating over Google Cloud Storage strings containing wildcards. The base class is abstract; you should instantiate using the wildcard_iterator() static factory method, which chooses the right implementation depending on the base string. c C s d| j j S )z2Returns string representation of WildcardIterator.zWildcardIterator(%s))�wildcard_url� url_string��self� r �&/opt/gsutil/gslib/wildcard_iterator.py�__repr__I s zWildcardIterator.__repr__N)�__name__� __module__�__qualname__�__doc__r r r r r r ? s r c @ s� e Zd ZdZddd�Zddd�Zdd � Zd d� Zdd � Zddd�Z ddd�Z d dd�Zdd� Zd!dd�Z d"dd�Zd#dd�ZdS )$�CloudWildcardIteratoraV WildcardIterator subclass for buckets, bucket subdirs and objects. Iterates over BucketListingRef matching the Url string wildcard. It's much more efficient to first get metadata that's available in the Bucket (for example to get the name and size of each object), because that information is available in the object list results. FNc C s* || _ || _|| _|| _|p"t�� | _dS )a� Instantiates an iterator that matches the wildcard URL. Args: wildcard_url: CloudUrl that contains the wildcard to iterate. gsutil_api: Cloud storage interface. Passed in for thread safety, also settable for testing/mocking. all_versions: If true, the iterator yields all versions of objects matching the wildcard. If false, yields just the live object version. project_id: Project ID to use for bucket listings. logger: logging.Logger used for outputting debug messages during iteration. If None, the root logger will be used. N)r �all_versions� gsutil_api� project_id�logging� getLogger�logger)r r r$ r# r% r( r r r �__init__W s zCloudWildcardIterator.__init__c c sF | j �� }d}|rxt� }|D ]}|�|� q| j|d�}|�ddg� |�dg� |s\| jrx|�ddg� |�dd g� | jd gd�D �]�}|j}| j � � �r|�rt |�}| jj|j d| j| j j|d �D ]:} | jtjjkr�| j|| j| jd�V q�| �|| j�V q�n|V q�t| j j��s�| j �� �r�| j�s�zL| jj| j j | j j| j j| j j|d�} | j| j j| | j�pp|d�V W dS ttf�y� Y n0 |�r�d|| j j| j jf }nd|t| j j��p�df }|g}|r�t |�d��}| � |j�\} }}}| �!|�}|�rtdg�n|}| jj|j | || j�p2|| j j|d�D ]�} |D ]�}| jtjjk�r�| j}|�"|j#��r4|�r�t|j#�|k�r�|�r�| �$|j��r�| j||| j�p�|d�V �q@nx| j} t| ��r�t%d|| f ��t| �}|�"|��rH|�r ||k�r d||d | f }|�&|� n| �|| �V �q@�qH�q@�q�q�dS )a! Iterator that gets called when iterating over the cloud wildcard. In the case where no wildcard is present, returns a single matching object, single matching prefix, or one of each if both exist. Args: bucket_listing_fields: Iterable fields to include in bucket listings. Ex. ['name', 'acl']. Iterator is responsible for converting these to list-style format ['items/name', 'items/acl'] as well as adding any fields necessary for listing such as prefixes. API implementation is responsible for adding pagination fields. If this is None, all fields are returned. expand_top_level_buckets: If true, yield no BUCKET references. Instead, expand buckets into top-level objects and prefixes. Yields: BucketListingRef of type BUCKET, OBJECT or PREFIX. N)� get_fieldsz items/name�prefixes�namezitems/generationzitems/metageneration� generation�metageneration�id�� bucket_fields�/)� delimiterr# �provider�fields)�with_version)r- r4 r5 �%s%s#%s�%s%sr )�prefixr3 r# r4 r5 znCloud folder %s%s contains a wildcard; gsutil does not currently support objects with wildcards in their name.)'r � HasGeneration�set�add�_GetToListFields�updater# �_ExpandBucketWildcardsr �IsBucketr r$ ZListObjects�bucket_name�scheme�datatyper ZCsObjectOrPrefixTypeZOBJECT� _GetObjectRef�data� _GetPrefixRefr �IsObjectZGetObjectMetadata�object_namer- �bucket_url_stringr r r �pop�_BuildBucketFilterStrings�_GetRegexPatterns�matchr, �_SingleVersionMatchesr �append)r �bucket_listing_fields�expand_top_level_bucketsZsingle_version_requestr* �field�bucket_listing_refrI �urlZ obj_or_prefix� get_objectr Zurls_needing_expansionr9 r3 �prefix_wildcard�suffix_wildcardZregex_patternsZlisting_fields�pattern� gcs_objectZrstripped_prefixZurl_append_stringr r r �__iter__p s� � �� � ��� ��� � �� � � �� ����zCloudWildcardIterator.__iter__c C sb |g}d|v r&|� dd�}|�|� n|}||fD ] }|�d�r2|�|dd� � q2dd� |D �S )a� Returns list of regex patterns derived from the wildcard patterns. Args: wildcard_pattern (str): A wilcard_pattern to filter the resources. Returns: List of compiled regex patterns. This translates the wildcard_pattern and also creates some additional patterns so that we can treat ** in a/b/c/**/d.txt as zero or more folders. This means, a/b/c/d.txt will also be returned along with a/b/c/e/f/d.txt. z/**/r2 �**/� Nc S s g | ]}t �t�|���qS r )�re�compile�fnmatch� translate)�.0�pr r r � <listcomp>7 � z;CloudWildcardIterator._GetRegexPatterns.<locals>.<listcomp>)�replacerO � startswith)r Zwildcard_patternZwildcard_patternsZupdated_patternrX r r r rL s z'CloudWildcardIterator._GetRegexPatternsc C s( t �|�}|s |}d}|}d}n�|�� dkrN|d|�� � }||�� d� }nd}|}|�d�}|dkrx|d|d � }|p~d| }|�d�s�t|�}||�� d� }|�d�}|dkr�d}n||d d� }|�d�dkr�d}||7 }d}nd}| j�d t |�t |�t |�t |�t |�� ||||fS ) a� Builds strings needed for querying a bucket and filtering results. This implements wildcard object name matching. Args: wildcard: The wildcard string to match to objects. Returns: (prefix, delimiter, prefix_wildcard, suffix_wildcard) where: prefix is the prefix to be sent in bucket GET request. delimiter is the delimiter to be sent in bucket GET request. prefix_wildcard is the wildcard to be used to filter bucket GET results. suffix_wildcard is wildcard to be appended to filtered bucket GET results for next wildcard expansion iteration. For example, given the wildcard gs://bucket/abc/d*e/f*.txt we would build prefix= abc/d, delimiter=/, prefix_wildcard=d*e, and suffix_wildcard=f*.txt. Using this prefix and delimiter for a bucket listing request will then produce a listing result set that can be filtered using this prefix_wildcard; and we'd use this suffix_wildcard to feed into the next call(s) to _BuildBucketFilterStrings(), for the next iteration of listing/filtering. Raises: AssertionError if wildcard doesn't contain any wildcard chars. r2 � r N���� r[ z**zMwildcard=%s, prefix=%s, delimiter=%s, prefix_wildcard=%s, suffix_wildcard=%s ) r �search�start�find�endswithr �endr( �debugr ) r �wildcardrM r9 r3 rV rW Z wildcard_partrn r r r rK 9 sD �z/CloudWildcardIterator._BuildBucketFilterStringsc C s t | j|�}t| jj�t|�kS �N)r r �strr- )r Zlisted_generationZdecoded_generationr r r rN � s �z+CloudWildcardIterator._SingleVersionMatchesc c s� t | jj�}|r:t|�tdg�kr:t| jj�s:t|�V n�| j�� rvt| jj�svt|| jj | jj| jj |d�d�V n~t�| jj�}t �|�}| �|�}|r�|�d� | jj|| j| jj d�D ]4}|�|j�r�t d| jj |jf �}t||d�V q�dS )aG Expands bucket and provider wildcards. Builds a list of bucket url strings that can be iterated on. Args: bucket_fields: If present, populate only these metadata fields for buckets. Example value: ['acl', 'defaultObjectAcl'] Yields: BucketListingRefereneces of type BUCKET. r/ )r4 r5 ��root_objectzitems/id)r5 r% r4 z%s://%s/N)r r rI r; r rA r r@ r$ Z GetBucketrB r_ r` r] r^ r= r<