<commit_before>from multisig import Multisig
from protocol import order
import StringIO
import gnupg
import hashlib
import json
import logging
import qrcode
import random
import string
import time
import urllib

class Orders(object):
    class State:
        '''Enum inner class. Python introduces enums in Python 3.0, but this should be good enough'''
        SENT = 'Sent'
        ACCEPTED = 'accepted'
        BID = 'bid'
        BUYER_PAID = 'Buyer Paid'
        NEED_TO_PAY = 'Need to Pay'
        NEW = 'new'
        NOTARIZED = 'Notarized'
        PAID = 'Paid'
        RECEIVED = 'received'
        SHIPPED = 'Shipped'
        WAITING_FOR_PAYMENT = 'Waiting for Payment'

    def __init__(self, transport, market_id, db):

        self._transport = transport
        self._priv = transport._myself
        self._market_id = market_id

        self._gpg = gnupg.GPG()
        self._db = db
        self._orders = self.get_orders()
        self.orders = self._orders

        self._transport.add_callback('order', self.on_order)

        self._log = logging.getLogger('[%s] %s' % (self._market_id, self.__class__.__name__))

    def get_offer_json(self, raw_contract, state):

        print state

        if state == Orders.State.SENT:
            offer_data = ''.join(raw_contract.split('\n')[5:])
            sig_index = offer_data.find('- -----BEGIN PGP SIGNATURE-----', 0, len(offer_data))
            offer_data_json = offer_data[0:sig_index]
            return json.loads(offer_data_json)

        if state in [Orders.State.WAITING_FOR_PAYMENT, Orders.State.NOTARIZED, Orders.State.NEED_TO_PAY, Orders.State.PAID]:
            start_line = 8
        else:
            start_line = 4

        offer_data = ''.join(raw_contract.split('\n')[start_line:])

        if state in [Orders.State.NOTARIZED, Orders.State.NEED_TO_PAY, Orders.State.PAID, Orders.State.BUYER_PAID]:
            index_of_seller_signature = offer_data.find('- -----BEGIN PGP SIGNATURE-----', 0, len(offer_data))
        else:
            index_of_seller_signature = offer_data.find('-----BEGIN PGP SIGNATURE-----', 0, len(offer_data))

        if state in (Orders.State.NEED_TO_PAY,
                               Orders.State.NOTARIZED,
                               Orders.State.BUYER_PAID,
                               Orders.State.PAID,
                               Orders.State.SHIPPED):
            offer_data_json = offer_data[0:index_of_seller_signature-2]
            offer_data_json = json.loads(offer_data_json)
        elif state in (Orders.State.WAITING_FOR_PAYMENT):
            offer_data_json = offer_data[0:index_of_seller_signature-4]
            offer_data_json = json.loads(str(offer_data_json))<commit_msg>Fix for Buyer_Paid<commit_after>from multisig import Multisig
from protocol import order
import StringIO
import gnupg
import hashlib
import json
import logging
import qrcode
import random
import string
import time
import urllib

class Orders(object):
    class State:
        '''Enum inner class. Python introduces enums in Python 3.0, but this should be good enough'''
        SENT = 'Sent'
        ACCEPTED = 'accepted'
        BID = 'bid'
        BUYER_PAID = 'Buyer Paid'
        NEED_TO_PAY = 'Need to Pay'
        NEW = 'new'
        NOTARIZED = 'Notarized'
        PAID = 'Paid'
        RECEIVED = 'received'
        SHIPPED = 'Shipped'
        WAITING_FOR_PAYMENT = 'Waiting for Payment'

    def __init__(self, transport, market_id, db):

        self._transport = transport
        self._priv = transport._myself
        self._market_id = market_id

        self._gpg = gnupg.GPG()
        self._db = db
        self._orders = self.get_orders()
        self.orders = self._orders

        self._transport.add_callback('order', self.on_order)

        self._log = logging.getLogger('[%s] %s' % (self._market_id, self.__class__.__name__))

    def get_offer_json(self, raw_contract, state):

        print state

        if state == Orders.State.SENT:
            offer_data = ''.join(raw_contract.split('\n')[5:])
            sig_index = offer_data.find('- -----BEGIN PGP SIGNATURE-----', 0, len(offer_data))
            offer_data_json = offer_data[0:sig_index]
            return json.loads(offer_data_json)

        if state in [Orders.State.WAITING_FOR_PAYMENT, Orders.State.NOTARIZED, Orders.State.NEED_TO_PAY, Orders.State.PAID, Orders.State.BUYER_PAID]:
            start_line = 8
        else:
            start_line = 4

        offer_data = ''.join(raw_contract.split('\n')[start_line:])

        if state in [Orders.State.NOTARIZED, Orders.State.NEED_TO_PAY, Orders.State.PAID, Orders.State.BUYER_PAID]:
            index_of_seller_signature = offer_data.find('- -----BEGIN PGP SIGNATURE-----', 0, len(offer_data))
        else:
            index_of_seller_signature = offer_data.find('-----BEGIN PGP SIGNATURE-----', 0, len(offer_data))

        if state in (Orders.State.NEED_TO_PAY,
                               Orders.State.NOTARIZED,
                               Orders.State.BUYER_PAID,
                               Orders.State.PAID,
                               Orders.State.SHIPPED):
            offer_data_json = offer_data[0:index_of_seller_signature-2]
            offer_data_json = json.loads(offer_data_json)
        elif state in (Orders.State.WAITING_FOR_PAYMENT):
            offer_data_json = offer_data[0:index_of_seller_signature-4]
            offer_data_json = json.loads(str(offer_data_json))
{'fraction_non_alphanumeric': 0.10538856304985338, 'fraction_numerical': 0.004765395894428153, 'mean_word_length': 2.240498812351544, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5850319', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1741, 'n_words': 356}