• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python parse.urlunsplit函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: extract_password_row

 def extract_password_row(self, row):
     res = ''
     hostname_split = urlparse.urlsplit(row[0])
     website = urlparse.urlunsplit((hostname_split.scheme, hostname_split.netloc, "", "", "")).strip('\n')
     username = ''
     password = ''
     form_url = ''
     user_field = ''
     pass_field = ''
     form_url_split = urlparse.urlsplit(row[1])
     form_url = urlparse.urlunsplit((form_url_split.scheme, form_url_split.netloc, "", "", "")).strip('\n')
     #print('\nusername = ', row[3], ' password RAW = ', row[5])
     password = self.decode_password(row[5])
     try:
         username = row[3]
         try:
             password = self.decode_password(row[5])
             self.num_passwords += 1
             pass
         except:
             print('ERROR - password = ', row[5])
         
         user_field = row[2]
         pass_field = row[4]
     except:
         print('non password entry (blacklists - ignoring)')
     res = self.format_list_csv([website, username, form_url, user_field, pass_field, password])
     return res
开发者ID:gitter-badger,项目名称:AIKIF,代码行数:28,代码来源:agent_browser.py


示例2: zoom_article

 def zoom_article(self, ticket_id, article_id):
     art_descr = self.__db.article_description(article_id)
     if art_descr[4] & ART_TEXT:
         return eval(self.__db.article_message(article_id))
     self.echo("Zoom article:", ticket_id, article_id)
     url_beg = urlsplit(self.runtime.get("site"))[:3]
     params = (
         ("Action", "AgentTicketZoom"), ("Subaction", "ArticleUpdate"),
         ("TicketID", ticket_id), ("ArticleID", article_id),
         ("OTRSAgentInterface", self.runtime["OTRSAgentInterface"]))
     url = urlunsplit(url_beg + (urlencode(params), ""))
     pg = TicketsPage(self.core)
     page = pg.load(url)
     if page is None:
         return
     mail_header = page.get("mail_header", [])
     if "mail_src" in page:
         url = urlunsplit(url_beg[:2] + urlsplit(page["mail_src"])[2:])
         self.echo("Get message:", url)
         pg = MessagePage(self.core)
         try:
             mail_text = pg.load(url)
         except LoginError:
             mail_text = pg.login()
     else:
         mail_text = page["message_text"]
     if mail_header:
         mail_text.insert(0, ("\n",))
     for i in reversed(mail_header):
         mail_text.insert(0, ("%s\t%s\n" % i,))
     shrink_tupled_text(mail_text)
     self.__db.article_message(article_id, repr(mail_text))
     return mail_text
开发者ID:Lysovenko,项目名称:OTRS_US,代码行数:33,代码来源:msg_ldr.py


示例3: encode

    def encode(self, path, parameters=None):
        '''
        @see: EncoderPath.encode
        '''
        assert isinstance(path, (Path, str)), 'Invalid path %s' % path
        if isinstance(path, Path):
            assert isinstance(path, Path)

            url = deque()
            url.append(self.root)
            url.append('/'.join(path.toPaths(self.converterPath)))
            if self.extension:
                url.append('.')
                url.append(self.extension)
            elif path.node.isGroup:
                url.append('/')

            query = urlencode(parameters) if parameters else ''
            return urlunsplit((self.scheme, self.host, ''.join(url), query, ''))
        else:
            assert isinstance(path, str), 'Invalid path %s' % path
            if not path.strip().startswith('/'):
                # TODO: improve the relative path detection
                # This is an absolute path so we will return it as it is.
                return path
            # The path is relative to this server so we will convert it in an absolute path
            url = urlsplit(path)
            return urlunsplit((self.scheme, self.host, url.path, url.query, url.fragment))
开发者ID:adityaathalye,项目名称:Ally-Py,代码行数:28,代码来源:uri.py


