codernity avatar codernity committed 9eb5652

Small code pretify

Comments (0)

Files changed (7)

CodernityDB/database_gevent.py

 
 class GeventDatabase(SafeDatabase):
     pass
-
-    # """
-    # A database that works with Gevent
-    # """
-
-    # def __init__(self, path):
-    #     super(GeventDatabase, self).__init__(path)
-    #     self.main_lock = RLock()
-    #     self.close_open_lock = RLock()
-    #     self.indexes_locks = {}
-
-    # def initialize(self, *args, **kwargs):
-    #     res = None
-    #     try:
-    #         self.close_open_lock.acquire()
-    #         res = super(GeventDatabase, self).initialize(*args, **kwargs)
-    #         for name in self.indexes_names.iterkeys():
-    #             self.indexes_locks[name] = RLock()
-    #     finally:
-    #         self.close_open_lock.release()
-    #     return res
-
-    # def open(self, *args, **kwargs):
-    #     res = None
-    #     try:
-    #         self.close_open_lock.acquire()
-    #         res = super(GeventDatabase, self).open(*args, **kwargs)
-    #         for name in self.indexes_names.iterkeys():
-    #             self.indexes_locks[name] = RLock()
-    #     finally:
-    #         self.close_open_lock.release()
-    #     return res
-
-    # def create(self, *args, **kwargs):
-    #     res = None
-    #     try:
-    #         self.close_open_lock.acquire()
-    #         res = super(GeventDatabase, self).create(*args, **kwargs)
-    #         for name in self.indexes_names.iterkeys():
-    #             self.indexes_locks[name] = RLock()
-    #     finally:
-    #         self.close_open_lock.release()
-    #     return res
-
-    # def close(self):
-    #     res = None
-    #     try:
-    #         self.close_open_lock.acquire()
-    #         res = super(GeventDatabase, self).close()
-    #     finally:
-    #         self.close_open_lock.release()
-    #     return res
-
-    # def destroy(self):
-    #     res = None
-    #     try:
-    #         self.close_open_lock.acquire()
-    #         res = super(GeventDatabase, self).destroy()
-    #     finally:
-    #         self.close_open_lock.release()
-    #         return res
-
-    # def add_index(self, *args, **kwargs):
-    #     res = None
-    #     try:
-    #         self.main_lock.acquire()
-    #         res = super(GeventDatabase, self).add_index(*args, **kwargs)
-    #     finally:
-    #         if self.opened:
-    #             self.indexes_locks[res] = RLock()
-    #         self.main_lock.release()
-    #     return res
-
-    # def edit_index(self, *args, **kwargs):
-    #     res = None
-    #     try:
-    #         self.main_lock.acquire()
-    #         res = super(GeventDatabase, self).edit_index(*args, **kwargs)
-    #     finally:
-    #         if self.opened:
-    #             self.indexes_locks[res] = RLock()
-    #         self.main_lock.release()
-    #     return res
-
-    # def set_indexes(self, *args, **kwargs):
-    #     try:
-    #         self.main_lock.acquire()
-    #         super(GeventDatabase, self).set_indexes(*args, **kwargs)
-    #     finally:
-    #         self.main_lock.release()
-
-    # def _read_indexes(self, *args, **kwargs):
-    #     try:
-    #         self.main_lock.acquire()
-    #         super(GeventDatabase, self)._read_indexes(*args, **kwargs)
-    #     finally:
-    #         self.main_lock.release()
-
-    # def insert_id_index(self, *args, **kwargs):
-    #     lock = self.indexes_locks['id']
-    #     try:
-    #         lock.acquire()
-    #         res = super(GeventDatabase, self).insert_id_index(*args, **kwargs)
-    #     finally:
-    #         lock.release()
-    #     return res
-
-    # def update_id_index(self, *args, **kwargs):
-    #     lock = self.indexes_locks['id']
-    #     res = None
-    #     try:
-    #         lock.acquire()
-    #         res = super(GeventDatabase, self).update_id_index(*args, **kwargs)
-    #     finally:
-    #         lock.release()
-    #     return res
-
-    # def delete_id_index(self, *args, **kwargs):
-    #     lock = self.indexes_locks['id']
-    #     res = None
-    #     try:
-    #         lock.acquire()
-    #         res = super(GeventDatabase, self).delete_id_index(*args, **kwargs)
-    #     finally:
-    #         lock.release()
-    #     return res
-
-    # def single_update_index(self, index, *args, **kwargs):
-    #     lock = self.indexes_locks[index.name]
-    #     try:
-    #         lock.acquire()
-    #         super(GeventDatabase, self).single_update_index(
-    #             index, *args, **kwargs)
-    #     finally:
-    #         lock.release()
-
-    # def single_insert_index(self, index, *args, **kwargs):
-    #     lock = self.indexes_locks[index.name]
-    #     try:
-    #         lock.acquire()
-    #         super(GeventDatabase, self).single_insert_index(
-    #             index, *args, **kwargs)
-    #     finally:
-    #         lock.release()
-
-    # def single_delete_index(self, index, *args, **kwargs):
-    #     lock = self.indexes_locks[index.name]
-    #     try:
-    #         lock.acquire()
-    #         super(GeventDatabase, self).single_delete_index(
-    #             index, *args, **kwargs)
-    #     finally:
-    #         lock.release()
-
-    # def single_compact_index(self, index, *args, **kwargs):
-    #     lock = self.indexes_locks[index.name]
-    #     try:
-    #         lock.acquire()
-    #         super(GeventDatabase, self).compact_index(index, *args, **kwargs)
-    #     finally:
-    #         lock.release()
-
-    # def reindex_index(self, index, *args, **kwargs):
-    #     if isinstance(index, basestring):
-    #         if not index in self.indexes_names:
-    #             raise PreconditionsException("No index named %s" % index)
-    #         index = self.indexes_names[index]
-    #     key = index.name + "reind"
-    #     self.main_lock.acquire()
-    #     if key in self.indexes_locks:
-    #         lock = self.indexes_locks[index.name + "reind"]
-    #     else:
-    #         self.indexes_locks[index.name + "reind"] = RLock()
-    #         lock = self.indexes_locks[index.name + "reind"]
-    #     self.main_lock.release()
-    #     try:
-    #         lock.acquire()
-    #         super(GeventDatabase, self).reindex_index(index, *args, **kwargs)
-    #     finally:
-    #         lock.release()
-
-    # def destroy_index(self, index, *args, **kwargs):
-    #     if isinstance(index, basestring):
-    #         if not index in self.indexes_names:
-    #             raise PreconditionsException("No index named %s" % index)
-    #         index = self.indexes_names[index]
-    #     lock = self.indexes_locks[index.name]
-    #     try:
-    #         lock.acquire()
-    #         super(GeventDatabase, self).destroy_index(index, *args, **kwargs)
-    #     finally:
-    #         lock.release()
-
-    # def flush(self):
-    #     try:
-    #         self.main_lock.acquire()
-    #         super(GeventDatabase, self).flush()
-    #     finally:
-    #         self.main_lock.release()
-
-    # def fsync(self):
-    #     try:
-    #         self.main_lock.acquire()
-    #         super(GeventDatabase, self).fsync()
-    #     finally:
-    #         self.main_lock.release()

