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


Python parse.unquote函数代码示例

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


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

示例1: getSongs

	def getSongs(self):
		format = "%Y-%m-%d %H:%M:%S"
		for trackid,attributes in self.il['Tracks'].items():
			s = Song()
			s.name = attributes.get('Name')
			s.artist = attributes.get('Artist')
			s.album_artist = attributes.get('Album Artist')
			s.composer = attributes.get('Composer')
			s.album = attributes.get('Album')
			s.genre = attributes.get('Genre')
			s.kind = attributes.get('Kind')
			if attributes.get('Size'):
				s.size = int(attributes.get('Size'))
			s.total_time = attributes.get('Total Time')
			s.track_number = attributes.get('Track Number')
			if attributes.get('Track Count'):
				s.track_count = int(attributes.get('Track Count'))
			if attributes.get('Disc Number'):
				s.disc_number = int(attributes.get('Disc Number'))
			if attributes.get('Disc Count'):
				s.disc_count = int(attributes.get('Disc Count'))
			if attributes.get('Year'):
				s.year = int(attributes.get('Year'))
			if attributes.get('Date Modified'):
				s.date_modified = time.strptime(str(attributes.get('Date Modified')),format)
			if attributes.get('Date Added'):
				s.date_added = time.strptime(str(attributes.get('Date Added')),format)
			if attributes.get('Bit Rate'):
				s.bit_rate = int(attributes.get('Bit Rate'))
			if attributes.get('Sample Rate'):
				s.sample_rate = int(attributes.get('Sample Rate'))
			s.comments = attributes.get("Comments	")
			if attributes.get('Rating'):
				s.rating = int(attributes.get('Rating'))
			if attributes.get('Play Count'):
				s.play_count = int(attributes.get('Play Count'))
			if attributes.get('Location'):
				if ( self.musicPathXML is None or self.musicPathSystem is None ):
					# s.location = text_type(urlparse.unquote(urlparse.urlparse(attributes.get('Location')).path[1:]),"utf8")
					s.location = text_type(urlparse.unquote(urlparse.urlparse(attributes.get('Location')).path[1:]))
				else:
					# s.location = text_type(urlparse.unquote(urlparse.urlparse(attributes.get('Location')).path[1:]).replace(self.musicPathXML,self.musicPathSystem),"utf8")
					s.location = text_type(urlparse.unquote(urlparse.urlparse(attributes.get('Location')).path[1:]).replace(self.musicPathXML,self.musicPathSystem))
			s.compilation = 'Compilation' in attributes
			if attributes.get('Play Date UTC'):
				s.lastplayed = time.strptime(str(attributes.get('Play Date UTC')),format)
			if attributes.get('Total Time'):
				s.length = int(attributes.get('Total Time'))
			if attributes.get('Grouping'):
				s.grouping = attributes.get('Grouping')
			if self.filesOnly==True and attributes.get('Track Type') == 'File':
				if self.legacymode:
					self.songs.append(s)
				else:
					self.songs[int(trackid)] = s
			elif self.filesOnly==False:
				if self.legacymode:
					self.songs.append(s)
				else:
					self.songs[int(trackid)] = s
开发者ID:rfilmyer,项目名称:pyitunes,代码行数:60,代码来源:Library.py

示例2: parse_header_string

def parse_header_string(data):
    if not isinstance(data, (six.text_type, six.binary_type)):
        data = str(data)
    if six.PY2:
        if isinstance(data, six.text_type):
            # Under Python2 requests only returns binary_type, but if we get
            # some stray text_type input, this should prevent unquote from
            # interpreting %-encoded data as raw code-points.
            data = data.encode('utf8')
        try:
            unquoted = unquote(data).decode('utf8')
        except UnicodeDecodeError:
            try:
                return data.decode('utf8')
            except UnicodeDecodeError:
                return quote(data).decode('utf8')
    else:
        if isinstance(data, six.binary_type):
            # Under Python3 requests only returns text_type and tosses (!) the
            # rest of the headers. If that ever changes, this should be a sane
            # approach.
            try:
                data = data.decode('ascii')
            except UnicodeDecodeError:
                data = quote(data)
        try:
            unquoted = unquote(data, errors='strict')
        except UnicodeDecodeError:
            return data
    return unquoted
