Skip to content

Commit aacf3a2

Browse files
Jorge Fernandez Hernandezbsipocz
authored andcommitted
EUCLIDPCR-1971 Update documentation for method upload_table
1 parent 0e6c08b commit aacf3a2

File tree

4 files changed

+87
-78
lines changed

4 files changed

+87
-78
lines changed

astroquery/utils/tap/core.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,7 +1381,7 @@ def upload_table(self, *, upload_resource=None, table_name=None, table_descripti
13811381
log.info(f"Uploaded table '{table_name}'.")
13821382
return None
13831383

1384-
def __uploadTableMultipart(self, resource, *, table_name=None, table_description=None, resource_format="votable",
1384+
def __uploadTableMultipart(self, resource, *, table_name=None, table_description=None, resource_format="votable",
13851385
verbose=False):
13861386
connHandler = self.__getconnhandler()
13871387
if isinstance(resource, Table):
@@ -1410,17 +1410,21 @@ def __uploadTableMultipart(self, resource, *, table_name=None, table_description
14101410
"TABLE_DESC": str(table_description),
14111411
"FORMAT": 'votable'}
14121412
log.info(f"Sending file: {resource}")
1413+
if resource.lower() == 'votable':
1414+
with open(resource, "r") as f:
1415+
chunk = f.read()
1416+
files = [['FILE', os.path.basename(resource), chunk]]
1417+
else:
1418+
table = Table.read(str(resource))
1419+
fh = tempfile.NamedTemporaryFile(delete=False)
1420+
table.write(fh, format='votable')
1421+
fh.close()
14131422

1414-
t = Table.read(str(resource) )
1415-
fh = tempfile.NamedTemporaryFile(delete=False)
1416-
t.write(fh, format='votable')
1417-
fh.close()
1418-
1419-
with open(fh.name, "r") as f:
1420-
chunk = f.read()
1423+
with open(fh.name, "r") as f:
1424+
chunk = f.read()
14211425

1422-
os.unlink(fh.name)
1423-
files = [['FILE', 'pytable', chunk]]
1426+
os.unlink(fh.name)
1427+
files = [['FILE', 'pytable', chunk]]
14241428

14251429
content_type, body = connHandler.encode_multipart(args, files)
14261430
else: # upload from URL

0 commit comments

Comments
 (0)