Browse Source

----------------------------------------------------------------------

Modified Files:
 	Utility.py -- need to do isfile check before calling mod func
           "urlopen" for cross-platform compat.

 ----------------------------------------------------------------------
main
Joshua Boverhof 20 years ago
parent
commit
ed6c54687a
1 changed files with 7 additions and 1 deletions
  1. +7
    -1
      Utility.py

+ 7
- 1
Utility.py View File

@@ -11,6 +11,7 @@ ident = "$Id$"


import types import types
import string, httplib, smtplib, urllib, socket, weakref import string, httplib, smtplib, urllib, socket, weakref
from os.path import isfile
from string import join, strip, split from string import join, strip, split
from UserDict import UserDict from UserDict import UserDict
from cStringIO import StringIO from cStringIO import StringIO
@@ -119,6 +120,7 @@ def urlopen(url, timeout=20, redirects=None):
"""A minimal urlopen replacement hack that supports timeouts for http. """A minimal urlopen replacement hack that supports timeouts for http.
Note that this supports GET only.""" Note that this supports GET only."""
scheme, host, path, params, query, frag = urlparse(url) scheme, host, path, params, query, frag = urlparse(url)

if not scheme in ('http', 'https'): if not scheme in ('http', 'https'):
return urllib.urlopen(url) return urllib.urlopen(url)
if params: path = '%s;%s' % (path, params) if params: path = '%s;%s' % (path, params)
@@ -601,7 +603,11 @@ class DOM:


def loadFromURL(self, url): def loadFromURL(self, url):
"""Load an xml file from a URL and return a DOM document.""" """Load an xml file from a URL and return a DOM document."""
file = urlopen(url) if isfile(url) is True:
file = open(url, 'r')
else:
file = urlopen(url)

try: try:
result = self.loadDocument(file) result = self.loadDocument(file)
except Exception, ex: except Exception, ex:


||||||
x
 
000:0
Loading…
Cancel
Save