CodernityDB/database_safe_shared.py

 
 from CodernityDB.env import cdb_environment
 from CodernityDB.database import PreconditionsException, RevConflict, Database
-#from database import Database
+# from database import Database
 
 from collections import defaultdict
 from functools import wraps

CodernityDB/indexcreator.py

                 if i not in self.allowed_props[self.index_type]:
                     raise IndexCreatorValueException("Properity %s is not allowed for index type: %s" % (i, self.index_type))
 
-        #print "".join(self.tokens_head)
-        #print "----------"
-        #print (" ".join(self.tokens))
+        # print "".join(self.tokens_head)
+        # print "----------"
+        # print (" ".join(self.tokens))
         return "".join(self.custom_header), "".join(self.tokens_head) + (" ".join(self.tokens))
 
     # has to be run BEFORE tokenize

CodernityDB/rr_cache.py

                 result = cache[args[0]][args[1]]
             except KeyError:
 #                print wrapper.cache_size
-                if  wrapper.cache_size == maxsize:
+                if wrapper.cache_size == maxsize:
                     to_delete = maxsize // 10 or 1
                     for i in xrange(to_delete):
                         key1 = choice(cache.keys())

CodernityDB/sharded_hash.py

         if kwargs.get('sh_nums', 0) > 255:
             raise IndexPreconditionsException("Too many shards")
         kwargs['ind_class'] = UniqueHashIndex
-        super(IU_ShardedUniqueHashIndex, self).__init__(db_path, name, *args, **kwargs)
+        super(IU_ShardedUniqueHashIndex, self).__init__(db_path,
+                                                        name, *args, **kwargs)
         self.patchers.append(ShardedUniqueHashIndex.wrap_insert_id_index)
 
     @staticmethod
             return _id
         if not clean:
             if hasattr(db_obj, '_insert_id_index_orig'):
-                raise IndexPreconditionsException("Already patched, something went wrong")
+                raise IndexPreconditionsException(
+                    "Already patched, something went wrong")
             setattr(db_obj, "_insert_id_index_orig", db_obj._insert_id_index)
             setattr(db_obj, "_insert_id_index", _insert_id_index)
         else:
 
     def __init__(self, db_path, name, *args, **kwargs):
         kwargs['ind_class'] = HashIndex
-        super(IU_ShardedHashIndex, self).__init__(db_path, name, *args, **kwargs)
+        super(IU_ShardedHashIndex, self).__init__(db_path, name, *
+                                                  args, **kwargs)
 
     def calculate_shard(self, key):
         """

tests/test_indexcreator_db.py

     for i in data:
         db.insert({key_name: i})
 
-    #for i in db.all(name):
-        #print i
+    # for i in db.all(name):
+        # print i
 
     for i, k in keys:
         if k is None:

tests/test_indexcreator_exec.py

 
 
 # This test are for checking Parser only, using simple exec isn't exactly what database does with simple index code,
-# they are used only because they allow handy check of correctness of generated code
+# they are used only because they allow handy check of correctness of
+# generated code
 
 from CodernityDB.indexcreator import Parser, IndexCreatorValueException, IndexCreatorFunctionException
 from CodernityDB.database import Database, RecordNotFound
         make_key_value:
         md5(b),a"""
 
-        simple_compare(s, [({'a': 'a'}, (md5('a').digest(), {'a':'a'})),
+        simple_compare(s, [({'a': 'a'}, (md5('a').digest(), {'a': 'a'})),
                            ({'a': 'qwerty'}, (
-                            md5('qwerty').digest(), {'a':'qwerty'}))
+                            md5('qwerty').digest(), {'a': 'qwerty'}))
                            ],
                        [
                        ({'a': 'e'}, md5('e').digest()),
                        ({'a': 'qwerty'}, md5('qwerty').digest())
                        ])
-        simple_compare(s2, [({'a': 'a'}, ('a', {'a':'a'})),
-                            ({'a': 'qwerty'}, ('qwerty', {'a':'qwerty'}))
+        simple_compare(s2, [({'a': 'a'}, ('a', {'a': 'a'})),
+                            ({'a': 'qwerty'}, ('qwerty', {'a': 'qwerty'}))
                             ],
                        [
                        ({'a': 'e'}, md5('e').digest()),
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.