Python urllib 模块,quote() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用urllib.quote()

项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def can_fetch(self, useragent, url):
        """using the parsed robots.txt decide if useragent can fetch url"""
        if self.disallow_all:
            return False
        if self.allow_all:
            return True
        # search for given user agent matches
        # the first match counts
        parsed_url = urlparse.urlparse(urllib.unquote(url))
        url = urlparse.urlunparse(('', '', parsed_url.path,
            parsed_url.params, parsed_url.query, parsed_url.fragment))
        url = urllib.quote(url)
        if not url:
            url = "/"
        for entry in self.entries:
            if entry.applies_to(useragent):
                return entry.allowance(url)
        # try the default entry last
        if self.default_entry:
            return self.default_entry.allowance(url)
        # agent not found ==> access granted
        return True
项目:supervising-ui    作者:USCDataScience    | 项目源码 | 文件源码
def webpage():
    url = request.args.get('url')
    if not url:
        # redirect with url query param so that user can navigate back later
        next_rec = service.get_next_unlabelled()
        if next_rec:
            return redirect("/?url=%s" % (urllib.quote(next_rec['url'])))
        else:
            featured_content = "No Unlabelled Record Found."
    else:
        featured_content = get_next(url)
    data = {
        'featured_content': featured_content,
        'status': service.overall_status()
    }
    return render_template('index.html', **data)
项目:dingdang-robot    作者:wzpan    | 项目源码 | 文件源码
def get_speech(self, phrase):
        getinfo_url = 'http://www.peiyinge.com/make/getSynthSign'
        voice_baseurl = 'http://proxy.peiyinge.com:17063/synth?ts='
        data = {
            'content': phrase.encode('utf8')
        }
        result_info = requests.post(getinfo_url, data=data).json()
        content = urllib.quote(phrase.encode('utf8'))
        ts = result_info['ts']
        sign = result_info['sign']
        voice_url = voice_baseurl + ts + '&sign=' + sign + \
            '&vid=' + self.vid + '&volume=&speed=0&content=' + content
        r = requests.get(voice_url)
        with tempfile.NamedTemporaryFile(suffix='.mp3', delete=False) as f:
            f.write(r.content)
            tmpfile = f.name
            return tmpfile
项目:dabdabrevolution    作者:harryparkdotio    | 项目源码 | 文件源码
def urlparts(self):
        """ The :attr:`url` string as an :class:`urlparse.SplitResult` tuple.
            The tuple contains (scheme, host, path, query_string and fragment),
            but the fragment is always empty because it is not visible to the
            server. """
        env = self.environ
        http = env.get('HTTP_X_FORWARDED_PROTO') \
             or env.get('wsgi.url_scheme', 'http')
        host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST')
        if not host:
            # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients.
            host = env.get('SERVER_NAME', '127.0.0.1')
            port = env.get('SERVER_PORT')
            if port and port != ('80' if http == 'http' else '443'):
                host += ':' + port
        path = urlquote(self.fullpath)
        return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def application_uri(environ):
    """Return the application's base URI (no PATH_INFO or QUERY_STRING)"""
    url = environ['wsgi.url_scheme']+'://'
    from urllib import quote

    if environ.get('HTTP_HOST'):
        url += environ['HTTP_HOST']
    else:
        url += environ['SERVER_NAME']

        if environ['wsgi.url_scheme'] == 'https':
            if environ['SERVER_PORT'] != '443':
                url += ':' + environ['SERVER_PORT']
        else:
            if environ['SERVER_PORT'] != '80':
                url += ':' + environ['SERVER_PORT']

    url += quote(environ.get('SCRIPT_NAME') or '/')
    return url
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def getEntries(person):
    """ Fetch a Advogato member's diary and return a dictionary in the form
        { date : entry, ... } 
    """

    parser = DiaryParser()
    f = urllib.urlopen("http://www.advogato.org/person/%s/diary.xml" % urllib.quote(person))

    s = f.read(8192)
    while s:
        parser.feed(s)
        s = f.read(8192)

    parser.close()
    result = {}
    for d, e in map(None, parser.dates, parser.entries):
        result[d] = e
    return result
项目:code    作者:ActiveState    | 项目源码 | 文件源码
def open_file(self, url):
        path = urllib.url2pathname(urllib.unquote(url))
        if os.path.isdir(path):
            if path[-1] != os.sep:
                url = url + '/'
            indexpath = os.path.join(path, "index.html")
            if os.path.exists(indexpath):
                return self.open_file(url + "index.html")
            try:
                names = os.listdir(path)
            except os.error, msg:
                raise IOError, msg, sys.exc_traceback
            names.sort()
            s = MyStringIO("file:"+url, {'content-type': 'text/html'})
            s.write('<BASE HREF="file:%s">\n' %
                    urllib.quote(os.path.join(path, "")))
            for name in names:
                q = urllib.quote(name)
                s.write('<A HREF="%s">%s</A>\n' % (q, q))
            s.seek(0)
            return s
        return urllib.FancyURLopener.open_file(self, url)