示例4: to_python

    def to_python(self, value):

        def split_url(url):
            """
            Return a list of url parts via urlparse.urlsplit(), or raise
            ValidationError for some malformed URLs.
            """
            try:
                return list(urlsplit(url))
            except ValueError:
                # urlparse.urlsplit can raise a ValueError with some
                # misformatted URLs.
                raise ValidationError(self.error_messages['invalid'], code='invalid')

        value = super().to_python(value)
        if value:
            url_fields = split_url(value)
            if not url_fields[0]:
                # If no URL scheme given, assume http://
                url_fields[0] = 'http'
            if not url_fields[1]:
                # Assume that if no domain is provided, that the path segment
                # contains the domain.
                url_fields[1] = url_fields[2]
                url_fields[2] = ''
                # Rebuild the url_fields list, since the domain segment may now
                # contain the path too.
                url_fields = split_url(urlunsplit(url_fields))
            value = urlunsplit(url_fields)
        return value
开发者ID:Damgaard,项目名称:django,代码行数:30,代码来源:fields.py


示例5: oauth

 def oauth(self, req, credentials = None, params = {}):
     #NOTE: While flickr supports HTTPS in its oauth endpoints, flickr
     #thinks that the HTTPS endpoints are being accessed via HTTP, and thus
     #constructs the signature base string accordingly, which
     #will hence not match the signature base string generated by
     #pyoauth1client. We solve this by replacing HTTPS with HTTP
     #when generating the signature base string, and then revert the change
     #after the base string is generated. This way the signature
     #base string will match the one generated by flickr even though
     #we are accessing the endpoints via HTTPS for ADDED SECURITY!!!111one
     x = urlsplit(req.url)
     if x.scheme == "https":
         #Remove the HTTPS Scheme
         https = True
         x = x._replace(scheme = "http")
         req = req._replace(url = urlunsplit(x))
     else:
         https = False
     y = super().oauth(req, credentials, params)
     if https:
         #Add back the HTTPS scheme
         x = urlsplit(y.url)
         x = x._replace(scheme = "https")
         y = y._replace(url = urlunsplit(x))
     return y
开发者ID:pyokagan,项目名称:pyoauth1client,代码行数:25,代码来源:__init__.py


示例6: clean_url

def clean_url(value):
    """
    Taken from Django' URLField, this helps to normalize URLs. Raises a
    ValueError if an invalid url is passed.

    Example:

    >>> clean_url("www.google.com")
    "http://www.google.com"

    >>> clean_url("_.com")
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    ValueError: Enter a valid URL.
    """
    if value:
        value = value.strip()
        value = value.encode('ascii', 'ignore').decode("utf-8")
        url_fields = list(urlsplit((value)))
        if not url_fields[0]:
            # If no URL scheme given, assume http://
            url_fields[0] = 'http'
        if not url_fields[1]:
            # Assume that if no domain is provided, that the path segment
            # contains the domain.
            url_fields[1] = url_fields[2]
            url_fields[2] = ''
            # Rebuild the url_fields list, since the domain segment may now
            # contain the path too.
            url_fields = list(urlsplit((urlunsplit(url_fields))))
        if not url_fields[2]:
            # the path portion may need to be added before query params
            url_fields[2] = '/'
        value = urlunsplit(url_fields)
    return value
开发者ID:TrackMaven,项目名称:trackmaven-common,代码行数:35,代码来源:urls.py


示例7: encode

    def encode(self, path, parameters=None):
        """
        @see: EncoderPath.encode
        """
        assert isinstance(path, (Path, str)), "Invalid path %s" % path
        if isinstance(path, Path):
            assert isinstance(path, Path)

            url = deque()
            url.append(self.root)
            url.append("/".join(path.toPaths(self.converterPath)))
            if self.extension:
                url.append(".")
                url.append(self.extension)
            elif path.node.isGroup:
                url.append("/")

            query = urlencode(parameters) if parameters else ""
            return urlunsplit((self.scheme, self.host, quote("".join(url)), query, ""))
        else:
            assert isinstance(path, str), "Invalid path %s" % path
            if not path.strip().startswith("/"):
                # TODO: improve the relative path detection
                # This is an absolute path so we will return it as it is.
                return quote(path)
            # The path is relative to this server so we will convert it in an absolute path
            url = urlsplit(path)
            return urlunsplit((self.scheme, self.host, quote(url.path), url.query, url.fragment))