开发者ID:HeyManLeader,项目名称:OpenStack-Swift-Ringinfo-Client,代码行数:30,代码来源:ringmanagement.py

示例3: object_request

 def object_request(self, req, api_version, account, container, obj,
                    allow_versioned_writes):
     container_name = unquote(container)
     object_name = unquote(obj)
     orig_container = get_unversioned_container(container_name)
     if orig_container != container_name:
         orig_object, version = \
             swift3_split_object_name_version(object_name)
         req.environ['oio.query'] = {'version': version}
         req.environ['PATH_INFO'] = '/%s/%s/%s/%s' % (api_version,
                                                      account,
                                                      quote(orig_container),
                                                      quote(orig_object))
     elif req.method == 'DELETE':
         ver_mode = req.headers.get('X-Backend-Versioning-Mode-Override',
                                    'history')
         if ver_mode == 'stack':
             # Do not create a delete marker, delete the latest version
             obj_inf = get_object_info(req.environ, self.app,
                                       swift_source='VW')
             req.environ['oio.query'] = {
                 'version': obj_inf.get('sysmeta', {}).get('version-id')
             }
     resp = req.get_response(self.app)
     if req.method == 'HEAD':
         close_if_possible(resp.app_iter)
     return resp
开发者ID:jfsmig,项目名称:oio-swift,代码行数:27,代码来源:versioned_writes.py

示例4: decode

def 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]).decode().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]).decode().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:rdegges,项目名称:python-basicauth,代码行数:33,代码来源:basicauth.py

示例5: render_PUT

    def render_PUT(self, request):
        parameters = http.parse_qs(request.content.read(), 1)

        if 'name' not in parameters or not parameters['name'] or not parameters['name'][0]:
            request.setResponseCode(http.BAD_REQUEST)
            return json.dumps({"error": "channel name cannot be empty"})

        if 'description' not in parameters or not parameters['description']:
            description = u''
        else:
            description = unquote(parameters['description'][0]).decode('utf-8')

        my_key = self.session.trustchain_keypair
        my_channel_pk = my_key.pub().key_to_bin()

        # Do not allow to add a channel twice
        if self.session.lm.mds.get_my_channel():
            request.setResponseCode(http.CONFLICT)
            return json.dumps({"error": "channel already exists"})

        title = unquote(parameters['name'][0]).decode('utf-8')
        self.session.lm.mds.ChannelMetadata.create_channel(title, description)
        return json.dumps({
            "added": hexlify(str(my_channel_pk)),
        })
开发者ID:Tribler,项目名称:tribler,代码行数:25,代码来源:mychannel_endpoint.py

示例6: download_request

 def download_request(self, request, spider):
     p = urlparse_cached(request)
     scheme = 'https' if request.meta.get('is_secure') else 'http'
     bucket = p.hostname
     path = p.path + '?' + p.query if p.query else p.path
     url = '{0!s}://{1!s}.s3.amazonaws.com{2!s}'.format(scheme, bucket, path)
     if self.anon:
         request = request.replace(url=url)
     elif self._signer is not None:
         import botocore.awsrequest
         awsrequest = botocore.awsrequest.AWSRequest(
             method=request.method,
             url='{0!s}://s3.amazonaws.com/{1!s}{2!s}'.format(scheme, bucket, path),
             headers=request.headers.to_unicode_dict(),
             data=request.body)
         self._signer.add_auth(awsrequest)
         request = request.replace(
             url=url, headers=awsrequest.headers.items())
     else:
         signed_headers = self.conn.make_request(
                 method=request.method,
                 bucket=bucket,
                 key=unquote(p.path),
                 query_args=unquote(p.query),
                 headers=request.headers,
                 data=request.body)
         request = request.replace(url=url, headers=signed_headers)
     return self._download_http(request, spider)
开发者ID:runt18,项目名称:scrapy,代码行数:28,代码来源:s3.py

示例7: on_PUT

    def on_PUT(self, request, room_id, user_id):
        requester = yield self.auth.get_user_by_req(request)

        room_id = urlparse.unquote(room_id)
        target_user = UserID.from_string(urlparse.unquote(user_id))

        content = parse_json_object_from_request(request)

        yield self.presence_handler.bump_presence_active_time(requester.user)

        # Limit timeout to stop people from setting silly typing timeouts.
        timeout = min(content.get("timeout", 30000), 120000)

        if content["typing"]:
            yield self.typing_handler.started_typing(
                target_user=target_user,
                auth_user=requester.user,
                room_id=room_id,
                timeout=timeout,
            )
        else:
            yield self.typing_handler.stopped_typing(
                target_user=target_user,
                auth_user=requester.user,
                room_id=room_id,
            )

        defer.returnValue((200, {}))