项目:Instagram-API    作者:danleyb2    | 项目源码 | 文件源码
def fbUserSearch(self, query):
        """
        facebook user search.
        :type query: str
        :param query:
        :rtype: object
        :return: query data
        """
        query = urllib.quote(query)
        query = \
            self.http.request("fbsearch/topsearch/?context=blended&query=" + query + "&rank_token=" + self.rank_token)[
                1]

        if query['status'] != 'ok':
            raise InstagramException(query['message'] + "\n")

        return query
项目:Instagram-API    作者:danleyb2    | 项目源码 | 文件源码
def searchFBLocation(self, query):
        """
        Get locations.
        :type query: str
        :param query: search query
        :rtype: object
        :return: Location location data
        """
        query = urllib.quote(query)
        endpoint = "fbsearch/places/?rank_token=" + self.rank_token + "&query=" + query

        locationFeed = self.http.request(endpoint)[1]

        if locationFeed['status'] != 'ok':
            raise InstagramException(locationFeed['message'] + "\n")

        return locationFeed
项目:cos-python-sdk-v5    作者:tencentyun    | 项目源码 | 文件源码
def head_object(self, Bucket, Key, **kwargs):
        """??????

        :param Bucket(string): ?????.
        :param Key(string): COS??.
        :param kwargs(dict): ????headers.
        :return(dict): ???metadata??.
        """
        headers = mapped(kwargs)
        url = self._conf.uri(bucket=Bucket, path=quote(Key, '/-_.~'))
        logger.info("head object, url=:{url} ,headers=:{headers}".format(
            url=url,
            headers=headers))
        rt = self.send_request(
            method='HEAD',
            url=url,
            auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key, Key),
            headers=headers)
        return rt.headers
项目:cos-python-sdk-v5    作者:tencentyun    | 项目源码 | 文件源码
def abort_multipart_upload(self, Bucket, Key, UploadId, **kwargs):
        """???????????????????????????.

        :param Bucket(string): ?????.
        :param Key(string): COS??.
        :param UploadId(string): ???????UploadId.
        :param kwargs(dict): ????headers.
        :return: None.
        """
        headers = mapped(kwargs)
        url = self._conf.uri(bucket=Bucket, path=quote(Key, '/-_.~')+"?uploadId={UploadId}".format(UploadId=UploadId))
        logger.info("abort multipart upload, url=:{url} ,headers=:{headers}".format(
            url=url,
            headers=headers))
        rt = self.send_request(
                method='DELETE',
                url=url,
                auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key, Key),
                headers=headers)
        return None
项目:BookCloud    作者:livro-aberto    | 项目源码 | 文件源码
def package():
    sent_package = {}
    sent_package['get_requests'] = get_requests
    def has_requests(project, branch):
        return len(get_requests(project, branch)) > 0
    sent_package['has_requests'] = has_requests
    sent_package['get_log_diff'] = get_log_diff
    sent_package['last_modified'] = last_modified
    sent_package['get_branch_by_name'] = get_branch_by_name
    sent_package['hash'] = lambda x: hashlib.sha256(x).hexdigest()
    sent_package['_'] = _
    sent_package['url_encode'] = lambda x: urllib.quote(x, safe='')
    sent_package['current_user'] = current_user
    sent_package['floor'] = math.floor
    sent_package['len'] = len
    sent_package['getattr'] = getattr
    sent_package['commit_diff'] = commit_diff
    return sent_package
