<commit_before>import os
import http
import json
import asyncio

from waterbutler.core import utils
from waterbutler.core import streams
from waterbutler.core import provider
from waterbutler.core import exceptions

from waterbutler.providers.box import settings
from waterbutler.providers.box.metadata import BoxRevision
from waterbutler.providers.box.metadata import BoxFileMetadata
from waterbutler.providers.box.metadata import BoxFolderMetadata


class BoxPath(utils.WaterButlerPath):

    def __init__(self, path, _id=None, prefix=False, suffix=False):
        super().__init__(path, prefix=prefix, suffix=suffix)
        try:
            self._id = str(int(self.parts[1]))
        except:
            self._id = _id

class BoxProvider(provider.BaseProvider):
    NAME = 'box'
    BASE_URL = settings.BASE_URL

    def __init__(self, auth, credentials, settings):
        super().__init__(auth, credentials, settings)
        self.token = self.credentials['token']
        self.folder = self.settings['folder']

    def can_intra_move(self, other):
        return self == other

    def can_intra_copy(self, other):
        return self == other

    def intra_copy(self, destination_provider, source_options, destination_options):
        source_path = BoxPath(source_options['path'], _id=self.folder)
        destination_path = BoxPath(destination_options['path'], _id=destination_provider.folder)

        #TODO Refactor this into handle_name_conflict
        conflicting_id = yield from destination_provider._check_conflict(destination_path)

        if conflicting_id:<commit_msg>Implement validate path for Box provider<commit_after>import os
import http
import json
import asyncio

from waterbutler.core import utils
from waterbutler.core import streams
from waterbutler.core import provider
from waterbutler.core import exceptions

from waterbutler.providers.box import settings
from waterbutler.providers.box.metadata import BoxRevision
from waterbutler.providers.box.metadata import BoxFileMetadata
from waterbutler.providers.box.metadata import BoxFolderMetadata


class BoxPath(utils.WaterButlerPath):

    def __init__(self, path, _id=None, prefix=False, suffix=False):
        super().__init__(path, prefix=prefix, suffix=suffix)
        try:
            self._id = str(int(self.parts[1]))
        except:
            self._id = _id

class BoxProvider(provider.BaseProvider):
    NAME = 'box'
    BASE_URL = settings.BASE_URL

    def __init__(self, auth, credentials, settings):
        super().__init__(auth, credentials, settings)
        self.token = self.credentials['token']
        self.folder = self.settings['folder']

    @asyncio.coroutine
    def validate_path(self, path, **kwargs):
        if path == '/':
            return p.WaterButlerPath('/', _ids=[self.folder])

        parts = path.strip('/').split('/')
        folder_or_file = 'folders' if path.endswith('/') else 'files'

        response = yield from self.make_request(
            'get',
            self.build_url(folder_or_file, parts[0]),
            expects=(200, ),
            throws=exceptions.MetadataError,
        )
        data = yield from response.json()

        names, ids = zip(*[(x['name'], x['id']) for x in data['path_collection']['entries'] + [data]])

        try:
            names, ids = names[ids.index(self.folder) + 1:], ids[ids.index(self.folder):]
        except ValueError:
            raise Exception  # TODO

        if len(parts) == 2:
            ids += (None, )
            names += (parts[1], )

        return p.WaterButlerPath('/'.join(('',) + names), _ids=ids, folder=folder_or_file)

    def can_intra_move(self, other):
        return self == other

    def can_intra_copy(self, other):
        return self == other

    def intra_copy(self, destination_provider, source_options, destination_options):
        source_path = BoxPath(source_options['path'], _id=self.folder)
        destination_path = BoxPath(destination_options['path'], _id=destination_provider.folder)

        #TODO Refactor this into handle_name_conflict
        conflicting_id = yield from destination_provider._check_conflict(destination_path)

        if conflicting_id:
{'fraction_non_alphanumeric': 0.10289542952859536, 'fraction_numerical': 0.0021536252692031586, 'mean_word_length': 3.3723849372384938, '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': '6423421', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1167, 'n_words': 285}