示例#1
0
    def parse(url):

        for k, v in parse_qsl(url.split("?")[1]):
            if k == "max_results":
                max_result = int(v)

        result = Result()
        result['entries'] = [
            get_random_arxiv_entry() for _ in range(max_result)]
        return result
示例#2
0
def seeker_filter_querystring(qs, keep):
    if isinstance(keep, basestring):
        keep = [keep]


#    qs_parts = [part for part in parse_qsl(qs, keep_blank_values=True) if part[0] in keep]
    qs_parts = [
        part for part in urllib.parse_qsl(qs, keep_blank_values=True)
        if part[0] in keep
    ]
    return urllib.urlencode(qs_parts)
示例#3
0
def format_querystring_params(querystring, params={}, **kwparams):
    if isinstance(querystring, str):
        querystring = urllib.parse_qsl(querystring)

    context = {**get_formatdata(params), **kwparams}
    parts = {}
    for k, v in querystring:
        value = format_safe(v, context)
        if value:
            parts[k] = value

    return urllib.urlencode(parts)
示例#4
0
def _parse_rfc1738_args(connection_url):
    pattern = re.compile(
        r'''(?P<name>[\w\+]+)://
            (?:
                (?P<username>[^:/]*)
                (?::(?P<password>[^/]*))?
            @)?
            (?:
                (?P<host>[^/:]*)
                (?::(?P<port>[^/]*))?
            )?
            (?:/(?P<database>.*))?
            ''', re.X)

    m = pattern.match(connection_url)
    if m is not None:
        components = m.groupdict()
        if components['database'] is not None:
            tokens = components['database'].split('?', 2)
            components['database'] = tokens[0]
            query = (len(tokens) > 1
                     and dict(urllib.parse_qsl(tokens[1]))) or None
            # Py2K
            if query is not None:
                query = dict((k.encode('ascii'), query[k]) for k in query)
            # end Py2K
        else:
            query = None
        components['query'] = query

        if components['password'] is not None:
            components['password'] = urllib.parse.unquote_plus(
                components['password'])

        return components.pop('name'), components
    else:
        raise Exception("Could not parse rfc1738 URL from string '%s'" %
                        connection_url)
示例#5
0
def oauth_requests():
    # Get request token
    auth = OAuth1(API_KEY, SECRET_KEY, callback_uri=callback_uri)
    r = requests.post(request_url, auth=auth)
    request_token = dict(urllib.parse.parse_qsl(r.text))

    print(request_token)

    # Getting the User Authorization
    webbrowser.open('%s?oauth_token=%s&perms=delete' %
                    (authorize_url, request_token['oauth_token'])
                    )  # ブラウザを開きOAuth認証確認画面を表示 ユーザーが許可するとPINコードが表示される

    oauth_verifier = input("Please input PIN code:")  # 上記PINコードを入力する
    auth = OAuth1(API_KEY,
                  SECRET_KEY,
                  request_token['oauth_token'],
                  request_token['oauth_token_secret'],
                  verifier=oauth_verifier)
    r = requests.post(access_token_url, auth=auth)

    access_token = dict(urllib.parse_qsl(r.text))
    return access_token
示例#6
0
    def __call__(self):
        self.request.response.setHeader('X-Theme-Applied', 'true')
        layout = self.request.get('layout')
        transform = theming.getTransform(self.context, self.request)

        layout = transform.get_layout(self.context,
                                      layout,
                                      request=self.request)
        portal = api.portal.get()
        portal_url = portal.absolute_url()
        context_url = self.context.absolute_url()

        theme_base_url = '%s/++%s++%s/index.html' % (
            portal_url, THEME_RESOURCE_NAME, transform.name)

        content = {'main': '<p>Content from page</p>', 'left': '', 'right': ''}

        utils = getMultiAdapter((self.context, self.request),
                                name='castle-utils')

        layout = layout(portal_url=portal_url,
                        site_url=portal_url,
                        context_url=context_url,
                        request=self.request,
                        context=self.context,
                        portal=portal,
                        site=portal,
                        theme_base_url=theme_base_url,
                        content=content,
                        anonymous=api.user.is_anonymous(),
                        debug=api.env.debug_mode(),
                        utils=utils,
                        raw=True)

        dom = getHTMLSerializer([layout])
        transform.rewrite(dom, theme_base_url)

        root = dom.tree.getroot()
        for tile in root.cssselect('[data-tile*="@@castle.cms.meta/"]'):
            slot_id = tile.attrib['data-tile'].split('/@@castle.cms.meta/')[-1]

            title = None
            if '?' in slot_id:
                slot_id, _, qs = slot_id.partition('?')
                query = dict(urllib.parse_qsl(qs))
                title = query.get('title')
            else:
                title = slot_id.replace('meta-',
                                        '').capitalize().replace('-', ' ')
            tile.attrib['data-tile-id'] = slot_id
            tile.attrib['data-tile-title'] = title
            tile.attrib['class'] = 'castle-tile-container'
            tile.text = 'Edit %s slot' % title

        overlay = etree.Element('div')
        overlay.attrib['class'] = 'expose-overlay'
        root.cssselect('body')[0].append(overlay)

        javascript = etree.Element('script')
        javascript.text = self.javascript
        root.cssselect('body')[0].append(javascript)

        style = etree.Element('style')
        style.text = self.styles
        root.cssselect('body')[0].append(style)

        transform.dynamic_grid(dom.tree)
        return tostring(dom.tree)