开发者ID:petrjasek,项目名称:Ally-Py,代码行数:28,代码来源:uri.py


示例8: authorizeApplication

    def authorizeApplication(app_id, username, password):
        '''Authorize an application to access a systems data
            and get the user_id'''

        scheme = 'https'
        base_url = 'enlighten.enphaseenergy.com'
        action = 'app_user_auth/new'
        query = p.urlencode({'app_id':app_id})

        request1 = p.urlunsplit((scheme,base_url,action,query,''))
        logging.debug(request1)

        opener = r.build_opener(r.HTTPCookieProcessor())
        opener.addheaders = [('User-agent','Mozilla/5.0')]
        r1 = opener.open(request1)

        action,hiddens = EnphaseInterface._processPage(r1)

        payload = {'user[email]':username,'user[password]':password}
        hiddens.update(payload)

        request2 = p.urlunsplit((scheme,base_url,action,query,''))
        r2 = opener.open(request2,p.urlencode(hiddens).encode(encoding='UTF-8'))
        action, hiddens = EnphaseInterface._processPage(r2)

        request3 = p.urlunsplit((scheme,base_url,action,query,''))
        r3 = opener.open(request3,p.urlencode(hiddens).encode(encoding='UTF-8'))

        if 'enlighten-api-user-id' not in r3.info():
            logging.critical('Failed to aquire user_id')

        logging.debug(r3.info()['enlighten-api-user-id'])
        return r3.info()['enlighten-api-user-id']
开发者ID:e2thenegpii,项目名称:EnphaseInterface,代码行数:33,代码来源:EnphaseInterface.py


示例9: to_python

    def to_python(self, value):

        def split_url(url):
            """
            Returns a list of url parts via ``urlparse.urlsplit`` (or raises a
            ``ValidationError`` exception for certain).
            """
            try:
                return list(urlsplit(url))
            except ValueError:
                # urlparse.urlsplit can raise a ValueError with some
                # misformatted URLs.
                raise ValidationError(self.error_messages['invalid'])

        value = super(URLField, self).to_python(value)
        if value:
            url_fields = split_url(value)
            if not url_fields[0]:
                # If no URL scheme given, assume http://
                url_fields[0] = 'http'
            if not url_fields[1]:
                # Assume that if no domain is provided, that the path segment
                # contains the domain.
                url_fields[1] = url_fields[2]
                url_fields[2] = ''
                # Rebuild the url_fields list, since the domain segment may now
                # contain the path too.
                url_fields = split_url(urlunsplit(url_fields))
            if not url_fields[2]:
                # the path portion may need to be added before query params
                url_fields[2] = '/'
            value = urlunsplit(url_fields)
        return value
开发者ID:klinskih,项目名称:django,代码行数:33,代码来源:fields.py


示例10: items

def items(id:int=None) -> str:
    valid_params = {'1': True, '0': False}
    starred = valid_params.get(request.query.getone('starred'))
    read = valid_params.get(request.query.getone('read'))

    channel_ids = [int(i) for i in request.query.getlist('channel')]
    channel_ids += [id] if id is not None else []
    since_id = request.query.since_id
    max_id = request.query.max_id
    count = int(request.query.count) if request.query.count else 25
    page = int(request.query.page) if request.query.page else 1
    search = request.query.q
    
    query = Item.select()
    #for channel_id in channel_ids:

    if channel_ids:
        query = query.where(Item.channel << channel_ids)
    if starred:
        query = query.where(Item.starred == starred)
    if read:
        query = query.where(Item.read == read)
    if since_id:
        query = query.where(Item.id >= since_id)
    if max_id:
        query = query.where(Item.id <= max_id)
    if search:
        search = '%' + search + '%'
        query = query.where(Item.title ** search | Item.description ** search | Item.author ** search)

    #total_count = query.count()
    if page and count: query = query.paginate(page, count)

    for it in query:
        it.new = False
        it.save()
    
    out = {'items': list(query.order_by(Item.updated.desc()).limit(count))}

    channels = Channel.select().order_by(Channel.title)
    for c in channels:
        c.filter = True if c.id in channel_ids else False

    #if channel:
        #Item.update(new=False).where(Item.channel == channel).execute()

    params = {}
    for p in request.query.keys():
        params[p] = request.query.getall(p)

    params['page'] = page + 1
    out['next'] = urlunsplit(('', '', request.fullpath, urlencode(params, doseq=True), ''))
    params['page'] = page - 1 if page > 1 else 1
    out['prev'] = urlunsplit(('', '', request.fullpath, urlencode(params, doseq=True), '')) if page > 1 else None

    if request_accept_json():
        return out
    else:
        return template('index', out, is_active=is_active, favicon=favicon, date_format=date_format, channels=channels)
