Skip to content

Commit

Permalink
Merge pull request #4703 from neutrinoceros/hotfix_urllib
Browse files Browse the repository at this point in the history
BUG: fix broken urllib imports
  • Loading branch information
chrishavlin authored Oct 11, 2023
2 parents 14c49c4 + e12ef79 commit 25f8f4b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
5 changes: 4 additions & 1 deletion yt/funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import sys
import time
import traceback
import urllib
from collections import UserDict
from collections.abc import Callable
from copy import deepcopy
Expand Down Expand Up @@ -619,6 +618,8 @@ def fancy_download_file(url, filename, requests=None):


def simple_download_file(url, filename):
import urllib.request

class MyURLopener(urllib.request.FancyURLopener):
def http_error_default(self, url, fp, errcode, errmsg, headers):
raise RuntimeError(
Expand All @@ -632,6 +633,8 @@ def http_error_default(self, url, fp, errcode, errmsg, headers):
# This code snippet is modified from Georg Brandl
def bb_apicall(endpoint, data, use_pass=True):
import getpass
import urllib.parse
import urllib.request

uri = f"https://api.bitbucket.org/1.0/{endpoint}/"
# since bitbucket doesn't return the required WWW-Authenticate header when
Expand Down
4 changes: 3 additions & 1 deletion yt/utilities/answer_testing/framework.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import sys
import tempfile
import time
import urllib
import warnings
import zlib
from collections import defaultdict
Expand Down Expand Up @@ -207,6 +206,9 @@ def get(self, ds_name, default=None):

class AnswerTestCloudStorage(AnswerTestStorage):
def get(self, ds_name, default=None):
import urllib.error
import urllib.request

if self.reference_name is None:
return default
if ds_name in self.cache:
Expand Down
10 changes: 9 additions & 1 deletion yt/utilities/command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import pprint
import sys
import textwrap
import urllib
from typing import Any, Optional, Union

import numpy as np
Expand Down Expand Up @@ -1202,6 +1201,9 @@ class YTDeleteImageCmd(YTCommand):
name = "delete_image"

def __call__(self, args):
import urllib.error
import urllib.request

headers = {"Authorization": f"Client-ID {ytcfg.get('yt', 'imagebin_api_key')}"}

delete_url = ytcfg.get("yt", "imagebin_delete_url")
Expand Down Expand Up @@ -1235,6 +1237,10 @@ class YTUploadImageCmd(YTCommand):
name = "upload_image"

def __call__(self, args):
import urllib.error
import urllib.parse
import urllib.request

filename = args.file
if not filename.endswith(".png"):
print("File must be a PNG file!")
Expand Down Expand Up @@ -1585,6 +1591,8 @@ def __call__(self, args):
print(f"File: {args.filename} downloaded successfully to {data_file}")

def get_list(self):
import urllib.request

data = (
urllib.request.urlopen("http://yt-project.org/data/datafiles.json")
.read()
Expand Down

0 comments on commit 25f8f4b

Please sign in to comment.