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


Python request.url方法代码示例

本文整理汇总了Python中urllib.request.url方法的典型用法代码示例。如果您正苦于以下问题:Python request.url方法的具体用法?Python request.url怎么用?Python request.url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urllib.request的用法示例。


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

示例1: request_to_dict

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def request_to_dict(self, request):
        '''
        Convert Request object to a dict.
        modified from scrapy.utils.reqser
        '''
        req_dict = {
            # urls should be safe (safe_string_url)
            'url': to_unicode(request.url),
            'method': request.method,
            'headers': dict(request.headers),
            'body': request.body,
            'cookies': request.cookies,
            'meta': request.meta,
            '_encoding': request._encoding,
            'priority': request.priority,
            'dont_filter': request.dont_filter,
             #  callback/errback are assumed to be a bound instance of the spider
            'callback': None if request.callback is None else request.callback.__name__,
            'errback': None if request.errback is None else request.errback.__name__,
        }
        return req_dict 
开发者ID:istresearch,项目名称:scrapy-cluster,代码行数:23,代码来源:distributed_scheduler.py

示例2: retrieveAlertsCyber

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveAlertsCyber():
    """ Retrieve Alerts from ElasticSearch and return formatted 
        XML with limited alert content
    """

    # get result from cache
    getCacheResult = getCache(request.url, "url")
    if getCacheResult is not False:
        app.logger.debug('Returning /retrieveAlertsCyber from Cache for %s' % str(request.remote_addr))
        return Response(getCacheResult)

    # query ES
    else:
        returnResult = formatAlertsXml(queryAlerts(app.config['MAXALERTS'], checkCommunityIndex(request), getRelevantIndices(2)))
        setCache(request.url, returnResult, 1, "url")
        app.logger.debug('Returning /retrieveAlertsCyber from ES for %s' % str(request.remote_addr))
        return Response(returnResult, mimetype='text/xml') 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:19,代码来源:peba.py

示例3: querySingleIP

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def querySingleIP():
    """ Retrieve Attack data from index about a single IP
    """

    # get result from cache
    getCacheResult = getCache(request.url, "url")
    if getCacheResult is not False:
        app.logger.debug('Returning /querySingleIP from Cache for %s' % str(request.remote_addr))
        return Response(getCacheResult)

    # query ES
    else:
        returnResult = formatSingleIP(queryForSingleIP(app.config['MAXALERTS'], request.args.get('ip'), checkCommunityIndex(request), getRelevantIndices(0)))
        setCache(request.url, returnResult, 60, "url")
        app.logger.debug('Returning /querySingleIP from ES for %s' % str(request.remote_addr))
        return Response(returnResult, mimetype='text/xml')

# Routes with both XML and JSON output 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:20,代码来源:peba.py

示例4: retrieveIPs

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveIPs():
    """ Retrieve IPs from ElasticSearch and return formatted XML or JSON with IPs """

    if request.args.get('out') and request.args.get('out') == 'json':
        getCacheResult = getCache(request.url, "url")
        if getCacheResult is not False:
            return jsonify(getCacheResult)
        else:
            returnResult = formatBadIP(
                queryBadIPs(app.config['BADIPTIMESPAN'], checkCommunityIndex(request), getRelevantIndices(2)), 'json')
            setCache(request.url, returnResult, 60, "url")
            return jsonify(returnResult)
    else:
        getCacheResult = getCache(request.url, "url")
        if getCacheResult is not False:
            return Response(getCacheResult, mimetype='text/xml')
        else:
            returnResult = formatBadIP(
                queryBadIPs(app.config['BADIPTIMESPAN'], checkCommunityIndex(request), getRelevantIndices(2)), 'xml')
            setCache(request.url, returnResult, 60, "url")
            return Response(returnResult, mimetype='text/xml') 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:23,代码来源:peba.py

示例5: retrieveIPs15m

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveIPs15m():
    """ Retrieve IPs from the last 15mins from ElasticSearch and return formatted XML or JSON with IPs """

    if request.args.get('out') and request.args.get('out') == 'json':
        getCacheResult = getCache(request.url, "url")
        if getCacheResult is not False:
            return jsonify(getCacheResult)
        else:
            returnResult = formatBadIP(
                queryBadIPs(15, checkCommunityIndex(request), getRelevantIndices(2)), 'json')
            setCache(request.url, returnResult, 60, "url")
            return jsonify(returnResult)
    else:
        getCacheResult = getCache(request.url, "url")
        if getCacheResult is not False:
            return Response(getCacheResult, mimetype='text/xml')
        else:
            returnResult = formatBadIP(
                queryBadIPs(15, checkCommunityIndex(request), getRelevantIndices(2)), 'xml')
            setCache(request.url, returnResult, 60, "url")
            return Response(returnResult, mimetype='text/xml')

