import signal
import socket
import urllib
import httplib

from gratia.common.config import ConfigProxy
from gratia.common.debug import DebugPrint, DebugPrintTraceback

# Hopefully these import lines go away when we can do relative imports
import gratia.common.ProxyUtil as ProxyUtil
import gratia.common.sandbox_mgmt as sandbox_mgmt
import gratia.common.response as response
import gratia.common.utils as utils
import gratia.common.global_state as global_state

Config = ConfigProxy()

# Instantiate a global connection object so it can be reused for
# the lifetime of the server Instantiate a 'connected' flag as
# well, because at times we cannot interrogate a connection
# object to see if it has been connected yet or not

connection = None
connected = False
connectionError = False
connectionRetries = 0
certificateRejected = False
certrequestRejected = False
__maxConnectionRetries__ = 2
__last_retry_time = None
__maximumDelay = 900