summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>1999-03-23 14:00:06 +0000
committerGreg Ward <gward@python.net>1999-03-23 14:00:06 +0000
commit782cdfe9f32fa69e0b797be3156a3599efd392cd (patch)
tree579a4937b1f7f2c70fe6f2bf535b4dd7b2b2296d /Lib
parentd709b487065a3bf341622d502135e55fe522ca87 (diff)
downloadcpython-git-782cdfe9f32fa69e0b797be3156a3599efd392cd.tar.gz
Changes to allow passing an open file to the constructor (to support
ProcessHierarchy's changes to support reading from a remote URL in ProcessDatabase).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/text_file.py27
1 files changed, 13 insertions, 14 deletions
diff --git a/Lib/distutils/text_file.py b/Lib/distutils/text_file.py
index eab498d76c..6153dea3df 100644
--- a/Lib/distutils/text_file.py
+++ b/Lib/distutils/text_file.py
@@ -13,9 +13,6 @@ import sys, os, string, re
class TextFile:
- filename = None
- file = None
- current_line = None
default_options = { 'strip_comments': 1,
'comment_re': re.compile (r'\s*#.*'),
@@ -26,7 +23,11 @@ class TextFile:
'collapse_ws': 0,
}
- def __init__ (self, filename=None, **options):
+ def __init__ (self, filename=None, file=None, **options):
+
+ if filename is None and file is None:
+ raise RuntimeError, \
+ "you must supply either or both of 'filename' and 'file'"
# set values for all options -- either from client option hash
# or fallback to default_options
@@ -45,18 +46,16 @@ class TextFile:
if not self.default_options.has_key (opt):
raise KeyError, "invalid TextFile option '%s'" % opt
- self.filename = filename
- if self.filename:
- self.open ()
-
-
- def open (self, filename=None):
- if not self.filename:
- if not filename:
- raise RuntimeError, "must provide a filename somehow"
-
+ if file is None:
+ self.open (filename)
+ else:
self.filename = filename
+ self.file = file
+ self.current_line = 0 # assuming that file is at BOF!
+
+ def open (self, filename):
+ self.filename = filename
self.file = open (self.filename, 'r')
self.current_line = 0