Skip to content

Commit 59c8512

Browse files
author
lantis63
committed
Renamed openSource to openStream might be more appropriate
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%4086
1 parent a1a2ab4 commit 59c8512

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

inputstream.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import codecs
22

3-
from utils.utils import openSource
3+
from utils.utils import openStream
44

55
class HTMLInputStream(object):
66
"""For reading data from an input stream
@@ -11,10 +11,10 @@ class HTMLInputStream(object):
1111
automatically, as you consume and unconsume characters.
1212
"""
1313

14-
def __init__(self, source, encoding = None):
14+
def __init__(self, stream, encoding = None):
1515
""" Initialise the HTMLInputReader.
1616
17-
The file parameter must be a File object.
17+
The stream can either be a file-object, filename, url or string
1818
1919
The optional encoding parameter must be a string that indicates
2020
the encoding. If specified, that encoding will be used,
@@ -29,7 +29,7 @@ def __init__(self, source, encoding = None):
2929
# Keep a reference to the unencoded file object so that a new
3030
# EncodedFile can be created later if the encoding is declared
3131
# in a meta element
32-
self.file = openSource(source)
32+
self.file = openStream(stream)
3333

3434
skipBOM = False
3535
self.charEncoding = self.detectBOM(self.file)

utils/utils.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,26 +34,26 @@ def __getitem__(self, key):
3434
else:
3535
raise
3636

37-
def openSource(source):
38-
""" Opens source first trying to open a local file, if that fails
39-
try to open as a URL and finally treating source as a string.
37+
def openStream(stream):
38+
""" Opens stream first trying the native open functino, if that
39+
fails try to open as a URL and finally treating stream as a string.
4040
4141
Returns a file-like object.
4242
"""
4343
# Already a file-like object?
44-
if hasattr(source, 'tell'):
45-
return source
44+
if hasattr(stream, 'tell'):
45+
return stream
4646

47-
# Try opening source normally
47+
# Try opening stream normally
4848
try:
49-
return open(source)
49+
return open(stream)
5050
except: pass
5151

52-
# Try opening source as a URL and storing the bytes returned so
52+
# Try opening stream as a URL and storing the bytes returned so
5353
# they can be turned into a file-like object below
5454
try:
5555
import urllib
56-
source = urllib.urlopen(source).read(-1)
56+
stream = urllib.urlopen(stream).read(-1)
5757
except: pass
5858

5959
# Treat source as a string and make it into a file-like object

0 commit comments

Comments
 (0)