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


Python urllib.unquote函数代码示例

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


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

示例1: DownloadUpdate

	def DownloadUpdate(self, file):
		self.log('Downloading: %s' % file)
		dirfile = os.path.join(self.UpdateTempDir,file)
		dirname, filename = os.path.split(dirfile)
		if not os.path.isdir(dirname):
			try:
				os.makedirs(dirname)
			except:
				self.log('Error creating directory: '  +dirname)
		url = self.SVNPathAddress+urllib.quote(file)
		try:
			if re.findall(".xbt",url):
				self.totalsize = int(re.findall("File length: ([0-9]*)",urllib2.urlopen(url+"?view=log").read())[0])
				urllib.urlretrieve( url.decode("utf-8"), dirfile.decode("utf-8"))
			else: urllib.urlretrieve( url.decode("utf-8"), dirfile.decode("utf-8") )
			self.DownloadedFiles.append(urllib.unquote(url))
			return 1
		except:
			try:
				time.sleep(2)
				if re.findall(".xbt",url):
					self.totalsize = int(re.findall("File length: ([0-9]*)",urllib2.urlopen(url+"?view=log").read())[0])
					urllib.urlretrieve(url.decode("utf-8"), dirfile.decode("utf-8"))
				else: urllib.urlretrieve(url.decode("utf-8"), dirfile.decode("utf-8") )
				urllib.urlretrieve(url.decode("utf-8"), dirfile.decode("utf-8"))
				self.DownloadedFiles.append(urllib.unquote(url))
				return 1
			except:
				self.log("Download failed: %s" % url)
				self.DownloadFailedFiles.append(urllib.unquote(url))
				return 0
开发者ID:reversTeam,项目名称:sualfreds-repo,代码行数:31,代码来源:updater_class.py

示例2: render

	def render(self, request):
		if 'dir' in request.args:
			dir = unquote(request.args['dir'][0])
		elif 'root' in request.args:
			dir = unquote(request.args['root'][0])
		else:
			dir = ''

		if 'file' in request.args:
			filename = unquote(request.args["file"][0])
			path = dir + filename

			#dirty backwards compatibility hack
			if not os_path.exists(path):
				path = resolveFilename(SCOPE_HDD, filename)

			print "[WebChilds.FileStreamer] path is %s" %path

			if os_path.exists(path):
				basename = filename.decode('utf-8', 'ignore').encode('ascii', 'ignore')

				if '/' in basename:
					basename = basename.split('/')[-1]

				request.setHeader("content-disposition", "attachment;filename=\"%s\"" % (basename))
				file = static.File(path, defaultType = "application/octet-stream")
				return file.render_GET(request)

			else:
				return resource.NoResource(message="file '%s' was not found" %(dir + filename)).render(request)
		else:
			return resource.NoResource(message="no file given with file={filename}").render(request)

		return server.NOT_DONE_YET
开发者ID:Blacksens,项目名称:enigma2-plugins,代码行数:34,代码来源:FileStreamer.py

示例3: get_objs_to_delete

    def get_objs_to_delete(self, req):
        """
        Will populate objs_to_delete with data from request input.
        :params req: a Swob request
        :returns: a list of the contents of req.body when separated by newline.
        :raises: HTTPException on failures
        """
        line = ''
        data_remaining = True
        objs_to_delete = []
        if req.content_length is None and \
                req.headers.get('transfer-encoding', '').lower() != 'chunked':
            raise HTTPLengthRequired(request=req)

        while data_remaining:
            if '\n' in line:
                obj_to_delete, line = line.split('\n', 1)
                objs_to_delete.append(unquote(obj_to_delete))
            else:
                data = req.environ['wsgi.input'].read(MAX_PATH_LENGTH)
                if data:
                    line += data
                else:
                    data_remaining = False
                    if line.strip():
                        objs_to_delete.append(unquote(line))
            if len(objs_to_delete) > self.max_deletes_per_request:
                raise HTTPRequestEntityTooLarge(
                    'Maximum Bulk Deletes: %d per request' %
                    self.max_deletes_per_request)
            if len(line) > MAX_PATH_LENGTH * 2:
                raise HTTPBadRequest('Invalid File Name')
        return objs_to_delete
开发者ID:sun3shines,项目名称:swift-1.7.4,代码行数:33,代码来源:bulk.py

示例4: crack_action

