def auth_texts(): response = make_response( jsonify(TRANSLATIONS.data[requested_lang()]['Auth'])) if not is_debug_mode(): # Cache for longer when not devving response.cache_control.max_age = 60 * 60 # Seconds return response
def send_email(recipient, subject, body_plain, body_html): try: result = email_client.send_email( Source=config['email']['sender'], Destination={'ToAddresses': [recipient]}, Message={ 'Subject': { 'Data': subject, 'Charset': 'UTF-8' }, 'Body': { 'Text': { 'Data': body_plain, 'Charset': 'UTF-8' }, 'Html': { 'Data': body_html, 'Charset': 'UTF-8' }, } }) except email_error as error: print('Email send error', error.response['Error']['Message']) except NoCredentialsError as e: if not is_debug_mode(): raise e else: print('Email sent to ' + recipient)
def data(self): # In debug mode, always reload all translations if self._data is None or utils.is_debug_mode(): translations = glob.glob('coursedata/texts/*.yaml') self._data = {} for trans_file in translations: lang = path.splitext(path.basename(trans_file))[0] self._data[lang] = courses.load_yaml(trans_file) return self._data
def add(self, record): bucket = div_clip(time.time(), self.batch_window_s) data = record.as_data() if self.do_print or utils.is_debug_mode(): logging.debug(repr(data)) with self.mutex: self.records_queue[bucket].append(data)
def get_parser(level): """Return the Lark parser for a given level. Uses caching if Hedy is NOT running in development mode. """ existing = PARSER_CACHE.get(level) if existing and not utils.is_debug_mode(): return existing ret = Lark(create_grammar(level)) PARSER_CACHE[level] = ret return ret
def error(): error_messages = TRANSLATIONS.get_translations(requested_lang(), "ClientErrorMessages") response = make_response( render_template("error_messages.js", error_messages=json.dumps(error_messages))) if not is_debug_mode(): # Cache for longer when not devving response.cache_control.max_age = 60 * 60 # Seconds return response
def get_parser(level, sub): """Return the Lark parser for a given level. Uses caching if Hedy is NOT running in development mode. """ key = str(level) + "." + str(sub) existing = PARSER_CACHE.get(key) if existing and not utils.is_debug_mode(): return existing grammar = create_grammar(level, sub) ret = Lark(grammar, regex=True) PARSER_CACHE[key] = ret return ret