<commit_before>#!/usr/bin/env python

# based on the 'calculator' demo in the Thrift source

import sys, os.path
sys.path.insert(0, os.path.join(os.path.abspath(os.path.split(sys.argv[0])[0]), 'gen-py'))
import tutorial.Calculator
from tutorial.ttypes import *
from thrift.transport import TTwisted
from thrift.protocol import TBinaryProtocol

from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientCreator

import txamqp.spec
from txamqp.protocol import AMQClient
from txamqp.client import TwistedDelegate
from txamqp.contrib.thrift import TwistedAMQPTransport

servicesExchange = "services"
responsesExchange = "responses"
calculatorQueue = "calculator_pool"
calculatorKey = "calculator"

def gotPing(_):
    print "Ping received"

def gotAddResults(results):
    print "Got results to add()"
    print results

def gotCalculateResults(results):
    print "Got results to calculate()"
    print results

def gotCalculateErrors(error):
    print "Got an error"
    print error.value.why

def gotClient(txclient):
    client = txclient.client
    
    d1 = client.ping().addCallback(gotPing)

    d2 = client.add(1, 2).addCallback(gotAddResults)

    w = Work({'num1': 2, 'num2': 3, 'op': Operation.ADD})

    d3 = client.calculate(1, w).addCallbacks(gotCalculateResults, gotCalculateErrors)
    
    w = Work({'num1': 2, 'num2': 3, 'op': Operation.SUBTRACT})
    
    d4 = client.calculate(2, w).addCallbacks(gotCalculateResults, gotCalculateErrors)

    w = Work({'num1': 2, 'num2': 3, 'op': Operation.MULTIPLY})
    
    d5 = client.calculate(3, w).addCallbacks(gotCalculateResults, gotCalculateErrors)

    w = Work({'num1': 2, 'num2': 3, 'op': Operation.DIVIDE})
    
    d6 = client.calculate(4, w).addCallbacks(gotCalculateResults, gotCalculateErrors)

    # This will fire an errback
    w = Work({'num1': 2, 'num2': 0, 'op': Operation.DIVIDE})
    
    d7 = client.calculate(5, w).addCallbacks(gotCalculateResults, gotCalculateErrors)

    d8 = client.zip()

    dl = defer.DeferredList([d1, d2, d3, d4, d5, d6, d7, d8])

    dl.addCallback(lambda _: reactor.stop())

def parseClientMessage(msg, channel, queue, pfactory, thriftClient):
    deliveryTag = msg.delivery_tag<commit_msg>removed unused gotClient function<commit_after>#!/usr/bin/env python

# based on the 'calculator' demo in the Thrift source

import sys, os.path
sys.path.insert(0, os.path.join(os.path.abspath(os.path.split(sys.argv[0])[0]), 'gen-py'))
import tutorial.Calculator
from tutorial.ttypes import *
from thrift.transport import TTwisted
from thrift.protocol import TBinaryProtocol

from twisted.internet import reactor, defer
from twisted.internet.protocol import ClientCreator

import txamqp.spec
from txamqp.protocol import AMQClient
from txamqp.client import TwistedDelegate
from txamqp.contrib.thrift import TwistedAMQPTransport

servicesExchange = "services"
responsesExchange = "responses"
calculatorQueue = "calculator_pool"
calculatorKey = "calculator"

def gotPing(_):
    print "Ping received"

def gotAddResults(results):
    print "Got results to add()"
    print results

def gotCalculateResults(results):
    print "Got results to calculate()"
    print results

def gotCalculateErrors(error):
    print "Got an error"
    print error.value.why

def parseClientMessage(msg, channel, queue, pfactory, thriftClient):
    deliveryTag = msg.delivery_tag
{'fraction_non_alphanumeric': 0.11088113542282672, 'fraction_numerical': 0.014488468361916026, 'mean_word_length': 4.743633276740238, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6163997', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1077, 'n_words': 284}