# Path: settings.py
# DEFAULT_USERNAME = "Username"
# 
# DEFAULT_PASSWORD = "Password"
# 
# Path: settings.py
# AUTHSERVER = _server_str % (PROTOCOL, HOSTNAME, AUTHSERVERPORT)
# 
# CHARSERVER = _server_str % (PROTOCOL, HOSTNAME, CHARSERVERPORT)
# 
# ZONESERVER = _server_str % (PROTOCOL, HOSTNAME, MASTERZONESERVERPORT)


import exceptions
import json
import pdb
import datetime
import requests
    import websocket
    import random
    import pprint
    import time
from time import sleep
from settings import *
from settings import DEFAULT_USERNAME, DEFAULT_PASSWORD
from settings import AUTHSERVER, CHARSERVER, ZONESERVER
    from random import randint
                print "Connecting failed:", exc

        print "Reconnecting in %.01f seconds..." % sleeptime
        sleep(sleeptime)
        sleeptime = sleeptime**1.5
        if sleeptime > CLIENT_TIMEOUT:
            raise requests.exceptions.Timeout("Gave up after %d seconds." % int(CLIENT_TIMEOUT))
    return True

class InvalidResponse(Exception):
    def __init__(self, status_code, content):
        self.status_code = status_code
        self.content = content

    def __str__(self):
        return "%d: %s" % (self.status_code, self.content)

def json_or_exception(response):
    '''Convert an HTTPResponse to JSON, if its status is 200 OK.
    Otherwise, raise an exception.'''
    if response.status_code == 200:
        try:
            return json.loads(response.content)
        except ValueError:
            return response.content
    else:
        raise InvalidResponse(response.status_code, response.content)

# Ping main server to make sure it's up, and really an authserver
def ping_authserver():

# Path: settings.py
# DEFAULT_USERNAME = "Username"
# 
# DEFAULT_PASSWORD = "Password"
# 
# Path: settings.py
# AUTHSERVER = _server_str % (PROTOCOL, HOSTNAME, AUTHSERVERPORT)
# 
# CHARSERVER = _server_str % (PROTOCOL, HOSTNAME, CHARSERVERPORT)
# 
# ZONESERVER = _server_str % (PROTOCOL, HOSTNAME, MASTERZONESERVERPORT)


# Path: idealclient.py
import exceptions
import json
import pdb
import datetime
import requests
    import websocket
    import random
    import pprint
    import time
from time import sleep
from settings import *
from settings import DEFAULT_USERNAME, DEFAULT_PASSWORD
from settings import AUTHSERVER, CHARSERVER, ZONESERVER
    from random import randint

                print "Connecting failed:", exc

        print "Reconnecting in %.01f seconds..." % sleeptime
        sleep(sleeptime)
        sleeptime = sleeptime**1.5
        if sleeptime > CLIENT_TIMEOUT:
            raise requests.exceptions.Timeout("Gave up after %d seconds." % int(CLIENT_TIMEOUT))
    return True

class InvalidResponse(Exception):
    def __init__(self, status_code, content):
        self.status_code = status_code
        self.content = content

    def __str__(self):
        return "%d: %s" % (self.status_code, self.content)

def json_or_exception(response):
    '''Convert an HTTPResponse to JSON, if its status is 200 OK.
    Otherwise, raise an exception.'''
    if response.status_code == 200:
        try:
            return json.loads(response.content)
        except ValueError:
            return response.content
    else:
        raise InvalidResponse(response.status_code, response.content)

# Ping main server to make sure it's up, and really an authserver
def ping_authserver():

    r = requests.get(''.join((AUTHSERVER, "/ping")))