# Path: authproxy.py
# class AuthServiceProxy(object):
#     def __init__(self, serviceURL, serviceName=None):
#         self.__serviceURL = serviceURL
#         self.__serviceName = serviceName
#         self.__url = urlparse.urlparse(serviceURL)
#         if self.__url.port is None:
#             port = 80
#         else:
#             port = self.__url.port
#         self.__idcnt = 0
#         authpair = "%s:%s" % (self.__url.username, self.__url.password)
#         self.__authhdr = "Basic %s" % (base64.b64encode(authpair))
#         self.__conn = httplib.HTTPConnection(self.__url.hostname, port, False,
#                              HTTP_TIMEOUT)
# 
#     def __getattr__(self, name):
#         if self.__serviceName != None:
#             name = "%s.%s" % (self.__serviceName, name)
#         return AuthServiceProxy(self.__serviceURL, name)
# 
#     def __call__(self, *args):
#         self.__idcnt += 1
# 
#         postdata = json.dumps({
#             'version': '1.1',
#              'method': self.__serviceName,
#             'params': args,
#             'id': self.__idcnt})
#         try:
#             self.__conn.request('POST', self.__url.path, postdata,
#                 { 'Host' : self.__url.hostname,
#                 'User-Agent' : USER_AGENT,
#                 'Authorization' : self.__authhdr,
#                 'Content-type' : 'application/json' })
#         except EnvironmentError as e:
#             if e.errno == errno.ECONNREFUSED:
#                 raise JSONRPCException({
#                     'code' : -341, 'message' : 'connection refused'})
#             else:
#                 raise # re-raise otherwise
# 
#         httpresp = self.__conn.getresponse()
#         if httpresp is None:
#              raise JSONRPCException({
#                  'code' : -342, 'message' : 'missing HTTP response from server'})
# 
#         resp = json.loads(httpresp.read(), parse_float=decimal.Decimal)
#         if resp['error'] != None:
#             raise JSONRPCException(resp['error'])
#         elif 'result' not in resp:
#              raise JSONRPCException({
#                  'code' : -343, 'message' : 'missing JSON-RPC result'})
#         else:
#             return resp['result']
# 
# class JSONRPCException(Exception):
#     def __init__(self, rpcError):
#         Exception.__init__(self)
#         self.error = rpcError


import qrencode
import urllib
import re
from StringIO import StringIO
from PIL import Image
from PyQt4 import QtGui
from PyQt4 import QtCore
from authproxy import AuthServiceProxy, JSONRPCException
from merchantgui import MerchantGUI
from customerdisplay import CustomerDisplay

class Controller:
    def __init__(self, settings, nfc_broadcast):
        self.nfc_broadcast = nfc_broadcast

# Path: authproxy.py
# class AuthServiceProxy(object):
#     def __init__(self, serviceURL, serviceName=None):
#         self.__serviceURL = serviceURL
#         self.__serviceName = serviceName
#         self.__url = urlparse.urlparse(serviceURL)
#         if self.__url.port is None:
#             port = 80
#         else:
#             port = self.__url.port
#         self.__idcnt = 0
#         authpair = "%s:%s" % (self.__url.username, self.__url.password)
#         self.__authhdr = "Basic %s" % (base64.b64encode(authpair))
#         self.__conn = httplib.HTTPConnection(self.__url.hostname, port, False,
#                              HTTP_TIMEOUT)
# 
#     def __getattr__(self, name):
#         if self.__serviceName != None:
#             name = "%s.%s" % (self.__serviceName, name)
#         return AuthServiceProxy(self.__serviceURL, name)
# 
#     def __call__(self, *args):
#         self.__idcnt += 1
# 
#         postdata = json.dumps({
#             'version': '1.1',
#              'method': self.__serviceName,
#             'params': args,
#             'id': self.__idcnt})
#         try:
#             self.__conn.request('POST', self.__url.path, postdata,
#                 { 'Host' : self.__url.hostname,
#                 'User-Agent' : USER_AGENT,
#                 'Authorization' : self.__authhdr,
#                 'Content-type' : 'application/json' })
#         except EnvironmentError as e:
#             if e.errno == errno.ECONNREFUSED:
#                 raise JSONRPCException({
#                     'code' : -341, 'message' : 'connection refused'})
#             else:
#                 raise # re-raise otherwise
# 
#         httpresp = self.__conn.getresponse()
#         if httpresp is None:
#              raise JSONRPCException({
#                  'code' : -342, 'message' : 'missing HTTP response from server'})
# 
#         resp = json.loads(httpresp.read(), parse_float=decimal.Decimal)
#         if resp['error'] != None:
#             raise JSONRPCException(resp['error'])
#         elif 'result' not in resp:
#              raise JSONRPCException({
#                  'code' : -343, 'message' : 'missing JSON-RPC result'})
#         else:
#             return resp['result']
# 
# class JSONRPCException(Exception):
#     def __init__(self, rpcError):
#         Exception.__init__(self)
#         self.error = rpcError


# Path: controller.py
import qrencode
import urllib
import re
from StringIO import StringIO
from PIL import Image
from PyQt4 import QtGui
from PyQt4 import QtCore
from authproxy import AuthServiceProxy, JSONRPCException
from merchantgui import MerchantGUI
from customerdisplay import CustomerDisplay


class Controller:
    def __init__(self, settings, nfc_broadcast):
        self.nfc_broadcast = nfc_broadcast

        self.bitcoind = AuthServiceProxy(settings['rpc_url'])