开发者ID:morganbengtsson,项目名称:microreader,代码行数:59,代码来源:microreader.py


示例11: assert_redirects_to

    def assert_redirects_to(self, response, url_name, status_code=302,
                            target_status_code=200, host=None, msg_prefix='', *args, **kwargs):
        '''
        Assert that the response is a redirect to a resolved url and that the URL can be loaded.

        It differs from Django TestCase.assertRedirects on the following points:

        - Takes a resolable url name as parameter
        - Query params are not taken in account for URL comparison, only for status code retrieval.
        '''
        if msg_prefix:
            msg_prefix += ": "

        if hasattr(response, 'redirect_chain'):
            # The request was a followed redirect
            self.assertTrue(len(response.redirect_chain) > 0,
                msg_prefix + "Response didn't redirect as expected: Response"
                " code was %d (expected %d)" %
                    (response.status_code, status_code))

            self.assertEqual(response.redirect_chain[0][1], status_code,
                msg_prefix + "Initial response didn't redirect as expected:"
                " Response code was %d (expected %d)" %
                    (response.redirect_chain[0][1], status_code))

            url, status_code = response.redirect_chain[-1]

            self.assertEqual(response.status_code, target_status_code,
                msg_prefix + "Response didn't redirect as expected: Final"
                " Response code was %d (expected %d)" %
                    (response.status_code, target_status_code))

        else:
            # Not a followed redirect
            self.assertEqual(response.status_code, status_code,
                msg_prefix + "Response didn't redirect as expected: Response"
                " code was %d (expected %d)" %
                    (response.status_code, status_code))

            url = response['Location']
            scheme, netloc, path, query, fragment = urlsplit(url)
            url = urlunsplit((scheme, netloc, path, None, None))

            redirect_response = response.client.get(path, QueryDict(query))

            # Get the redirection page, using the same client that was used
            # to obtain the original response.
            self.assertEqual(redirect_response.status_code, target_status_code,
                msg_prefix + "Couldn't retrieve redirection page '%s':"
                " response code was %d (expected %d)" %
                    (path, redirect_response.status_code, target_status_code))

        path = reverse(url_name, *args, **kwargs)
        expected_url = urlunsplit(('http', host or 'testserver', path, None, None))

        self.assertEqual(url, expected_url,
            msg_prefix + "Response redirected to '%s', expected '%s'" %
                (url, expected_url))
开发者ID:etalab,项目名称:youckan,代码行数:58,代码来源:utils.py


