def calculate(self, cart, contact):
        """
        Based on the chosen UPS method, we will do our call to UPS and see how much it will
        cost.
        We will also need to store the results for further parsing and return via the
        methods above
        """
        from satchmo_store.shop.models import Config
        
        settings =  config_get_group('shipping.modules.ups')
        self.delivery_days = _("3 - 4") #Default setting for ground delivery
        shop_details = Config.objects.get_current()
        # Get the code and description for the packaging
        container = settings.SHIPPING_CONTAINER.value
        container_description = settings.SHIPPING_CONTAINER.choices[int(container)][1]
        configuration = {
            'xml_key': settings.XML_KEY.value,
            'account': settings.ACCOUNT.value,
            'userid': settings.USER_ID.value,
            'password': settings.USER_PASSWORD.value,
            'container': container,
            'container_description': container_description,
            'pickup': settings.PICKUP_TYPE.value,
            'ship_type': self.service_type_code,
            'shop_details':shop_details,
        }
        
        shippingdata = {
            'single_box': False,
            'config': configuration,
            'contact': contact,
            'cart': cart,
            'shipping_address' : shop_details,
            'shipping_phone' : shop_details.phone,
            'shipping_country_code' : shop_details.country.iso2_code
            }
            
        if settings.SINGLE_BOX.value:
            log.debug("Using single-box method for ups calculations.")

            box_weight = Decimal("0.00")
            for product in cart.get_shipment_list():
                if product.smart_attr('weight') is None:
                    log.warn("No weight on product (skipping for ship calculations): %s", product)
                else:
                    box_weight += product.smart_attr('weight')
                if product.smart_attr('weight_units') and product.smart_attr('weight_units') != "":
                    box_weight_units = product.smart_attr('weight_units')
                else:
                    log.warn("No weight units for product")

            if box_weight < Decimal("0.1"):
                log.debug("Total box weight too small, defaulting to 0.1")
                box_weight = Decimal("0.1")

            shippingdata['single_box'] = True
            shippingdata['box_weight'] = '%.1f' % box_weight
            shippingdata['box_weight_units'] = box_weight_units.upper()

        signals.shipping_data_query.send(Shipper, shipper=self, cart=cart, shippingdata=shippingdata)
        c = Context(shippingdata)
        t = loader.get_template('shipping/ups/request.xml')
        request = t.render(c)
        self.is_valid = False
        if settings.LIVE.value:
            connection = settings.CONNECTION.value
        else:
            connection = settings.CONNECTION_TEST.value
        cache_key_response = "ups-cart-%s-response" % int(cart.id)
        cache_key_request = "ups-cart-%s-request" % int(cart.id)
        last_request = cache.get(cache_key_request)
        tree = cache.get(cache_key_response)

        if (last_request != request) or tree is None:
            self.verbose_log("Requesting from UPS [%s]\n%s", cache_key_request, request)
            cache.set(cache_key_request, request, 60)
            tree = self._process_request(connection, request)
            self.verbose_log("Got from UPS [%s]:\n%s", cache_key_response, self.raw)
            needs_cache = True
        else:
            needs_cache = False

        try:
            status_code = tree.getiterator('ResponseStatusCode')
            status_val = status_code[0].text
            self.verbose_log("UPS Status Code for cart #%s = %s", int(cart.id), status_val)
        except __HOLE__:
            status_val = "-1"
        
        if status_val == '1':
            self.is_valid = False
            self._calculated = False
            all_rates = tree.getiterator('RatedShipment')
            for response in all_rates:
                if self.service_type_code == response.find('.//Service/Code/').text:
                    self.charges = response.find('.//TotalCharges/MonetaryValue').text
                    if response.find('.//GuaranteedDaysToDelivery').text:
                        self.delivery_days = response.find('.//GuaranteedDaysToDelivery').text
                    self.is_valid = True
                    self._calculated = True
                    if needs_cache:
                        cache.set(cache_key_response, tree, 60)
                        
            if not self.is_valid:
                self.verbose_log("UPS Cannot find rate for code: %s [%s]", self.service_type_code, self.service_type_text)
        
        else:
            self.is_valid = False
            self._calculated = False

            try:
                errors = tree.find('.//Error')
                log.info("UPS %s Error: Code %s - %s" % (errors[0].text, errors[1].text, errors[2].text))
            except AttributeError:
                log.info("UPS error - cannot parse response:\n %s", self.raw)
dataset/ETHPy150Open dokterbob/satchmo/satchmo/apps/shipping/modules/ups/shipper.py/Shipper.calculate