当前位置: 首页>>代码示例>>Python>>正文


Python urllib2.url2pathname函数代码示例

本文整理汇总了Python中urllib2.url2pathname函数的典型用法代码示例。如果您正苦于以下问题:Python url2pathname函数的具体用法?Python url2pathname怎么用?Python url2pathname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了url2pathname函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getVideoUrl

def getVideoUrl(content):
    fmtre = re.search('(?<=fmt_stream_map=).*', content)
    grps = fmtre.group(0).split('&amp;')
    vurls = urllib2.unquote(grps[0])
    videoUrl = None
    for vurl in vurls.split(','):
        print urllib2.url2pathname(vurl[4:]),"\n"
        if vurl.find('itag=5') > 0:
            continue
            return urllib2.url2pathname(vurl[4:])
    exit()
    return None
开发者ID:Zhomart,项目名称:youtap,代码行数:12,代码来源:youtap.py

示例2: set_album_art

	def set_album_art(self, button) :
		tburl = self.webview.get_main_frame().get_title()
                
		if not tburl:
			return
		print "Url: " + tburl
		filep = tburl.split('/')
		filepath = filep[len(filep)-1]
		(filen, filextn) = os.path.splitext(filepath)
		request = urllib2.Request(tburl)
		opener = urllib2.build_opener()
		image = None
		try:
			image = opener.open(request).read()
		except:
			print "Failed to download image"
		
		if(self.mode == self.MODE_RHYTHM):
			filename = os.environ['HOME']+"/.cache/rhythmbox/covers/" + self.current_artist + " - " + self.current_album + ".jpg"
       
		else:
			location_path_improper = urllib2.url2pathname(self.current_location)
			location_path_arr = location_path_improper.split("//")
			location_path = location_path_arr[1]
			filename = location_path.rsplit("/",1)[0] + "/" + "folder.jpg"
                    

		output = open(filename, 'w')
		output.write(image)
		output.close()
开发者ID:echofourpapa,项目名称:rhythmbox-plugins,代码行数:30,代码来源:AlbumArtSearch.py

示例3: _download_url

    def _download_url(self, scheme, url, tmpdir):
        # Determine download filename
        #
        name = filter(None,urlparse.urlparse(url)[2].split('/'))
        if name:
            name = name[-1]
            while '..' in name:
                name = name.replace('..','.').replace('\\','_')
        else:
            name = "__downloaded__"    # default if URL has no path contents

        if name.endswith('.egg.zip'):
            name = name[:-4]    # strip the extra .zip before download

        filename = os.path.join(tmpdir,name)

        # Download the file
        #
        if scheme=='svn' or scheme.startswith('svn+'):
            return self._download_svn(url, filename)
        elif scheme=='file':
            return urllib2.url2pathname(urlparse.urlparse(url)[2])
        else:
            self.url_ok(url, True)   # raises error if not allowed
            return self._attempt_download(url, filename)
开发者ID:ahendy0,项目名称:Holdem,代码行数:25,代码来源:package_index.py

示例4: local_open

def local_open(url):
    """Read a local path, with special support for directories"""
    scheme, server, path, param, query, frag = urlparse.urlparse(url)
    filename = urllib2.url2pathname(path)
    if os.path.isfile(filename):
        return urllib2.urlopen(url)
    elif path.endswith('/') and os.path.isdir(filename):
        files = []
        for f in os.listdir(filename):
            if f=='index.html':
                fp = open(os.path.join(filename,f),'rb')
                body = fp.read()
                fp.close()
                break
            elif os.path.isdir(os.path.join(filename,f)):
                f+='/'
            files.append("<a href=%r>%s</a>" % (f,f))
        else:
            body = ("<html><head><title>%s</title>" % url) + \
                "</head><body>%s</body></html>" % '\n'.join(files)
        status, message = 200, "OK"
    else:
        status, message, body = 404, "Path not found", "Not found"

    return urllib2.HTTPError(url, status, message,
            {'content-type':'text/html'}, cStringIO.StringIO(body))
开发者ID:Arsenalist,项目名称:sportsapi,代码行数:26,代码来源:package_index.py

