summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2023-04-19 23:31:13 +0000
committermilde <milde@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2023-04-19 23:31:13 +0000
commit227f9287314e183d6513385920b2dbb3bcf1661d (patch)
treeb2e2cbd0ebe17db2b9539cf4b1f0a93476ab5f7f
parent364c5a8121611f814c0dc2f78832a9743ae82256 (diff)
downloaddocutils-227f9287314e183d6513385920b2dbb3bcf1661d.tar.gz
Move import of "urllib" to the top of modules.
The reasons for deferring the import of "urllib" to later in the code no longer merit deviating from coding style policy. (Loading time improved from 0.15s to 0.03s with the switch to Py3k.) git-svn-id: https://svn.code.sf.net/p/docutils/code/trunk@9358 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--docutils/docutils/parsers/rst/directives/misc.py11
-rw-r--r--docutils/docutils/parsers/rst/directives/tables.py11
2 files changed, 5 insertions, 17 deletions
diff --git a/docutils/docutils/parsers/rst/directives/misc.py b/docutils/docutils/parsers/rst/directives/misc.py
index 26446e5cc..10619dac5 100644
--- a/docutils/docutils/parsers/rst/directives/misc.py
+++ b/docutils/docutils/parsers/rst/directives/misc.py
@@ -9,10 +9,8 @@ __docformat__ = 'reStructuredText'
from pathlib import Path
import re
import time
-# from urllib.request import urlopen
-# from urllib.error import URLError
-# deferred to Raw.run() because import may fail due to broken SSL dependencies
-# and it took about 0.15 seconds to load. Update: < 0.03s with Py3k.
+from urllib.request import urlopen
+from urllib.error import URLError
from docutils import io, nodes, statemachine, utils
from docutils.parsers.rst import Directive, convert_directive_function
@@ -271,11 +269,6 @@ class Raw(Directive):
attributes['source'] = path
elif 'url' in self.options:
source = self.options['url']
- # Do not import urllib at the top of the module because
- # it may fail due to broken SSL dependencies, and it takes
- # about 0.15 seconds to load. Update: < 0.03s with Py3k.
- from urllib.request import urlopen
- from urllib.error import URLError
try:
raw_text = urlopen(source).read()
except (URLError, OSError) as error:
diff --git a/docutils/docutils/parsers/rst/directives/tables.py b/docutils/docutils/parsers/rst/directives/tables.py
index 8ba858a9a..328554da1 100644
--- a/docutils/docutils/parsers/rst/directives/tables.py
+++ b/docutils/docutils/parsers/rst/directives/tables.py
@@ -17,6 +17,8 @@ from docutils import io, nodes, statemachine, utils
from docutils.utils import SystemMessagePropagation
from docutils.parsers.rst import Directive
from docutils.parsers.rst import directives
+from urllib.request import urlopen
+from urllib.error import URLError
def align(argument):
@@ -351,13 +353,6 @@ class CSVTable(Table):
else:
self.state.document.settings.record_dependencies.add(source)
elif 'url' in self.options:
- # CSV data is from a URL.
- # Do not import urllib at the top of the module because
- # it may fail due to broken SSL dependencies, and it takes
- # about 0.15 seconds to load. Update: < 0.03s with Py3k.
- from urllib.request import urlopen
- from urllib.error import URLError
-
source = self.options['url']
try:
with urlopen(source) as response:
@@ -400,7 +395,7 @@ class CSVTable(Table):
return s
def parse_csv_data_into_rows(self, csv_data, dialect, source):
- csv_reader = csv.reader([line + '\n' for line in csv_data],
+ csv_reader = csv.reader((line + '\n' for line in csv_data),
dialect=dialect)
rows = []
max_cols = 0