# Routes with JSON output 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:25,代码来源:peba.py

示例6: retrieveAlertsJson

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveAlertsJson():
    """ Retrieve last 5 Alerts in JSON without IPs """

    # set cacheItem independent from url parameters, respect community index
    cacheEntry = request.url

    # get result from cache
    getCacheResult = getCache(cacheEntry, "url")
    if getCacheResult is not False:
        app.logger.debug('Returning /retrieveAlertsJson from Cache %s' % str(request.remote_addr))
        return jsonify(getCacheResult)

    # query ES
    else:
        numAlerts = 35
        # Retrieve last X Alerts from ElasticSearch and return JSON formatted with limited alert content
        returnResult =  formatAlertsJson(queryAlertsWithoutIP(numAlerts, checkCommunityIndex(request), getRelevantIndices(2)))
        setCache(cacheEntry, returnResult, 25, "url")
        app.logger.debug('UNCACHED %s' % str(request.url))
        return jsonify(returnResult) 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:22,代码来源:peba.py

示例7: retrieveDatasetAlertsPerMonth

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveDatasetAlertsPerMonth():
    """ Retrieve the attacks / day in the last x days from elasticsearch
        and return as JSON for the last months, defaults to last month,
        if no GET parameter days is given
    """

    # get result from cache
    getCacheResult = getCache(request.url, "url")
    if getCacheResult is not False:
        return jsonify(getCacheResult)

    # query ES
    else:
        if not request.args.get('days'):
            # Using default : within the last month (max 31 day indices)
            returnResult = formatDatasetAlertsPerMonth(queryDatasetAlertsPerMonth(None, checkCommunityIndex(request), getRelevantIndices(32)))
        else:
            if request.args.get('days').isdecimal() and int(request.args.get('days'))<=31:
                indexDays = int(request.args.get('days')) + 1
            else:
                indexDays = 0
            returnResult = formatDatasetAlertsPerMonth(queryDatasetAlertsPerMonth(request.args.get('days'), checkCommunityIndex(request), getRelevantIndices(indexDays)))
        setCache(request.url, returnResult, 600, "url")
        return jsonify(returnResult) 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:26,代码来源:peba.py

示例8: retrieveDatasetAlertTypesPerMonth

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveDatasetAlertTypesPerMonth():
    """ Retrieve the attacks / day in the last x days from elasticsearch,
        split by attack group
        and return as JSON for the last x months, defaults to last month,
        if no GET parameter days is given
    """

    # get result from cache
    getCacheResult = getCache(request.url, "url")
    if getCacheResult is not False:
        return jsonify(getCacheResult)

    # query ES
    else:
        if not request.args.get('days'):
            # Using default : within the last month (max 31 day indices)
            returnResult = formatDatasetAlertTypesPerMonth(queryDatasetAlertTypesPerMonth(None, checkCommunityIndex(request), getRelevantIndices(32)))
        else:
            if request.args.get('days').isdecimal() and int(request.args.get('days')) <= 31:
                indexDays = int(request.args.get('days'))+1
            else:
                indexDays = 0
            returnResult = formatDatasetAlertTypesPerMonth(queryDatasetAlertTypesPerMonth(request.args.get('days'), checkCommunityIndex(request), getRelevantIndices(indexDays)))
        setCache(request.url, returnResult, 3600, "url")
        return jsonify(returnResult) 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:27,代码来源:peba.py

示例9: retrieveAlertStats

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveAlertStats():
    """ Retrieve combined statistics
        AlertsLastMinute, AlertsLastHour,  AlertsLast24Hours
    """

    # get result from cache
    getCacheResult = getCache(request.url, "url")
    if getCacheResult is not False:
        return jsonify(getCacheResult)

    # query ES
    else:
        returnResult = formatAlertStats(queryAlertStats(checkCommunityIndex(request), getRelevantIndices(2)))
        setCache(request.url, returnResult, 13, "url")
        app.logger.debug('UNCACHED %s' % str(request.url))
        return jsonify(returnResult) 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:18,代码来源:peba.py