示例5: open

    def open(self, request):
        """
        Open a file or url
        If request.url can't be identified as a url, it will
        return the content in a file-like object
        @param request: A suds Request
        @type Request: suds.transport.Request
        @return: A file-like object
        @rtype: file
        """
        log.debug('opening: (%s)', request.url)

        fp = None
        location = request.url.lstrip()
        if location.startswith('<?'):
            log.debug('returning url (%s) as StringIO file')
            fp = cStringIO.StringIO(location)
        else:
            parsed = urlparse(request.url)
            if parsed.scheme == 'file':
                # the path component of the urlparse output is not automatically a valid filesystem path!
                filepath = u2.url2pathname(parsed.path)
                
                log.debug('opening file (%s) with open', filepath)
                try:
                    fp = open(filepath)
                except Exception, e:
                    raise TransportError(str(e), 500, None)
            else:
开发者ID:CashStar,项目名称:suds-gzip,代码行数:29,代码来源:http.py

示例6: add_paths

    def add_paths(self, paths):
        """Add the given URLs to the control

        paths - a sequence of URLs
        """
        uid = uuid.uuid4()
        npaths = len(paths)
        for i, path in enumerate(paths):
            if i % 100 == 0:
                cellprofiler.preferences.report_progress(
                        uid, float(i) / npaths,
                             "Loading %s into UI" % path)
            folder, filename = self.splitpath(path)
            display_name = urllib2.url2pathname(filename)
            width, _ = self.GetTextExtent(display_name)
            idx = bisect.bisect_left(self.folder_names, folder)
            if idx >= len(self.folder_names) or self.folder_names[idx] != folder:
                folder_item = self.FolderItem(self, folder)
                self.folder_names.insert(idx, folder)
                self.folder_items.insert(idx, folder_item)
            else:
                folder_item = self.folder_items[idx]
            fp = folder_item.filenames
            pidx = bisect.bisect_left(fp, filename)
            if pidx >= len(fp) or fp[pidx] != filename:
                fp.insert(pidx, filename)
                folder_item.widths.insert(pidx, width)
                folder_item.file_display_names.insert(pidx, display_name)
                folder_item.enabled.insert(pidx, True)
        if len(paths) > 0:
            cellprofiler.preferences.report_progress(uid, 1, "Done")
        self.schmutzy = True
        self.Refresh(eraseBackground=False)
开发者ID:0x00B1,项目名称:CellProfiler,代码行数:33,代码来源:pathlist.py

示例7: downloadLatest

def downloadLatest(d, location='downloads\\'):
    """Download the latest version of the package d.

    Use the information specified in the package d to download the latest
    version of the package from the web. The default download location is
    './downloads'

    @param d The dictionary entry for a package, containing at least a 'name', 
    as well as a 'version', and 'download' dict containing 'url', 'regex', and
    'regexpos'.
    @param location The location to download the file to.
    @return the path to the downloaded file.
    """
    try:
        name = d['name']
        version = getWebVersion(d)
        downurl = getDownloadURL(d)
        furl = urllib2.urlopen(downurl)
        filecontents = furl.read()
        furl.close()
        parsed=urllib2.urlparse.urlparse(furl.geturl())
        pathname = urllib2.url2pathname(parsed.path)
        filename = pathname.split("\\")[-1]
        newfileloc = location + name + '---' + version + '---' + filename
        with open(newfileloc, "wb") as f:
            f.write(filecontents)
    except IOError as (errno, strerror):
        print 'could not open file, I/O error({0}): {1}'.format(errno, strerror)
        print 'when calling downloadLatest(%s, %s)' %(d, location)
开发者ID:PhillipNordwall,项目名称:windows-installer,代码行数:29,代码来源:utils_old.py

示例8: open_local_file

 def open_local_file(self, req):
     import email.Utils
     host = req.get_host()
     file = req.get_selector()
     localfile = url2pathname(file)
     stats = os.stat(localfile)
     size = stats.st_size
     modified = email.Utils.formatdate(stats.st_mtime, usegmt=True)
     mtype = mimetypes.guess_type(file)[0]
     headers = mimetools.Message(StringIO(
         'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
         (mtype or 'text/plain', size, modified)))
     if host:
         host, port = splitport(host)
     if not host or \
        (not port and socket.gethostbyname(host) in self.get_names()):
         try:
           file_list = dircache.listdir(localfile)
           s = StringIO()
           s.write('<html><head><base href="%s"/></head><body>' % ('file:' + file))
           s.write('<p>Directory Content:</p>')
           for f in file_list:
             s.write('<p><a href="%s">%s</a></p>\n' % (urllib.quote(f), f))
           s.write('</body></html>')
           s.seek(0)
           headers = mimetools.Message(StringIO(
               'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
               ('text/html', size, modified)))
           return addinfourl(s, headers, 'file:' + file)
         except OSError:
           return addinfourl(open(localfile, 'rb'),
                             headers, 'file:'+file)
     raise URLError('file not on local host')
