Exemple #1
0
class TestBTreesUnicode(unittest.TestCase):
    """ test unicode"""
    def setUp(self):
        #setup an OOBTree with some unicode strings
        from BTrees.OOBTree import OOBTree

        self.s = b'dreit\xe4gigen'.decode('latin1')

        self.data = [
            (b'alien', 1),
            (b'k\xf6nnten', 2),
            (b'fox', 3),
            (b'future', 4),
            (b'quick', 5),
            (b'zerst\xf6rt', 6),
            (u'dreit\xe4gigen', 7),
        ]

        self.tree = OOBTree()
        for k, v in self.data:
            if isinstance(k, bytes):
                k = k.decode('latin1')
            self.tree[k] = v

    def testAllKeys(self):
        # check every item of the tree
        for k, v in self.data:
            if isinstance(k, bytes):
                k = k.decode(encoding)
            self.assertIn(k, self.tree)
            self.assertEqual(self.tree[k], v)

    def testUnicodeKeys(self):
        # try to access unicode keys in tree
        k, v = self.data[-1]
        self.assertEqual(k, self.s)
        self.assertEqual(self.tree[k], v)
        self.assertEqual(self.tree[self.s], v)

    def testAsciiKeys(self):
        # try to access some "plain ASCII" keys in the tree;
        # they get upconverted to unicode for comparison on Python 2
        for k, v in self.data[0], self.data[2]:
            self.assertIsInstance(k, bytes)
            if bytes is str:
                self.assertEqual(self.tree[k], v)
            else:
                with self.assertRaises(TypeError):
                    self.tree.__getitem__(k)
Exemple #2
0
    def __getitem__(self, item):
        if not isinstance(item, slice):
            return OOBTree.__getitem__(self, item)

        # Performance shortcuts
        if item.start is None and item.stop is None:
            if item.step == -1:
                return reversed(OOBTree.values(self))
            if item.step == 1 or item.step is None:
                return OOBTree.values(self)

        keys = OOBTree.keys(self, min=item.start, max=item.stop)
        if item.step and item.step < 0:
            return (OOBTree.__getitem__(self, keys[i - 1])
                    for i in range(len(keys), 0, item.step))

        return (OOBTree.__getitem__(self, keys[i])
                for i in range(0, len(keys), item.step or 1))
Exemple #3
0
 def __getitem__(self, key): 
     return OOBTree.__getitem__(self, key).data
Exemple #4
0
 def __getitem__(self, key):
     if key == 'display':
         return OOBTree.__getitem__(self, key)
     else:
         return OOBTree.__getitem__(self, key).data
Exemple #5
0
        self.row_num = []
        self.business_id = []
    def insert(self,row,b_id):
        self.row_num.append(row)
        self.business_id.append(b_id)
        

        
datas = pandas.read_csv(path+"review-1m.csv")
for i in range (datas.shape[0]):
    print(i)
    row = i
    b_id = datas.iloc[row]['business_id']
    key = datas.iloc[row]['useful']
    if t.has_key(key):
        c = t.__getitem__(key)
        c.insert(row,b_id)
        t.update({key:c})
    else:
        c = content()
        c.insert(row,b_id)
        t.update({key:c})
        
funny_file = open(r'../test/useful.pkl', 'wb')
pickle.dump(t, funny_file)
funny_file.close()
#c = content(1)
#c.insert(1,100,200)
#c.insert(1,200,300)
#print(c.key,c.row_num,c.business_id)
#
Exemple #6
0
 def __getitem__(self, key):
     return OOBTree.__getitem__(self, key).data
Exemple #7
0
        self.row_num = []
        self.business_id = []

    def insert(self, row, b_id):
        self.row_num.append(row)
        self.business_id.append(b_id)


datas = pandas.read_csv(path + "review-1m.csv")
for i in range(datas.shape[0]):
    print(i)
    row = i
    b_id = datas.iloc[row]['business_id']
    key = datas.iloc[row]['useful']
    if t.has_key(key):
        c = t.__getitem__(key)
        c.insert(row, b_id)
        t.update({key: c})
    else:
        c = content()
        c.insert(row, b_id)
        t.update({key: c})

funny_file = open(r'../test/useful.pkl', 'wb')
pickle.dump(t, funny_file)
funny_file.close()
#c = content(1)
#c.insert(1,100,200)
#c.insert(1,200,300)
#print(c.key,c.row_num,c.business_id)
#
Exemple #8
0
 def __getitem__(self, key):  
     if key == 'display':
         return OOBTree.__getitem__(self, key)
     else:
         return OOBTree.__getitem__(self, key).data