B
    }d                 @   s   d Z ddlZddlmZ ddlmZmZmZm	Z	 yddl
mZ W n  ek
r`   ddlmZ Y nX ejZddlmZ dd	lmZmZ d
Zdd ZdddZej e_ dd ZdS )zI/O registry extensions on top of `astropy.io.registry`

This module imports a subset of the useful functions from
:mod:`astropy.io.registry` for convenience.
    N)wraps)
get_readerregister_identifierregister_readerregister_writer)default_registry)_get_valid_format)get_readable_fileobj   )	file_list	FILE_LIKEz(Duncan Macleod <duncan.macleod@ligo.org>c                s   t   fdd}|S )zDecorate an I/O identifier to handle a list of files as input

    This function tries to resolve a single file path as a `str` from any
    file-like or collection-of-file-likes to pass to the underlying
    identifier for comparison.
    c                s   yt |d }W nd tk
rb   |d kr^yt |d }W n ttfk
rP   Y nX |r^|d }Y n tk
rt   Y nX  | ||f||S )Nr   )r   
ValueError
IndexError)originfilepathfileobjargskwargsfiles)
identifier ]/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/gwpy/io/registry.pydecorated_func8   s    z*identify_with_list.<locals>.decorated_func)r   )r   r   r   )r   r   identify_with_list1   s    r   Fc             C   s   t | |t||dS )N)force)astropy_register_identifierr   )Zdata_formatZ
data_classr   r   r   r   r   r   L   s    r   c          	   C   s   d}t |tr(|}t|dr"|jnd}nJ|}yt|dd}| }W n, tk
rZ    Y n tk
rp   d}Y nX ztd| ||||S |dk	r|j	t
   X dS )z7Determine the read format for a given input source
    Nnamebinary)encodingread)
isinstancer   hasattrr   r	   	__enter__IOError	Exception
get_format__exit__sysexc_info)clssourcer   r   ctxr   r   r   r   r   get_read_formatU   s     

r,   )F)__doc__r'   	functoolsr   Zastropy.io.registryr   r   r   r   r   Zastropy.io.registry.compatr   ModuleNotFoundErrorr   r%   Zastropy.utils.datar	   utilsr   r   
__author__r   r,   r   r   r   r   <module>   s   