开发者ID:DoubleMalt,项目名称:synapse,代码行数:28,代码来源:room.py

示例8: testGETListIncludeCertainFields

    def testGETListIncludeCertainFields(self):
        modelList = self._getOrCreateModelList()
        modelsByUrl = {self._getAbsoluteDetailURI(model): model for model in modelList}
        includeFields = self._getIncludeFields()
        fieldsQueryParamValue = includeFields.buildQueryParamValue()

        modelCount = len(modelList)
        queryParams = {self._PAGE_SIZE_FIELD_NAME: modelCount, self._QUERY_PARAM_FIELDS: fieldsQueryParamValue}
        wildcardedParentLookups = self._getWildcardedParentLookups(self._getModelClass())
        resp = self._doGETList(self._getModelClass(), queryParams, wildcardedParentLookups)
        self.assertEqual(200, resp.status_code, resp.content)
        stateAttrs, linkAttrs, embeddedAttrs = self._splitContent(resp.data)

        self.assertEqual(stateAttrs[self._COUNT_FIELD_NAME], modelCount)
        self.assertEqual(stateAttrs[self._PAGE_SIZE_FIELD_NAME], modelCount)
        selfUrl = unquote(linkAttrs[self._SELF_FIELD_NAME])
        self.assertTrue(
            selfUrl.startswith(unquote(self._getAbsoluteListURI(self._getModelClass(), wildcardedParentLookups)))
        )
        self.assertTrue("{}={}".format(self._QUERY_PARAM_FIELDS, fieldsQueryParamValue) in selfUrl)
        self.assertTrue("{}={}".format(self._PAGE_SIZE_FIELD_NAME, modelCount) in selfUrl)
        self.assertEqual(modelCount, len(embeddedAttrs))

        for embeddedObjectAttrs in embeddedAttrs:
            modelObj = modelsByUrl[embeddedObjectAttrs[LINKS_FIELD_NAME][self._SELF_FIELD_NAME]]
            self.assertIsNotNone(modelObj)
            self.__assertIncludeFieldsContentEqual(includeFields, modelObj, embeddedObjectAttrs)
开发者ID:seebass,项目名称:drf-tools,代码行数:27,代码来源:base.py

示例9: get_runs_by_run_metadata_key

def get_runs_by_run_metadata_key(run_metadata_key, value):
    run_metadata_key = parse.unquote(run_metadata_key)
    value = parse.unquote(value)
    start_date = _parse_datetimes(flask.request.args.get('start_date', None))
    stop_date = _parse_datetimes(flask.request.args.get('stop_date', None))
    datetime_resolution = flask.request.args.get('datetime_resolution', 'day')

    if datetime_resolution not in ['sec', 'min', 'hour', 'day']:
        message = ('Datetime resolution: %s, is not a valid'
                   ' choice' % datetime_resolution)
        status_code = 400
        return abort(make_response(message, status_code))

    with session_scope() as session:
        runs = (api.get_time_series_runs_by_key_value(run_metadata_key,
                                                      value,
                                                      start_date,
                                                      stop_date,
                                                      session))
        # Groups runs by metadata
        group_by = "build_name"
        runs_by_build_name = _group_runs_by_key(runs, group_by)

        # Group runs by the chosen data_range.
        # That does not apply when you choose 'sec' since runs are already
        # grouped by it.
        aggregated_runs = \
            RunAggregator(runs_by_build_name).aggregate(datetime_resolution)

        return jsonify(_aggregate_runs(aggregated_runs))
开发者ID:openstack,项目名称:openstack-health,代码行数:30,代码来源:api.py

