1
1
import importlib
2
2
import pkgutil
3
3
4
+
4
5
def snake_to_camel (snake_case_string ):
5
- return snake_case_string .replace ('_' , ' ' ).title ().replace (' ' ,'' )
6
+ return snake_case_string .replace ("_" , " " ).title ().replace (" " , "" )
7
+
6
8
7
9
class TableCache :
8
10
def __init__ (self , table_class ):
@@ -27,26 +29,28 @@ def delete_entry(self, key):
27
29
def get_entry (self , key ):
28
30
if key in self .entries :
29
31
return self .entries [key ]
30
-
32
+
31
33
def values (self ):
32
34
return self .entries .values ()
33
35
34
36
35
37
class ClientCache :
36
38
def __init__ (self , autogen_package ):
37
-
38
39
self .tables = {}
39
40
self .reducer_cache = {}
40
41
41
- for importer , module_name , is_package in pkgutil .iter_modules (autogen_package .__path__ ):
42
+ for importer , module_name , is_package in pkgutil .iter_modules (
43
+ autogen_package .__path__
44
+ ):
42
45
if not is_package :
43
46
module = importlib .import_module (
44
- f"{ autogen_package .__name__ } .{ module_name } " )
47
+ f"{ autogen_package .__name__ } .{ module_name } "
48
+ )
45
49
46
50
# check if its a reducer
47
51
if module_name .endswith ("_reducer" ):
48
- reducer_name = module_name [: - len ( "_reducer" )]
49
- args_class = getattr (module ,"_decode_args" )
52
+ reducer_name = getattr ( module , "reducer_name" )
53
+ args_class = getattr (module , "_decode_args" )
50
54
self .reducer_cache [reducer_name ] = args_class
51
55
else :
52
56
# Assuming table class name is the same as the module name
@@ -56,11 +60,11 @@ def __init__(self, autogen_package):
56
60
table_class = getattr (module , table_class_name )
57
61
58
62
# Check for a special property, e.g. 'is_table_class'
59
- if getattr (table_class , ' is_table_class' , False ):
63
+ if getattr (table_class , " is_table_class" , False ):
60
64
self .tables [table_class_name ] = TableCache (table_class )
61
65
62
66
def get_table_cache (self , table_name ):
63
- return self .tables [table_name ]
67
+ return self .tables [table_name ]
64
68
65
69
def decode (self , table_name , value ):
66
70
if not table_name in self .tables :
@@ -94,5 +98,5 @@ def get_entry(self, table_name, key):
94
98
if not table_name in self .tables :
95
99
print (f"[get_entry] Error, table not found. ({ table_name } )" )
96
100
return
97
-
98
- return self .tables [table_name ].get_entry (key )
101
+
102
+ return self .tables [table_name ].get_entry (key )
0 commit comments