Re: Agnostic fetching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ivan Ven Osdel

    Re: Agnostic fetching

    >----- Original Message -----
    >From: "Diez B. Roggisch" <deets@nospam.w eb.de>
    >To: python-list@python.org
    >Sent: Saturday, August 2, 2008 11:05:07 AM GMT -06:00 US/Canada Central
    >Subject: Re: Agnostic fetching
    >Bruce Frederiksen schrieb:
    On Fri, 01 Aug 2008 17:05:00 -0700, jorpheus wrote:
    >
    >OK, that sounds stupid. Anyway, I've been learning Python for some
    >time now, and am currently having fun with the urllib and urllib2
    >modules, but have run into a problem(?) - is there any way to fetch
    >(urllib.retrie ve) files from a server without knowing the filenames?
    >For instance, there is smth like folder/spam.egg, folder/
    >unpredictable. egg and so on. If not, perhaps some kind of glob to
    >create a list of existing files? I'd really appreciate some help,
    >since I'm really out of my (newb) depth here.
    >
    You might try the os.path module and/or the glob module in the standard
    python library.
    >Not on remote locations. The only work on your local filesystem.
    >Diez
    Here's a function I wrote for checking remote or local file existence. It works for me but admittedly I haven't tested many cases with it. Also its currently specific to an http URI scheme.

    def fileExists(self , fileUrlPath):
    fileExists = False
    if "http:" in fileUrlPath.low er():
    #We don't want to open the file so ask the header if the
    #file exists
    urlParts = urlparse(fileUr lPath)
    host = urlParts[1]
    http = httplib.HTTP(ho st)
    http.putrequest ("HEAD", fileUrlPath)
    http.putheader( "Host", host)
    http.endheaders ()
    errorcode, errormessage, headers = http.getreply()
    if errorcode == 200:
    fileExists = True
    else:
    fileExists = path.exists(fil eUrlPath)

    return fileExists

    --
    Ivan Ven Osdel

  • Diez B. Roggisch

    #2
    Re: Agnostic fetching

    Ivan Ven Osdel wrote:
    >>----- Original Message -----
    >>From: "Diez B. Roggisch" <deets@nospam.w eb.de>
    >>To: python-list@python.org
    >>Sent: Saturday, August 2, 2008 11:05:07 AM GMT -06:00 US/Canada Central
    >>Subject: Re: Agnostic fetching
    >
    >>Bruce Frederiksen schrieb:
    >On Fri, 01 Aug 2008 17:05:00 -0700, jorpheus wrote:
    >>
    >>OK, that sounds stupid. Anyway, I've been learning Python for some
    >>time now, and am currently having fun with the urllib and urllib2
    >>modules, but have run into a problem(?) - is there any way to fetch
    >>(urllib.retri eve) files from a server without knowing the filenames?
    >>For instance, there is smth like folder/spam.egg, folder/
    >>unpredictable .egg and so on. If not, perhaps some kind of glob to
    >>create a list of existing files? I'd really appreciate some help,
    >>since I'm really out of my (newb) depth here.
    >>
    >You might try the os.path module and/or the glob module in the standard
    >python library.
    >
    >>Not on remote locations. The only work on your local filesystem.
    >
    >>Diez
    >
    Here's a function I wrote for checking remote or local file existence. It
    works for me but admittedly I haven't tested many cases with it. Also its
    currently specific to an http URI scheme.
    <snip/>

    The idea was to *not* know the filenames beforehand, but instead get a
    directory-listing. Which is impossible to get.

    Diez

    Comment

    Working...