项目:sndlatr    作者:Schibum    | 项目源码 | 文件源码
def _tostring_path(varname, value, explode, operator, safe=""):
  joiner = operator
  if type(value) == type([]):
    if explode == "+":
      return joiner.join([varname + "." + urllib.quote(x, safe) for x in value])
    elif explode == "*":
      return joiner.join([urllib.quote(x, safe) for x in value])
    else:
      return ",".join([urllib.quote(x, safe) for x in value])
  elif type(value) == type({}):
    keys = value.keys()
    keys.sort()
    if explode == "+":
      return joiner.join([varname + "." + urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
    elif explode == "*":
      return joiner.join([urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
    else:
      return ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
  else:
    if value:
      return urllib.quote(value, safe)
    else:
      return ""
项目:health-mosconi    作者:GNUHealth-Mosconi    | 项目源码 | 文件源码
def __get__(self, inst, cls):
        from trytond.model import Model
        from trytond.wizard import Wizard
        from trytond.report import Report

        url_part = {}
        if issubclass(cls, Model):
            url_part['type'] = 'model'
        elif issubclass(cls, Wizard):
            url_part['type'] = 'wizard'
        elif issubclass(cls, Report):
            url_part['type'] = 'report'
        else:
            raise NotImplementedError

        url_part['name'] = cls.__name__
        url_part['database'] = Transaction().cursor.database_name

        local_part = urllib.quote('%(database)s/%(type)s/%(name)s' % url_part)
        if isinstance(inst, Model) and inst.id:
            local_part += '/%d' % inst.id
        return 'tryton://%s/%s' % (HOSTNAME, local_part)
项目:routersploit    作者:reverse-shell    | 项目源码 | 文件源码
def execute(self, cmd):
        cmd = quote(cmd)

        url = "{}:{}/userRpm/DebugResultRpm.htm?cmd={}&usr=osteam&passwd=5up".format(self.target, self.port, cmd)

        response = http_request(method="GET", url=url, auth=(self.username, self.password))
        if response is None:
            return ""

        if response.status_code == 200:
            regexp = 'var cmdResult = new Array\(\n"(.*?)",\n0,0 \);'
            res = re.findall(regexp, response.text)

            if len(res):
                # hard to extract response
                return "\n".join(res[0].replace("\\r\\n", "\r\n").split("\n")[1:])

        return ""
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def renameListGroup(self, groupID, newName):
        """
        Used to rename an existing list group.
        A default callback is added to the returned
        Deferred which updates the contacts attribute
        of the factory.

        @param groupID: the ID of the desired group to rename.
        @param newName: the desired new name for the group.

        @return: A Deferred, the callback for which will be called
                 when the server clarifies the renaming.
                 The callback argument will be a tuple of 3 elements,
                 the new list version (int), the group id (int) and
                 the new group name (str).
        """

        id, d = self._createIDMapping()
        self.sendLine("REG %s %s %s 0" % (id, groupID, quote(newName)))
        def _cb(r):
            self.factory.contacts.version = r[0]
            self.factory.contacts.setGroup(r[1], r[2])
            return r
        return d.addCallback(_cb)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def changeScreenName(self, newName):
        """
        Used to change your current screen name.
        A default callback is added to the returned
        Deferred which updates the screenName attribute
        of the factory and also updates the contact list
        version.

        @param newName: the new screen name

        @return: A Deferred, the callback for which will be called
                 when the server sends an adequate reply.
                 The callback argument will be a tuple of 2 elements:
                 the new list version and the new screen name.
        """

        id, d = self._createIDMapping()
        self.sendLine("REA %s %s %s" % (id, self.factory.userHandle, quote(newName)))
        def _cb(r):
            self.factory.contacts.version = r[0]
            self.factory.screenName = r[1]
            return r
        return d.addCallback(_cb)
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def wmfactory_listing(self, request):
        if self.dirs is None:
            directory = os.listdir(self.path)
            directory.sort()
        else:
            directory = self.dirs

        files = []; dirs = []

        for path in directory:
            url = urllib.quote(path, "/")
            if os.path.isdir(os.path.join(self.path, path)):
                url = url + '/'
                dirs.append({'link':{"text": path + "/", "href":url},
                             'type': '[Directory]', 'encoding': ''})
            else:
                mimetype, encoding = getTypeAndEncoding(path, self.contentTypes,
                                                        self.contentEncodings,
                                                        self.defaultType)
                files.append({
                    'link': {"text": path, "href": url},
                    'type': '[%s]' % mimetype,
                    'encoding': (encoding and '[%s]' % encoding or '')})

        return files + dirs
项目:hostapd-mana    作者:adde88    | 项目源码 | 文件源码
def application_uri(environ):
    """Return the application's base URI (no PATH_INFO or QUERY_STRING)"""
    url = environ['wsgi.url_scheme']+'://'
    from urllib import quote

    if environ.get('HTTP_HOST'):
        url += environ['HTTP_HOST']
    else:
        url += environ['SERVER_NAME']

        if environ['wsgi.url_scheme'] == 'https':
            if environ['SERVER_PORT'] != '443':
                url += ':' + environ['SERVER_PORT']
        else:
            if environ['SERVER_PORT'] != '80':
                url += ':' + environ['SERVER_PORT']

    url += quote(environ.get('SCRIPT_NAME') or '/')
    return url
项目:WikiExtractor_To_the_one_text    作者:j-min    | 项目源码 | 文件源码
def makeInternalLink(title, label):
    colon = title.find(':')
    if colon > 0 and title[:colon] not in acceptedNamespaces:
        return ''
    if colon == 0:
        # drop also :File:
        colon2 = title.find(':', colon + 1)
        if colon2 > 1 and title[colon + 1:colon2] not in acceptedNamespaces:
            return ''
    if Extractor.keepLinks:
        return '<a href="%s">%s</a>' % (quote(title.encode('utf-8')), label)
    else:
        return label


# ----------------------------------------------------------------------
# External links

# from: https://doc.wikimedia.org/mediawiki-core/master/php/DefaultSettings_8php_source.html
项目:MoegirlUpdater    作者:kafuuchino    | 项目源码 | 文件源码
def _encode_params(**kw):
    '''
    do url-encode parameters

    >>> _encode_params(a=1, b='R&D')
    'a=1&b=R%26D'
    >>> _encode_params(a=u'\u4e2d\u6587', b=['A', 'B', 123])
    'a=%E4%B8%AD%E6%96%87&b=A&b=B&b=123'
    '''
    args = []
    for k, v in kw.iteritems():
        if isinstance(v, basestring):
            qv = v.encode('utf-8') if isinstance(v, unicode) else v
            args.append('%s=%s' % (k, urllib.quote(qv)))
        elif isinstance(v, collections.Iterable):
            for i in v:
                qv = i.encode('utf-8') if isinstance(i, unicode) else str(i)
                args.append('%s=%s' % (k, urllib.quote(qv)))
        else:
            qv = str(v)
            args.append('%s=%s' % (k, urllib.quote(qv)))
    return '&'.join(args)
项目:AlexaPi    作者:alexa-pi    | 项目源码 | 文件源码
def code(self, var=None, **params):     # pylint: disable=unused-argument
        code = quote(cherrypy.request.params['code'])
        callback = cherrypy.url()
        payload = {
            "client_id": config['alexa']['Client_ID'],
            "client_secret": config['alexa']['Client_Secret'],
            "code": code,
            "grant_type": "authorization_code",
            "redirect_uri": callback
        }
        url = "https://api.amazon.com/auth/o2/token"
        response = requests.post(url, data=payload)
        resp = response.json()

        alexapi.config.set_variable(['alexa', 'refresh_token'], resp['refresh_token'])

        return "<h2>Success!</h2>" \
                "<p>The refresh token has been added to your config file.</p>" \
                "<p>Now:</p>" \
                "<ul>" \
                "<li>close your this browser window,</li>" \
                "<li>exit the setup script as indicated,</li>" \
                "<li>and follow the Post-installation steps.</li>" \
                "</ul>"
项目:GAMADV-XTD    作者:taers232c    | 项目源码 | 文件源码
def _string_expansion(self, name, value, explode, prefix):
        if value is None:
            return None

        tuples, items = is_list_of_tuples(value)

        if list_test(value) and not tuples:
            return ','.join(quote(v, self.safe) for v in value)

        if dict_test(value) or tuples:
            items = items or sorted(value.items())
            format_str = '%s=%s' if explode else '%s,%s'

            return ','.join(
                format_str % (
                    quote(k, self.safe), quote(v, self.safe)
                ) for k, v in items
            )

        value = value[:prefix] if prefix else value
        return quote(value, self.safe)
项目:purelove    作者:hucmosin    | 项目源码 | 文件源码
def execute(self, cmd):
        cmd = quote(cmd)

        url = "{}:{}/userRpm/DebugResultRpm.htm?cmd={}&usr=osteam&passwd=5up".format(self.target, self.port, cmd)

        response = http_request(method="GET", url=url, auth=(self.username, self.password))
        if response is None:
            return ""

        if response.status_code == 200:
            regexp = 'var cmdResult = new Array\(\n"(.*?)",\n0,0 \);'
            res = re.findall(regexp, response.text)

            if len(res):
                # hard to extract response
                return "\n".join(res[0].replace("\\r\\n", "\r\n").split("\n")[1:])

        return ""
项目:API.AI-RoboED    作者:VycktorStark    | 项目源码 | 文件源码
def Weather(req):
    if req.get("result").get("action") != "WeatherRequest": ## DEFINING THE PREFIX TO EXECUTE FUNCTION
        return {}
    city = req.get("result").get("parameters").get("geo-city").encode("utf8")
    clean = re.compile('ã') ## REMOVING ERROR UTF8
    city = re.sub(clean, 'a', city)
    city = urllib.quote(city.encode("utf8")) ## REMOVING ACCENTUATION
    result = urllib.urlopen(WeatherRequest.format(cidade=city, key=WeatherKey)).read() ## DEFINING URL
    query = json.loads(result) ## LOADING JSON TO SELECT SOME PARAMETERS
    main = query.get('main')
    speech = lang.WeatherMSG.format(cidade=query.get('name'), temperatura=main.get('temp') + 3)
    return {
        "speech": speech,
        "displayText": speech,
        "source": source
    }
项目:plugin.audio.euskarazko-irratiak    作者:aldatsa    | 项目源码 | 文件源码
def list_podcast_programs(programs):
    program_list = []

    # iterate over the contents of the list of programs
    for program in programs:
        url = build_url({'mode': 'podcasts-radio-program', 'foldername': urllib.quote(program['name'].encode('utf8')), 'url': program['url'], 'name': urllib.quote(program['name'].encode('utf8')), 'radio': program['radio']})
        li = xbmcgui.ListItem(program['name'], iconImage='DefaultFolder.png')
        program_list.append((url, li, True))

    # add list to Kodi per Martijn
    # http://forum.kodi.tv/showthread.php?tid=209948&pid=2094170#pid2094170
    xbmcplugin.addDirectoryItems(addon_handle, program_list, len(program_list))

    # set the content of the directory
    xbmcplugin.setContent(addon_handle, 'songs')
    xbmcplugin.endOfDirectory(addon_handle)
项目:containerregistry    作者:google    | 项目源码 | 文件源码
def _start_upload(
      self,
      digest,
      mount=None
  ):
    """POST to begin the upload process with optional cross-repo mount param."""
    if not mount:
      # Do a normal POST to initiate an upload if mount is missing.
      url = '{base_url}/blobs/uploads/'.format(base_url=self._base_url())
      accepted_codes = [httplib.ACCEPTED]
    else:
      # If we have a mount parameter, try to mount the blob from another repo.
      mount_from = '&'.join(
          ['from=' + urllib.quote(repo.repository, '') for repo in self._mount])
      url = '{base_url}/blobs/uploads/?mount={digest}&{mount_from}'.format(
          base_url=self._base_url(),
          digest=digest,
          mount_from=mount_from)
      accepted_codes = [httplib.CREATED, httplib.ACCEPTED]

    resp, unused_content = self._transport.Request(
        url, method='POST', body=None,
        accepted_codes=accepted_codes)
    return resp.status == httplib.CREATED, resp.get('location')  # type: ignore
项目:Mmrz-Sync    作者:zhanglintc    | 项目源码 | 文件源码
def urlparts(self):
        ''' The :attr:`url` string as an :class:`urlparse.SplitResult` tuple.
            The tuple contains (scheme, host, path, query_string and fragment),
            but the fragment is always empty because it is not visible to the
            server. '''
        env = self.environ
        http = env.get('HTTP_X_FORWARDED_PROTO') or env.get('wsgi.url_scheme', 'http')
        host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST')
        if not host:
            # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients.
            host = env.get('SERVER_NAME', '127.0.0.1')
            port = env.get('SERVER_PORT')
            if port and port != ('80' if http == 'http' else '443'):
                host += ':' + port
        path = urlquote(self.fullpath)
        return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
项目:ynm3k    作者:socrateslee    | 项目源码 | 文件源码
def urlparts(self):
        ''' The :attr:`url` string as an :class:`urlparse.SplitResult` tuple.
            The tuple contains (scheme, host, path, query_string and fragment),
            but the fragment is always empty because it is not visible to the
            server. '''
        env = self.environ
        http = env.get('HTTP_X_FORWARDED_PROTO') or env.get('wsgi.url_scheme', 'http')
        host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST')
        if not host:
            # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients.
            host = env.get('SERVER_NAME', '127.0.0.1')
            port = env.get('SERVER_PORT')
            if port and port != ('80' if http == 'http' else '443'):
                host += ':' + port
        path = urlquote(self.fullpath)
        return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
项目:office-interoperability-tools    作者:milossramek    | 项目源码 | 文件源码
def _tostring_path(varname, value, explode, operator, safe=""):
  joiner = operator
  if type(value) == type([]):
    if explode == "+":
      return joiner.join([varname + "." + urllib.quote(x, safe) for x in value])
    elif explode == "*":
      return joiner.join([urllib.quote(x, safe) for x in value])
    else:
      return ",".join([urllib.quote(x, safe) for x in value])
  elif type(value) == type({}):
    keys = value.keys()
    keys.sort()
    if explode == "+":
      return joiner.join([varname + "." + urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
    elif explode == "*":
      return joiner.join([urllib.quote(key, safe) + joiner + urllib.quote(value[key], safe) for key in keys])
    else:
      return ",".join([urllib.quote(key, safe) + "," + urllib.quote(value[key], safe) for key in keys])
  else:
    if value:
      return urllib.quote(value, safe)
    else:
      return ""
项目:warriorframework    作者:warriorframework    | 项目源码 | 文件源码
def urlparts(self):
        """ The :attr:`url` string as an :class:`urlparse.SplitResult` tuple.
            The tuple contains (scheme, host, path, query_string and fragment),
            but the fragment is always empty because it is not visible to the
            server. """
        env = self.environ
        http = env.get('HTTP_X_FORWARDED_PROTO') or env.get('wsgi.url_scheme', 'http')
        host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST')
        if not host:
            # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients.
            host = env.get('SERVER_NAME', '127.0.0.1')
            port = env.get('SERVER_PORT')
            if port and port != ('80' if http == 'http' else '443'):
                host += ':' + port
        path = urlquote(self.fullpath)
        return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
项目:warriorframework    作者:warriorframework    | 项目源码 | 文件源码
def urlparts(self):
        """ The :attr:`url` string as an :class:`urlparse.SplitResult` tuple.
            The tuple contains (scheme, host, path, query_string and fragment),
            but the fragment is always empty because it is not visible to the
            server. """
        env = self.environ
        http = env.get('HTTP_X_FORWARDED_PROTO') \
             or env.get('wsgi.url_scheme', 'http')
        host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST')
        if not host:
            # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients.
            host = env.get('SERVER_NAME', '127.0.0.1')
            port = env.get('SERVER_PORT')
            if port and port != ('80' if http == 'http' else '443'):
                host += ':' + port
        path = urlquote(self.fullpath)
        return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
项目:aardvark    作者:Netflix-Skunkworks    | 项目源码 | 文件源码
def _get_creds(self):
        """
        Assumes into the target account and obtains Access Key, Secret Key, and Token

        :return: URL-encoded dictionary containing Access Key, Secret Key, and Token
        """
        client, credentials = boto3_cached_conn(
            'iam', account_number=self.account_number, assume_role=self.role_name, return_credentials=True)

        creds = json.dumps(dict(
            sessionId=credentials['AccessKeyId'],
            sessionKey=credentials['SecretAccessKey'],
            sessionToken=credentials['SessionToken']
        ))
        creds = urllib.quote(creds, safe='')
        return creds
项目:wikipedia_multilang    作者:ivanvladimir    | 项目源码 | 文件源码
def makeInternalLink(title, label):
    colon = title.find(':')
    if colon > 0 and title[:colon] not in options.acceptedNamespaces:
        return ''
    if colon == 0:
        # drop also :File:
        colon2 = title.find(':', colon + 1)
        if colon2 > 1 and title[colon + 1:colon2] not in options.acceptedNamespaces:
            return ''
    if options.keepLinks:
        return '<a href="%s">%s</a>' % (quote(title.encode('utf-8')), label)
    else:
        return label


# ----------------------------------------------------------------------
# External links

# from: https://doc.wikimedia.org/mediawiki-core/master/php/DefaultSettings_8php_source.html
项目:animeDown    作者:ekistece    | 项目源码 | 文件源码
def SearchEngine(search):
    searchUrl = 'https://www.underanime.net/?s='
    search = urllib.quote(search)
    page = GetUrl(searchUrl + search)
    animeLinks = page.xpath('//*/div/div/div/div[@class="base_inner h255 loading"]/a/@href')
    animeNames = page.xpath('//*/div/div/div/div[@class="base_inner h255 loading"]/a/@title')

    #check links, todo better
    linkNum = len(animeLinks)
    if linkNum != len(animeNames):
        print '[!] Error, some links missing!'
        return False

    #create anime list
    animeList = []

    for n in range(0, linkNum):
        anime = Anime(animeNames[n].encode(sys.stdout.encoding, errors='replace'), animeLinks[n], n)
        animeList.append(anime)
    return animeList
项目:base_function    作者:Rockyzsu    | 项目源码 | 文件源码
def query(kw):
    for i in range(1, 10):
        encode_kw = urllib.quote(kw)
        print i
        url = 'https://m.anjuke.com/ajax/autocomplete/?city_id=13&kw=%s&from=1&callback=jsonp%d' % (encode_kw, i)
        s = requests.Session()
        headers = {
            'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.221 Safari/537.36 SE 2.X MetaSr 1.0'}
        js = s.get(url, headers=headers)
        print js.status_code
        # print js.text
        try:
            result = re.findall('jsonp7\((.*?)\);', js.text)[0]
            dic = json.loads(result)
            print '*' * 20
            print dic['data']['match'][0]['comm_id']
        except Exception, e:
            print e


# ??????????
项目:Cortex-Analyzers    作者:CERT-BDF    | 项目源码 | 文件源码
def query_rrset(self, oname, rrtype=None, bailiwick=None, before=None, after=None):
        if bailiwick:
            if not rrtype:
                rrtype = 'ANY'
            path = 'rrset/name/%s/%s/%s' % (quote(oname), rrtype, quote(bailiwick))
        elif rrtype:
            path = 'rrset/name/%s/%s' % (quote(oname), rrtype)
        else:
            path = 'rrset/name/%s' % quote(oname)
        return self._query(path, before, after)
项目:Cortex-Analyzers    作者:CERT-BDF    | 项目源码 | 文件源码
def query_rdata_name(self, rdata_name, rrtype=None, before=None, after=None):
        if rrtype:
            path = 'rdata/name/%s/%s' % (quote(rdata_name), rrtype)
        else:
            path = 'rdata/name/%s' % quote(rdata_name)
        return self._query(path, before, after)
项目:Cortex-Analyzers    作者:CERT-BDF    | 项目源码 | 文件源码
def quote(path):
    return urllib.quote(path, safe='')
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def pathname2url(p):
    """OS-specific conversion from a file system path to a relative URL
    of the 'file' scheme; not recommended for general use."""
    # e.g.
    # C:\foo\bar\spam.foo
    # becomes
    # ///C|/foo/bar/spam.foo
    import urllib
    if not ':' in p:
        # No drive specifier, just convert slashes and quote the name
        if p[:2] == '\\\\':
        # path is something like \\host\path\on\remote\host
        # convert this to ////host/path/on/remote/host
        # (notice doubling of slashes at the start of the path)
            p = '\\\\' + p
        components = p.split('\\')
        return urllib.quote('/'.join(components))
    comp = p.split(':')
    if len(comp) != 2 or len(comp[0]) > 1:
        error = 'Bad path: ' + p
        raise IOError, error

    drive = urllib.quote(comp[0].upper())
    components = comp[1].split('\\')
    path = '///' + drive + ':'
    for comp in components:
        if comp:
            path = path + '/' + urllib.quote(comp)
    return path
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def __init__(self, path, allowance):
        if path == '' and not allowance:
            # an empty value means allow all
            allowance = True
        self.path = urllib.quote(path)
        self.allowance = allowance
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def encode_rfc2231(s, charset=None, language=None):
    """Encode string according to RFC 2231.

    If neither charset nor language is given, then s is returned as-is.  If
    charset is given but not language, the string is encoded using the empty
    string for language.
    """
    import urllib
    s = urllib.quote(s, safe='')
    if charset is None and language is None:
        return s
    if language is None:
        language = ''
    return "%s'%s'%s" % (charset, language, s)
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def request_uri(environ, include_query=1):
    """Return the full request URI, optionally including the query string"""
    url = application_uri(environ)
    from urllib import quote
    path_info = quote(environ.get('PATH_INFO',''),safe='/;=,')
    if not environ.get('SCRIPT_NAME'):
        url += path_info[1:]
    else:
        url += path_info
    if include_query and environ.get('QUERY_STRING'):
        url += '?' + environ['QUERY_STRING']
    return url
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def escape_path(path):
    """Escape any invalid characters in HTTP URL, and uppercase all escapes."""
    # There's no knowing what character encoding was used to create URLs
    # containing %-escapes, but since we have to pick one to escape invalid
    # path characters, we pick UTF-8, as recommended in the HTML 4.0
    # specification:
    # http://www.w3.org/TR/REC-html40/appendix/notes.html#h-B.2.1
    # And here, kind of: draft-fielding-uri-rfc2396bis-03
    # (And in draft IRI specification: draft-duerst-iri-05)
    # (And here, for new URI schemes: RFC 2718)
    if isinstance(path, unicode):
        path = path.encode("utf-8")
    path = urllib.quote(path, HTTP_PATH_SAFE)
    path = ESCAPED_CHAR_RE.sub(uppercase_escaped_char, path)
    return path
项目:kinect-2-libras    作者:inessadl    | 项目源码 | 文件源码
def _pncomp2url(component):
    component = urllib.quote(component[:31], safe='')  # We want to quote slashes
    return component
项目:cbapi-python    作者:carbonblack    | 项目源码 | 文件源码
def watchlist_modify(self, id, watchlist):
        """
        updates a watchlist
        """
        url = "%s/api/v1/watchlist/%s" % (self.server, id)
        watchlist['search_query'] = urllib.quote(watchlist['search_query'])
        # ensure that it starts with the proper url parameters
        if not watchlist['search_query'].startswith("cb.urlver=1&q="):
            watchlist['search_query'] = "cb.urlver=1&q=" + watchlist['search_query']
        r = self.cbapi_put(url, data=json.dumps(watchlist))
        r.raise_for_status()

        return r.json()
项目:LFISuite    作者:D35m0nd142    | 项目源码 | 文件源码
def send(self, *a, **kw):
        a[0].url = a[0].url.replace(urllib.quote("<"), "<")
        a[0].url = a[0].url.replace(urllib.quote(" "), " ")
        a[0].url = a[0].url.replace(urllib.quote(">"), ">")
        return requests.Session.send(self, *a, **kw)
项目:segno    作者:heuer    | 项目源码 | 文件源码
def make_make_email_data(to, cc=None, bcc=None, subject=None, body=None):
    """\
    Creates either a simple "mailto:" URL or complete e-mail message with
    (blind) carbon copies and a subject and a body.

    :param str|iterable to: The email address (recipient). Multiple
            values are allowed.
    :param str|iterable|None cc: The carbon copy recipient. Multiple
            values are allowed.
    :param str|iterable|None bcc: The blind carbon copy recipient.
            Multiple values are allowed.
    :param str|None subject: The subject.
    :param str|None body: The message body.
    """
    def multi(val):
        if not val:
            return ()
        if isinstance(val, str_type):
            return (val,)
        return tuple(val)

    delim = '?'
    data = ['mailto:']
    if not to:
        raise ValueError('"to" must not be empty or None')
    data.append(','.join(multi(to)))
    for key, val in (('cc', cc), ('bcc', bcc)):
        vals = multi(val)
        if vals:
            data.append('{0}{1}={2}'.format(delim, key, ','.join(vals)))
            delim = '&'
    for key, val in (('subject', subject), ('body', body)):
        if val is not None:
            data.append('{0}{1}={2}'.format(delim, key, quote(val.encode('utf-8'))))
        delim = '&'
    return ''.join(data)
项目:segno    作者:heuer    | 项目源码 | 文件源码
def as_svg_data_uri(matrix, version, scale=1, border=None, color='#000',
                    background=None, xmldecl=False, svgns=True, title=None,
                    desc=None, svgid=None, svgclass='segno',
                    lineclass='qrline', omitsize=False, unit='',
                    encoding='utf-8', svgversion=None, nl=False,
                    encode_minimal=False, omit_charset=False):
    """\
    Converts the matrix to a SVG data URI.

    The XML declaration is omitted by default (set ``xmldecl`` to ``True``
    to enable it), further the newline is omitted by default (set ``nl`` to
    ``True`` to enable it).

    Aside from the missing ``out`` parameter and the different ``xmldecl``
    and ``nl`` default values and the additional parameter ``encode_minimal``
    and ``omit_charset`` this function uses the same parameters as the
    usual SVG serializer.

    :param bool encode_minimal: Indicates if the resulting data URI should
                    use minimal percent encoding (disabled by default).
    :param bool omit_charset: Indicates if the ``;charset=...`` should be omitted
                    (disabled by default)
    :rtype: str
    """
    encode = partial(quote, safe=b"") if not encode_minimal else partial(quote, safe=b" :/='")
    buff = io.BytesIO()
    write_svg(matrix, version, buff, scale=scale, color=color, background=background,
              border=border, xmldecl=xmldecl, svgns=svgns, title=title,
              desc=desc, svgclass=svgclass, lineclass=lineclass,
              omitsize=omitsize, encoding=encoding, svgid=svgid, unit=unit,
              svgversion=svgversion, nl=nl)
    return 'data:image/svg+xml{0},{1}' \
                .format(';charset=' + encoding if not omit_charset else '',
                        # Replace " quotes with ' and URL encode the result
                        # See also https://codepen.io/tigt/post/optimizing-svgs-in-data-uris
                        encode(_replace_quotes(buff.getvalue())))
项目:plugin.video.exodus    作者:lastship    | 项目源码 | 文件源码
def __handle_escape(self, key):
        while True:
            start_js = self.js
            offset = self.js.find(key) + len(key)
            if self.js[offset] == '(' and self.js[offset + 2] == ')':
                c = self.js[offset + 1]
                self.js = self.js.replace('%s(%s)' % (key, c), urllib.quote(c))

            if start_js == self.js:
                break