# Path: shippo/error.py
# class ShippoError(Exception):
# class APIError(ShippoError):
# class APIConnectionError(ShippoError):
# class AddressError(ShippoError):
# class InvalidRequestError(ShippoError):
# class AuthenticationError(ShippoError):
#     def __init__(self, message=None, http_body=None, http_status=None,
#                  json_body=None):
#     def __init__(self, message, param, code, http_body=None,
#                  http_status=None, json_body=None):
#     def __init__(self, message, param, http_body=None,
#                  http_status=None, json_body=None):


import os
import sys
import textwrap
    import requests
from shippo import error
    from google.appengine.api import urlfetch

            # This causes the content to actually be read, which could cause
            # e.g. a socket timeout. TODO: The other fetch methods probably
            # are succeptible to the same and should be updated.

            content = result.content
            status_code = result.status_code
        except Exception as e:
            # Would catch just requests.exceptions.RequestException, but can
            # also raise ValueError, RuntimeError, etc.
            self._handle_request_error(e)
        return content, status_code

    def _handle_request_error(self, e):
        if isinstance(e, requests.exceptions.RequestException):
            msg = ("Unexpected error communicating with Shippo.  "
                   "If this problem persists, let us know at "
                   "support@goshippo.com.")
            err = "%s: %s" % (type(e).__name__, str(e))
        else:
            msg = ("Unexpected error communicating with Shippo. "
                   "It looks like there's probably a configuration "
                   "issue locally.  If this problem persists, let us "
                   "know at support@goshippo.com.")
            err = "A %s was raised" % (type(e).__name__,)
            if str(e):
                err += " with error message %s" % (str(e),)
            else:
                err += " with no error message"
        msg = textwrap.fill(msg) + "\n\n(Network error: %s)" % (err,)

# Path: shippo/error.py
# class ShippoError(Exception):
# class APIError(ShippoError):
# class APIConnectionError(ShippoError):
# class AddressError(ShippoError):
# class InvalidRequestError(ShippoError):
# class AuthenticationError(ShippoError):
#     def __init__(self, message=None, http_body=None, http_status=None,
#                  json_body=None):
#     def __init__(self, message, param, code, http_body=None,
#                  http_status=None, json_body=None):
#     def __init__(self, message, param, http_body=None,
#                  http_status=None, json_body=None):


# Path: shippo/http_client.py
import os
import sys
import textwrap
    import requests
from shippo import error
    from google.appengine.api import urlfetch


            # This causes the content to actually be read, which could cause
            # e.g. a socket timeout. TODO: The other fetch methods probably
            # are succeptible to the same and should be updated.

            content = result.content
            status_code = result.status_code
        except Exception as e:
            # Would catch just requests.exceptions.RequestException, but can
            # also raise ValueError, RuntimeError, etc.
            self._handle_request_error(e)
        return content, status_code

    def _handle_request_error(self, e):
        if isinstance(e, requests.exceptions.RequestException):
            msg = ("Unexpected error communicating with Shippo.  "
                   "If this problem persists, let us know at "
                   "support@goshippo.com.")
            err = "%s: %s" % (type(e).__name__, str(e))
        else:
            msg = ("Unexpected error communicating with Shippo. "
                   "It looks like there's probably a configuration "
                   "issue locally.  If this problem persists, let us "
                   "know at support@goshippo.com.")
            err = "A %s was raised" % (type(e).__name__,)
            if str(e):
                err += " with error message %s" % (str(e),)
            else:
                err += " with no error message"
        msg = textwrap.fill(msg) + "\n\n(Network error: %s)" % (err,)

        raise error.APIConnectionError(msg)