示例12: compute_url_from_payload

    def compute_url_from_payload(self, data_item):
        url = data_item[DomFuzzerQueueTable.URL]
        target = data_item[DomFuzzerQueueTable.TARGET]
        param = data_item[DomFuzzerQueueTable.PARAM]
        test = data_item[DomFuzzerQueueTable.TEST]

        if 'url' == target:
            if not param:
                return url + test
            else:
                # TODO: fix me
                return url + test + '=X'

        splitted = urlparse.urlsplit(url)
        if 'fragment' == target:
            url_field = splitted.fragment
        elif 'query' == target:
            url_field = splitted.query
        else:
            raise Exception('unsupported target: %s' % (target))

        if not url_field:
            raise Exception('missing URL field in url: %s' % (url))
        else:
            # TODO: this duplicates previous work, so could consider pre-storing target urls?
            url_io = StringIO()
            pairs = self.re_delim.split(url_field)
            found = False
            for offset in range(0, len(pairs)):
                values = pairs[offset]
                if values == ';' or values == '&':
                    url_io.write(values)
                    continue
                if '=' in values:
                    name, value = values.split('=', 1)
                    separator = '='
                else:
                    name, value = values, ''
                    separator = ''

                if name == param:
                    value += test
                    found = True

                url_io.write(name)
                url_io.write(separator)
                url_io.write(value)

            if not found:
                url_io.write(test)
                
        if 'fragment' == target:
            target_url = urlparse.urlunsplit((splitted.scheme, splitted.netloc, splitted.path, splitted.query, url_io.getvalue()))
        elif 'query' == target:
            target_url = urlparse.urlunsplit((splitted.scheme, splitted.netloc, splitted.path, url_io.getvalue(), splitted.fragment))

        return target_url
开发者ID:Averroes,项目名称:raft,代码行数:57,代码来源:DomFuzzerThread.py


示例13: doEncodePath

     def doEncodePath(path):
         '''
         Do encode the path.
         '''
         assert isinstance(path, str), 'Invalid path %s' % path
         url = urlsplit(path)
 
         if url.scheme or url.netloc: return urlunsplit((url.scheme, url.netloc, url.path, url.query, url.fragment))
         # Is a relative URI so we append the scheme and host.
         return urlunsplit((scheme, host, url.path, url.query, url.fragment))
开发者ID:cristidomsa,项目名称:Ally-Py,代码行数:10,代码来源:path_encoder.py


示例14: children

 def children(root, soup):
     """ Return a set of child URLs within a HTML soup,
         relative to the given root """
     # Establish the root URL base parameters
     root_s = urlparse.urlsplit(root.url)
     root_url = urlparse.urlunsplit(root_s)
     root_url_slash = urlparse.urlunsplit(
         (root_s.scheme, root_s.netloc, "/", root_s.query, "")
     )
     # Collect all interesting <a> tags from the soup and obtain their href-s:
     fetch = set()
     for link in soup.find_all("a"):
         href = link.get("href")
         if not href:
             continue
         # Split the href into its components
         s = urlparse.urlsplit(href)
         if s.scheme and s.scheme not in {"http", "https"}:
             # Not HTTP
             continue
         if s.netloc and not (
             s.netloc == root.domain or s.netloc.endswith("." + root.domain)
         ):
             # External domain - we're not interested
             continue
         # Seems to be a bug in urllib: fragments are put into the
         # path if there is no canonical path
         newpath = s.path
         if newpath.startswith("#") or newpath.startswith("/#"):
             newpath = ""
         if not newpath and not s.query:
             # No meaningful path info present
             continue
         # Make sure the newpath is properly urlencoded
         if newpath:
             newpath = urlparse.quote(newpath)
         # Fill in missing stuff from the root URL base parameters
         newurl = (
             s.scheme or root_s.scheme,
             s.netloc or root_s.netloc,
             newpath,
             s.query,
             ""
         )
         # Make a complete new URL to fetch
         url = urlparse.urlunsplit(newurl)
         if url in {root_url, root_url_slash}:
             # Exclude the root URL
             continue
         # Looks legit: add to the fetch set
         fetch.add(url)
     return fetch
开发者ID:vthorsteinsson,项目名称:Reynir,代码行数:52,代码来源:fetcher.py


