def openAnything(source, searchpaths=None):
if hasattr(source, "<STR_LIT>"):<EOL><INDENT>return source<EOL><DEDENT>if source == "<STR_LIT:->":<EOL><INDENT>import sys<EOL>return sys.stdin<EOL><DEDENT>import urllib.request, urllib.parse, urllib.error<EOL>try:<EOL><INDENT>return urllib.request.urlopen(source)<EOL><DEDENT>except (IOError, OSError):<EOL><INDENT>pass<EOL><DEDENT>for path in searchpaths or ['<STR_LIT:.>']:<EOL><INDENT>try:<EOL><INDENT>return open(os.path.join(path, source))<EOL><DEDENT>except (IOError, OSError):<EOL><INDENT>pass<EOL><DEDENT><DEDENT>import io<EOL>return io.StringIO(str(source))<EOL>
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.

    Examples:
    >>> from xml.dom import minidom
    >>> sock = openAnything("http://localhost/kant.xml")
    >>> doc = minidom.parse(sock)
    >>> sock.close()
    >>> sock = openAnything("c:\\inetpub\\wwwroot\\kant.xml")
    >>> doc = minidom.parse(sock)
    >>> sock.close()
    >>> sock = openAnything("<ref id='conjunction'><text>and</text><text>or</text></ref>")
    >>> doc = minidom.parse(sock)
    >>> sock.close()