Beispiel #1
0
def http_post(reactor, url, value):
    agent = client.Agent(reactor)
    d = agent.request('POST', url,
        headers=client.Headers({'Content-Type': ['application/json']}),
        # in principle this could be streaming if we had a pipe-thing to glue between json.dump and FileBodyProducer
        bodyProducer=client.FileBodyProducer(StringIO.StringIO(json.dumps(value))))
    return _handle_agent_response(d)
Beispiel #2
0
    def __repr__(self):
        return ('<%(klass)s:%(id)s:maxBad=%(maxBad)s,bad=%(bad)s>' %
                dict(klass=self.__class__.__name__,
                     id=hex(id(self)),
                     maxBad=self.maxBad,
                     bad=self.bad))

Settings = collections.namedtuple('Settings', 'reactor agent')

_USER_AGENT = ('NColony HTTP Check ('
               'NColony/' + ncolony.__version__ + ', '
               'Twisted/' + twisted.__version__ + ', '
               'Python ' + sys.version.replace('\n', '') + ')'
              )

_standardHeaders = client.Headers({'User-Agent': [_USER_AGENT]})

## pylint: disable=too-many-instance-attributes

class State(object):

    """State of an HTTP check"""

    KEY = 'ncolony.httpcheck'

    def __init__(self, location, settings):
        self.location = location
        self.settings = settings
        self.closed = False
        self.content = None
        self.call = None