- if not options.stdin and http:
- try:
- import httplib2
- except ImportError:
- import urllib2
-
- # Try and play nice with HTTP servers unless something goes wrong. We don't
- # really care about this cache (A lot of ics files seem to be generated with
- # php which hates caching with a passion).
- h = False
- if 'httplib2' in sys.modules:
- try: h = httplib2.Http('.httplib2-cache')
- except OSError: h = httplib2.Http()
-
- # Load urllib2 if this is not a stdin
- if not options.stdin and (not http or not 'httplib2' in sys.modules):
- import urllib2
-
- try:
- content = u and (h and h.request(url)[1] or urllib2.urlopen(url).read())
- except (ValueError, urllib2.URLError), e:
- sys.stderr.write('%s\n'%e)
- sys.exit(1)
-
- if not u and not options.stdin:
- try: content = open(os.path.abspath(url),'r').read()
- except (IOError, OSError), e:
- sys.stderr.write('%s\n'%e)
- sys.exit(1)
-
- if options.stdin:
- content = sys.stdin.read()