<commit_before>import logging
import re
import time
import traceback

import praw
from requests.exceptions import HTTPError, Timeout

import db
from db import Battle, Region, Processed, SkirmishAction, User
from utils import now, num_to_team, team_to_num, timestr


def failable(f):
    def wrapped(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except praw.errors.APIException:
            full = traceback.format_exc()
            logging.warning("Reddit API call failed! %s" % full)
            return None
        except Timeout:
            full = traceback.format_exc()
            logging.warning("Socket timeout! %s" % full)
            return None
        except HTTPError:
            full = traceback.format_exc()
            logging.warning("HTTP error timeout! %s" % full)
            return None
    return wrapped


class Context(object):
    def __init__(self, player, config, session, comment, reddit):
        self.player = player    # a DB object
        self.config = config
        self.session = session
        self.comment = comment  # a praw object
        self.reddit = reddit    # root praw object

    @failable
    def reply(self, reply, pm=True):
        was_comment = getattr(self.comment, 'was_comment', True)
        header = ""
        if was_comment and pm:
            header = ("(In response to [this comment](%s))" %<commit_msg>ConnectionErrors will no longer cause crashes<commit_after>import logging
import re
import time
import traceback

import praw
from requests.exceptions import ConnectionError, HTTPError, Timeout

import db
from db import Battle, Region, Processed, SkirmishAction, User
from utils import now, num_to_team, team_to_num, timestr


def failable(f):
    def wrapped(*args, **kwargs):
        try:
            return f(*args, **kwargs)
        except praw.errors.APIException:
            full = traceback.format_exc()
            logging.warning("Reddit API call failed! %s" % full)
            return None
        except ConnectionError:
            full = traceback.format_exc()
            logging.warning("Connection error: %s", full)
        except Timeout:
            full = traceback.format_exc()
            logging.warning("Socket timeout! %s" % full)
            return None
        except HTTPError:
            full = traceback.format_exc()
            logging.warning("HTTP error timeout! %s" % full)
            return None
    return wrapped


class Context(object):
    def __init__(self, player, config, session, comment, reddit):
        self.player = player    # a DB object
        self.config = config
        self.session = session
        self.comment = comment  # a praw object
        self.reddit = reddit    # root praw object

    @failable
    def reply(self, reply, pm=True):
        was_comment = getattr(self.comment, 'was_comment', True)
        header = ""
        if was_comment and pm:
            header = ("(In response to [this comment](%s))" %
{'fraction_non_alphanumeric': 0.08879919273461151, 'fraction_numerical': 0.0, 'mean_word_length': 2.349099099099099, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '729759', 'n_tokens_mistral': 804, 'n_tokens_neox': 814, 'n_words': 262}