def crack_action(params):
    if params[1] == 'search':
        load_search(params[2])
    elif params[1] == 'choose_file':
        callback = params[2]
        file_path = utils.open_file_chooser_dialog()
        webv.execute_script('%s("%s")' % (callback, file_path))
    elif params[1] == 'save_avatar':
        img_uri = urllib.unquote(params[2])
        avatar_file = urllib.unquote(params[3])
        avatar_path = os.path.join(config.AVATAR_CACHE_DIR, avatar_file)
        if not (os.path.exists(avatar_path) and avatar_file.endswith(img_uri[img_uri.rfind('/')+1:])):
            print 'Download:', img_uri , 'To' , avatar_path
            th = threading.Thread(
                target = save_file_proc, 
                args=(img_uri, avatar_path))
            th.start()
    elif params[1] == 'log':
        print '\033[1;31;40m[%s]\033[0m %s' % (urllib.unquote(params[2]) ,urllib.unquote(params[3]))
    elif params[1] == 'paste_clipboard_text':
        webv.paste_clipboard();
    elif params[1] == 'set_clipboard_text':
        clipboard = gtk.clipboard_get()
        text = list(params)
        del text[0:2]
        clipboard.set_text('/'.join(text))
开发者ID:fma16,项目名称:Hotot,代码行数:26,代码来源:agent.py

示例5: get

 def get(self):
   user = users.get_current_user()
   user_oauth = oauth.get_current_user()
   self.response.write(user_oauth)
   if user:
     client_id = "676481030478-0fi923mg6rbe1tqbvffr8n5ih56p63gg.apps.googleusercontent.com"
     client_secret = "AXSaN3iaVse0lL_GCRp7ioPQ"
     scope = urllib.unquote(self.request.get("scope")).decode("utf-8")
     redirect_uri = urllib.unquote(self.request.get("redirect_uri")).decode("utf-8")
     flow = Oauth2WebServerFlow(client_id, client_secret, scope,redirect_uri=redirect_uri)
     code = self.request.get("code")
     redirect_uri = "http://localhost:19080/oauth"
     grant_type = "authorization_code"
     form_fields = {
       "code" : code,
       "client_id" : client_id,
       "client_secret" : client_secret,
       "redirect_uri" : redirect_uri,
       "grant_type" : grant_type,
     }
     form_data = urllib.urlencode(form_fields)
     url_validator = "https://www.googleapis.com/oauth2/v1/tokeninfo"
     #url_validator = "https://www.googleapis.com/o/oauth2/token?access_token=" + code
     result = urlfetch.fetch(
       headers = {'Content-Type': 'application/x-www-form-urlencoded'},
       url = url_validator,
       payload = form_data,
       method = urlfetch.POST,
     )
     self.response.write(result.content)
开发者ID:fritzdenim,项目名称:gcdc2013-mapjobs,代码行数:30,代码来源:main2.py

示例6: PLAY

def PLAY(params):
    # -- get filter parameters
    par = Get_Parameters(params)

    # -- if requested continious play
    if Addon.getSetting("continue_play") == "true":
        # create play list
        pl = xbmc.PlayList(1)
        pl.clear()
        # -- get play list
        playlist = Get_PlayList(par.playlist)
        is_found = False
        for rec in playlist:
            name = rec["comment"].encode("utf-8")
            s_url = rec["file"]
            # -- add item to play list
            if s_url == par.url:
                is_found = True

            if is_found:
                i = xbmcgui.ListItem(name, path=urllib.unquote(s_url), thumbnailImage=par.img)
                i.setProperty("IsPlayable", "true")
                pl.add(s_url, i)

        xbmc.Player().play(pl)
    # -- play only selected item
    else:
        i = xbmcgui.ListItem(par.name, path=urllib.unquote(par.url), thumbnailImage=par.img)
        i.setProperty("IsPlayable", "true")
        xbmcplugin.setResolvedUrl(h, True, i)
开发者ID:Stevie-Bs,项目名称:ru,代码行数:30,代码来源:default.py

示例7: filter_headers

def filter_headers(headers, prefix):
    meta = {}
    for k, v in headers.iteritems():
        if not k.startswith(prefix):
            continue
        meta[unquote(k[len(prefix):])] = unquote(v)
    return meta
开发者ID:antonis-m,项目名称:synnefo,代码行数:7,代码来源:__init__.py