示例15: webfuzzer_populate_response_id

    def webfuzzer_populate_response_id(self, Id):

        self.clear_data_dictionary()
        
        row = self.Data.read_responses_by_id(self.cursor, Id)
        if not row:
            return

        responseItems = interface.data_row_to_response_items(row)

        url = responseItems[ResponsesTable.URL]
        reqHeaders = responseItems[ResponsesTable.REQ_HEADERS].decode('utf-8', 'ignore')
        reqData = responseItems[ResponsesTable.REQ_DATA].decode('utf-8', 'ignore')
        method = responseItems[ResponsesTable.REQ_METHOD]
        splitted = urlparse.urlsplit(url)
        
        # Create a new parsed object removing the scheme and netloc
        base_url = urlparse.urlunsplit((splitted[0], splitted[1], splitted[2], '', ''))
        req_loc = ("", "", "", splitted.query, splitted.fragment)

        useragent = self.framework.useragent()
        has_cookie = False
        template = StringIO()
        template.write('${method} ${request_uri}%s HTTP/1.1\n' % urlparse.urlunsplit(req_loc))
        first = True
        for line in reqHeaders.splitlines():
            if not line:
                break
            if first and self.re_request.match(line):
                first = False
                continue
            if ':' in line:
                name, value = [v.strip() for v in line.split(':', 1)]
                lname = name.lower()
                if 'host' == lname:
                    if splitted.hostname and value == splitted.hostname:
                        template.write('Host: ${host}\n')
                        continue
                elif 'user-agent' == lname:
                    if useragent == value:
                        template.write('User-Agent: ${user_agent}\n')
                        continue
            template.write(line)
            template.write('\n')
        template.write('\n')
        template.write(reqData)

        self.set_combo_box_text(self.mainWindow.stdFuzzerReqMethod, method.upper())
        self.mainWindow.wfStdUrlEdit.setText(base_url)
        self.mainWindow.wfStdEdit.setPlainText(template.getvalue())
开发者ID:Averroes,项目名称:raft,代码行数:50,代码来源:WebFuzzerTab.py


示例16: do_populateExistingFuzzData

    def do_populateExistingFuzzData(self):
        self.qlock.lock()
        try:
            rows = []
            dup_rows = []
            already_seen = {}
            for row in self.Data.get_dom_fuzzer_queue_items(self.read_cursor, 'P'):
                data_item = [m or '' for m in row]
                # check for duplicates and prioritize uniques first
                url = data_item[DomFuzzerQueueTable.URL]
                target = data_item[DomFuzzerQueueTable.TARGET]
                param = data_item[DomFuzzerQueueTable.PARAM]
                test = data_item[DomFuzzerQueueTable.TEST]

                # TODO: remove this
#                 if 'fragment' == target or '#' == url[-1]:
#                     dup_rows.append(data_item)
#                     continue

                splitted = urlparse.urlsplit(url)
                if 'url' == target:
                    dupcheck = urlparse.urlunsplit((splitted.scheme, splitted.netloc, splitted.path, '', ''))
                else:
                    qs_values = None
                    if 'query' == target and splitted.query:
                        qs_values = urlparse.parse_qs(splitted.query, True)
                        dupcheck = urlparse.urlunsplit((splitted.scheme, splitted.netloc, splitted.path, '&'.join(list(qs_values.keys())), splitted.fragment))
                    elif 'fragment' == target and splitted.fragment:
                        qs_values = urlparse.parse_qs(splitted.fragment, True)
                        dupcheck = urlparse.urlunsplit((splitted.scheme, splitted.netloc, splitted.path, splitted.query, '&'.join(list(qs_values.keys()))))
                    else:
                        dupcheck = url

                dupcheck = '%s||%s||%s' % (dupcheck, param, test)

                if dupcheck not in already_seen:
                    rows.append(data_item)
                    already_seen[dupcheck] = True
                else:
                    dup_rows.append(data_item)

            self.queueDataModel.append_data(rows)
            self.queueDataModel.append_data(dup_rows)
            rows = []
            for row in self.Data.read_dom_fuzzer_results_info(self.read_cursor):
                rows.append([m or '' for m in row])
            self.resultsDataModel.append_data(rows)
        finally:
            self.qlock.unlock()
开发者ID:Averroes,项目名称:raft,代码行数:49,代码来源:DomFuzzerThread.py


示例17: set_url_cred

def set_url_cred(url, username=None, password=None,
        _protocols=('http', 'https')):
    urlparts = list(urlsplit(url))
    if urlparts[0] not in _protocols:
        return url

    if '@' in urlparts[1]:
        urlparts[1] = urlparts[1].split('@')[-1]

    if username is None or password is None:
        return urlunsplit(urlparts)

    urlparts[1] = '%s:%[email protected]%s' % (username, password, urlparts[1])

    return urlunsplit(urlparts)