示例10: avatars

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def avatars():
    hashes = set(request.query['hashes'].split(','))
    size = request.query.get('size', 20)
    default = request.query.get('default', 'identicon')
    cls = request.query.get('cls', '.pic-%s')

    response.content_type = 'text/css'
    return '\n'.join((
        '%s {background-image: url(data:image/gif;base64,%s);}'
        % ((cls % h), i.decode())
    ) for h, i in fetch_avatars(hashes, size, default)) 
开发者ID:naspeh,项目名称:mailur,代码行数:13,代码来源:web.py

示例11: proxy

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def proxy():
    url = request.query.get('url')
    if not url:
        return abort(400)

    return proxy_by_nginx(url) 
开发者ID:naspeh,项目名称:mailur,代码行数:8,代码来源:web.py

示例12: redirect

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def redirect(url, code=None):
    if not code:
        code = 303 if request.get('SERVER_PROTOCOL') == 'HTTP/1.1' else 302
    response.status = code
    response.body = ''
    response.set_header('Location', urllib.parse.urljoin(request.url, url))
    return response 
开发者ID:naspeh,项目名称:mailur,代码行数:9,代码来源:web.py

示例13: proxy_by_nginx

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def proxy_by_nginx(url):
    url = '/.proxy?url=%s' % url
    response.set_header('X-Accel-Redirect', url)
    return '' 
开发者ID:naspeh,项目名称:mailur,代码行数:6,代码来源:web.py

示例14: generate_feed

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def generate_feed():
    # app.logger.warning(request.args)

    param = request.args.get('username')
    if param:
        username = urllib.parse.unquote(param).strip()
        match, display = fetch.is_valid_username(username)

        if (match):
            # get posts
            site_url = fetch.build_site_url(username)
            data = fetch.get_remote_data(site_url)
            items = fetch.extract_items(username, data)

            if (items and len(items) > 0):
                # create feed
                feed = AtomFeed('{0} FB Posts'.format(display),
                                subtitle=site_url,
                                feed_url=request.url,
                                url=request.url_root)

                for post in items:
                    feed.add(post['title'],
                             post['article'],
                             content_type='html',
                             author=post['author'],
                             url=post['url'],
                             updated=post['date'],
                             published=post['date'])

                return feed.get_response()
            else:
                return 'No posts found. Are you sure you put in the correct username?'
        else:
            return 'Invalid username provided'
    else:
        return 'No username provided in query string'


# launch 
开发者ID:irfancharania,项目名称:fb-feed-gen,代码行数:42,代码来源:app.py

示例15: retrieveAlertsCount

# 需要导入模块: from urllib import request [as 别名]
# 或者: from urllib.request import url [as 别名]
def retrieveAlertsCount():
    """ Retrieve number of alerts in timeframe (GET-Parameter time as decimal or "day") """

    # Retrieve Number of Alerts from ElasticSearch and return as xml / json
    if not request.args.get('time'):
        app.logger.error('No time GET-parameter supplied in retrieveAlertsCount. Must be decimal number (in minutes) or string "day"')
        return app.config['DEFAULTRESPONSE']
    else:
        if request.args.get('out') and request.args.get('out') == 'json':
            # get result from cache
            getCacheResult = getCache(request.url, "url")
            if getCacheResult is not False:
                return jsonify(getCacheResult)
            else:
                if request.args.get('time').isdecimal() and int(request.args.get('time')) <= 46080:
                    indexDays=(int(int(request.args.get('time'))/1440))+2
                elif request.args.get('time') == "day":
                    indexDays=1
                else:
                    indexDays=0
                returnResult = formatAlertsCount(queryAlertsCount(request.args.get('time'), checkCommunityIndex(request), getRelevantIndices(indexDays)), 'json')
                setCache(request.url, returnResult, 60, "url")
                return jsonify(returnResult)

        else:
            # get result from cache
            getCacheResult = getCache(request.url, "url")
            if getCacheResult is not False:
                return Response(getCacheResult, mimetype='text/xml')
            else:
                if request.args.get('time').isdecimal() and int(request.args.get('time')) <= 46080:
                    indexDays=(int(int(request.args.get('time'))/1440))+2
                elif request.args.get('time') == "day":
                    indexDays=1
                else:
                    indexDays=0
                returnResult = formatAlertsCount(queryAlertsCount(request.args.get('time'), checkCommunityIndex(request), getRelevantIndices(indexDays)), 'xml')
                setCache(request.url, returnResult, 60, "url")
                return Response(returnResult, mimetype='text/xml') 
开发者ID:dtag-dev-sec,项目名称:PEBA,代码行数:41,代码来源:peba.py


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