<commit_before>cdef class MobID(object):

    def __init__(self, mobID = None):
        if not mobID:
            return
        if isinstance(mobID, dict):
            self._from_dict(mobID)
        elif isinstance(mobID, (tuple, list)):
            self._from_list(mobID)
        else:
            self._from_str(mobID)

    cdef object _from_str(self, object mob_id):
    
        s = str(mob_id).replace("urn:smpte:umid:" ,"")
        
        items = s.split(".")
        
        if len(items) != 8:
            raise ValueError("Invalid MobID")

        
        self.mobID.SMPTELabel[0] = int(items[0][:2], 16)
        self.mobID.SMPTELabel[1] = int(items[0][2:4], 16)
        self.mobID.SMPTELabel[2] = int(items[0][4:6], 16)
        self.mobID.SMPTELabel[3] = int(items[0][6:8], 16)
        
        self.mobID.SMPTELabel[4] = int(items[1][:2], 16)
        self.mobID.SMPTELabel[5] = int(items[1][2:4], 16)
        self.mobID.SMPTELabel[6] = int(items[1][4:6], 16)
        self.mobID.SMPTELabel[7] = int(items[1][6:8], 16)
        
        self.mobID.SMPTELabel[8] = int(items[2][:2], 16)
        self.mobID.SMPTELabel[9] = int(items[2][2:4], 16)
        self.mobID.SMPTELabel[10] = int(items[2][4:6], 16)
        self.mobID.SMPTELabel[11] = int(items[2][6:8], 16)
        
        self.mobID.length = int(items[3][:2], 16)
        
        self.mobID.instanceHigh = int(items[3][2:4], 16)
        self.mobID.instanceMid = int(items[3][4:6], 16)
        self.mobID.instanceLow = int(items[3][6:8], 16)
        
        self.mobID.material.Data4[0] = int(items[4][:2], 16)
        self.mobID.material.Data4[1] = int(items[4][2:4], 16)
        self.mobID.material.Data4[2] = int(items[4][4:6], 16)
        self.mobID.material.Data4[3] = int(items[4][6:8], 16)
        
        self.mobID.material.Data4[4] = int(items[5][:2], 16)
        self.mobID.material.Data4[5] = int(items[5][2:4], 16)
        self.mobID.material.Data4[6] = int(items[5][4:6], 16)
        self.mobID.material.Data4[7] = int(items[5][6:8], 16)
        
        self.mobID.material.Data1 = int(items[6], 16)
        
        self.mobID.material.Data2 = int(items[7][0:4], 16)
        self.mobID.material.Data3 = int(items[7][4:], 16)
        
    cdef object _from_list(self, object id_list):
        f = "urn:smpte:umid:%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x." + \
             "%02x"  + \
             "%02x%02x%02x." + \
             "%02x%02x%02x%02x.%02x%02x%02x%02x.%08x.%04x%04x"
             
        self._from_str(f % tuple(id_list))
    
    cdef object _from_dict(self, dict d):
        self.mobID.length = d.get("length", 0)
        self.mobID.instanceHigh = d.get("instanceHigh", 0)
        self.mobID.instanceMid = d.get("instanceMid", 0)
        self.mobID.instanceLow = d.get("instanceLow", 0)
        
        material = d.get("material", {'Data1':0, 'Data2':0, 'Data3':0})
        
        self.mobID.material.Data1 = material.get('Data1', 0)
        self.mobID.material.Data2 = material.get('Data2', 0)
        self.mobID.material.Data3 = material.get('Data3', 0)
        
        Data4 = material.get("Data4", [0 for i in xrange(8)])
        
        for i in xrange(8):
            if i >= len(Data4):
                break
            self.mobID.material.Data4[i] = Data4[i]
            
        SMPTELabel = d.get("SMPTELabel", [0 for i in xrange(12)])
        for i in xrange(12):
            if i >= len(SMPTELabel):
                break
            self.mobID.SMPTELabel[i] = SMPTELabel[i]


    cdef lib.aafMobID_t get_aafMobID_t(self):
        return self.mobID
    
    @staticmethod
    def from_dict(dict d):
        return MobID(d)

    @staticmethod
    def from_list(mobid_list):
        return MobID(mobid_list)
    
    def to_list(self):
        l = []
        for i in xrange(12):
            l.append(self.mobID.SMPTELabel[i])
        
        l.append(self.mobID.length)
        l.append(self.mobID.instanceHigh)
        l.append(self.mobID.instanceMid)
        l.append(self.mobID.instanceLow)
        
        for i in xrange(8):
            l.append(self.mobID.material.Data4[i])
            
        l.append(self.mobID.material.Data1)
        l.append(self.mobID.material.Data2)
        l.append(self.mobID.material.Data3)
        
        return l
    
    def to_dict(self):
        
        material = {'Data1': self.mobID.material.Data1,
                    'Data2': self.mobID.material.Data2,
                    'Data3': self.mobID.material.Data3,
                    'Data4': [self.mobID.material.Data4[i] for i in xrange(8)]
                    }
        SMPTELabel = [self.mobID.SMPTELabel[i] for i in xrange(12)]
        
        return {'material':material, 
                'length': self.mobID.length,
                'instanceHigh': self.mobID.instanceHigh,
                'instanceMid': self.mobID.instanceMid,
                'instanceLow': self.mobID.instanceLow,
                'SMPTELabel': SMPTELabel
                }
    
    def __richcmp__(x, y, int op):
        if op == 2 or 3:
            result = False
            if str(MobID(x)) == str(MobID(y)):
                result = True
            if op == 3:
                return not result
            return result
        
        raise NotImplemented("richcmp %d not not Implemented" % op)
        
    
    def __repr__(self):
        return '<%s.%s of %s at 0x%x>' % (
            self.__class__.__module__,
            self.__class__.__name__,
            str(self),
            id(self),
        )

    def __str__(self):
        
        f = "urn:smpte:umid:%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x." + \
             "%02x"  + \
             "%02x%02x%02x." + \
             "%02x%02x%02x%02x.%02x%02x%02x%02x.%08x.%04x%04x"
        mobID = self.mobID
        return f % (
             mobID.SMPTELabel[0], mobID.SMPTELabel[1], mobID.SMPTELabel[2],  mobID.SMPTELabel[3],
             mobID.SMPTELabel[4], mobID.SMPTELabel[5], mobID.SMPTELabel[6],  mobID.SMPTELabel[7],
             mobID.SMPTELabel[8], mobID.SMPTELabel[9], mobID.SMPTELabel[10], mobID.SMPTELabel[11],
             mobID.length,
             mobID.instanceHigh, mobID.instanceMid, mobID.instanceLow,
             mobID.material.Data4[0], mobID.material.Data4[1], mobID.material.Data4[2], mobID.material.Data4[3],
             mobID.material.Data4[4], mobID.material.Data4[5], mobID.material.Data4[6], mobID.material.Data4[7],
             mobID.material.Data1, mobID.material.Data2, mobID.material.Data3)<commit_msg>added material property<commit_after>cdef class MobID(object):

    def __init__(self, mobID = None):
        if not mobID:
            return
        if isinstance(mobID, dict):
            self._from_dict(mobID)
        elif isinstance(mobID, (tuple, list)):
            self._from_list(mobID)
        else:
            self._from_str(mobID)

    cdef object _from_str(self, object mob_id):
    
        s = str(mob_id).replace("urn:smpte:umid:" ,"")
        
        items = s.split(".")
        
        if len(items) != 8:
            raise ValueError("Invalid MobID")

        
        self.mobID.SMPTELabel[0] = int(items[0][:2], 16)
        self.mobID.SMPTELabel[1] = int(items[0][2:4], 16)
        self.mobID.SMPTELabel[2] = int(items[0][4:6], 16)
        self.mobID.SMPTELabel[3] = int(items[0][6:8], 16)
        
        self.mobID.SMPTELabel[4] = int(items[1][:2], 16)
        self.mobID.SMPTELabel[5] = int(items[1][2:4], 16)
        self.mobID.SMPTELabel[6] = int(items[1][4:6], 16)
        self.mobID.SMPTELabel[7] = int(items[1][6:8], 16)
        
        self.mobID.SMPTELabel[8] = int(items[2][:2], 16)
        self.mobID.SMPTELabel[9] = int(items[2][2:4], 16)
        self.mobID.SMPTELabel[10] = int(items[2][4:6], 16)
        self.mobID.SMPTELabel[11] = int(items[2][6:8], 16)
        
        self.mobID.length = int(items[3][:2], 16)
        
        self.mobID.instanceHigh = int(items[3][2:4], 16)
        self.mobID.instanceMid = int(items[3][4:6], 16)
        self.mobID.instanceLow = int(items[3][6:8], 16)
        
        self.mobID.material.Data4[0] = int(items[4][:2], 16)
        self.mobID.material.Data4[1] = int(items[4][2:4], 16)
        self.mobID.material.Data4[2] = int(items[4][4:6], 16)
        self.mobID.material.Data4[3] = int(items[4][6:8], 16)
        
        self.mobID.material.Data4[4] = int(items[5][:2], 16)
        self.mobID.material.Data4[5] = int(items[5][2:4], 16)
        self.mobID.material.Data4[6] = int(items[5][4:6], 16)
        self.mobID.material.Data4[7] = int(items[5][6:8], 16)
        
        self.mobID.material.Data1 = int(items[6], 16)
        
        self.mobID.material.Data2 = int(items[7][0:4], 16)
        self.mobID.material.Data3 = int(items[7][4:], 16)
        
    cdef object _from_list(self, object id_list):
        f = "urn:smpte:umid:%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x." + \
             "%02x"  + \
             "%02x%02x%02x." + \
             "%02x%02x%02x%02x.%02x%02x%02x%02x.%08x.%04x%04x"
             
        self._from_str(f % tuple(id_list))
    
    cdef object _from_dict(self, dict d):
        self.mobID.length = d.get("length", 0)
        self.mobID.instanceHigh = d.get("instanceHigh", 0)
        self.mobID.instanceMid = d.get("instanceMid", 0)
        self.mobID.instanceLow = d.get("instanceLow", 0)
        
        material = d.get("material", {'Data1':0, 'Data2':0, 'Data3':0})
        
        self.mobID.material.Data1 = material.get('Data1', 0)
        self.mobID.material.Data2 = material.get('Data2', 0)
        self.mobID.material.Data3 = material.get('Data3', 0)
        
        Data4 = material.get("Data4", [0 for i in xrange(8)])
        
        for i in xrange(8):
            if i >= len(Data4):
                break
            self.mobID.material.Data4[i] = Data4[i]
            
        SMPTELabel = d.get("SMPTELabel", [0 for i in xrange(12)])
        for i in xrange(12):
            if i >= len(SMPTELabel):
                break
            self.mobID.SMPTELabel[i] = SMPTELabel[i]


    cdef lib.aafMobID_t get_aafMobID_t(self):
        return self.mobID
    
    @staticmethod
    def from_dict(dict d):
        return MobID(d)

    @staticmethod
    def from_list(mobid_list):
        return MobID(mobid_list)
    
    def to_list(self):
        l = []
        for i in xrange(12):
            l.append(self.mobID.SMPTELabel[i])
        
        l.append(self.mobID.length)
        l.append(self.mobID.instanceHigh)
        l.append(self.mobID.instanceMid)
        l.append(self.mobID.instanceLow)
        
        for i in xrange(8):
            l.append(self.mobID.material.Data4[i])
            
        l.append(self.mobID.material.Data1)
        l.append(self.mobID.material.Data2)
        l.append(self.mobID.material.Data3)
        
        return l
    
    def to_dict(self):
        
        material = {'Data1': self.mobID.material.Data1,
                    'Data2': self.mobID.material.Data2,
                    'Data3': self.mobID.material.Data3,
                    'Data4': [self.mobID.material.Data4[i] for i in xrange(8)]
                    }
        SMPTELabel = [self.mobID.SMPTELabel[i] for i in xrange(12)]
        
        return {'material':material, 
                'length': self.mobID.length,
                'instanceHigh': self.mobID.instanceHigh,
                'instanceMid': self.mobID.instanceMid,
                'instanceLow': self.mobID.instanceLow,
                'SMPTELabel': SMPTELabel
                }
    
    def __richcmp__(x, y, int op):
        if op == 2 or 3:
            result = False
            if str(MobID(x)) == str(MobID(y)):
                result = True
            if op == 3:
                return not result
            return result
        
        raise NotImplemented("richcmp %d not not Implemented" % op)
        
    
    def __repr__(self):
        return '<%s.%s of %s at 0x%x>' % (
            self.__class__.__module__,
            self.__class__.__name__,
            str(self),
            id(self),
        )

    def __str__(self):
        
        f = "urn:smpte:umid:%02x%02x%02x%02x.%02x%02x%02x%02x.%02x%02x%02x%02x." + \
             "%02x"  + \
             "%02x%02x%02x." + \
             "%02x%02x%02x%02x.%02x%02x%02x%02x.%08x.%04x%04x"
        mobID = self.mobID
        return f % (
             mobID.SMPTELabel[0], mobID.SMPTELabel[1], mobID.SMPTELabel[2],  mobID.SMPTELabel[3],
             mobID.SMPTELabel[4], mobID.SMPTELabel[5], mobID.SMPTELabel[6],  mobID.SMPTELabel[7],
             mobID.SMPTELabel[8], mobID.SMPTELabel[9], mobID.SMPTELabel[10], mobID.SMPTELabel[11],
             mobID.length,
             mobID.instanceHigh, mobID.instanceMid, mobID.instanceLow,
             mobID.material.Data4[0], mobID.material.Data4[1], mobID.material.Data4[2], mobID.material.Data4[3],
             mobID.material.Data4[4], mobID.material.Data4[5], mobID.material.Data4[6], mobID.material.Data4[7],
             mobID.material.Data1, mobID.material.Data2, mobID.material.Data3)
        
    property material:
        
        def __get__(self):
            cdef AUID auid = AUID()
            auid.auid = self.mobID.material
            return auid
{'fraction_non_alphanumeric': 0.15231537530266342, 'fraction_numerical': 0.0537227602905569, 'mean_word_length': 1.9022837066315328, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, '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': '611126', 'n_tokens_mistral': 5243, 'n_tokens_neox': 4903, 'n_words': 709}