<commit_before># coding=utf-8

import datetime
import os.path
import six
import re
import locale

try:
    import urlparse
except ImportError:
    import urllib.parse as urlparse

from .. import main
from .s3 import S3ResponseError


class Validate(object):
    def __init__(self, content, service, posted_data, uploader=None):
        self.content = content
        self.service = service
        self.posted_data = posted_data
        self.uploader = uploader
        self.clean_data = None
        self.dirty_data = None
        self._errors = None

    @property
    def errors(self):
        if self._errors is not None:
            return self._errors
        errors = {}
        self.clean_data = {}
        self.dirty_data = {}
        for question_id in self.posted_data:
            question_errors = self.question_errors(question_id)
            if question_errors:
                errors[question_id] = question_errors

        self._errors = errors
        return errors

    def question_errors(self, question_id):
        question = self.posted_data[question_id]
        question_content = self.content.get_question(question_id)

        if not self.test(question_id, question, "answer_required"):
            if "optional" in question_content:
                return
            # File has previously been uploaded
            if (
                question_id in self.service and
                'upload' == question_content.get('type')
            ):
                return
<commit_msg>Fix the failing answer_required test for text field<commit_after># coding=utf-8

import datetime
import os.path
import six
import re
import locale

try:
    import urlparse
except ImportError:
    import urllib.parse as urlparse

from .. import main
from .s3 import S3ResponseError


class Validate(object):
    def __init__(self, content, service, posted_data, uploader=None):
        self.content = content
        self.service = service
        self.posted_data = posted_data
        self.uploader = uploader
        self.clean_data = None
        self.dirty_data = None
        self._errors = None

    @property
    def errors(self):
        if self._errors is not None:
            return self._errors
        errors = {}
        self.clean_data = {}
        self.dirty_data = {}
        for question_id in self.posted_data:
            question_errors = self.question_errors(question_id)
            if question_errors:
                errors[question_id] = question_errors

        self._errors = errors
        return errors

    def question_errors(self, question_id):
        question = self.posted_data[question_id]
        question_content = self.content.get_question(question_id)

        if not self.test(question_id, question, "answer_required"):
            if "optional" in question_content:
                if question_content.get('type') != 'upload':
                    self.clean_data[question_id] = question
                return
            # File has previously been uploaded
            if (
                question_id in self.service and
                'upload' == question_content.get('type')
            ):
                return

{'fraction_non_alphanumeric': 0.07140600315955767, 'fraction_numerical': 0.0018957345971563982, 'mean_word_length': 2.0708050436469447, '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': '5199105', 'n_tokens_mistral': 849, 'n_tokens_neox': 822, 'n_words': 226}