Best Python code snippet using lisa_python
DNSSEC_resolver_check.py
Source:DNSSEC_resolver_check.py
...81 self.init_done = False82 self.init_variables()83 def set_reason(self, msg):84 self.reason = msg85 def add_reason(self, msg):86 self.reason += msg87 def get_reason(self):88 return self.reason89 @classmethod90 def get_version(cls):91 return cls.revision.split()[1]92 @classmethod93 def get_local_resolvers(cls):94 return dns.resolver.Resolver().nameservers95 def set_abort(self, val):96 self.abort = val97 def set_message(self, val):98 if val:99 self.user_message = ".Msg=%s" % val100 def set_show_test_results(self, val):101 self.show_report = val102 def set_submit_report(self, val):103 self.submit_report = val104 def set_debug(self, val):105 self.debug = val106 def set_verbose_report(self, val):107 self.detailed_report = val108 def ad_reset(self):109 self.ad_seen = False110 self.ad_current = False111 def ad_add(self, val):112 self.ad_current = not not val113 self.ad_seen = self.ad_seen or val114 def clear_tc_bit(self):115 self.is_tc_set = False116 def set_tc_bit(self, val):117 self.is_tc_set = val118 def get_tc_bit(self):119 return self.is_tc_set120 def report_reset(self):121 if not self.init_done:122 self.init_variables()123 else:124 for i in range(len(self.test)):125 self.test_performed[i] = self.test[i] = self.ad_res[i] = self.timeout[i] = False126 self.test_msg[i] = None127 self.test_size[i] = 0128 self.R_code[i] = 0129 self.tests_run = 0130 self.abort_test = 0131 self.failed_test = False132 self.is_tc_set = False133 self.saw_timeout = False134 self.user_message = ".Msg="135 def push_abort(self, val):136 save_abort = self.abort137 self.abort = val138 return save_abort139 def pop_abort(self, val):140 self.push_abort(val)141 def make_query(self, domain, rdatatype, resolver, debug=False, noRec=False):142 answer = super(DNSSEC_resolver_check, self).make_query(domain, rdatatype, resolver, debug, noRec)143 if answer is not None:144 self.response_size = len(answer.response.to_wire())145 return answer146 def response_ok(self, res, domain, rdtype):147 ans_container = self.make_query(domain, rdtype, res, self.debug);148 if ans_container is None or ans_container.response is None:149 return None150 response = ans_container.response151 if self.debug:152 print(response)153 ad = response.flags & dns.flags.AD154 self.ad_add(ad); # log ad bit155 if response.rcode() != dns.rcode.NOERROR:156 self.add_reason( "RCODE=%s" % (response.rcode(), ))157 return None158 return response;159 def register_test_result(self, test_number, result, msg, bad):160 if self.debug:161 self.println("Registering %d %s %s" % (test_number, result, bad, ))162 self.test_performed[test_number] = True163 self.timeout[test_number] = self.query_timeout()164 self.tests_run += 1165 self.ad_res[test_number] = self.ad_current166 self.ad_current = False167 self.test_size[test_number] = self.response_size168 self.test_msg[test_number] = "%s -- %s" % (msg, self.get_reason(), )169 self.R_code[test_number] = self.rcode170 if (self.debug):171 self.println(" in register result %s %d %d" % (bad, self.rcode, self.response_size, ))172 if result == bad:173 # got bad result174 if self.debug:175 self.println(" in register bad %s %s %s" % (bad, self.rcode, self.response_size, ))176 self.failed_test = True177 if self.timeout[test_number] and self.timeout_is_failure[test_number]:178 if self.rcode > 0:179 if self.debug:180 self.println(" in register rcode %s %s %s" % (bad, self.rcode, self.response_size, ))181 self.abort_test = self.tests_run182 return True183 self.set_reason("")184 return self.abort185 return self.abort186 else:187 #got expected result...188 self.test[test_number] = True189 return False190 def display_result(self):191 self.println(self.get_reason())192 def test_letter(self, i):193 letter = "Y"194 if self.test_performed[i] == False:195 letter = "S"196 elif self.R_code[i] > 0:197 letter = "R=%s," % dns.rcode.to_text(self.R_code[i])198 elif self.timeout[i] == True and self.timeout_is_failure[i] == False:199 letter = "T"200 elif self.test[i] == True:201 letter = "A" if self.ad_res[i] else "P"202 else:203 letter = "F" if not self.ad_res[i] else "X"204 return letter;205 def test_results(self):206 out = "" # Summary line207 if self.failed_test:208 # First report on each test209 rep = "" # Explanation of failed tests210 for i in range(len(self.test)):211 out += " T%d%s/%d" % (i, self.test_letter(i), self.test_size[i], )212 if self.test_performed[i] == False:213 rep += " T%d %s := Skipped\n" % (i, self.test_name[i], )214 elif self.test[i] == False: # failed215 if self.test_msg[i]:216 rep += " T%d %s := %s\n" % (i, self.test_name[i], self.test_msg[i], )217 if self.detailed_report:218 out += "\nFailed tests:\n" + rep219 elif self.tests_run > 1:220 out = "All tests passed"221 else:222 out = "No Tests Run"223 return out224 def string_result(self):225 out = ''226 top = len(self.test) if self.abort_test == 0 else self.abort_test227 for i in range(1, top):228 out += self.test_letter(i)229 return out230 def count_rr(self, section, name, rdtype):231 source = RRSetSource(section)232 return source.count(rdtype)233 def first_check(self, res, domain, qtype, edns, log_ad=False):234 answer = self.make_query(domain, qtype, res, self.debug)235 if answer is None or answer.response is None:236 return False237 response = answer.response238 ad = log_ad and (response.flags & dns.flags.AD)239 self.ad_add(ad) # log AD bit240 if self.debug:241 self.println(response)242 self.rcode = response.rcode()243 if self.rcode != dns.rcode.NOERROR:244 self.add_reason("DNS Error %s" % (dns.rcode.to_text(self.rcode), ))245 return False246 if not response.flags & dns.flags.RA:247 self.add_reason("Error: Not a recursive resolver - RA flag missing")248 return False249 Ans = response.answer250 name = self.Str_to_Name(domain);251 if self.count_rr(Ans, name, qtype) == 0:252 self.add_reason( "No %s seen in answer" % (dns.rdatatype.to_text(qtype), ))253 return False254 if edns:255 if not response.ednsflags:256 self.add_reason("No Opt returned")257 return False258 259 size = len(response.to_wire())260 if(size > 512):261 self.big_ok = True262 payloadSize = response.payload263 if payloadSize < size:264 self.add_reason("Small ENDS reported %d < %d" % (payloadSize, size, ))265 return True266 def tcp_test(self, resolver):267 self.tcp_works = False;268 tcp = self.get_resolver(resolver, tcp=True, debug=self.debug)269 if not tcp:270 return False271 if not self.first_check(tcp, "net.", dns.rdatatype.SOA, False):272 self.add_reason( "TCP not offered")273 return False274 self.tcp_works = True275 return True276 def dname_check(self, res, domain, rdtype, target, count_rrsig):277 ans_container = self.make_query(domain, rdtype, res, self.debug)278 if not ans_container or not ans_container.response or not ans_container.response.answer:279 self.add_reason( "DNAME lookup failed")280 return False281 answer = ans_container.response.answer282 if self.debug:283 self.println(answer)284 # log ad bit285 ad = count_rrsig and (ans_container.response.flags & dns.flags.AD)286 self.ad_add(ad)287 cnt = len(answer)288 if cnt <= 0:289 self.add_reason( "Empty DNAME Answer")290 return False291 name = self.Str_to_Name(domain)292 if self.count_rr(answer, name, dns.rdatatype.DNAME) == 0:293 self.add_reason("NO DNAME seen in answer")294 return False295 if count_rrsig:296 source = RRSetSource(answer)297 if cnt < 2:298 #DNAME and target RRset are signed299 self.add_reason("Not enoght records in DNAME answer")300 return False301 rrset = source.get_rrset(dns.rdatatype.DNAME)302 if not source.find_covering_rrsigset(rrset):303 self.add_reason("Missing RRSIG(DNAME)")304 return False305 last_rrset = answer[len(answer)-1]306 res_target = last_rrset.name.to_text()307 if res_target != target:308 self.addr_reason("DNAME name mismatch %s !+ %s" % (target, res_target, ))309 return False310 return True311 def positive_check(self, res, domain, rdtype, ad):312 self.clear_tc_bit()313 response = self.response_ok(res, domain, rdtype)314 if not response:315 self.add_reason("empty response")316 return False317 tc = response.flags & dns.flags.TC318 self.set_tc_bit(tc)319 def negative_check(self, res, domain, rdtype, ad):320 my_name = self.Str_to_Name(domain)321 if not my_name:322 return False323 response = self.response_ok(res, domain, rdtype)324 if not response:325 return False326 if len(response.answer):327 self.add_reason( "Answer != empty %s %s" % (domain, dns.rdatatype.to_text(rdtype), ))328 return False329 auth = response.authority330 if len(auth) == 0: # empty authority331 self.add_reason("Empty negative answer")332 return False333 elif self.count_rr(auth, my_name, dns.rdatatype.SOA) > 0:334 # must be backwards compatibility335 # Now count the records that I expect to find in the authority seciton336 n = self.count_rr(auth, my_name, dns.rdatatype.NSEC) #either NSEC or NSEC3337 n3 = self.count_rr(auth, my_name, dns.rdatatype.NSEC3) # must be there338 if (n + n3) > 0 and (n == 0 or n3 == 0):339 # make sure there are NSEC or NSEC3 but not both340 x = self.count_rr(auth, my_name, dns.rdatatype.RRSIG) # signatures present ?341 if x > 1: # at least SOA and one NSECx record must be signed342 return True343 else:344 self.add_reason("Not enough RRSIG (%d)" % (x, ))345 else:346 self.add_reason("Missing NSEC/NSEC3 %d/%d" % (n, n3, ))347 return False348 def expect_failure(self, res, domain, rdtype):349 rrr = self.get_reason()350 response = self.response_ok(res, domain, rdtype);351 if not response:352 self.set_reason(rrr)353 return True354 else:355 my_name = self.Str_to_Name(domain)356 ans = response.answer357 so = self.count_rr(ans, my_name, rdtype)358 rsig = self.count_rr(ans, my_name, dns.rdatatype.RRSIG)359 rdtype_as_string = dns.rdatatype.to_text(rdtype)360 self.println("expect_failure %s %s Got:%s != SERVFAIL # %s %s #RRSI %d"361 % (domain, rdtype_as_string, response.rcode(), rdtype_as_string, so, rsig, ))362 if self.debug:363 self.println(response) # not the whole packet need to parse it364 return False365 def run_tests(self, resolver, fail_allowed):366 self.big_ok = False367 msg = None368 res = self.get_resolver(resolver, debug=self.debug)369 if not res:370 self.add_reason("Cannot create resolver")371 return False372 #does it answer questions?373 msg = "Can't resolve com. soa not a useful resolver "374 first_one = self.first_check(res, "com.", dns.rdatatype.SOA, False)375 if self.register_test_result(1, first_one, msg, False):376 return False377 if not first_one:378 return False379 380 # do not fall back to TCP381 res.no_tcp_on_tc = True382 #check for old DNS extensions383 res.use_edns(0, dns.flags.DO, self.ed_buff)384 385 x = self.push_abort(True)386 msg = "org DNSKEY lookup failed RFC4034"387 if self.register_test_result(2, self.first_check(res, "org.", dns.rdatatype.DNSKEY, True), msg, False):388 fail_allowed -= 1389 if fail_allowed < 0:390 return False391 self.pop_abort(x)392 #check for new/unknown records (update over time)393 msg = "Unknown RR failure RFC3597"394 fc = self.first_check(res, "tlsa.ogud.com", dns.rdatatype.TLSA, True)395 if self.register_test_result(3, fc, msg, False) or not fc:396 fail_allowed -= 1397 if fail_allowed < 0:398 return False399 #is TCP supported?400 msg = "TCP Failed RFC1035/RFC5966 violation"401 if (self.register_test_result(4, self.tcp_test(resolver), msg, False)):402 return True403 #is DNAME supported and returned?404 msg = "DNAME Not Supported RFC2672/RFC6672"405 if self.register_test_result(5,406 self.dname_check(res, "grade.goal.ogud.com", dns.rdatatype.TXT, "grade.shinkuro.com.", False),407 msg,408 False):409 return True410 # Make sure we got some answer that was bigger than 512 bytes i.e. via411 # Edns0 or TCP412 msg = "No answers > 512 seen"413 if self.register_test_result(6, self.big_ok, msg, False):414 return True415 return self.dnssec_tests(res)416 def dnssec_tests(self, res):417 res.use_edns(0, dns.flags.DO, self.ed_buff)418 self.ad_reset()419 msg = "No Signed SOA RFC4035"420 if self.register_test_result(7,421 self.positive_check(res, "iab.org.", dns.rdatatype.SOA, True),422 msg,423 False):424 return False425 msg = "no DS received RFC4035"426 if self.register_test_result(8,427 self.positive_check(res, "ietf.org.", dns.rdatatype.DS, True),428 msg, False):429 return False430 # check Signed DNAME431 msg = "NO signed DNAME RFC4035"432 if self.register_test_result(9,433 self.dname_check(res, "grade.goal.ogud.com.", dns.rdatatype.TXT, "grade.shinkuro.com.", True),434 msg,435 False):436 return false;437 # I ask for names that exist but for types that do not438 msg = "Expecting NSEC RFC4305"439 if self.register_test_result(10,440 self.negative_check(res, "us.", dns.rdatatype.SPF, True),441 msg,442 False): # NSEC signed443 return False444 msg = "Expecting NSEC3 RFC5155"445 if self.register_test_result(11,446 self.negative_check(res, "de.", dns.rdatatype.SPF, True),447 msg,448 False): # NSEC3 signed449 return False450 # set big buffer size451 res.use_edns(0, dns.flags.DO, 2800)452 big = self.positive_check(res, "shinkuro.net.", dns.rdatatype.A, True)453 msg = "Big UDP answer > 1500 failed bad path?"454 if self.register_test_result(12, big and ( self.get_tc_bit() and self.tcp_works ), msg, False):455 return False456 if not big:457 self.warn_msg = "Link does not support fragmented UDP"458 if self.ad_seen:459 msg = "Bogus returned on badly signed answer"460 if self.register_test_result(13,461 self.expect_failure(res, "dnssec-failed.org.", dns.rdatatype.SOA),462 msg,463 False):464 self.add_reason("returned known bad DNSSEC answer")465 return False466 return True467 def generate_report(self, resolver, submit_report, debug):468 out = "Generate_report: %s %s" % (resolver, submit_report, )469 SResolv = "N/A"470 if (debug):471 self.println(out)472 result = "Test=%s" % (self.string_result(), )473 Resolv = self.addr_lookup(resolver, self.getting_address)474 # use this as an indicator if we can talk directly to resolver475 My_addr = self.addr_lookup(resolver, self.getting_address) # use dnspython recursive resolver to get own address476 name = (result + ".NS=" + resolver +477 ".Resolv=" + Resolv + ".Me=" + My_addr + ".Version=" +478 self.get_version() + self.user_message.replace(' ', '+'))...
data.py
Source:data.py
...251 from moviehubapi import Moviehub252 p = Moviehub(client_id=request.args.get("id"), client_secret=request.args.get("secret"),253 access_token=request.args.get("token"))254 movies = p.movies()255 p.add_reason(movie_ids="%d,%d" % (movies[0].id, movies[1].id),256 body="Both asian films, not much relevance both pretty dark stories.", rating=70)257 p.add_reason(movie_ids="%d,%d" % (movies[12].id, movies[13].id),258 body="Both are Guy Riche movies, mostly the same cast but abit different setting and story", rating=95)259 p.add_reason(movie_ids="%d,%d" % (movies[12].id, movies[14].id),260 body="Both are Guy Riche movies, mostly the same cast but abit different setting and story", rating=90)261 p.add_reason(movie_ids="%d,%d" % (movies[11].id, movies[16].id),262 body="Movies about heavy drug usage, but Fear and Loathing is a comedy where A Scanner Darkly is more serious and dark"263 , rating=60)264 p.add_reason(movie_ids="%d,%d" % (movies[17].id, movies[44].id),265 body="Fantasy movies, both in very isolated setting, some very random twists", rating=50)266 p.add_reason(movie_ids="%d,%d" % (movies[45].id, movies[46].id), body="Fantasy movies, both very magical films!",267 rating=90)268 p.add_reason(movie_ids="%d,%d" % (movies[51].id, movies[52].id),269 body="Two very similar movies, both about the wonders of magic shows!", rating=98)270 p.add_reason(movie_ids="%d,%d" % (movies[65].id, movies[23].id),271 body="Both stories about a police task force trying to find a killer on the loose.", rating=85)272 p.add_reason(movie_ids="%d,%d" % (movies[24].id, movies[62].id),273 body="Both movies are about a criminal side vs a police side", rating=66)274 p.add_reason(movie_ids="%d,%d" % (movies[25].id, movies[87].id),275 body="Movies about famous american boxers! Both surprisingly good", rating=85)276 p.add_reason(movie_ids="%d,%d" % (movies[91].id, movies[61].id), body="Crazy paced action films! Both very funny!",277 rating=72)278 p.add_reason(movie_ids="%d,%d" % (movies[58].id, movies[9].id),279 body="Films about how boring everyday life can be, but very funny for the people watching.", rating=83)280 p.add_reason(movie_ids="%d,%d" % (movies[37].id, movies[69].id), body="Wonderful stories in fantasy settings!",281 rating=77)282 p.add_reason(movie_ids="%d,%d" % (movies[82].id, movies[80].id), body="Movies about drugs, same kind of humour",283 rating=59)284 p.add_reason(movie_ids="%d,%d" % (movies[81].id, movies[43].id), body="Both are feelgood movies!", rating=43)285 p.add_reason(movie_ids="%d,%d" % (movies[90].id, movies[9].id), body="Two of the funniest movies every created",286 rating=69)287 p.add_reason(movie_ids="%d,%d" % (movies[48].id, movies[49].id), body="Jim Carry in two very touching stories!",288 rating=80)289 p.add_reason(movie_ids="%d,%d" % (movies[59].id, movies[60].id), body="Quentin Tarantino at his best!", rating=97)290 p.add_reason(movie_ids="%d,%d" % (movies[73].id, movies[41].id),291 body="Two movies about wars, but in different setting and reality", rating=64)292 p.add_reason(movie_ids="%d,%d" % (movies[55].id, movies[89].id), body="Two movies about where hate will lead you",293 rating=71)294 p.add_reason(movie_ids="%d,%d" % (movies[98].id, movies[99].id), body="Self explanatory", rating=100)295 p.add_reason(movie_ids="%d,%d" % (movies[77].id, movies[78].id), body="Asian peoples fighting becomes comedy!",296 rating=65)297 p.add_reason(movie_ids="%d,%d" % (movies[5].id, movies[19].id),298 body="Both super fascinating stories based on actual people!", rating=89)299 p.add_reason(movie_ids="%d,%d" % (movies[2].id, movies[6].id),300 body="Movies that actually pull of timetravel! Mighty impressive and both very good", rating=67)301 p.add_reason(movie_ids="%d,%d" % (movies[27].id, movies[66].id),302 body="These two movies are about the life of musicians, good music in both", rating=91)303 p.add_reason(movie_ids="%d,%d" % (movies[2].id, movies[20].id), body="Main characters both suffer from insanity.",304 rating=88)305 p.add_reason(movie_ids="%d,%d" % (movies[2].id, movies[79].id),306 body="Both movies circle around a set of very mysterious events", rating=79)307 p.add_reason(movie_ids="%d,%d" % (movies[2].id, movies[22].id), body="Imaginary friends! That's a spoiler FYI!",308 rating=76)309 p.add_reason(movie_ids="%d,%d" % (movies[8].id, movies[76].id),310 body="Both filmes are made by Stanley Kubrick, very dark and violent movies.", rating=92)311 p.add_reason(movie_ids="%d,%d" % (movies[8].id, movies[1].id), body="The not so very orthodox main character",312 rating=64)313 p.add_reason(movie_ids="%d,%d" % (movies[8].id, movies[38].id),314 body="Both movies circling around outcasts of the society, where hate leads them to act the way they do.",315 rating=66)316 p.add_reason(movie_ids="%d,%d" % (movies[9].id, movies[86].id),317 body="Movies are both made by Kevin Smith, same humour, mostly the same actors but a completely different story and setting"318 , rating=87)...
chat_message.py
Source:chat_message.py
1import yaml2import html3from datetime import datetime4import traceback5from enum import IntFlag6from elements import STYLE_WORD_BREAK7from chat_re import list_res, list_res_variety, re_spaces, LANGUAGES8from elements import Reason, deltaseconds, get_highlight_style, config_file9class AddButtons(IntFlag):10 No = 011 Ban = 112 Dismiss = 213 BanAndDismiss = 314def load_res():15 try:16 with open(config_file) as stream:17 config = yaml.safe_load(stream)18 timeouts = config.get('timeouts', "En, Spam").lower()19 list_re = []20 for group in LANGUAGES.keys():21 if group.lower() in timeouts:22 list_re.extend(list_res[group])23 list_re_variety = list_res_variety if 'spam' in timeouts else []24 except Exception as e:25 print(f"There appears to be a syntax problem with your config.yml: {e}")26 list_re = [list_res['En']]27 list_re.extend(list_res['Spam'])28 list_re_variety = list_res_variety29 return list_re, list_re_variety30class Message:31 global_id = 032 list_res, list_res_variety = load_res()33 def __init__(self, data, tournament, now=None, delay=None):34 self.id: int = None35 self.time: datetime = now36 self.delay: int = delay37 self.username = data['u']38 self.text = data['t']39 self.eval_text = ""40 self.is_official = (self.username == "lichess")41 self.is_deleted = False # was available before and now isn't on the page42 self.is_removed = data.get('r', False) # SB'ed, was never visible43 self.is_disabled = data.get('d', False) # deleted by mods44 self.is_reset = False # processed as good45 self.is_timed_out = False # processed as bad46 self.tournament = tournament47 self.score: int = None48 self.reasons = [0] * Reason.Size49 self.scores = [0] * Reason.Size50 def best_ban_reason(self):51 ban_sum = sum(self.reasons)52 if ban_sum < 1:53 return int(Reason.No)54 arg_max = max(range(len(self.reasons)), key=self.reasons.__getitem__)55 return arg_max56 def best_score_reason(self):57 if max(self.scores) == 0:58 return int(Reason.No)59 arg_max = max(range(len(self.scores)), key=self.scores.__getitem__)60 return arg_max61 def best_reason(self):62 reason = self.best_ban_reason()63 if reason != Reason.No:64 return reason65 return self.best_score_reason()66 def format_reason(self, i_reason, text, add_reason, best_reason):67 if self.scores[i_reason] == 0 and i_reason != add_reason:68 return text69 if i_reason == best_reason:70 return f'<b class="text-warning">{text}</b>'71 return f'<b>{text}</b>'72 def update(self, msg):73 self.is_removed = msg.is_removed74 self.is_disabled = msg.is_disabled75 def __eq__(self, other):76 return self.username.lower() == other.username.lower() and self.text == other.text \77 and self.tournament.id == other.tournament.id78 def __repr__(self):79 return f"[{self.username}]: {self.text}"80 def evaluate(self, re_usernames):81 if self.is_official:82 self.eval_text = self.text83 self.score = 084 return85 try:86 # Remove multiple spaces87 text = re_spaces.sub(" ", self.text)88 # Add usernames and evaluate89 res_all = re_usernames.copy()90 res_all.extend([re_i for re_i in Message.list_res91 if (re_i.exclude_tournaments is None or self.tournament.t_type not in re_i.exclude_tournaments)])92 result_all = res_all[0].eval(text, res_all, 0)93 result_variety = Message.list_res_variety[0].eval(text, Message.list_res_variety, 0)94 ban_points_all = sum(result_all.ban_points)95 ban_points_variety = sum(result_variety.ban_points)96 result = result_all if ban_points_all > ban_points_variety else result_variety \97 if ban_points_all < ban_points_variety or result_all.total_score() < result_variety.total_score() \98 else result_all99 self.eval_text = result.element100 self.scores = result.scores101 self.score = result.total_score()102 self.reasons = result.ban_points103 if self.score >= 50:104 self.eval_text.replace('<span class="text-warning"', '<span class="text-danger"')105 if self.score > 60:106 self.eval_text.replace('<span class="text-warning"', '<span class="text-danger bg-warning"')107 except Exception as exception:108 print(f"ERROR when processing: {self}")109 traceback.print_exception(type(exception), exception, exception.__traceback__)110 self.eval_text = self.text111 self.score = 0112 def is_hidden(self):113 return self.is_removed or self.is_disabled or \114 self.is_reset or self.is_timed_out or self.is_official # or self.is_deleted115 def get_info(self, tag, show_hidden=None, add_buttons=None, base_time=None, rename_dismiss=None, add_user=True,116 add_mscore=False, add_reason=None, highlight_user=None, is_selected=False, is_centered=False,117 add_selection=False):118 if show_hidden is None:119 show_hidden = (base_time is not None)120 if add_buttons is None:121 add_buttons = AddButtons.BanAndDismiss if base_time is None else AddButtons.No122 if self.is_official or self.is_disabled or self.is_removed:123 add_buttons = AddButtons.No124 elif (self.score == 0 and not rename_dismiss) or self.is_reset or self.is_timed_out:125 add_buttons &= ~AddButtons.Dismiss126 if not show_hidden and (self.is_hidden() or not self.score):127 return ""128 if base_time is None:129 str_time = ""130 else:131 ds = deltaseconds(self.time, base_time)132 dt = f"{abs(ds)}s" if abs(ds) < 60 \133 else f"{abs(ds) // 60}m{abs(ds) % 60:02d}s" if abs(ds) < 300 \134 else f"{int(round(abs(ds) / 60))}m"135 str_time = f"−{dt} " if ds < 0 else f'+{dt} ' if ds > 0 else "== "136 str_time = f'<abbr title="{self.time.astimezone(tz=None):%H:%M:%S}" class="user-select-none" ' \137 f'style="text-decoration:none;">{str_time}</abbr>'138 score_theme = "" if self.score is None else ' text-danger' if self.score > 50 \139 else ' text-warning' if self.score > 10 else ""140 score = f'<span class="user-select-none{score_theme}">{self.score}</span>' if self.score and self.score > 0 else ""141 username = f"<b><u>{self.username}</u></b>" if highlight_user is True or highlight_user == self.username \142 else self.username143 user = f'<a class="text-info user-select-none" href="https://lichess.org/@/{self.username.lower()}" target="_blank" ' \144 f'onclick="prevent_click(event)">{username}</a>' if add_user else ""145 highlight_style = "" if not highlight_user or highlight_user != self.username else get_highlight_style(0.2)146 name_dismiss = rename_dismiss if rename_dismiss else "Dismiss"147 class_dismiss = "btn-secondary" if rename_dismiss else "btn-primary"148 button_dismiss = f'<button class="btn {class_dismiss} text-nowrap align-baseline flex-grow-0 py-0 px-1 ml-1" ' \149 f'onclick="set_ok(\'{tag}{self.id}\');">{name_dismiss}</button> ' \150 if add_buttons & AddButtons.Dismiss else ""151 best_ban_reason = self.best_ban_reason()152 best_reason = best_ban_reason if best_ban_reason != Reason.No else self.best_score_reason()153 if best_reason == Reason.No and add_reason is not None:154 best_reason = int(add_reason)155 r = Reason.to_Tag(best_reason)156 class_ban = "btn-warning" if self.score and self.score >= 50 else "btn-secondary"157 button_ban = f'<button class="btn {class_ban} nav-item dropdown-toggle align-baseline mr-1 px-1 py-0" ' \158 f'data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="cursor:pointer;">' \159 f'Ban</button><span class="dropdown-menu" style="">' \160 f'<button class="dropdown-item btn-primary" onclick="timeout(\'{tag}{self.id}\', 1);">' \161 f'{self.format_reason(Reason.Shaming, "Public Shaming", add_reason, best_reason)}</button>' \162 f'<button class="dropdown-item btn-primary" onclick="timeout(\'{tag}{self.id}\', 2);">' \163 f'{self.format_reason(Reason.Offensive, "Offensive Language", add_reason, best_reason)}</button>' \164 f'<button class="dropdown-item btn-primary" onclick="timeout(\'{tag}{self.id}\', 3);">' \165 f'{self.format_reason(Reason.Spam, "Spamming", add_reason, best_reason)}</button>' \166 f'<button class="dropdown-item btn-primary" onclick="timeout(\'{tag}{self.id}\', 4);">' \167 f'{self.format_reason(Reason.Other, "Inappropriate Behaviour", add_reason, best_reason)}</button>' \168 f'</span>' if add_buttons & AddButtons.Ban else ""169 if add_buttons & AddButtons.Ban:170 if best_ban_reason != Reason.No or (best_reason != Reason.No and self.score and self.score >= 50):171 button_ban = f'<button class="btn btn-danger align-baseline flex-grow-0 py-0 px-1" ' \172 f'onclick="timeout(\'{tag}{self.id}\');">{r}</button>{button_ban}'173 class_name = "text-muted" if self.is_deleted or self.is_reset \174 else "text-secondary" if self.is_removed or self.is_disabled or self.is_timed_out or self.is_official else ""175 text = f'<s style="text-decoration-style:double;">{self.eval_text}</s>' if self.is_removed \176 else f'<s style="text-decoration-style:dotted;"><u style="text-decoration-style:wavy;">' \177 f'{self.eval_text}</u></s>' if self.is_timed_out \178 else f'<s>{self.eval_text}</s>' if self.is_disabled \179 else f'<small>{self.eval_text}</small>' if self.is_reset \180 else f'<small><i>{self.eval_text}</i></small>' if self.is_official \181 else self.eval_text if self.is_deleted \182 else self.eval_text183 text = f'<span class="{class_name}" style="{STYLE_WORD_BREAK}">{text}</span>'184 mscore = f' data-mscore={self.score}' if add_mscore else ""185 selection = html.escape(self.text).replace("'", "'")186 selection = f' data-selection=\'{self.username}: "{selection}"\'' if add_selection else ""187 onclick = "" if is_selected else f' onclick="select_message(event,\'{tag}{self.id}\')"'188 selectee_class = "selectee selectee-center" if is_centered else "selectee"189 if add_buttons == AddButtons.No:190 div = f'<div id="msg{tag}{self.id}"{mscore}{selection} class="align-items-baseline {selectee_class} px-1" ' \191 f'style="{STYLE_WORD_BREAK}"{onclick}>' \192 f'{str_time}{user} <b>{score}</b> {text}</div>'193 elif add_buttons & AddButtons.Ban:194 div = f'<div id="msg{tag}{self.id}"{mscore}{selection} class="align-items-baseline {selectee_class} px-1" ' \195 f'style="{STYLE_WORD_BREAK}"{onclick}>' \196 f'<div class="d-flex justify-content-between"><span>{button_ban}{str_time}{user} {text}</span> ' \197 f'<span class="text-nowrap"><b class="pl-2">{score}</b>{button_dismiss}</span></div></div>'198 else:199 div = f'<div id="msg{tag}{self.id}"{mscore}{selection} class="align-items-baseline {selectee_class} ' \200 f'px-1" {onclick}>' \201 f'<div class="d-flex justify-content-between">' \202 f'<span class="d-flex flex-row">{button_ban}{str_time}{user}</span>' \203 f'<span class="d-flex flex-row">{score}{button_dismiss}</span></div>' \204 f'<div class="align-items-baseline" style="{STYLE_WORD_BREAK}">{text}</div></div>'...
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!!