(source, etag=None, modified=None, agent=None, referrer=None, startRange=None, endRange=None)
return StringIO.StringIO(str(source))
URI, filename, or string --> stream

    This function lets you define parsers that take any input source
    (URL, pathname to local or network file, or actual data as a string)
    and deal with it in a uniform manner.  Returned object is guaranteed
    to have all the basic stdio read methods (read, readline, readlines).
    Just .close() the object when you're done with it.

    If the etag argument is supplied, it will be used as the value of an
    If-None-Match request header.

    If the modified argument is supplied, it must be a tuple of 9 integers
    as returned by gmtime() in the standard Python time module. This MUST
    be in GMT (Greenwich Mean Time). The formatted date/time will be used
    as the value of an If-Modified-Since request header.

    If the agent argument is supplied, it will be used as the value of a
    User-Agent request header.

    If the referrer argument is supplied, it will be used as the value of a
    Referer[sic] request header.
URI, filename, or string --> stream
URI filename or string -- > stream
def open_resource(source, etag=None, modified=None, agent=None, referrer=None, startRange=None, endRange=None):
    """
    URI, filename, or string --> stream

    This function lets you define parsers that take any input source
    (URL, pathname to local or network file, or actual data as a string)
    and deal with it in a uniform manner.  Returned object is guaranteed
    to have all the basic stdio read methods (read, readline, readlines).
    Just .close() the object when you're done with it.

    If the etag argument is supplied, it will be used as the value of an
    If-None-Match request header.

    If the modified argument is supplied, it must be a tuple of 9 integers
    as returned by gmtime() in the standard Python time module. This MUST
    be in GMT (Greenwich Mean Time). The formatted date/time will be used
    as the value of an If-Modified-Since request header.

    If the agent argument is supplied, it will be used as the value of a
    User-Agent request header.

    If the referrer argument is supplied, it will be used as the value of a
    Referer[sic] request header.
    """

    if hasattr(source, "read"):
        return source

    if source == "-":
        return sys.stdin

    if not agent:
        agent = USER_AGENT
        
    # try to open with urllib2 (to use optional headers)
    request = urllib2.Request(source)
    if etag:
        request.add_header("If-None-Match", etag)
    if modified:
        request.add_header("If-Modified-Since", format_http_date(modified))
    request.add_header("User-Agent", agent)
    if referrer:
        request.add_header("Referer", referrer)
        request.add_header("Accept-encoding", "gzip")
    start = 0
    if startRange:
        start = startRange
    end = ""
    if endRange:
        end = endRange
    if startRange or endRange:
        range = "bytes=%s-%s" % (start, end)
        print range
        request.add_header("Range", range)
                           
    opener = urllib2.build_opener(MiscURLHandler())
    #print request.headers
    opener.addheaders = [] # RMK - must clear so we only send our custom User-Agent
    #return opener.open(request)
    try:
        return opener.open(request)
    except OSError:
	print "%s not a valud URL" % source
        # source is not a valid URL, but it might be a valid filename
        pass
    except ValueError:
	print "%s is of an unknown URL type" % source
    	pass


    # try to open with native open function (if source is a filename)
    try:
        return open(source)
    except:
	print sys.exc_info()
	print sys.exc_type
        pass

    # huh, not sure I like that at all... probabaly need
    # to change this to returning a fd/fh and reading on it.
    # but shrug, this is just for local files anway... -akl
    # treat source as string
    return StringIO.StringIO(str(source))
def open_resource ( source , etag = None , modified = None , agent = None , referrer = None , startRange = None , endRange = None ) : if hasattr ( source , "read" ) : return source if source == "-" : return sys . stdin if not agent : agent = USER_AGENT # try to open with urllib2 (to use optional headers) request = urllib2 . Request ( source ) if etag : request . add_header ( "If-None-Match" , etag ) if modified : request . add_header ( "If-Modified-Since" , format_http_date ( modified ) ) request . add_header ( "User-Agent" , agent ) if referrer : request . add_header ( "Referer" , referrer ) request . add_header ( "Accept-encoding" , "gzip" ) start = 0 if startRange : start = startRange end = "" if endRange : end = endRange if startRange or endRange : range = "bytes=%s-%s" % ( start , end ) print range request . add_header ( "Range" , range ) opener = urllib2 . build_opener ( MiscURLHandler ( ) ) #print request.headers opener . addheaders = [ ] # RMK - must clear so we only send our custom User-Agent #return opener.open(request) try : return opener . open ( request ) except OSError : print "%s not a valud URL" % source # source is not a valid URL, but it might be a valid filename pass except ValueError : print "%s is of an unknown URL type" % source pass # try to open with native open function (if source is a filename) try : return open ( source ) except : print sys . exc_info ( ) print sys . exc_type pass # huh, not sure I like that at all... probabaly need # to change this to returning a fd/fh and reading on it. # but shrug, this is just for local files anway... -akl # treat source as string return StringIO . StringIO ( str ( source ) )