开发者ID:smetsjp,项目名称:erp5,代码行数:33,代码来源:ContributionOpener.py

示例9: _url_to_local_path

def _url_to_local_path(url, path):
    """Mirror a url path in a local destination (keeping folder structure)"""
    destination = urlparse.urlparse(url).path
    # First char should be '/', and it needs to be discarded
    if len(destination) < 2 or destination[0] != '/':
        raise ValueError('Invalid URL')
    destination = os.path.join(path, urllib2.url2pathname(destination)[1:])
    return destination
开发者ID:dichaelen,项目名称:mne-python,代码行数:8,代码来源:utils.py

示例10: texthandler

def texthandler(parseString=None):
	# s = re.sub(r'%0A', r'\n', parseString)
	# s = re.sub(r'\n+', r'\\n\\n', parseString)
	s = urllib2.url2pathname(parseString)
	s = re.sub(r'\n+', r'\\n\\n', s)
	print s

	return render_template('spritz.html', text=s, filename="", titleText="Highlighted Text") 
开发者ID:NamiKuro,项目名称:Readsy,代码行数:8,代码来源:application.py

示例11: _raise_open_error

 def _raise_open_error(self, url, message):
     if url[:7].lower() == "file://":
         what = "file"
         ident = urllib2.url2pathname(url[7:])
     else:
         what = "URL"
         ident = url
     raise ZConfig.ConfigurationError("error opening %s %s: %s" % (what, ident, message), url)
开发者ID:Petchesi-Iulian,项目名称:Crawler,代码行数:8,代码来源:loader.py

示例12: url_or_fname_to_fname

def url_or_fname_to_fname(url_or_fname):
    """ Assert that is_local(url_or_fname) then if it is a "file:" url, parse it and run url2pathname on it, else just return it. """
    assert is_local(url_or_fname)

    mo = URL_SCHEME(url_or_fname)
    if mo:
        return urllib2.url2pathname(urlparse.urlparse(url)[2])
    else:
        return url_or_fname
开发者ID:ArtRichards,项目名称:tahoe-lafs,代码行数:9,代码来源:package_index.py

示例13: dispatch_selected

def dispatch_selected(*args):
    """BGG BSG Function to dispatch a single user hand"""
    
    document = XSCRIPTCONTEXT.getDocument()
    maindir = urllib2.url2pathname(os.path.dirname(document.Location.replace("file://","")))
    logfile = os.path.join(maindir, 'bsg-dispatcher-debug.log')
    sys.stdout = open(logfile, "w", 0) # unbuffered

    # Useful variables so we don't need to do a lot of typing
    worksheet = document.getSheets().getByName('Game State')
    dispatcherinfo = document.getSheets().getByName('Posting Templates')
    
    # Find the selected char
    selected_char = worksheet.DrawPage.Forms.getByName('formGameState').getByName('lstPlayers').CurrentValue
    selected_player = ''
    if not selected_char:
        MessageBox(document, "Error: no player selected", "Invalid player", "warningbox")
        return False
    
    # Find out which player we're looking at
    for i in range(7):
        charname = worksheet.getCellByPosition(4, 2+i).getString()    # Character name on Game State
        if charname == selected_char:
            selected_player = worksheet.getCellByPosition(1, 2+i).getString()  # Player name on Game State
            player_id = i
            break
    else:
        MessageBox(document, "Error: player not found, maybe a bug?", "Invalid player", "warningbox")
        return False
    
    # Verify if file exists
    playerfile = os.path.join(maindir, selected_char + '.txt')
    if not os.path.exists(playerfile):
        MessageBox(document, "Error: file '%s' not found (use the 'Create Hand Lists' first)" % (selected_char + '.txt'), "File not found", "warningbox")
        return False
    
    # Verify if we already sent this file
    old_md5 = dispatcherinfo.getCellByPosition(player_id+4, 31).getString()
    current_md5 = get_md5(playerfile)
    if old_md5 == current_md5: # We DID send this already!!!
        confirm = MessageBox(document, "It seems we've already sent this file. Send again?", "File already sent", "querybox", YES_NO)
        if confirm == 3:  # Pressed "No"
            return False
    
    # Now we finally try to send our files
    try:
        gm = GeekMail(workdir=maindir)
        gm.dispatch(selected_player, playerfile)
        # Set the current MD5 on the spreadsheet (so that we only send it again after something is changed)
        dispatcherinfo.getCellByPosition(player_id+4, 31).setString(current_md5)
    except Exception as e:
        MessageBox(document, e.message, "Alert!", "warningbox")
        return False
    
    MessageBox(document, "Successfully sent file to %s" % selected_player, "Success!", "infobox")
