<commit_before>import logging


log = logging.getLogger(__name__)


class IntegerTemplate:
    """Template for an integer value with constraints."""

    def __init__(self):
        pass


class StringTemplate:
    """Template for a string value with constraints."""

    def __init__(self):
        pass


class FloatTemplate:
    """Template for a floating point value with constraints."""

    def __init__(self):
        pass


class BoolTemplate:
    """Template for a boolean with constraints."""

    def __init__(self):
        pass


class ParameterTemplate:
    """Template for a parameter to pass to an operation on an endpoint."""

    def __init__(self, parameter):
        assert parameter.type is not None
        self._type = parameter.type
        assert parameter.name is not None
        self._name = parameter.name

    def __repr__(self):
        return "{}(name={}, type={})".format(self.__class__.__name__,
                                             self._name,
                                             self._type)

    @property
    def name(self):
        return self._name

    @property
    def type(self):
        return self._type


class ModelTemplate:
    """Template for a generic parameter, which may be one of many types,
    defining the model it follows.

    In the Swagger/OpenAPI world, this maps to a `Schema Object`.
    """

    def __init__(self, app, schema):
        self._app = app
        self._schema = schema
        self._contents = None

        self._build()

    @property
    def contents(self):
        return self._contents

    def _build(self):
        # The object may actually be a reference to the definition - if so
        # resolve it.
        ref = getattr(self._schema, '$ref')
        log.debug("Ref is: %r", ref)
        if ref is not None:
            schema = self._app.resolve(ref)
        else:
            schema = self._schema
        log.debug("Schema: %r", schema)
        log.debug("Schema name: %r", schema.name)

        # Populate the model based on its type.
        if schema.type == 'object':
            # If this is an oject with no properties, treat it as a freeform
            # JSON object - which we leave denoted by None.
            log.debug("Properties: %r", schema.properties)
            if len(schema.properties) > 0:
                self._contents = {}
                for prop_name in schema.properties:
                    log.debug("This prop: %r", prop_name)
                    child = ModelTemplate(self._app,
                                          schema.properties[prop_name])
                    self._contents[prop_name] = child
        elif schema.type == 'integer':
            log.debug("Model is integer")
            self._contents = IntegerTemplate()
        elif schema.type == 'string':
            log.debug("Model is string")
            self._contents = StringTemplate()
        elif schema.type == 'number':
            log.debug("Model is float")
            self._contents = FloatTemplate()
        elif schema.type == 'boolean':
            log.debug("Model is boolean")
            self._contents = BoolTemplate()
        else:
            log.warning("SKIPPING SCHEMA TYPE: %r - NOT IMPLEMENTED",
                        schema.type)


class OperationTemplate:
    """Template for an operation on an endpoint."""

    def __init__(self, app, operation):
        self._app = app
        self._operation = operation
        self._parameters = {}
        self._response_codes = [int(code) for code in operation.responses]

        self._populate_parameters()

    def __repr__(self):
        return "{}(operation={}, params={})".format(self.__class__.__name__,
                                                    self._operation,
                                                    self._parameters)

    @property
    def operation(self):
        return self._operation

    @property
    def parameters(self):
        return self._parameters

    @property
    def response_codes(self):
        return self._response_codes

    def _populate_parameters(self):
        for parameter in self._operation.parameters:
            log.debug("Handling parameter: %r", parameter.name)<commit_msg>Add support for 'default' response code value<commit_after>import logging


log = logging.getLogger(__name__)


class IntegerTemplate:
    """Template for an integer value with constraints."""

    def __init__(self):
        pass


class StringTemplate:
    """Template for a string value with constraints."""

    def __init__(self):
        pass


class FloatTemplate:
    """Template for a floating point value with constraints."""

    def __init__(self):
        pass


class BoolTemplate:
    """Template for a boolean with constraints."""

    def __init__(self):
        pass


class ParameterTemplate:
    """Template for a parameter to pass to an operation on an endpoint."""

    def __init__(self, parameter):
        assert parameter.type is not None
        self._type = parameter.type
        assert parameter.name is not None
        self._name = parameter.name

    def __repr__(self):
        return "{}(name={}, type={})".format(self.__class__.__name__,
                                             self._name,
                                             self._type)

    @property
    def name(self):
        return self._name

    @property
    def type(self):
        return self._type


class ModelTemplate:
    """Template for a generic parameter, which may be one of many types,
    defining the model it follows.

    In the Swagger/OpenAPI world, this maps to a `Schema Object`.
    """

    def __init__(self, app, schema):
        self._app = app
        self._schema = schema
        self._contents = None

        self._build()

    @property
    def contents(self):
        return self._contents

    def _build(self):
        # The object may actually be a reference to the definition - if so
        # resolve it.
        ref = getattr(self._schema, '$ref')
        log.debug("Ref is: %r", ref)
        if ref is not None:
            schema = self._app.resolve(ref)
        else:
            schema = self._schema
        log.debug("Schema: %r", schema)
        log.debug("Schema name: %r", schema.name)

        # Populate the model based on its type.
        if schema.type == 'object':
            # If this is an oject with no properties, treat it as a freeform
            # JSON object - which we leave denoted by None.
            log.debug("Properties: %r", schema.properties)
            if len(schema.properties) > 0:
                self._contents = {}
                for prop_name in schema.properties:
                    log.debug("This prop: %r", prop_name)
                    child = ModelTemplate(self._app,
                                          schema.properties[prop_name])
                    self._contents[prop_name] = child
        elif schema.type == 'integer':
            log.debug("Model is integer")
            self._contents = IntegerTemplate()
        elif schema.type == 'string':
            log.debug("Model is string")
            self._contents = StringTemplate()
        elif schema.type == 'number':
            log.debug("Model is float")
            self._contents = FloatTemplate()
        elif schema.type == 'boolean':
            log.debug("Model is boolean")
            self._contents = BoolTemplate()
        else:
            log.warning("SKIPPING SCHEMA TYPE: %r - NOT IMPLEMENTED",
                        schema.type)


class OperationTemplate:
    """Template for an operation on an endpoint."""

    def __init__(self, app, operation):
        self._app = app
        self._operation = operation
        self._parameters = {}
        # 'default' is a special value to cover undocumented response codes:
        # https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#fixed-fields-9
        self._response_codes = [int(code) for code in operation.responses
                                if code != "default"]

        self._populate_parameters()

    def __repr__(self):
        return "{}(operation={}, params={})".format(self.__class__.__name__,
                                                    self._operation,
                                                    self._parameters)

    @property
    def operation(self):
        return self._operation

    @property
    def parameters(self):
        return self._parameters

    @property
    def response_codes(self):
        return self._response_codes

    def _populate_parameters(self):
        for parameter in self._operation.parameters:
            log.debug("Handling parameter: %r", parameter.name)
{'fraction_non_alphanumeric': 0.09480579177200643, 'fraction_numerical': 0.0005745805561939783, 'mean_word_length': 1.8311646063760572, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2792222', 'n_tokens_mistral': 2171, 'n_tokens_neox': 2092, 'n_words': 685}