示例10: login

    def login(self):
        """
        登录账户
        """
        # 登陆前清空 cookie, 能够防止再次登陆时因携带 cookie 可能提示有未进行教学评估的课程导致接口不可用
        self.cookies.clear_session_cookies()

        if self.campus == HF:
            login_data = {'IDToken1': self.account, 'IDToken2': self.password}
            login_url = 'http://ids1.hfut.edu.cn/amserver/UI/Login'
            super(StudentSession, self).request('post', login_url, data=login_data)

            method = 'get'
            url = 'StuIndex.asp'
            data = None
        else:
            method = 'post'
            url = 'pass.asp'
            data = {"user": self.account, "password": self.password, "UserStyle": 'student'}
        # 使用重载的 request 会造成递归调用
        response = super(StudentSession, self).request(method, url, data=data, allow_redirects=False)
        logged_in = response.status_code == 302
        if not logged_in:
            msg = '登陆失败, 请检查你的账号和密码'
            raise SystemLoginFailed(msg)

        escaped_name = self.cookies.get('xsxm')
        if six.PY3:
            self.name = parse.unquote(escaped_name, ENV['SITE_ENCODING'])
        else:
            name = parse.unquote(escaped_name)
            self.name = name.decode(ENV['SITE_ENCODING'])
开发者ID:er1iang,项目名称:hfut-stu-lib,代码行数:32,代码来源:session.py

示例11: _get_parameters_from_request

 def _get_parameters_from_request(self, request, exception=False):
     """Get parameters to log in OPERATION_LOG."""
     user = request.user
     referer_url = None
     try:
         referer_dic = urlparse.urlsplit(
             urlparse.unquote(request.META.get('HTTP_REFERER')))
         referer_url = referer_dic[2]
         if referer_dic[3]:
             referer_url += "?" + referer_dic[3]
         if isinstance(referer_url, str):
             referer_url = referer_url.decode('utf-8')
     except Exception:
         pass
     return {
         'domain_name': getattr(user, 'domain_name', None),
         'domain_id': getattr(user, 'domain_id', None),
         'project_name': getattr(user, 'project_name', None),
         'project_id': getattr(user, 'project_id', None),
         'user_name': getattr(user, 'username', None),
         'user_id': request.session.get('user_id', None),
         'request_scheme': request.scheme,
         'referer_url': referer_url,
         'request_url': urlparse.unquote(request.path),
         'method': request.method if not exception else None,
         'param': self._get_request_param(request),
     }
开发者ID:ContrastingSounds,项目名称:horizon,代码行数:27,代码来源:operation_log.py

示例12: get_request_data

    def get_request_data(self):
        data = {}

        if self.request.body:
            items = self.request.body.decode('utf-8').split('&')
            for item in items:
                if '=' in item:
                    key, value = item.split('=')
                else:
                    key, value = 'item', item

                if key in data:
                    if not isinstance(data[key], (tuple, list)):
                        old = data[key]
                        data[key] = []
                        data[key].append(old)
                    data[key].append(unquote(value))
                else:
                    data[key] = unquote(value)
        else:
            for arg in list(self.request.arguments.keys()):
                data[arg] = self.get_argument(arg)
                if data[arg] == '':  # Tornado 3.0+ compatibility... Hard to test...
                    data[arg] = None

        return data
开发者ID:scorphus,项目名称:bzz,代码行数:26,代码来源:rest_handler.py

示例13: parse_irc_uri

def parse_irc_uri(uri):
    if not uri:
        return {}
    uri = uri.replace('#', '%23')

    parsed = urlparse(uri)
    if sys.version_info < (2, 7) and '?' in parsed.path:
        query = parsed.path[parsed.path.find('?')+1:]
        path = parsed.path[:parsed.path.find('?')]
    else:
        query = parsed.query
        path = parsed.path

    result = {}

    if parsed.hostname:
        result['server'] = parsed.hostname
    if parsed.scheme:
        result['ssl'] = '+ssl' in parsed.scheme
    if path and len(path) > 1:
        result['channel'] = unquote(path[1:])
    if parsed.username:
        result['nickname'] = unquote(parsed.username)
    if parsed.password:
        result['password'] = unquote(parsed.password)
    if parsed.port:
        result['port'] = int(parsed.port)

    if query:
        for keyword, value_list in parse_qs(query).items():
            value = value_list[0]
            result[keyword] = PARAMS.get(keyword, text_type)(value)

    return result
开发者ID:coddingtonbear,项目名称:ircpdb,代码行数:34,代码来源:parse.py