开发者ID:PMR2,项目名称:pmr2.wfctrl,代码行数:15,代码来源:utils.py


示例18: update_querystring

def update_querystring(url, querystringargs, ignore_none_values=True):
    """
    Update the querystring portion of the given ``url``.

    Parameters:
        querystringargs (dict): The querystring args to add/replace.
        ignore_none_values (bool): If this is ``True`` (default),
            we ignore ``None`` values in ``querystringargs``.

    Returns:
        The updated url.

    Examples:

        Add querystring argument::

            from django_cradmin import urlutils
            urlutils.update_querystring('http://example.com', {'search': 'test'})

        Update querystring argument::

            urlutils.update_querystring('http://example.com?search=something&page=2',
                {'search': 'updated'})
    """
    parsed_url = urlsplit(url)
    querydict = create_querydict(querystringargs=querystringargs,
                                 initial_query_string=parsed_url.query,
                                 ignore_none_values=ignore_none_values)
    return urlunsplit((
        parsed_url.scheme,
        parsed_url.netloc,
        parsed_url.path,
        querydict.urlencode(),
        parsed_url.fragment
    ))
开发者ID:appressoas,项目名称:django_cradmin,代码行数:35,代码来源:urlutils.py


示例19: hashed_name

 def hashed_name(self, name, content=None):
     parsed_name = urlsplit(unquote(name))
     clean_name = parsed_name.path.strip()
     opened = False
     if content is None:
         if not self.exists(clean_name):
             raise ValueError("The file '%s' could not be found with %r." %
                              (clean_name, self))
         try:
             content = self.open(clean_name)
         except IOError:
             # Handle directory paths and fragments
             return name
         opened = True
     try:
         file_hash = self.file_hash(clean_name, content)
     finally:
         if opened:
             content.close()
     path, filename = os.path.split(clean_name)
     root, ext = os.path.splitext(filename)
     if file_hash is not None:
         file_hash = ".%s" % file_hash
     hashed_name = os.path.join(path, "%s%s%s" %
                                (root, file_hash, ext))
     unparsed_name = list(parsed_name)
     unparsed_name[2] = hashed_name
     # Special casing for a @font-face hack, like url(myfont.eot?#iefix")
     # http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
     if '?#' in name and not unparsed_name[3]:
         unparsed_name[2] += '?'
     return urlunsplit(unparsed_name)
开发者ID:nai-central,项目名称:django-mediafiles,代码行数:32,代码来源:storage.py


示例20: smart_urlquote

def smart_urlquote(url):
    "Quotes a URL if it isn't already quoted."
    def unquote_quote(segment):
        segment = unquote(segment)
        # Tilde is part of RFC3986 Unreserved Characters
        # http://tools.ietf.org/html/rfc3986#section-2.3
        # See also http://bugs.python.org/issue16285
        segment = quote(segment, safe=RFC3986_SUBDELIMS + RFC3986_GENDELIMS + str('~'))
        return force_text(segment)

    # Handle IDN before quoting.
    try:
        scheme, netloc, path, query, fragment = urlsplit(url)
    except ValueError:
        # invalid IPv6 URL (normally square brackets in hostname part).
        return unquote_quote(url)

    try:
        netloc = netloc.encode('idna').decode('ascii')  # IDN -> ACE
    except UnicodeError:  # invalid domain part
        return unquote_quote(url)

    if query:
        # Separately unquoting key/value, so as to not mix querystring separators
        # included in query values. See #22267.
        query_parts = [(unquote(q[0]), unquote(q[1]))
                       for q in parse_qsl(query, keep_blank_values=True)]
        # urlencode will take care of quoting
        query = urlencode(query_parts)

    path = unquote_quote(path)
    fragment = unquote_quote(fragment)

    return urlunsplit((scheme, netloc, path, query, fragment))
开发者ID:zalmoxis,项目名称:django,代码行数:34,代码来源:html.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python request.add_header函数代码示例发布时间:2022-05-27
下一篇:
Python parse.urlunparse函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap