<commit_before># -*- coding: utf-8 -*-

"""
requests.async
~~~~~~~~~~~~~~

This module contains an asynchronous replica of ``requests.api``, powered
by gevent. All API methods return a ``Request`` instance (as opposed to
``Response``). A list of requests can be sent with ``map()``.
"""

try:
    import gevent
    from gevent import monkey as curious_george
except ImportError:
    raise RuntimeError('Gevent is required for requests.async.')

# Monkey-patch.
curious_george.patch_all(thread=False)

from . import api
from .hooks import dispatch_hook


__all__ = (
    'map',
    'get', 'head', 'post', 'put', 'patch', 'delete', 'request'
)


def _patched(f):
    """Patches a given API function to not send."""

    def wrapped(*args, **kwargs):
        return f(*args, return_response=False, **kwargs)

    return wrapped


def _send(r, pools=None):
    """Sends a given Request object."""

    if pools:
        r._pools = pools

    r.send()

    # Post-request hook.
    r = dispatch_hook('post_request', r.hooks, r)

    # Response manipulation hook.
    r.response = dispatch_hook('response', r.hooks, r.response)

    return r.response


# Patched requests.api functions.
get = _patched(api.get)
head = _patched(api.head)
post = _patched(api.post)
put = _patched(api.put)
patch = _patched(api.patch)
delete = _patched(api.delete)
request = _patched(api.request)


def map(requests):
    """Concurrently converts a list of Requests to Responses.

    :param requests: a collection of Request objects.
    :param keep_alive: If True, HTTP Keep-Alive will be used.
    """

    jobs = [gevent.spawn(_send, r) for r in requests]
    gevent.joinall(jobs)

    return [r.response for r in requests]



<commit_msg>prefetch=False for async.map<commit_after># -*- coding: utf-8 -*-

"""
requests.async
~~~~~~~~~~~~~~

This module contains an asynchronous replica of ``requests.api``, powered
by gevent. All API methods return a ``Request`` instance (as opposed to
``Response``). A list of requests can be sent with ``map()``.
"""

try:
    import gevent
    from gevent import monkey as curious_george
except ImportError:
    raise RuntimeError('Gevent is required for requests.async.')

# Monkey-patch.
curious_george.patch_all(thread=False)

from . import api
from .hooks import dispatch_hook


__all__ = (
    'map',
    'get', 'head', 'post', 'put', 'patch', 'delete', 'request'
)


def _patched(f):
    """Patches a given API function to not send."""

    def wrapped(*args, **kwargs):
        return f(*args, return_response=False, **kwargs)

    return wrapped


def _send(r, pools=None):
    """Sends a given Request object."""

    if pools:
        r._pools = pools

    r.send()

    # Post-request hook.
    r = dispatch_hook('post_request', r.hooks, r)

    # Response manipulation hook.
    r.response = dispatch_hook('response', r.hooks, r.response)

    return r.response


# Patched requests.api functions.
get = _patched(api.get)
head = _patched(api.head)
post = _patched(api.post)
put = _patched(api.put)
patch = _patched(api.patch)
delete = _patched(api.delete)
request = _patched(api.request)


def map(requests, prefetch=True):
    """Concurrently converts a list of Requests to Responses.

    :param requests: a collection of Request objects.
    :param prefetch: If False, the content will not be downloaded immediately.
    """

    jobs = [gevent.spawn(_send, r) for r in requests]
    gevent.joinall(jobs)

    if prefetch:
        [r.response.content for r in requests]

    return [r.response for r in requests]




{'fraction_non_alphanumeric': 0.1319796954314721, 'fraction_numerical': 0.0005640157924421884, 'mean_word_length': 3.501269035532995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4965097', 'n_tokens_mistral': 1165, 'n_tokens_neox': 1109, 'n_words': 360}