U
    3ìdõ  ã                   @   s@   d dl Z d dlmZ d dlmZ d dlmZ G dd„ deƒZdS )é    N)ÚKey)ÚSimpleResultSet)ÚBucketListResultSetc                   @   sZ   e Zd Zdd„ Zdd„ Zdd„ Zddd	„Zdd
d„Zddej	fdd„Z
dej	fdd„ZdS )ÚBucketc                 C   s   || _ || _dS )zHInstantiate an anonymous file-based Bucket around a single key.
        N)ÚnameÚcontained_key)Úselfr   r   © r	   ú4/tmp/pip-unpacked-wheel-d7dsrkjd/boto/file/bucket.pyÚ__init__   s    zBucket.__init__c                 C   s   t t| ƒƒS )N)Úiterr   ©r   r	   r	   r
   Ú__iter__%   s    zBucket.__iter__c                 C   s
   d| j  S )Nzanonymous bucket for file://)r   r   r	   r	   r
   Ú__str__(   s    zBucket.__str__Nc                 C   s   t  |¡ dS )a<  
        Deletes a key from the bucket.

        :type key_name: string
        :param key_name: The key name to delete

        :type version_id: string
        :param version_id: Unused in this subclass.

        :type mfa_token: tuple or list of strings
        :param mfa_token: Unused in this subclass.
        N)ÚosÚremove)r   Úkey_nameÚheadersÚ
version_idZ	mfa_tokenr	   r	   r
   Ú
delete_key+   s    zBucket.delete_keyc                 K   s   t | j| jƒ}t|gƒS )zÛ
        This method returns the single key around which this anonymous Bucket
        was instantiated.

        :rtype: SimpleResultSet
        :return: The result from file system listing the keys requested

        )r   r   r   r   )r   r   ÚparamsÚkeyr	   r	   r
   Úget_all_keys;   s    	zBucket.get_all_keysc                 C   s6   |dkrt | jdt jdS t|dƒ}t | j||ƒS dS )a  
        Check to see if a particular key exists within the bucket.
        Returns: An instance of a Key object or None

        :type key_name: string
        :param key_name: The name of the key to retrieve

        :type version_id: string
        :param version_id: Unused in this subclass.

        :type stream_type: integer
        :param stream_type: Type of the Key - Regular File or input/output Stream

        :rtype: :class:`boto.file.key.Key`
        :returns: A Key object from this bucket.
        ú-©Úkey_typeÚrbN)r   r   ZKEY_STREAM_READABLEÚopen)r   r   r   r   r   Úfpr	   r	   r
   Úget_keyG   s    
zBucket.get_keyc                 C   s\   |dkrt | jdt jdS tj |¡}|r@tj |¡s@t |¡ t|dƒ}t | j||ƒS dS )zä
        Creates a new key

        :type key_name: string
        :param key_name: The name of the key to create

        :rtype: :class:`boto.file.key.Key`
        :returns: An instance of the newly created key object
        r   r   ÚwbN)	r   r   ZKEY_STREAM_WRITABLEr   ÚpathÚdirnameÚexistsÚmakedirsr   )r   r   r   Zdir_namer   r	   r	   r
   Únew_key_   s    


zBucket.new_key)NNN)N)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r   ZKEY_REGULAR_FILEr   r%   r	   r	   r	   r
   r      s       ÿ

ÿ
r   )	r   Zboto.file.keyr   Zboto.file.simpleresultsetr   Zboto.s3.bucketlistresultsetr   Úobjectr   r	   r	   r	   r
   Ú<module>   s   