<commit_before>from __future__ import absolute_import
from __future__ import print_function

import json
import logging

import requests

from .base import Provider as BaseProvider

logger = logging.getLogger(__name__)


def ProviderParser(subparser):
    subparser.add_argument("--auth-token", help="specify token used authenticate to DNS provider")

class Provider(BaseProvider):

    def __init__(self, options, engine_overrides=None):
        super(Provider, self).__init__(options, engine_overrides)
        self.domain_id = None
        self.api_endpoint = self.engine_overrides.get('api_endpoint', 'https://api.digitalocean.com/v2')

    def authenticate(self):

        payload = self._get('/domains/{0}'.format(self.options['domain']))
        self.domain_id = self.options['domain']

    def create_record(self, type, name, content):
        # check if record already exists
        existing_records = self.list_records(type,name,content)
        if len(existing_records) == 1:
            return True

        record = {
            'type': type,
            'name': self._relative_name(name),
            'data': content,

        }
        if type == 'CNAME':
            record['data'] = record['data'].rstrip('.') + '.' # make sure a the data is always a FQDN for CNAMe.

        payload = self._post('/domains/{0}/records'.format(self.domain_id), record)

        logger.debug('create_record: %s', True)
        return True

    # List all records. Return an empty list if no records found
    # type, name and content are used to filter records.
    # If possible filter during the query, otherwise filter after response is received.
    def list_records(self, type=None, name=None, content=None):
        url = '/domains/{0}/records'.format(self.domain_id)
        records = []
        payload = {}

        next = url
        while next is not None:<commit_msg>cleaner duplicate check for digitalocean.<commit_after>from __future__ import absolute_import
from __future__ import print_function

import json
import logging

import requests

from .base import Provider as BaseProvider

logger = logging.getLogger(__name__)


def ProviderParser(subparser):
    subparser.add_argument("--auth-token", help="specify token used authenticate to DNS provider")

class Provider(BaseProvider):

    def __init__(self, options, engine_overrides=None):
        super(Provider, self).__init__(options, engine_overrides)
        self.domain_id = None
        self.api_endpoint = self.engine_overrides.get('api_endpoint', 'https://api.digitalocean.com/v2')

    def authenticate(self):

        payload = self._get('/domains/{0}'.format(self.options['domain']))
        self.domain_id = self.options['domain']

    def create_record(self, type, name, content):
        # check if record already exists
        if len(self.list_records(type, name, content)) == 0:
            record = {
                'type': type,
                'name': self._relative_name(name),
                'data': content,

            }
            if type == 'CNAME':
                record['data'] = record['data'].rstrip('.') + '.' # make sure a the data is always a FQDN for CNAMe.

            payload = self._post('/domains/{0}/records'.format(self.domain_id), record)
        logger.debug('create_record: %s', True)
        return True

    # List all records. Return an empty list if no records found
    # type, name and content are used to filter records.
    # If possible filter during the query, otherwise filter after response is received.
    def list_records(self, type=None, name=None, content=None):
        url = '/domains/{0}/records'.format(self.domain_id)
        records = []
        payload = {}

        next = url
        while next is not None:
{'fraction_non_alphanumeric': 0.11140724946695096, 'fraction_numerical': 0.0026652452025586353, 'mean_word_length': 2.873065015479876, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '951953', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1021, 'n_words': 297}