initial commit
This commit is contained in:
		
							parent
							
								
									69d0f7498e
								
							
						
					
					
						commit
						32d18c880b
					
				
							
								
								
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										2
									
								
								.gitignore
									
									
									
									
										vendored
									
									
										Normal file
									
								
							@ -0,0 +1,2 @@
 | 
				
			|||||||
 | 
					.idea/
 | 
				
			||||||
 | 
					**/__pycache__/
 | 
				
			||||||
							
								
								
									
										34
									
								
								examples.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								examples.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					from pseudodb import pseudodb
 | 
				
			||||||
 | 
					from utils.file_utils import search_path
 | 
				
			||||||
 | 
					from utils.str_utils import obscure, unobscure, get_random_string, get_dash_suffix
 | 
				
			||||||
 | 
					from utils.misc_utils import immutable_to_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					if __name__ == '__main__':
 | 
				
			||||||
 | 
					    db = pseudodb.PseudoDB('pseudodb.default.data')
 | 
				
			||||||
 | 
					    print("Collections in Pseudodb: "+str(db.data_list()))
 | 
				
			||||||
 | 
					    for collection in db.data_list():
 | 
				
			||||||
 | 
					        print("Collection: "+collection)
 | 
				
			||||||
 | 
					        for key in db.get_keys(collection):
 | 
				
			||||||
 | 
					            print(key+": "+str(db.get_values(collection, key)))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    immutable_list = ('one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine')
 | 
				
			||||||
 | 
					    print("Immutable: "+str(immutable_list))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    shuffled_list = immutable_to_list(immutable_list, scramble=True)
 | 
				
			||||||
 | 
					    print("Shuffled Mutable: "+str(shuffled_list))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    files = search_path("./utils", "misc")
 | 
				
			||||||
 | 
					    print("Search Results: "+str(files))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    rando_string = get_random_string(30, caps=True, numbers=True, specials=True)
 | 
				
			||||||
 | 
					    print("Random: "+rando_string)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    obscured = obscure(rando_string)
 | 
				
			||||||
 | 
					    print("Obscured: "+str(obscured))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    unobscured = unobscure(obscured)
 | 
				
			||||||
 | 
					    print("Unobscured: "+unobscured)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    dash_suffix = get_dash_suffix("example-silly-string-with-dashes-"+get_random_string(10))
 | 
				
			||||||
 | 
					    print("Suffix found: "+dash_suffix)
 | 
				
			||||||
							
								
								
									
										0
									
								
								pseudodb/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								pseudodb/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										0
									
								
								pseudodb/default/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								pseudodb/default/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										16
									
								
								pseudodb/default/data.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								pseudodb/default/data.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					names = {
 | 
				
			||||||
 | 
					    "male": ["Greg", "John", "Edward", "Francis", "Charles", "Luke", "Thomas"],
 | 
				
			||||||
 | 
					    "female": ["Doreen", "Janice", "Sue", "Mary", "Lisa", "Janine", "Doris"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					cars = {
 | 
				
			||||||
 | 
					    "chevy": ["Blazer", "Tahoe", "Caprice", "Suburban", "Silverado"],
 | 
				
			||||||
 | 
					    "ford": ["Mustang", "Bronco", "Focus", "Taurus", "Escape"],
 | 
				
			||||||
 | 
					    "chrysler": ["Sebring", "Crossfire", "Pacifica", "Voyager"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					languages = {
 | 
				
			||||||
 | 
					    "compiled": ["C++", "C#", "C", "Assembler", "Rust", "Go"],
 | 
				
			||||||
 | 
					    "interpreted": ["Ruby", "Rexx", "Perl"],
 | 
				
			||||||
 | 
					    "bytecode": ["Java", "Python", "VisualBasic"]
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										51
									
								
								pseudodb/pseudodb.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										51
									
								
								pseudodb/pseudodb.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,51 @@
 | 
				
			|||||||
 | 
					import importlib
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class PseudoDB:
 | 
				
			||||||
 | 
					    def __init__(self, datasource="default.data"):
 | 
				
			||||||
 | 
					        self.datasource = datasource
 | 
				
			||||||
 | 
					        self.data = self.load_data()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def load_data(self):
 | 
				
			||||||
 | 
					        module_name = self.datasource.replace('.py', '')
 | 
				
			||||||
 | 
					        try:
 | 
				
			||||||
 | 
					            module = importlib.import_module(module_name)
 | 
				
			||||||
 | 
					            return module
 | 
				
			||||||
 | 
					        except ImportError:
 | 
				
			||||||
 | 
					            print(f"Data module '{module_name}' not found.")
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def data_list(self):
 | 
				
			||||||
 | 
					        # Check if default has been successfully loaded
 | 
				
			||||||
 | 
					        if self.data is not None:
 | 
				
			||||||
 | 
					            attr_names = []
 | 
				
			||||||
 | 
					            for attr_name in dir(self.data):
 | 
				
			||||||
 | 
					                if not attr_name.startswith('__'):
 | 
				
			||||||
 | 
					                    attr_names.append(attr_name)
 | 
				
			||||||
 | 
					            return attr_names
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return []
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def collections(self, attr_name):
 | 
				
			||||||
 | 
					        if self.data is not None:
 | 
				
			||||||
 | 
					            return getattr(self.data, attr_name)
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_keys(self, attr_name):
 | 
				
			||||||
 | 
					        if self.data is not None:
 | 
				
			||||||
 | 
					            collection = getattr(self.data, attr_name)
 | 
				
			||||||
 | 
					            if isinstance(collection, dict):
 | 
				
			||||||
 | 
					                return list(collection.keys())
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    def get_values(self, attr_name, key):
 | 
				
			||||||
 | 
					        if self.data is not None:
 | 
				
			||||||
 | 
					            collection = getattr(self.data, attr_name)
 | 
				
			||||||
 | 
					            if isinstance(collection, dict):
 | 
				
			||||||
 | 
					                return list(collection[key])
 | 
				
			||||||
 | 
					            else:
 | 
				
			||||||
 | 
					                return collection
 | 
				
			||||||
 | 
					        else:
 | 
				
			||||||
 | 
					            return None
 | 
				
			||||||
							
								
								
									
										0
									
								
								utils/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								utils/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										21
									
								
								utils/file_utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										21
									
								
								utils/file_utils.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,21 @@
 | 
				
			|||||||
 | 
					import os
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def search_path(path, substring):
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    given a search substring, retrieve all the files in the Store
 | 
				
			||||||
 | 
					    that have that substring in them.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Args:
 | 
				
			||||||
 | 
					        path (string): path to search
 | 
				
			||||||
 | 
					        substring (string): the string to be matched against
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Returns:
 | 
				
			||||||
 | 
					        list: a pythonized list of all the files in which the search
 | 
				
			||||||
 | 
					              substring is contained.
 | 
				
			||||||
 | 
					    """
 | 
				
			||||||
 | 
					    matched_files = [matched_file
 | 
				
			||||||
 | 
					                     for matched_file in os.listdir(path)
 | 
				
			||||||
 | 
					                     if substring in matched_file]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return matched_files
 | 
				
			||||||
							
								
								
									
										16
									
								
								utils/misc_utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								utils/misc_utils.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,16 @@
 | 
				
			|||||||
 | 
					from random import shuffle
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def immutable_to_list(immutable, scramble=False, prune=0):
 | 
				
			||||||
 | 
					    indices = list(range(len(immutable)))
 | 
				
			||||||
 | 
					    if scramble:
 | 
				
			||||||
 | 
					        shuffle(indices)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    python_list = [immutable[i] for i in indices]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    if prune > 0:
 | 
				
			||||||
 | 
					        del python_list[prune:]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return python_list
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
							
								
								
									
										36
									
								
								utils/str_utils.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								utils/str_utils.py
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,36 @@
 | 
				
			|||||||
 | 
					import random
 | 
				
			||||||
 | 
					import string
 | 
				
			||||||
 | 
					import base64
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def obscure(content):
 | 
				
			||||||
 | 
					    data = content.encode('utf-8')
 | 
				
			||||||
 | 
					    return base64.b64encode(data)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def unobscure(content):
 | 
				
			||||||
 | 
					    data = content.decode('utf-8')
 | 
				
			||||||
 | 
					    return str(base64.b64decode(data))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_random_string(length, caps=False, numbers=False, specials=False):
 | 
				
			||||||
 | 
					    letters = string.ascii_lowercase
 | 
				
			||||||
 | 
					    if caps:
 | 
				
			||||||
 | 
					        letters += string.ascii_uppercase
 | 
				
			||||||
 | 
					    if numbers:
 | 
				
			||||||
 | 
					        letters += string.digits
 | 
				
			||||||
 | 
					    if specials:
 | 
				
			||||||
 | 
					        letters += string.punctuation
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    return ''.join(random.choice(letters) for _ in range(length))
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_colon_prefix(content):
 | 
				
			||||||
 | 
					    split_string = content.split(":", 1)
 | 
				
			||||||
 | 
					    return split_string[0].strip()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def get_dash_suffix(content):
 | 
				
			||||||
 | 
					    last_dash = content.rfind("-")
 | 
				
			||||||
 | 
					    rando = content[last_dash + 1:]
 | 
				
			||||||
 | 
					    return rando
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user