开发者ID:mawkee,项目名称:BSG-Moderator-Tools,代码行数:55,代码来源:bsg-dispatcher.py

示例14: do_GET

    def do_GET(self):
        """Serve a GET request."""

        command = self.path.split('/')
        command.remove('')
        try:
            if self.path == "/start":
                print "intra ffs"
                buttons_list = BROWSER.start()
                print buttons_list
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=None)
            elif self.path == "/next":
                buttons_list = BROWSER.next()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=None)
            elif self.path == "/prev":
                buttons_list = BROWSER.prev()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=None)
            elif self.path == "/close":
                buttons_list = BROWSER.close()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=None)
            elif self.path == "/":
                buttons_list = BROWSER.home()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=None)
            elif self.path.startswith('/expand/'):
                path = urllib2.url2pathname(self.path[len('/expand'):])
                BROWSER.click_expand_collapse(path)
                buttons_list, fields_list = BROWSER.get_current_page_options()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=fields_list)
            elif command[0] == "get-current-options":
                buttons_list, fields_list = BROWSER.get_current_page_options()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=fields_list)
            else:
                BROWSER.navigate_to(self.path)
                buttons_list, fields_list = BROWSER.get_current_page_options()
                response = Response(code=200, current_page=BROWSER.current_url,
                                    buttons=buttons_list, fields=fields_list)
        except:
            buttons_list, fields_list = BROWSER.get_current_page_options()
            response = Response(code=405,  message="Not allowed",
                                current_page=BROWSER.current_url,
                                buttons=buttons_list, fields=fields_list)
        finally:
            self.send_response(response)
开发者ID:paulaCrismaru,项目名称:raspberrypi_cloud_videostreaming,代码行数:50,代码来源:server.py

示例15: scrape_bizSource

  def scrape_bizSource(self):
    if self.bizSource != None:
      try:
        self.bizSoup = BS(self.bizSource)
      except:
        print 'Incompatible with soup: this url: ' + self.bizUrl.encode('utf-8')
	print 'given on this page: ' + self.path
	return
     
      comments = self.bizSoup.findAll (text=lambda text:isinstance(text, Comment))
      [comment.extract() for comment in comments]

      bizContacts = self.bizSoup.findAll('a')
      regex_contact = re.compile (r'.*contact.*', re.IGNORECASE)
      for link in bizContacts:
        result = re.search (regex_contact, str(link))

	if result != None:
	  try:
	    self.bizContactLink = urljoin ( self.bizUrl, urllib2.url2pathname(link['href']) )
	    break
	  except:
	    continue
      
      if self.bizContactLink != None:

        try:
	  self.bizContactSource = urllib2.urlopen (self.bizContactLink, timeout=300)
	  try:
	    if 'text/html' in self.bizContactSource.info()['content-type']:
	      try:
	        self.bizContactSource = self.bizContactSource.read() #now just HTML source
              except:
		print 'Failed to read contact-us source for: ' + self.bizContactLink.encode('utf-8')
		self.bozContactSource = None
	    else:
	      print 'Contact Us page in NOT HTML for: ' + self.bizContactLink.encode('utf-8')
	      self.bizContactSource = None
	  except:
	      self.bizContactSource = None

	except:
	  print 'unable to open the contact us link: ' + self.bizContactLink.encode('utf-8')
	  self.bizContactSource = None


        if self.bizContactSource != None:
	  self.scrape_bizContactSource()

	self.scrape_bizEmail (str(self.bizSoup))
开发者ID:bhansa,项目名称:Scraper,代码行数:50,代码来源:scraper.py


注:本文中的urllib2.url2pathname函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。