U
    W+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-dlxw5sjy/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   