示例14: object_request

    def object_request(self, req, version, account, container, obj,
                       allow_versioned_writes):
        account_name = unquote(account)
        container_name = unquote(container)
        object_name = unquote(obj)
        container_info = None
        resp = None
        is_enabled = config_true_value(allow_versioned_writes)
        if req.method in ('PUT', 'DELETE'):
            container_info = get_container_info(
                req.environ, self.app)
        elif req.method == 'COPY' and 'Destination' in req.headers:
            if 'Destination-Account' in req.headers:
                account_name = req.headers.get('Destination-Account')
                account_name = check_account_format(req, account_name)
            container_name, object_name = check_destination_header(req)
            req.environ['PATH_INFO'] = "/%s/%s/%s/%s" % (
                version, account_name, container_name, object_name)
            container_info = get_container_info(
                req.environ, self.app)

        if not container_info:
            return self.app

        # To maintain backwards compatibility, container version
        # location could be stored as sysmeta or not, need to check both.
        # If stored as sysmeta, check if middleware is enabled. If sysmeta
        # is not set, but versions property is set in container_info, then
        # for backwards compatibility feature is enabled.
        object_versions = container_info.get(
            'sysmeta', {}).get('versions-location')
        if object_versions and isinstance(object_versions, six.text_type):
            object_versions = object_versions.encode('utf-8')
        elif not object_versions:
            object_versions = container_info.get('versions')
            # if allow_versioned_writes is not set in the configuration files
            # but 'versions' is configured, enable feature to maintain
            # backwards compatibility
            if not allow_versioned_writes and object_versions:
                is_enabled = True

        if is_enabled and object_versions:
            object_versions = unquote(object_versions)
            vw_ctx = VersionedWritesContext(self.app, self.logger)
            if req.method in ('PUT', 'COPY'):
                policy_idx = req.headers.get(
                    'X-Backend-Storage-Policy-Index',
                    container_info['storage_policy'])
                resp = vw_ctx.handle_obj_versions_put(
                    req, object_versions, object_name, policy_idx)
            else:  # handle DELETE
                resp = vw_ctx.handle_obj_versions_delete(
                    req, object_versions, account_name,
                    container_name, object_name)

        if resp:
            return resp
        else:
            return self.app
开发者ID:bkolli,项目名称:swift,代码行数:59,代码来源:versioned_writes.py

示例15: __call__

    def __call__(self, env, start_response):
        request = Request(env)
        if not request.path.startswith(self.endpoints_path):
            return self.app(env, start_response)

        if request.method != 'GET':
            return HTTPMethodNotAllowed(
                req=request, headers={"Allow": "GET"})(env, start_response)

        try:
            version, account, container, obj = self._parse_path(request)
        except ValueError as err:
            return HTTPBadRequest(str(err))(env, start_response)

        if account is not None:
            account = unquote(account)
        if container is not None:
            container = unquote(container)
        if obj is not None:
            obj = unquote(obj)

        storage_policy_index = None
        if obj is not None:
            container_info = get_container_info(
                {'PATH_INFO': '/v1/%s/%s' % (account, container)},
                self.app, swift_source='LE')
            storage_policy_index = container_info['storage_policy']
            obj_ring = self.get_object_ring(storage_policy_index)
            partition, nodes = obj_ring.get_nodes(
                account, container, obj)
            endpoint_template = 'http://{ip}:{port}/{device}/{partition}/' + \
                                '{account}/{container}/{obj}'
        elif container is not None:
            partition, nodes = self.container_ring.get_nodes(
                account, container)
            endpoint_template = 'http://{ip}:{port}/{device}/{partition}/' + \
                                '{account}/{container}'
        else:
            partition, nodes = self.account_ring.get_nodes(
                account)
            endpoint_template = 'http://{ip}:{port}/{device}/{partition}/' + \
                                '{account}'

        endpoints = []
        for node in nodes:
            endpoint = endpoint_template.format(
                ip=node['ip'],
                port=node['port'],
                device=node['device'],
                partition=partition,
                account=quote(account),
                container=quote(container or ''),
                obj=quote(obj or ''))
            endpoints.append(endpoint)

        resp = self.response_map[version](
            request, endpoints=endpoints,
            storage_policy_index=storage_policy_index)
        return resp(env, start_response)
开发者ID:bkolli,项目名称:swift,代码行数:59,代码来源:list_endpoints.py


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