<commit_before>from __future__ import unicode_literals
from moto.core.responses import BaseResponse
from moto.core.utils import camelcase_to_underscores
from moto.ec2.utils import filters_from_querystring


class VPCs(BaseResponse):
    def create_vpc(self):
        cidr_block = self._get_param("CidrBlock")
        instance_tenancy = self._get_param("InstanceTenancy", if_none="default")
        amazon_provided_ipv6_cidr_blocks = self._get_param(
            "AmazonProvidedIpv6CidrBlock"
        )
        vpc = self.ec2_backend.create_vpc(
            cidr_block,
            instance_tenancy,
            amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_blocks,
        )
        doc_date = (
            "2013-10-15"
            if "Boto/" in self.headers.get("user-agent", "")
            else "2016-11-15"
        )
        template = self.response_template(CREATE_VPC_RESPONSE)
        return template.render(vpc=vpc, doc_date=doc_date)

    def delete_vpc(self):
        vpc_id = self._get_param("VpcId")
        vpc = self.ec2_backend.delete_vpc(vpc_id)
        template = self.response_template(DELETE_VPC_RESPONSE)
        return template.render(vpc=vpc)

    def describe_vpcs(self):
        vpc_ids = self._get_multi_param("VpcId")
        filters = filters_from_querystring(self.querystring)
        vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
        doc_date = (
            "2013-10-15"
            if "Boto/" in self.headers.get("user-agent", "")
            else "2016-11-15"
        )
        template = self.response_template(DESCRIBE_VPCS_RESPONSE)
        return template.render(vpcs=vpcs, doc_date=doc_date)

    def describe_vpc_attribute(self):
        vpc_id = self._get_param("VpcId")
        attribute = self._get_param("Attribute")
        attr_name = camelcase_to_underscores(attribute)
        value = self.ec2_backend.describe_vpc_attribute(vpc_id, attr_name)
        template = self.response_template(DESCRIBE_VPC_ATTRIBUTE_RESPONSE)
        return template.render(vpc_id=vpc_id, attribute=attribute, value=value)

    def describe_vpc_classic_link_dns_support(self):
        vpc_ids = self._get_multi_param('VpcIds')
        filters = filters_from_querystring(self.querystring)
        vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(DESCRIBE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE)
        return template.render(vpcs=vpcs, doc_date=doc_date)

    def enable_vpc_classic_link_dns_support(self):
        vpc_id = self._get_param('VpcId')
        classic_link_dns_supported = self.ec2_backend.enable_vpc_classic_link_dns_support(vpc_id=vpc_id)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(ENABLE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE)
        return template.render(classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date)

    def disable_vpc_classic_link_dns_support(self):
        vpc_id = self._get_param('VpcId')
        classic_link_dns_supported = self.ec2_backend.disable_vpc_classic_link_dns_support(vpc_id=vpc_id)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(DISABLE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE)
        return template.render(classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date)

    def describe_vpc_classic_link(self):
        vpc_ids = self._get_multi_param('VpcId')
        filters = filters_from_querystring(self.querystring)
        vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(DESCRIBE_VPC_CLASSIC_LINK_RESPONSE)
        return template.render(vpcs=vpcs, doc_date=doc_date)

    def enable_vpc_classic_link(self):
        vpc_id = self._get_param('VpcId')
        classic_link_enabled = self.ec2_backend.enable_vpc_classic_link(vpc_id=vpc_id)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(ENABLE_VPC_CLASSIC_LINK_RESPONSE)
        return template.render(classic_link_enabled=classic_link_enabled, doc_date=doc_date)

    def disable_vpc_classic_link(self):
        vpc_id = self._get_param('VpcId')
        classic_link_enabled = self.ec2_backend.disable_vpc_classic_link(vpc_id=vpc_id)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(DISABLE_VPC_CLASSIC_LINK_RESPONSE)
        return template.render(classic_link_enabled=classic_link_enabled, doc_date=doc_date)

    def modify_vpc_attribute(self):
        vpc_id = self._get_param("VpcId")

        for attribute in ("EnableDnsSupport", "EnableDnsHostnames"):
            if self.querystring.get("%s.Value" % attribute):
                attr_name = camelcase_to_underscores(attribute)
                attr_value = self.querystring.get("%s.Value" % attribute)[0]
                self.ec2_backend.modify_vpc_attribute(vpc_id, attr_name, attr_value)
                return MODIFY_VPC_ATTRIBUTE_RESPONSE

    def associate_vpc_cidr_block(self):
        vpc_id = self._get_param("VpcId")
        amazon_provided_ipv6_cidr_blocks = self._get_param(
            "AmazonProvidedIpv6CidrBlock"<commit_msg>Refactored doc_date into method.<commit_after>from __future__ import unicode_literals
from moto.core.responses import BaseResponse
from moto.core.utils import camelcase_to_underscores
from moto.ec2.utils import filters_from_querystring


class VPCs(BaseResponse):
    def _get_doc_date(self):
        return '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'

    def create_vpc(self):
        cidr_block = self._get_param('CidrBlock')
        instance_tenancy = self._get_param('InstanceTenancy', if_none='default')
        amazon_provided_ipv6_cidr_blocks = self._get_param('AmazonProvidedIpv6CidrBlock')
        vpc = self.ec2_backend.create_vpc(cidr_block, instance_tenancy,
                                          amazon_provided_ipv6_cidr_block=amazon_provided_ipv6_cidr_blocks)
        doc_date = self._get_doc_date()
        template = self.response_template(CREATE_VPC_RESPONSE)
        return template.render(vpc=vpc, doc_date=doc_date)

    def delete_vpc(self):
        vpc_id = self._get_param("VpcId")
        vpc = self.ec2_backend.delete_vpc(vpc_id)
        template = self.response_template(DELETE_VPC_RESPONSE)
        return template.render(vpc=vpc)

    def describe_vpcs(self):
        vpc_ids = self._get_multi_param("VpcId")
        filters = filters_from_querystring(self.querystring)
        vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
        doc_date = '2013-10-15' if 'Boto/' in self.headers.get('user-agent', '') else '2016-11-15'
        template = self.response_template(DESCRIBE_VPCS_RESPONSE)
        return template.render(vpcs=vpcs, doc_date=doc_date)

    def describe_vpc_attribute(self):
        vpc_id = self._get_param("VpcId")
        attribute = self._get_param("Attribute")
        attr_name = camelcase_to_underscores(attribute)
        value = self.ec2_backend.describe_vpc_attribute(vpc_id, attr_name)
        template = self.response_template(DESCRIBE_VPC_ATTRIBUTE_RESPONSE)
        return template.render(vpc_id=vpc_id, attribute=attribute, value=value)

    def describe_vpc_classic_link_dns_support(self):
        vpc_ids = self._get_multi_param('VpcIds')
        filters = filters_from_querystring(self.querystring)
        vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
        doc_date = self._get_doc_date()
        template = self.response_template(DESCRIBE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE)
        return template.render(vpcs=vpcs, doc_date=doc_date)

    def enable_vpc_classic_link_dns_support(self):
        vpc_id = self._get_param('VpcId')
        classic_link_dns_supported = self.ec2_backend.enable_vpc_classic_link_dns_support(vpc_id=vpc_id)
        doc_date = self._get_doc_date()
        template = self.response_template(ENABLE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE)
        return template.render(classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date)

    def disable_vpc_classic_link_dns_support(self):
        vpc_id = self._get_param('VpcId')
        classic_link_dns_supported = self.ec2_backend.disable_vpc_classic_link_dns_support(vpc_id=vpc_id)
        doc_date = self._get_doc_date()
        template = self.response_template(DISABLE_VPC_CLASSIC_LINK_DNS_SUPPORT_RESPONSE)
        return template.render(classic_link_dns_supported=classic_link_dns_supported, doc_date=doc_date)

    def describe_vpc_classic_link(self):
        vpc_ids = self._get_multi_param('VpcId')
        filters = filters_from_querystring(self.querystring)
        vpcs = self.ec2_backend.get_all_vpcs(vpc_ids=vpc_ids, filters=filters)
        doc_date = self._get_doc_date()
        template = self.response_template(DESCRIBE_VPC_CLASSIC_LINK_RESPONSE)
        return template.render(vpcs=vpcs, doc_date=doc_date)

    def enable_vpc_classic_link(self):
        vpc_id = self._get_param('VpcId')
        classic_link_enabled = self.ec2_backend.enable_vpc_classic_link(vpc_id=vpc_id)
        doc_date = self._get_doc_date()
        template = self.response_template(ENABLE_VPC_CLASSIC_LINK_RESPONSE)
        return template.render(classic_link_enabled=classic_link_enabled, doc_date=doc_date)

    def disable_vpc_classic_link(self):
        vpc_id = self._get_param('VpcId')
        classic_link_enabled = self.ec2_backend.disable_vpc_classic_link(vpc_id=vpc_id)
        doc_date = self._get_doc_date()
        template = self.response_template(DISABLE_VPC_CLASSIC_LINK_RESPONSE)
        return template.render(classic_link_enabled=classic_link_enabled, doc_date=doc_date)

    def modify_vpc_attribute(self):
        vpc_id = self._get_param("VpcId")

        for attribute in ("EnableDnsSupport", "EnableDnsHostnames"):
            if self.querystring.get("%s.Value" % attribute):
                attr_name = camelcase_to_underscores(attribute)
                attr_value = self.querystring.get("%s.Value" % attribute)[0]
                self.ec2_backend.modify_vpc_attribute(vpc_id, attr_name, attr_value)
                return MODIFY_VPC_ATTRIBUTE_RESPONSE

    def associate_vpc_cidr_block(self):
        vpc_id = self._get_param("VpcId")
        amazon_provided_ipv6_cidr_blocks = self._get_param(
            "AmazonProvidedIpv6CidrBlock"
{'fraction_non_alphanumeric': 0.09183484539900018, 'fraction_numerical': 0.018329938900203666, 'mean_word_length': 3.77797434763379, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6856817', 'n_tokens_mistral': 3943, 'n_tokens_neox': 3805, 'n_words': 456}