<commit_before># django imports
from django.core.exceptions import ObjectDoesNotExist
from django.core.cache import cache
from django.core.urlresolvers import reverse

# lfs imports
from lfs.cart.models import CartItem
from lfs.cart.models import Cart
from lfs.payment import utils as payment_utils
from lfs.shipping import utils as shipping_utils

def get_cart_max_delivery_time(request, cart):
    """Returns the delivery time object with the maximal delivery time of all
    products within the cart. Takes the selected shipping method into account.

    This is used within the cart to display the maximal delivery time.
    """
    max_delivery_time = None
    for item in cart.items():
        # Calculate the delivery time of the product. Takes the selected
        # shipping method into account.
        delivery_time = shipping_utils.get_product_delivery_time(
            request, item.product.slug, for_cart=True)
        if (max_delivery_time is None) or \
           (delivery_time.as_hours() > max_delivery_time.as_hours()):
            max_delivery_time = delivery_time
    return max_delivery_time

# TODO: Remove cart from signature?
def get_cart_price(request, cart, total=False):
    """Returns price of the given cart.
    """
    return get_cart_costs(request, cart, total)["price"]

def get_cart_costs(request, cart, total=False):
    """Returns price and tax of the given cart.
    """
    if cart is None:
        return {"price" : 0, "tax" : 0}

    cache_key = "cart-costs-%s-%s" % (total, cart.id)
    cart_costs = cache.get(cache_key)

    if cart_costs is None:
        cart_price = 0
        cart_tax = 0
        for item in cart.items():
            cart_price += item.get_price()
            cart_tax += item.get_tax()

        if total:
            # Shipping
            shipping_method = shipping_utils.get_selected_shipping_method(request)<commit_msg>Improved docstring<commit_after># django imports
from django.core.exceptions import ObjectDoesNotExist
from django.core.cache import cache
from django.core.urlresolvers import reverse

# lfs imports
from lfs.cart.models import CartItem
from lfs.cart.models import Cart
from lfs.payment import utils as payment_utils
from lfs.shipping import utils as shipping_utils

def get_cart_max_delivery_time(request, cart):
    """Returns the delivery time object with the maximal delivery time of all
    products within the cart. Takes the selected shipping method into account.

    This is used within the cart to display the maximal delivery time.
    """
    max_delivery_time = None
    for item in cart.items():
        # Calculate the delivery time of the product. Takes the selected
        # shipping method into account.
        delivery_time = shipping_utils.get_product_delivery_time(
            request, item.product.slug, for_cart=True)
        if (max_delivery_time is None) or \
           (delivery_time.as_hours() > max_delivery_time.as_hours()):
            max_delivery_time = delivery_time
    return max_delivery_time

# TODO: Remove cart from signature?
def get_cart_price(request, cart, total=False):
    """Returns price of the given cart.
    """
    return get_cart_costs(request, cart, total)["price"]

def get_cart_costs(request, cart, total=False):
    """Returns a dictionary with price and tax of the given cart:

        returns {
            "price" : the cart's price,
            "tax" : the cart's tax,
        }
    """
    if cart is None:
        return {"price" : 0, "tax" : 0}

    cache_key = "cart-costs-%s-%s" % (total, cart.id)
    cart_costs = cache.get(cache_key)

    if cart_costs is None:
        cart_price = 0
        cart_tax = 0
        for item in cart.items():
            cart_price += item.get_price()
            cart_tax += item.get_tax()

        if total:
            # Shipping
            shipping_method = shipping_utils.get_selected_shipping_method(request)
{'fraction_non_alphanumeric': 0.07940573770491803, 'fraction_numerical': 0.0020491803278688526, 'mean_word_length': 2.976578411405295, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5585432', 'n_tokens_mistral': 1148, 'n_tokens_neox': 1128, 'n_words': 368}