示例8: fromString

    def fromString(self, tagstring):
        """
        go from string to Tag class filled in
        
        @param tagstring: example "important customer:kristof"
        @type tagstring: string        
        """

        tagstring=j.tools.text.hrd2machinetext(tagstring)

        if not tagstring:
            return


        tags = tagstring.split()
        for tag in tags:                
            if tag.find(':') > 0:
                key = tag.split(':',1)[0]
                value = tag.split(':',1)[1]
                key=unquote(key)
                value = unquote(j.tools.text.machinetext2hrd(value))
                self.tags[key.lower()] = value
                self.tags[key] = value
            else:
                self.labels.add(unquote(j.tools.text.machinetext2hrd(tag)))

        self.tagstring=tagstring
开发者ID:jumpscale7,项目名称:jumpscale6_core,代码行数:27,代码来源:Tags.py

示例9: _lookup

 def _lookup(self, next, *rest):
     next = h.really_unicode(unquote(next))
     if not rest:
         # Might be a file rather than a dir
         filename = h.really_unicode(
             unquote(
                 request.environ['PATH_INFO'].rsplit('/')[-1]))
         if filename:
             try:
                 obj = self._tree[filename]
             except KeyError:
                 raise exc.HTTPNotFound()
             if isinstance(obj, M.repository.Blob):
                 return self.FileBrowserClass(
                     self._commit,
                     self._tree,
                     filename), rest
     elif rest == ('index', ):
         rest = (request.environ['PATH_INFO'].rsplit('/')[-1],)
     try:
         tree = self._tree[next]
     except KeyError:
         raise exc.HTTPNotFound
     return self.__class__(
         self._commit,
         tree,
         self._path + '/' + next,
         self), rest
开发者ID:apache,项目名称:allura,代码行数:28,代码来源:repository.py

示例10: _check_oob_iq

    def _check_oob_iq(self, iq_event):
        assert iq_event.iq_type == 'set'
        assert iq_event.connection == self.incoming
        self.iq = iq_event.stanza
        assert self.iq['to'] == self.contact_name
        query = self.iq.firstChildElement()
        assert query.uri == 'jabber:iq:oob'
        url_node = xpath.queryForNodes("/iq/query/url", self.iq)[0]
        assert url_node['type'] == 'file'
        assert url_node['size'] == str(self.file.size)
        assert url_node['mimeType'] == self.file.content_type
        self.url = url_node.children[0]
        _, self.host, self.filename, _, _, _ = urlparse.urlparse(self.url)
        urllib.unquote(self.filename) == self.file.name
        desc_node = xpath.queryForNodes("/iq/query/desc", self.iq)[0]
        self.desc = desc_node.children[0]
        assert self.desc == self.file.description

        # Metadata forms
        forms = extract_data_forms(xpath.queryForNodes('/iq/query/x', self.iq))

        if self.service_name:
            assertEquals({'ServiceName': [self.service_name]},
                         forms[ns.TP_FT_METADATA_SERVICE])
        else:
            assert ns.TP_FT_METADATA_SERVICE not in forms

        if self.metadata:
            assertEquals(self.metadata, forms[ns.TP_FT_METADATA])
        else:
            assert ns.TP_FT_METADATA not in forms
开发者ID:freedesktop-unofficial-mirror,项目名称:telepathy__telepathy-salut,代码行数:31,代码来源:file_transfer_helper.py

示例11: parse_args

def parse_args(args=""):
    "Parse input args"

    out_args = {
       "verb"             : "",
       "metadataPrefix"   : "",
       "from"             : "",
       "until"            : "",
       "set"              : "",
       "identifier"       : "",
       "resumptionToken"  : ""
    }

    if args == "" or args is None:
        pass
    else:

        list_of_arguments = args.split('&')

        for item in list_of_arguments:
            keyvalue = item.split('=')
            if len(keyvalue) == 2:
                if (out_args.has_key(keyvalue[0])):
                    if(out_args[keyvalue[0]] != ""):
                        out_args[keyvalue[0]] = "Error"
                    else:
                        out_args[keyvalue[0]] = urllib.unquote(keyvalue[1])
                else:
                    out_args[keyvalue[0]] = urllib.unquote(keyvalue[1])
            else:
                out_args['verb'] = ""

    return out_args
开发者ID:NikolaYolov,项目名称:invenio_backup,代码行数:33,代码来源:oai_repository_server.py

示例12: basicauth_decode

