Best Python code snippet using pyatom_python
settings.py
Source:settings.py
...46 def __init__(47 self, guild, member_role_id, guest_role_id, mute_role_id, jail_role_id, focus_role_id, nonpurge_role_id48 ):49 self.guild = guild50 self.member_role = self._get_role(member_role_id)51 self.guest_role = self._get_role(guest_role_id)52 self.mute_role = self._get_role(mute_role_id)53 self.jail_role = self._get_role(jail_role_id)54 self.focus_role = self._get_role(focus_role_id)55 self.nonpurge_role = self._get_role(nonpurge_role_id)56 def update(self, attrs):57 logger.debug("Updating special role storage: %s", attrs)58 if "member" in attrs:59 self.member_role = attrs["member"]60 if "guest" in attrs:61 self.guest_role = attrs["guest"]62 if "mute" in attrs:63 self.mute_role = attrs["mute"]64 if "jail" in attrs:65 self.jail_role = attrs["jail"]66 if "focus" in attrs:67 self.focus_role = attrs["focus"]68 if "nonpurge" in attrs:69 self.nonpurge_role = attrs["nonpurge"]70 @property71 def member(self):72 return self.member_role73 @property74 def guest(self):75 return self.guest_role76 @property77 def mute(self):78 return self.mute_role79 @property80 def jail(self):81 return self.jail_role82 @property83 def focus(self):84 return self.focus_role85 @property86 def nonpurge(self):87 return self.nonpurge_role88 def _get_role(self, id):89 if id is None:90 return None91 return discord.utils.get(self.guild.roles, id=id)92 def __iter__(self):93 yield self.member_role94 yield self.guest_role95 yield self.mute_role96 yield self.jail_role97 yield self.focus_role98 yield self.nonpurge_role99class TrackingBlacklistData:100 __slots__ = ("guild", "blacklisted_channels", "blacklisted_users")101 def __init__(self, guild, blacklist):102 # blacklist is an iterable of (type, data_id)...
sql.py
Source:sql.py
...33 query = session.query(RoleTable)34 query = query.filter(RoleTable.id.in_(ids))35 role_refs = query.all()36 return [role_ref.to_dict() for role_ref in role_refs]37 def _get_role(self, session, role_id):38 ref = session.query(RoleTable).get(role_id)39 if ref is None:40 raise exception.RoleNotFound(role_id=role_id)41 return ref42 def get_role(self, role_id):43 with sql.transaction() as session:44 return self._get_role(session, role_id).to_dict()45 @sql.handle_conflicts(conflict_type='role')46 def update_role(self, role_id, role):47 with sql.transaction() as session:48 ref = self._get_role(session, role_id)49 old_dict = ref.to_dict()50 for k in role:51 old_dict[k] = role[k]52 new_role = RoleTable.from_dict(old_dict)53 for attr in RoleTable.attributes:54 if attr != 'id':55 setattr(ref, attr, getattr(new_role, attr))56 ref.extra = new_role.extra57 return ref.to_dict()58 def delete_role(self, role_id):59 with sql.transaction() as session:60 ref = self._get_role(session, role_id)61 session.delete(ref)62class RoleTable(sql.ModelBase, sql.DictBase):63 __tablename__ = 'role'64 attributes = ['id', 'name']65 id = sql.Column(sql.String(64), primary_key=True)66 name = sql.Column(sql.String(255), unique=True, nullable=False)67 extra = sql.Column(sql.JsonBlob())...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!