prompt
large_stringlengths
72
9.34k
completion
large_stringlengths
0
7.61k
<|file_name|>datastore_summary_maintenance_mode_state.py<|end_file_name|><|fim▁begin|>######################################## # Automatically generated, do not edit. ######################################## <|fim▁hole|> DatastoreSummaryMaintenanceModeState = Enum( 'enteringMaintenance', 'inMaintenance', 'normal', )<|fim▁end|>
from pyvisdk.thirdparty import Enum
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None):<|fim▁hole|> query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0<|fim▁end|>
query = {} if email is not None:
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): <|fim_middle|> class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): <|fim_middle|> pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
Exception.__init__(self, message)
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): <|fim_middle|> class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!")
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): <|fim_middle|> @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
Exception.__init__(self, message)
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): <|fim_middle|> class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
return UserServiceException("Cannot delete super admin user!")
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): <|fim_middle|> <|fim▁end|>
def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): <|fim_middle|> def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
self.db = db self.users = self.db.user_collection
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): <|fim_middle|> def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20))
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): <|fim_middle|> def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item)
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): <|fim_middle|> def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
return self.users.find_one({"email": email})
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): <|fim_middle|> def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
query = {'email': username, 'password': password} return self.users.find(query).count() > 0
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): <|fim_middle|> def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)]
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): <|fim_middle|> def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)})
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): <|fim_middle|> def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
return self.users.find_one({"_id": ObjectId(id)})
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): <|fim_middle|> def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
return self.users.find_one({"api_key": api_key})
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): <|fim_middle|> def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): <|fim_middle|> <|fim▁end|>
query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): <|fim_middle|> item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
raise DuplicateUserException()
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: <|fim_middle|> if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
item['api_key'] = self.generate_api_key()
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: <|fim_middle|> return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
item['roles'] = ['member']
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: <|fim_middle|> return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
query['email'] = email
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: <|fim_middle|> return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
raise UserServiceException.cannot_delete_super_admin()
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: <|fim_middle|> if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
return item
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): <|fim_middle|> item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
raise DuplicateUserException()
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: <|fim_middle|> query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
query = {"_id": {"$ne": ObjectId(id)}}
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def <|fim_middle|>(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
__init__
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def <|fim_middle|>(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
__init__
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def <|fim_middle|>(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
cannot_delete_super_admin
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def <|fim_middle|>(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
__init__
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def <|fim_middle|>(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
generate_api_key
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def <|fim_middle|>(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
create
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def <|fim_middle|>(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
get_by_email
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def <|fim_middle|>(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
validate_user
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def <|fim_middle|>(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
search
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def <|fim_middle|>(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
delete
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def <|fim_middle|>(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
get_by_id
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def <|fim_middle|>(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
get_by_api_key
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def <|fim_middle|>(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def user_exists(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
update
<|file_name|>UserService.py<|end_file_name|><|fim▁begin|>from datetime import datetime import random import string from bson import ObjectId class DuplicateUserException(Exception): def __init__(self, message='User name/email already exits'): Exception.__init__(self, message) pass class UserServiceException(Exception): def __init__(self, message=None): Exception.__init__(self, message) @classmethod def cannot_delete_super_admin(cls): return UserServiceException("Cannot delete super admin user!") class UserService(object): def __init__(self, db): self.db = db self.users = self.db.user_collection def generate_api_key(self): s = string.ascii_letters + string.digits return ''.join(random.sample(s, 20)) def create(self, item): if self.user_exists(item['email']): raise DuplicateUserException() item.pop('_id', None) item['created_at'] = datetime.now() item['status'] = True if 'api_key' not in item: item['api_key'] = self.generate_api_key() if 'roles' not in item or item['roles'] is None or len(item['roles']) == 0: item['roles'] = ['member'] return self.users.insert(item) def get_by_email(self, email): return self.users.find_one({"email": email}) def validate_user(self, username, password): query = {'email': username, 'password': password} return self.users.find(query).count() > 0 def search(self, email=None): query = {} if email is not None: query['email'] = email return [x for x in self.users.find(query)] def delete(self, id): item = self.get_by_id(id) if item and 'roles' in item and item['roles'] is not None and 'super_admin' in item['roles']: raise UserServiceException.cannot_delete_super_admin() return self.users.remove({"_id": ObjectId(id)}) def get_by_id(self, id): return self.users.find_one({"_id": ObjectId(id)}) def get_by_api_key(self, api_key): return self.users.find_one({"api_key": api_key}) def update(self, item): if item['_id'] is None: return item if self.user_exists(item['email'], str(item['_id'])): raise DuplicateUserException() item['updated_at'] = datetime.now() self.users.save(item) return item def <|fim_middle|>(self, email, id=None): query = {} if id is not None: query = {"_id": {"$ne": ObjectId(id)}} query['email'] = email return self.users.find(query).count() > 0 <|fim▁end|>
user_exists
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK..<|fim▁hole|> def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {}<|fim▁end|>
self.arg_comp.validate_all() return tmp_arg_dict
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to <|fim_middle|> <|fim▁end|>
version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {}
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): <|fim_middle|> def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
pass
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): <|fim_middle|> def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options()
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): <|fim_middle|> def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
log = logger.Logger() self.logger = log.logger
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): <|fim_middle|> def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions <|fim_middle|> def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): <|fim_middle|> def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
""" Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): <|fim_middle|> def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
return self.__list_handlers().keys() + self.__base_methods.keys()
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): <|fim_middle|> def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
return self.version
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): <|fim_middle|> def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
return self.api_version
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): <|fim_middle|> def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
return self.description
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): <|fim_middle|> def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): <|fim_middle|> def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
""" Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): <|fim_middle|> <|fim▁end|>
""" That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {}
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): <|fim_middle|> return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
handlers[attr] = getattr(self, attr)
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': <|fim_middle|> return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
return True
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: <|fim_middle|> #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
return {}
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): <|fim_middle|> #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__))
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def <|fim_middle|>(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__init__
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def <|fim_middle|>(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__init_log
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def <|fim_middle|>(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__init_options
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def <|fim_middle|>(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
register_rpc
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def <|fim_middle|>(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__list_handlers
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def <|fim_middle|>(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__list_methods
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def <|fim_middle|>(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__module_version
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def <|fim_middle|>(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__module_api_version
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def <|fim_middle|>(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__module_description
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def <|fim_middle|>(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__is_public_valid_method
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def <|fim_middle|>(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def register_method_args(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
__get_method_args
<|file_name|>func_module.py<|end_file_name|><|fim▁begin|>## ## Copyright 2007, Red Hat, Inc ## see AUTHORS ## ## This software may be freely redistributed under the terms of the GNU ## general public license. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ## import inspect from func import logger from func.config import read_config, BaseConfig from func.commonconfig import FuncdConfig from func.minion.func_arg import * #the arg getter stuff class FuncModule(object): # the version is meant to version = "0.0.0" api_version = "0.0.0" description = "No Description provided" class Config(BaseConfig): pass def __init__(self): config_file = '/etc/func/minion.conf' self.config = read_config(config_file, FuncdConfig) self.__init_log() self.__base_methods = { # __'s so we don't clobber useful names "module_version" : self.__module_version, "module_api_version" : self.__module_api_version, "module_description" : self.__module_description, "list_methods" : self.__list_methods, "get_method_args" : self.__get_method_args, } self.__init_options() def __init_log(self): log = logger.Logger() self.logger = log.logger def __init_options(self): options_file = '/etc/func/modules/'+self.__class__.__name__+'.conf' self.options = read_config(options_file, self.Config) return def register_rpc(self, handlers, module_name): # add the internal methods, note that this means they # can get clobbbered by subclass versions for meth in self.__base_methods: handlers["%s.%s" % (module_name, meth)] = self.__base_methods[meth] # register our module's handlers for name, handler in self.__list_handlers().items(): handlers["%s.%s" % (module_name, name)] = handler def __list_handlers(self): """ Return a dict of { handler_name, method, ... }. All methods that do not being with an underscore will be exposed. We also make sure to not expose our register_rpc method. """ handlers = {} for attr in dir(self): if self.__is_public_valid_method(attr): handlers[attr] = getattr(self, attr) return handlers def __list_methods(self): return self.__list_handlers().keys() + self.__base_methods.keys() def __module_version(self): return self.version def __module_api_version(self): return self.api_version def __module_description(self): return self.description def __is_public_valid_method(self,attr): if inspect.ismethod(getattr(self, attr)) and attr[0] != '_' and\ attr != 'register_rpc' and attr!='register_method_args': return True return False def __get_method_args(self): """ Gets arguments with their formats according to ArgCompatibility class' rules. @return : dict with args or Raise Exception if something wrong happens """ tmp_arg_dict = self.register_method_args() #if it is not implemeted then return empty stuff if not tmp_arg_dict: return {} #see if user tried to register an not implemented method :) for method in tmp_arg_dict.iterkeys(): if not hasattr(self,method): raise NonExistingMethodRegistered("%s is not in %s "%(method,self.__class__.__name__)) #create argument validation instance self.arg_comp = ArgCompatibility(tmp_arg_dict) #see if all registered arguments are there for method in tmp_arg_dict.iterkeys(): self.arg_comp.is_all_arguments_registered(self,method,tmp_arg_dict[method]['args']) #see if the options that were used are OK.. self.arg_comp.validate_all() return tmp_arg_dict def <|fim_middle|>(self): """ That is the method where users should override in their modules according to be able to send their method arguments to the Overlord. If they dont have it nothing breaks just that one in the base class is called @return : empty {} """ # to know they didnt implement it return {} <|fim▁end|>
register_method_args
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def is_matchable_type(expected_type): if isinstance(expected_type, type):<|fim▁hole|> return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False<|fim▁end|>
return True if isinstance(expected_type, six.class_types):
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): <|fim_middle|> def is_matchable_type(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
"""Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x)
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def is_matchable_type(expected_type): <|fim_middle|> <|fim▁end|>
if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): <|fim_middle|> else: return equal_to(x) def is_matchable_type(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
return x
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: <|fim_middle|> def is_matchable_type(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
return equal_to(x)
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def is_matchable_type(expected_type): if isinstance(expected_type, type): <|fim_middle|> if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
return True
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def is_matchable_type(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): <|fim_middle|> if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
return True
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def is_matchable_type(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): <|fim_middle|> return False <|fim▁end|>
return True
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def <|fim_middle|>(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def is_matchable_type(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
wrap_matcher
<|file_name|>wrap_matcher.py<|end_file_name|><|fim▁begin|>import six from hamcrest.core.base_matcher import Matcher from hamcrest.core.core.isequal import equal_to __author__ = "Jon Reid" __copyright__ = "Copyright 2011 hamcrest.org" __license__ = "BSD, see License.txt" import types def wrap_matcher(x): """Wraps argument in a matcher, if necessary. :returns: the argument as-is if it is already a matcher, otherwise wrapped in an :py:func:`~hamcrest.core.core.isequal.equal_to` matcher. """ if isinstance(x, Matcher): return x else: return equal_to(x) def <|fim_middle|>(expected_type): if isinstance(expected_type, type): return True if isinstance(expected_type, six.class_types): return True if isinstance(expected_type, tuple) and \ expected_type and \ all(map(is_matchable_type, expected_type)): return True return False <|fim▁end|>
is_matchable_type
<|file_name|>item.py<|end_file_name|><|fim▁begin|># =============================================================================== # Copyright (C) 2010 Diego Duclos # # This file is part of eos. # # eos is free software: you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published by # the Free Software Foundation, either version 2 of the License, or # (at your option) any later version. # # eos is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with eos. If not, see <http://www.gnu.org/licenses/>. # =============================================================================== from sqlalchemy import Column, String, Integer, Boolean, ForeignKey, Table, Float from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.orm import relation, mapper, synonym, deferred from sqlalchemy.orm.collections import attribute_mapped_collection<|fim▁hole|> from eos.db import gamedata_meta from eos.types import Icon, Attribute, Item, Effect, MetaType, Group, Traits items_table = Table("invtypes", gamedata_meta, Column("typeID", Integer, primary_key=True), Column("typeName", String, index=True), Column("description", String), Column("raceID", Integer), Column("factionID", Integer), Column("volume", Float), Column("mass", Float), Column("capacity", Float), Column("published", Boolean), Column("marketGroupID", Integer, ForeignKey("invmarketgroups.marketGroupID")), Column("iconID", Integer, ForeignKey("icons.iconID")), Column("groupID", Integer, ForeignKey("invgroups.groupID"), index=True)) from .metaGroup import metatypes_table # noqa from .traits import traits_table # noqa mapper(Item, items_table, properties={"group": relation(Group, backref="items"), "icon": relation(Icon), "_Item__attributes": relation(Attribute, collection_class=attribute_mapped_collection('name')), "effects": relation(Effect, collection_class=attribute_mapped_collection('name')), "metaGroup": relation(MetaType, primaryjoin=metatypes_table.c.typeID == items_table.c.typeID, uselist=False), "ID": synonym("typeID"), "name": synonym("typeName"), "description": deferred(items_table.c.description), "traits": relation(Traits, primaryjoin=traits_table.c.typeID == items_table.c.typeID, uselist=False) }) Item.category = association_proxy("group", "category")<|fim▁end|>
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser']<|fim▁hole|> class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id)<|fim▁end|>
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): <|fim_middle|> <|fim▁end|>
ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id)
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): <|fim_middle|> def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id) <|fim▁end|>
url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs)
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): <|fim_middle|> def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id) <|fim▁end|>
self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents()
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): <|fim_middle|> <|fim▁end|>
try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id)
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): <|fim_middle|> <|fim▁end|>
return self.page.get_torrent(_id)
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def <|fim_middle|>(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id) <|fim▁end|>
__init__
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def <|fim_middle|>(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def get_torrent(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id) <|fim▁end|>
iter_torrents
<|file_name|>browser.py<|end_file_name|><|fim▁begin|># -*- coding: utf-8 -*- # Copyright(C) 2010-2015 Julien Veyssier, Laurent Bachelier # # This file is part of weboob. # # weboob is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # weboob is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see <http://www.gnu.org/licenses/>. import random import urllib from urlparse import urlsplit from weboob.deprecated.browser import Browser, BrowserHTTPNotFound from .pages.index import IndexPage from .pages.torrents import TorrentPage, TorrentsPage __all__ = ['PiratebayBrowser'] class PiratebayBrowser(Browser): ENCODING = 'utf-8' DOMAINS = ['thepiratebay.vg', 'thepiratebay.la', 'thepiratebay.mn', 'thepiratebay.gd'] def __init__(self, url, *args, **kwargs): url = url or 'https://%s/' % random.choice(self.DOMAINS) url_parsed = urlsplit(url) self.PROTOCOL = url_parsed.scheme self.DOMAIN = url_parsed.netloc self.PAGES = { '%s://%s/' % (self.PROTOCOL, self.DOMAIN): IndexPage, '%s://%s/search/.*/0/7/0' % (self.PROTOCOL, self.DOMAIN): TorrentsPage, '%s://%s/torrent/.*' % (self.PROTOCOL, self.DOMAIN): TorrentPage } Browser.__init__(self, *args, **kwargs) def iter_torrents(self, pattern): self.location('%s://%s/search/%s/0/7/0' % (self.PROTOCOL, self.DOMAIN, urllib.quote_plus(pattern.encode('utf-8')))) assert self.is_on_page(TorrentsPage) return self.page.iter_torrents() def <|fim_middle|>(self, _id): try: self.location('%s://%s/torrent/%s/' % (self.PROTOCOL, self.DOMAIN, _id)) except BrowserHTTPNotFound: return if self.is_on_page(TorrentPage): return self.page.get_torrent(_id) <|fim▁end|>
get_torrent
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated]<|fim▁hole|> serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<|fim▁end|>
class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all()
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): <|fim_middle|> class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated] class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<|fim▁end|>
queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny]
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): <|fim_middle|> class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<|fim▁end|>
queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated]
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated] class AccountRetrieveView(generics.RetrieveAPIView): <|fim_middle|> class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<|fim▁end|>
queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated] class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): <|fim_middle|> class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<|fim▁end|>
queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated]
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated] class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): <|fim_middle|> <|fim▁end|>
queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated] class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): <|fim_middle|> <|fim▁end|>
data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK) return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
<|file_name|>views.py<|end_file_name|><|fim▁begin|>from rest_framework import generics, permissions, views, response,status from .models import Account from .serializers import AccountCreateSerializer, AccountSerializer, AuthenticateSerializer, \ UpdateAccountSerializer, AccountRetrieveSerializer # Create your views here. class AccountCreateView(generics.CreateAPIView): queryset = Account.objects.all() serializer_class = AccountCreateSerializer permission_classes = [permissions.AllowAny] class AccountListView(generics.ListAPIView): queryset = Account.objects.all() serializer_class = AccountSerializer permission_classes = [permissions.IsAuthenticated] class AccountRetrieveView(generics.RetrieveAPIView): queryset = Account.objects.all() serializer_class = AccountRetrieveSerializer class UpdateAccountView(generics.UpdateAPIView): queryset = Account.objects.all() serializer_class = UpdateAccountSerializer # permission_classes = [permissions.IsAuthenticated] class AccountAuthenticationView(views.APIView): queryset = Account.objects.all() serializer_class = AuthenticateSerializer def post(self, request): data = request.data serializer = AuthenticateSerializer(data=data) if serializer.is_valid(raise_exception=True): <|fim_middle|> return response.Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)<|fim▁end|>
new_date = serializer.data return response.Response(new_date,status=status.HTTP_200_OK)