def basicauth_decode(encoded_str):
    """Decode an encrypted HTTP basic authentication string. Returns a tuple of
    the form (username, password), and raises a DecodeError exception if
    nothing could be decoded.
    """
    split = encoded_str.strip().split(' ')

    # If split is only one element, try to decode the username and password
    # directly.
    if len(split) == 1:
        try:
            username, password = b64decode(split[0]).split(':', 1)
        except:
            raise DecodeError

    # If there are only two elements, check the first and ensure it says
    # 'basic' so that we know we're about to decode the right thing. If not,
    # bail out.
    elif len(split) == 2:
        if split[0].strip().lower() == 'basic':
            try:
                username, password = b64decode(split[1]).split(':', 1)
            except:
                raise DecodeError
        else:
            raise DecodeError

    # If there are more than 2 elements, something crazy must be happening.
    # Bail.
    else:
        raise DecodeError

    return unquote(username), unquote(password)
开发者ID:mayblue9,项目名称:react-django-admin,代码行数:33,代码来源:utils_basicauth.py

示例13: _form_uri_parts

 def _form_uri_parts(self, netloc, path):
     if netloc != '':
         # > Python 2.6.1
         if '@' in netloc:
             creds, netloc = netloc.split('@')
         else:
             creds = None
     else:
         # Python 2.6.1 compat
         # see lp659445 and Python issue7904
         if '@' in path:
             creds, path = path.split('@')
         else:
             creds = None
         netloc = path[0:path.find('/')].strip('/')
         path = path[path.find('/'):].strip('/')
     if creds:
         cred_parts = creds.split(':')
         if len(cred_parts) < 2:
             reason = _("Badly formed credentials in Swift URI.")
             LOG.info(reason)
             raise exceptions.BadStoreUri(message=reason)
         key = cred_parts.pop()
         user = ':'.join(cred_parts)
         creds = urllib.unquote(creds)
         try:
             self.user, self.key = creds.rsplit(':', 1)
         except exceptions.BadStoreConfiguration:
             self.user = urllib.unquote(user)
             self.key = urllib.unquote(key)
     else:
         self.user = None
         self.key = None
     return netloc, path
开发者ID:saeki-masaki,项目名称:glance_store,代码行数:34,代码来源:store.py

示例14: createMediaRequest

    def createMediaRequest(self,stream):
        if stream == None:
            self.error_str = "No event-id present to create media request."
            raise

        try:
            sessionKey = urllib.unquote(self.session.cookies['ftmu'])
        except:
            sessionKey = None
      
        # Query values
        query_values = {
            'contentId': self.content_id,
            'sessionKey': sessionKey,
            'fingerprint': urllib.unquote(self.session.cookies['fprt']),
            'identityPointId': self.session.cookies['ipid'],
            'playbackScenario': self.scenario,
            'subject': self.subject
        }
        # Build query
        url = self.base_url + urllib.urlencode(query_values)
        
        # And make the request
        req = urllib2.Request(url)
        response = urllib2.urlopen(req)
        reply = xml.dom.minidom.parse(response)
        return reply
开发者ID:HyShai,项目名称:mlbviewer,代码行数:27,代码来源:milbMediaStream.py

示例15: download

def download(url, path_to_directory):
    print "starting download with", url, path_to_directory
    if "geoserver/wfs" in url:
        filename = unquote(search("(?<=typename=)[^&]*",url).group(0)).replace(":","_")
        extension = "zip"
        filename_with_extension = filename + "." + extension
    else:
        filename_with_extension = unquote(url.split("?")[0].split("/")[-1])
        print "filename_with_extension = ", filename_with_extension
        filename = filename_with_extension.split(".")[0]
        
    print "filename is", filename
    print "filename_with_extension = ", filename_with_extension
    path_to_directory_of_downloadable = path_to_directory + "/" + filename
    if not isdir(path_to_directory_of_downloadable):
        mkdir(path_to_directory_of_downloadable)
    path_to_downloaded_file = path_to_directory_of_downloadable + "/" + filename_with_extension
    if not isfile(path_to_downloaded_file):
        urlretrieve(url, path_to_downloaded_file)
        print "saved file to ", path_to_downloaded_file
    if path_to_downloaded_file.endswith("zip"):         
        if is_zipfile(path_to_downloaded_file):    
            with zipfile.ZipFile(path_to_downloaded_file, "r") as z:
                z.extractall(path_to_directory_of_downloadable)
                print "unzipped", path_to_downloaded_file
        else:
            remove(path_to_downloaded_file)
            print "removed file because it wasn't a zip file eventhough had zip extension"
开发者ID:DanielJDufour,项目名称:firstdraft,代码行数:28,代码来源:load.py


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