# Path: SAGA/database/core.py
# class DownloadableBase(ABC):
# class FileObject(DownloadableBase):
# class CsvTable(FileObject):
# class FastCsvTable(FileObject):
# class EcsvTable(FileObject):
# class GoogleSheets(FastCsvTable):
# class FitsTableGeneric(FileObject):
# class FitsTable(FileObject):
# class NumpyBinary(FileObject):
# class DataObject(object):
#     def download_as_file(self, file_path, overwrite=False, compress=False):
#     def __init__(self, path=None, **kwargs):
#     def _gz_fallback(file_path):
#     def read(self):
#     def write(self, table, **kwargs):
#     def download_as_file(self, file_path, overwrite=False, compress=False):
#     def isfile(self):
#     def __init__(self, key, gid, **kwargs):
#     def read(self):
#     def write(self, table, **kwargs):
#     def read(self):
#     def write(self, table, **kwargs):
#     def read(self):
#     def write(self, table, **kwargs):
#     def __init__(self, remote, local=None, cache_in_memory=False, use_local_first=False):
#     def local(self):
#     def local(self, value):
#     def read(self, reload=False, **kwargs):
#     def write(self, table, dest=None, overwrite=False, **kwargs):
#     def download(self, local_file_path=None, overwrite=False, compress=False, set_as_local=True):
#     def _copy_table(table):
#     def clear_cache(self):
#     def retrive_cache(self):
#     def store_cache(self, table):
#     def path(self):
#     def isfile(self):


import gzip
import os
import time
import requests
from io import BytesIO
from urllib.parse import urlencode
from astropy.table import Table
from .core import DownloadableBase, FastCsvTable, makedirs_if_needed
        path = "http://leda.univ-lyon1.fr/fG.cgi?n=meandata&c=o&of=1,leda,simbad&nra=l&nakd=1&" + urlencode(
            {
                "d": self._default_fields if fields is None else fields,
                "sql": self._default_conditions if conditions is None else conditions,
                "ob": "pgc",
                "a": "csv[,]",
            }
        )
        super().__init__(path, **kwargs)

    def write(self, table, **kwargs):
        raise AttributeError("`HyperledaQuery` do not have write method.")


class EddQuery(DownloadableBase):
    def __init__(self, query, **kwargs):
        self.query = query
        self.kwargs = kwargs

    def _get_raw_output(self):
        return requests.post(
            "http://edd.ifa.hawaii.edu/download.php",
            {"queryall": self.query, "delimiter": ","},
            timeout=(120, 3600),
        ).text

    def read(self):
        return Table.read(BytesIO(self._get_raw_output().encode()), format="ascii.fast_csv")

    def download_as_file(self, file_path, overwrite=False, compress=False):

# Path: SAGA/database/core.py
# class DownloadableBase(ABC):
# class FileObject(DownloadableBase):
# class CsvTable(FileObject):
# class FastCsvTable(FileObject):
# class EcsvTable(FileObject):
# class GoogleSheets(FastCsvTable):
# class FitsTableGeneric(FileObject):
# class FitsTable(FileObject):
# class NumpyBinary(FileObject):
# class DataObject(object):
#     def download_as_file(self, file_path, overwrite=False, compress=False):
#     def __init__(self, path=None, **kwargs):
#     def _gz_fallback(file_path):
#     def read(self):
#     def write(self, table, **kwargs):
#     def download_as_file(self, file_path, overwrite=False, compress=False):
#     def isfile(self):
#     def __init__(self, key, gid, **kwargs):
#     def read(self):
#     def write(self, table, **kwargs):
#     def read(self):
#     def write(self, table, **kwargs):
#     def read(self):
#     def write(self, table, **kwargs):
#     def __init__(self, remote, local=None, cache_in_memory=False, use_local_first=False):
#     def local(self):
#     def local(self, value):
#     def read(self, reload=False, **kwargs):
#     def write(self, table, dest=None, overwrite=False, **kwargs):
#     def download(self, local_file_path=None, overwrite=False, compress=False, set_as_local=True):
#     def _copy_table(table):
#     def clear_cache(self):
#     def retrive_cache(self):
#     def store_cache(self, table):
#     def path(self):
#     def isfile(self):


# Path: SAGA/database/external_masterlist.py
import gzip
import os
import time
import requests
from io import BytesIO
from urllib.parse import urlencode
from astropy.table import Table
from .core import DownloadableBase, FastCsvTable, makedirs_if_needed

        path = "http://leda.univ-lyon1.fr/fG.cgi?n=meandata&c=o&of=1,leda,simbad&nra=l&nakd=1&" + urlencode(
            {
                "d": self._default_fields if fields is None else fields,
                "sql": self._default_conditions if conditions is None else conditions,
                "ob": "pgc",
                "a": "csv[,]",
            }
        )
        super().__init__(path, **kwargs)

    def write(self, table, **kwargs):
        raise AttributeError("`HyperledaQuery` do not have write method.")


class EddQuery(DownloadableBase):
    def __init__(self, query, **kwargs):
        self.query = query
        self.kwargs = kwargs

    def _get_raw_output(self):
        return requests.post(
            "http://edd.ifa.hawaii.edu/download.php",
            {"queryall": self.query, "delimiter": ","},
            timeout=(120, 3600),
        ).text

    def read(self):
        return Table.read(BytesIO(self._get_raw_output().encode()), format="ascii.fast_csv")

    def download_as_file(self, file_path, overwrite=False, compress=False):

        makedirs_if_needed(file_path)