# Path: opennode/knot/backend/billing.py
# class ICreditCheckCall(Interface):
# 
#     def get_credit(self, uid):
#         """ Get credit """


from grokcore.component import implements, GlobalUtility
from StringIO import StringIO
from twisted.internet import defer
from twisted.internet import reactor
from twisted.internet.protocol import Protocol
from twisted.web.client import Agent, ResponseDone
from twisted.web.http_headers import Headers
from twisted.web.http import PotentialDataLoss
from twisted.web.iweb import IBodyProducer
from urllib import urlencode
from opennode.knot.backend.billing import ICreditCheckCall
from opennode.oms.config import get_config
import json
import hashlib
import logging
import sys





log = logging.getLogger(__name__)


class ResponseProtocol(Protocol):
    def __init__(self, finished, size):
        self.finished = finished
        self.remaining = size
        self.data = StringIO()

    def dataReceived(self, bytes):
        display = bytes[:self.remaining]
        self.data.write(display)
        self.remaining -= len(display)

    def connectionLost(self, reason):
        if type(reason.value) in (ResponseDone, PotentialDataLoss):
            self.finished.callback(self.data.getvalue())
        else:

# Path: opennode/knot/backend/billing.py
# class ICreditCheckCall(Interface):
# 
#     def get_credit(self, uid):
#         """ Get credit """


# Path: opennode/knot/backend/whmcs.py
from grokcore.component import implements, GlobalUtility
from StringIO import StringIO
from twisted.internet import defer
from twisted.internet import reactor
from twisted.internet.protocol import Protocol
from twisted.web.client import Agent, ResponseDone
from twisted.web.http_headers import Headers
from twisted.web.http import PotentialDataLoss
from twisted.web.iweb import IBodyProducer
from urllib import urlencode
from opennode.knot.backend.billing import ICreditCheckCall
from opennode.oms.config import get_config
import json
import hashlib
import logging
import sys






log = logging.getLogger(__name__)


class ResponseProtocol(Protocol):
    def __init__(self, finished, size):
        self.finished = finished
        self.remaining = size
        self.data = StringIO()

    def dataReceived(self, bytes):
        display = bytes[:self.remaining]
        self.data.write(display)
        self.remaining -= len(display)

    def connectionLost(self, reason):
        if type(reason.value) in (ResponseDone, PotentialDataLoss):
            self.finished.callback(self.data.getvalue())
        else:

            self.finished.errback(reason)