<commit_before>from yowsup.structs import ProtocolEntity, ProtocolTreeNode
from .receipt import ReceiptProtocolEntity
class IncomingReceiptProtocolEntity(ReceiptProtocolEntity):

    '''
    delivered:
    <receipt to="<EMAIL>" id="1415389947-15"></receipt>

    read
    <receipt to="<EMAIL>" id="1415389947-15" type="read"></receipt>

    INCOMING
    <receipt offline="0" from="<EMAIL>" id="1415577964-1" t="1415578027"></receipt>
    '''

    def __init__(self, _id, _from, timestamp, offline = None, type = None):
        super(IncomingReceiptProtocolEntity, self).__init__(_id)
        self.setIncomingData(_from, timestamp, offline, type)

    def setIncomingData(self, _from, timestamp, offline, type = None):
        self._from = _from
        self.timestamp = timestamp
        self.type = type
        if offline is not None:
            self.offline = True if offline == "1" else False
        else:
            self.offline = None

    def toProtocolTreeNode(self):
        node = super(IncomingReceiptProtocolEntity, self).toProtocolTreeNode()
        node.setAttribute("from", self._from)
        node.setAttribute("timestamp", str(self.timestamp))
        if self.offline is not None:
            node.setAttribute("1" if self.offline else "0")
        if self.type is not None:
            node.setAttribute("type", self.type)
        return node

    def __str__(self):
        out = super(IncomingReceiptProtocolEntity, self).__str__()
        out += "From: \n%s" % self._from
        out += "Timestamp: \n%s" % self.timestamp
        if self.offline is not None:
            out += "Offline: %s\n" % ("1" if self.offline else "0")
        if self.type is not None:
            out += "Type: %s\n" % (self.type)
        return out

    @staticmethod
    def fromProtocolTreeNode(node):
        return IncomingReceiptProtocolEntity(
            node.getAttributeValue("id"),
            node.getAttributeValue("from"),
            node.getAttributeValue("timestamp"),
            node.getAttributeValue("offline"    ),
            node.getAttributeValue("type")
            )<commit_msg>Fix some bugs in receipt_incoming.py<commit_after>from yowsup.structs import ProtocolEntity, ProtocolTreeNode
from .receipt import ReceiptProtocolEntity
class IncomingReceiptProtocolEntity(ReceiptProtocolEntity):

    '''
    delivered:
    <receipt to="<EMAIL>" id="1415389947-15"></receipt>

    read
    <receipt to="<EMAIL>" id="1415389947-15" type="read"></receipt>

    INCOMING
    <receipt offline="0" from="<EMAIL>" id="1415577964-1" t="1415578027"></receipt>
    '''

    def __init__(self, _id, _from, timestamp, offline = None, type = None):
        super(IncomingReceiptProtocolEntity, self).__init__(_id)
        self.setIncomingData(_from, timestamp, offline, type)

    def setIncomingData(self, _from, timestamp, offline, type = None):
        self._from = _from
        self.timestamp = timestamp
        self.type = type
        if offline is not None:
            self.offline = True if offline == "1" else False
        else:
            self.offline = None

    def toProtocolTreeNode(self):
        node = super(IncomingReceiptProtocolEntity, self).toProtocolTreeNode()
        node.setAttribute("from", self._from)
        node.setAttribute("timestamp", str(self.timestamp))
        if self.offline is not None:
            node.setAttribute("offline", "1" if self.offline else "0")
        if self.type is not None:
            node.setAttribute("type", self.type)
        return node

    def __str__(self):
        out = super(IncomingReceiptProtocolEntity, self).__str__()
        out += "From: %s\n" % self._from
        out += "Timestamp: %s\n" % self.timestamp
        if self.offline is not None:
            out += "Offline: %s\n" % ("1" if self.offline else "0")
        if self.type is not None:
            out += "Type: %s\n" % (self.type)
        return out

    @staticmethod
    def fromProtocolTreeNode(node):
        return IncomingReceiptProtocolEntity(
            node.getAttributeValue("id"),
            node.getAttributeValue("from"),
            node.getAttributeValue("t"),
            node.getAttributeValue("offline"),
            node.getAttributeValue("type")
            )
{'fraction_non_alphanumeric': 0.11956521739130435, 'fraction_numerical': 0.024102079395085067, 'mean_word_length': 2.645994832041344, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '2654190', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1238, 'n_words': 293}