def _fetch_rates_no_cache_failure(): """ Retrieve most recent currency exchange rates from the European Central Bank. This value is cached with a 24h expiry period. Failures are cached for one hour. """ if not config.config_read_bool('convert_currency'): return None try: response = d.http_get("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml") except WeasylError: # http_get already logged the exception return None else: request = get_current_request() request.environ['raven.captureMessage']("Fetched exchange rates", level=logging.INFO) rates = {'EUR': 1.0} for match in re.finditer(r"currency='([A-Z]{3})' rate='([0-9.]+)'", response.content): code, rate = match.groups() try: rate = float(rate) except ValueError: pass else: if 0.0 < rate < float('inf'): rates[code] = rate return rates
def _fetch_rates_no_cache_failure(): """ Retrieve most recent currency exchange rates from the European Central Bank. This value is cached with a 24h expiry period. Failures are cached for one hour. """ if not config.config_read_bool('convert_currency'): return None try: response = d.http_get( "https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml") except WeasylError: # http_get already logged the exception return None else: request = get_current_request() request.environ['raven.captureMessage']("Fetched exchange rates", level=logging.INFO) rates = {'EUR': 1.0} for match in re.finditer(r"currency='([A-Z]{3})' rate='([0-9.]+)'", response.content): code, rate = match.groups() try: rate = float(rate) except ValueError: pass else: if 0.0 < rate < float('inf'): rates[code] = rate return rates
def _captcha_public(): """ Returns the reCAPTCHA public key, or None if CAPTCHA verification is disabled. """ if config_read_bool("captcha_disable_verification"): return None return config_obj.get(_captcha_section(), 'public_key')
def captcha_public(): """ Returns the reCAPTCHA public key, or None if CAPTCHA verification is disabled. """ if config_read_bool("captcha_disable_verification", value=False): return None return config_obj.get(_captcha_section(), 'public_key')
def captcha_verify(captcha_response): if config_read_bool("captcha_disable_verification"): return True if not captcha_response: return False data = dict( secret=config_obj.get(_captcha_section(), 'private_key'), response=captcha_response, remoteip=get_address()) response = http_post('https://www.google.com/recaptcha/api/siteverify', data=data) captcha_validation_result = response.json() return captcha_validation_result['success']
def captcha_verify(form): if config_read_bool("captcha_disable_verification", value=False): return True if not form.g_recaptcha_response: return False data = dict( secret=config_obj.get(_captcha_section(), 'private_key'), response=form.g_recaptcha_response['g-recaptcha-response'], remoteip=get_address()) response = http_post('https://www.google.com/recaptcha/api/siteverify', data=data) captcha_validation_result = response.json() return captcha_validation_result['success']
def captcha_verify(form): if config_read_bool("captcha_disable_verification", value=False): return True if not form.recaptcha_response_field: return False data = dict( privatekey=config_obj.get(_captcha_section(), 'private_key'), remoteip=get_address(), challenge=form.recaptcha_challenge_field.encode('utf-8'), response=form.recaptcha_response_field.encode('utf-8')) response = http_post('https://www.google.com/recaptcha/api/verify', data=data) result = response.text.splitlines() return result[0] == 'true'
def _fetch_rates_xml(): """ Retrieve most recent currency exchange rates from the European Central Bank. This value is cached with a 24h expiry period. """ if not config.config_read_bool('convert_currency'): return None try: response = d.http_get("https://www.ecb.europa.eu/stats/eurofxref/eurofxref-daily.xml") except WeasylError: # http_get already logged the exception return None else: request = get_current_request() request.environ['raven.captureMessage']("Fetched exchange rates", level=logging.INFO) return response.content
import logging import os from akismet import Akismet, SpamStatus # Imported as RequestsConnectionError to not conflict with Python 3's built-in ConnectionError exception from requests.exceptions import ConnectionError as RequestsConnectionError from weasyl import config from weasyl import define as d from weasyl.error import WeasylError FILTERING_ENABLED = config.config_read_bool(setting='enabled', section='spam_filtering') AKISMET_KEY = config.config_read_setting(setting='key', value=None, section='spam_filtering') # Used to set the `is_spam` flag on requests sent to the backend _IS_ENVIRONMENT_TESTING = True if os.environ.get( "WEASYL_TESTING_ENV") else False # AKA, the link to the main page of the web application AKISMET_BLOG_URL = "http://lo.weasyl.com" if _IS_ENVIRONMENT_TESTING else "https://www.weasyl.com" if all([FILTERING_ENABLED, AKISMET_KEY]): _akismet = Akismet(AKISMET_KEY, blog=AKISMET_BLOG_URL, application_user_agent="weasyl/+({0})".format( "https://github.com/weasyl/weasyl")) else: FILTERING_ENABLED = False