Skip to content

Commit

Permalink
Merge pull request #2657 from eerovaher/rm-cgi
Browse files Browse the repository at this point in the history
Remove all uses of `cgi`
  • Loading branch information
bsipocz authored Apr 28, 2023
2 parents 630686c + 7e69666 commit 87b80b1
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
16 changes: 7 additions & 9 deletions astroquery/esa/hsa/core.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Licensed under a 3-clause BSD style license - see LICENSE.rst

import cgi
import os
import re
import shutil
from email.message import Message
from pathlib import Path

from astropy import units as u
Expand Down Expand Up @@ -113,10 +113,9 @@ def download_data(self, *, retrieval_type="OBSERVATION", observation_id=None,
error = "Please set either 'obervation_id' or 'filename' for the output"
raise ValueError(error)

_, res_params = cgi.parse_header(response.headers['Content-Disposition'])

r_filename = res_params["filename"]
suffixes = Path(r_filename).suffixes
message = Message()
message["content-type"] = response.headers["Content-Disposition"]
suffixes = Path(message.get_param("filename")).suffixes

if len(suffixes) > 1 and suffixes[-1] == ".jpg":
filename += suffixes[-1]
Expand Down Expand Up @@ -205,10 +204,9 @@ def get_observation(self, observation_id, instrument_name, *, filename=None,

response.raise_for_status()

_, res_params = cgi.parse_header(response.headers['Content-Disposition'])

r_filename = res_params["filename"]
suffixes = Path(r_filename).suffixes
message = Message()
message["content-type"] = response.headers["Content-Disposition"]
suffixes = Path(message.get_param("filename")).suffixes

if filename is None:
filename = observation_id
Expand Down
8 changes: 4 additions & 4 deletions astroquery/esa/iso/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from astroquery.utils.tap.core import TapPlus
from astroquery.query import BaseQuery
import shutil
import cgi
from email.message import Message
from requests import HTTPError
from pathlib import Path

Expand Down Expand Up @@ -122,9 +122,9 @@ def download_data(self, tdt, *, retrieval_type=None, filename=None,
response.raise_for_status()

# Get original extension
_, params = cgi.parse_header(response.headers['Content-Disposition'])
r_filename = params["filename"]
suffixes = Path(r_filename).suffixes
message = Message()
message["content-type"] = response.headers["Content-Disposition"]
suffixes = Path(message.get_param("filename")).suffixes

if filename is None:
filename = tdt
Expand Down
6 changes: 4 additions & 2 deletions astroquery/esa/xmm_newton/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
"""
import re
import shutil
import cgi
from pathlib import Path
import tarfile
import os
import configparser
from email.message import Message

from astropy.io import fits
from astroquery import log
Expand Down Expand Up @@ -293,7 +293,9 @@ def _request_link(self, link, cache):
response = self._request('HEAD', link, save=False, cache=cache)
# Get original extension
if 'Content-Type' in response.headers and 'text' not in response.headers['Content-Type']:
_, params = cgi.parse_header(response.headers['Content-Disposition'])
message = Message()
message["content-type"] = response.headers["Content-Disposition"]
params = dict(message.get_params()[1:])
elif response.status_code == 401:
error = "Data protected by proprietary rights. Please check your credentials"
raise LoginError(error)
Expand Down
2 changes: 0 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ filterwarnings =
ignore:distutils Version classes are deprecated:DeprecationWarning
# Remove along with astropy-helpers, once we switch to a new versioning scheme
ignore:Use setlocale:DeprecationWarning
# Remove with fix for https://github.com/astropy/astroquery/issues/2628
ignore:\'cgi\' is deprecated and:DeprecationWarning
# Upstream issues in many packages, not clear whether we can do anything about these in astroquery
ignore:unclosed <socket.socket:ResourceWarning
ignore:unclosed <ssl.SSLSocket:ResourceWarning
Expand Down

0 comments on commit 87b80b1

Please sign in to comment.