Best Python code snippet using localstack_python
logger.py
Source:logger.py
...15 the logging panel cannot be used without it")16 logging.Handler.__init__(self)17 self.records = {} # a dictionary that maps threads to log records18 def emit(self, record):19 self.get_records().append(record)20 def get_records(self, thread=None):21 """22 Returns a list of records for the provided thread, of if none is provided,23 returns a list for the current thread.24 """25 if thread is None:26 thread = threading.currentThread()27 if thread not in self.records:28 self.records[thread] = []29 return self.records[thread]30 def clear_records(self, thread=None):31 if thread is None:32 thread = threading.currentThread()33 if thread in self.records:34 del self.records[thread]35handler = None36_init_lock = threading.Lock()37def _init_once():38 global handler39 if handler is not None:40 return41 with _init_lock:42 if handler is not None:43 return44 # Call werkzeug's internal logging to make sure it gets configured45 # before we add our handler. Otherwise werkzeug will see our handler46 # and not configure console logging for the request log.47 # Werkzeug's default log level is INFO so this message probably won't be48 # seen.49 try:50 from werkzeug._internal import _log51 except ImportError:52 pass53 else:54 _log('debug', 'Initializing Flask-DebugToolbar log handler')55 handler = ThreadTrackingHandler()56 logging.root.addHandler(handler)57class LoggingPanel(DebugPanel):58 name = 'Logging'59 has_content = True60 def process_request(self, request):61 _init_once()62 handler.clear_records()63 def get_and_delete(self):64 records = handler.get_records()65 handler.clear_records()66 return records67 def process_response(self, request, response):68 records = []69 for record in self.get_and_delete():70 records.append({71 'message': record.getMessage(),72 'time': datetime.datetime.fromtimestamp(record.created),73 'level': record.levelname,74 'file': format_fname(record.pathname),75 'file_long': record.pathname,76 'line': record.lineno,77 })78 self.data = self.context.copy()79 self.data.update({'records': records})80 if self.cache:81 self.cache.set("DEBUGTOOLBAR:%s" % self.name, self.render_cache())82 def nav_title(self):83 return _("Logging")84 def nav_subtitle(self):85 # FIXME l10n: use ngettext86 return "%s message%s" % \87 (len(handler.get_records()), (len(handler.get_records()) == 1) and '' or 's')88 def title(self):89 return _('Log Messages')90 def url(self):91 return ''92 def render_cache(self):93 return {"title": self.title(), "nav_subtitile": self.nav_subtitle(), "content": self.content()}94 def content(self):...
recordhandler.py
Source:recordhandler.py
...13 ).fetchall()14 return render_template('record/recordlist.html', records=records)15 else:16 flash(u'The sensor does not exist. Showing all records instead!', 'error')17 return get_records()18@bp.route('/')19def get_records():20 db = get_db()21 records = db.execute(22 'SELECT record.id, sensor.sensorname, timepoint, temperature, humidity, pressure FROM record INNER JOIN sensor on record.sensor_id = sensor.id; '23 ).fetchall()24 return render_template('record/recordlist.html', records=records, showsensorname = True)25@bp.route('/delete/<int:record_id>')26def delete_record(record_id):27 # TODO: Sanitychecks, i.e. if recordid exists28 db = get_db()29 db.execute('DELETE FROM record WHERE id = ?', (record_id,))30 db.commit()31 flash(u'The record has been deleted!', 'success')...
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!!