Mercurial > python-cmd2
changeset 223:1702ce785a8d
trying @http://
author | catherine@Elli.myhome.westell.com |
---|---|
date | Thu, 19 Mar 2009 05:55:15 -0400 |
parents | 1d3ad27f2b9e |
children | 0a7e97f79a60 |
files | cmd2.py |
diffstat | 1 files changed, 24 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/cmd2.py Thu Mar 19 00:01:06 2009 -0400 +++ b/cmd2.py Thu Mar 19 05:55:15 2009 -0400 @@ -26,7 +26,7 @@ flagReader.py options are still supported for backward compatibility """ import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest -import unittest, string, datetime +import unittest, string, datetime, urllib from optparse import make_option __version__ = '0.4.8' @@ -873,24 +873,32 @@ except Exception, e: print 'Error saving %s: %s' % (fname, str(e)) - def do_load(self, fname=None): + urlre = re.compile('(https?://[-\\w\\./]+)') + def do_load(self, fname=None): """Runs command(s) from a file.""" if fname is None: fname = self.default_file_name - fname = os.path.expanduser(fname) - keepstate = Statekeeper(self, ('stdin','use_rawinput','prompt','continuation_prompt')) - if isinstance(fname, file): - self.stdin = fname - else: - try: - self.stdin = open(os.path.expanduser(fname), 'r') - except IOError, e: - try: - self.stdin = open('%s.%s' % (os.path.expanduser(fname), self.defaultExtension), 'r') - except IOError: - print 'Problem opening file %s: \n%s' % (fname, e) - keepstate.restore() - return + #keepstate = Statekeeper(self, ('stdin','use_rawinput','prompt','continuation_prompt')) + keepstate = Statekeeper(self, ('stdin','use_rawinput','continuation_prompt')) + try: + if isinstance(fname, file): + target = open(fname, 'r') + else: + match = self.urlre.match(fname) + if match: + target = urllib.urlopen(match.group(1)) + else: + fname = os.path.expanduser(fname) + try: + target = open(os.path.expanduser(fname), 'r') + except IOError, e: + target = open('%s.%s' % (os.path.expanduser(fname), + self.defaultExtension), 'r') + except IOError, e: + print 'Problem opening file %s: \n%s' % (fname, e) + keepstate.restore() + return + self.stdin = target self.use_rawinput = False self.prompt = self.continuation_prompt = '' stop = self.cmdloop()