<commit_before>#!/usr/bin/env python3

try:
    import configparser
except ImportError:
    raise ImportError("Must be using Python 3")

import argparse
import os
import re
import subprocess
import sys
from typing import Any, Dict, List, Match, Optional # NOQA
import webbrowser


__version__ = '2.6.0'
USER_REGEX = '(?P<user>[\w\.@:\/~_-]+)'
REPOSITORY_REGEX = '(?P<repository>[\w\.@:\/~_-]+)'
GITHUB_SSH_URL = 'git@github.com:%s/%s' % (USER_REGEX, REPOSITORY_REGEX)
GITHUB_HTTPS_URL = 'https://github.com/%s/%s' % (USER_REGEX, REPOSITORY_REGEX)
UBER_SSH_GITOLITE_URL = '<EMAIL>:%s' % (REPOSITORY_REGEX)
UBER_SSH_CONFIG_GITOLITE_URL = '<EMAIL>:%s' % \
    (REPOSITORY_REGEX)
UBER_HTTPS_GITOLITE_URL = 'https://code.uber.internal/%s/%s' % \
    (USER_REGEX, REPOSITORY_REGEX)


class GithubHost(object):
    GITHUB_URL = "https://github.com/"

    def __init__(self, user: str, repository: str) -> None:
        self.user = user
        self.repository = repository

    @staticmethod
    def create(url_regex_match: Match) -> 'GithubHost':
        repository = url_regex_match.group('repository')
        if repository[-4:] == '.git':
            repository = repository[:-4]
        user = url_regex_match.group('user')
        return GithubHost(user, repository)

    def get_url(self, git_object: 'GitObject') -> str:
        repository_url = "%s%s/%s" % (
            self.GITHUB_URL,
            self.user,
            self.repository
        )
        if git_object.is_commit_hash():
            return self.commit_hash_url(repository_url, git_object)
        if git_object.is_root():
            return self.root_url(repository_url, git_object)
        if git_object.is_directory():
            return self.directory_url(repository_url, git_object)
        return self.file_url(repository_url, git_object)

    def commit_hash_url(
            self,
            repository_url: str,
            focus_hash: 'GitObject') -> str:
        repository_url = "%s/commit/%s" % (
            repository_url,
            focus_hash.identifier
        )
        return repository_url

    def root_url(self, repository_url: str, focus_object: 'GitObject') -> str:
        return repository_url

    def directory_url(
            self,
            repository_url: str,
            focus_object: 'GitObject') -> str:
        repository_url = "%s/tree/master/%s" % (
            repository_url,
            focus_object.identifier
        )
        return repository_url

    def file_url(self, repository_url: str, focus_object: 'GitObject') -> str:
        repository_url = "%s/blob/master/%s" % (
            repository_url,
            focus_object.identifier
        )
        return repository_url

    def valid_focus_object(self, arg: str):
        return None


class PhabricatorHost(object):
    PHABRICATOR_OBJECT_REGEX = '^[DT][0-9]+$'

    def __init__(self):
        pass

    @staticmethod
    def create(url_regex_match: str=None) -> 'PhabricatorHost':
        return PhabricatorHost()

    def get_url(self, git_object: 'GitObject') -> List[str]:
        path = git_object.identifier
        # arc browse requires an object, provide the root object by default
        if git_object.is_root():
            path = '.'
        command = ['arc', 'browse']
        if path:
            command.append(path)
        return command

    def valid_focus_object(self, arg: str) -> Optional['PhabricatorObject']:
        if re.search(self.PHABRICATOR_OBJECT_REGEX, arg):
            return PhabricatorObject(arg)
        return None


HOST_REGEXES = {
    GITHUB_SSH_URL: GithubHost,
    GITHUB_HTTPS_URL: GithubHost,
    UBER_SSH_GITOLITE_URL: PhabricatorHost,
    UBER_SSH_CONFIG_GITOLITE_URL: PhabricatorHost,
    UBER_HTTPS_GITOLITE_URL: PhabricatorHost,
}  # type: Dict[str, Any]


class GitObject(object):
    def __init__(self, identifier: str) -> None:
        self.identifier = identifier

    def is_commit_hash(self) -> bool:
        return False

    def is_root(self) -> bool:
        return False

    def is_directory(self) -> bool:
        return False
<commit_msg>Add skeleton SourcegraphHost object<commit_after>#!/usr/bin/env python3

try:
    import configparser
except ImportError:
    raise ImportError("Must be using Python 3")

import argparse
import os
import re
import subprocess
import sys
from typing import Any, Dict, List, Match, Optional # NOQA
import webbrowser


__version__ = '2.6.0'
USER_REGEX = '(?P<user>[\w\.@:\/~_-]+)'
REPOSITORY_REGEX = '(?P<repository>[\w\.@:\/~_-]+)'
GITHUB_SSH_URL = 'git@github.com:%s/%s' % (USER_REGEX, REPOSITORY_REGEX)
GITHUB_HTTPS_URL = 'https://github.com/%s/%s' % (USER_REGEX, REPOSITORY_REGEX)
UBER_SSH_GITOLITE_URL = 'git<EMAIL>:%s' % (REPOSITORY_REGEX)
UBER_SSH_CONFIG_GITOLITE_URL = 'git<EMAIL>:%s' % \
    (REPOSITORY_REGEX)
UBER_HTTPS_GITOLITE_URL = 'https://code.uber.internal/%s/%s' % \
    (USER_REGEX, REPOSITORY_REGEX)


class GithubHost(object):
    GITHUB_URL = "https://github.com/"

    def __init__(self, user: str, repository: str) -> None:
        self.user = user
        self.repository = repository

    @staticmethod
    def create(url_regex_match: Match) -> 'GithubHost':
        repository = url_regex_match.group('repository')
        if repository[-4:] == '.git':
            repository = repository[:-4]
        user = url_regex_match.group('user')
        return GithubHost(user, repository)

    def get_url(self, git_object: 'GitObject') -> str:
        repository_url = "%s%s/%s" % (
            self.GITHUB_URL,
            self.user,
            self.repository
        )
        if git_object.is_commit_hash():
            return self.commit_hash_url(repository_url, git_object)
        if git_object.is_root():
            return self.root_url(repository_url, git_object)
        if git_object.is_directory():
            return self.directory_url(repository_url, git_object)
        return self.file_url(repository_url, git_object)

    def commit_hash_url(
            self,
            repository_url: str,
            focus_hash: 'GitObject') -> str:
        repository_url = "%s/commit/%s" % (
            repository_url,
            focus_hash.identifier
        )
        return repository_url

    def root_url(self, repository_url: str, focus_object: 'GitObject') -> str:
        return repository_url

    def directory_url(
            self,
            repository_url: str,
            focus_object: 'GitObject') -> str:
        repository_url = "%s/tree/master/%s" % (
            repository_url,
            focus_object.identifier
        )
        return repository_url

    def file_url(self, repository_url: str, focus_object: 'GitObject') -> str:
        repository_url = "%s/blob/master/%s" % (
            repository_url,
            focus_object.identifier
        )
        return repository_url

    def valid_focus_object(self, arg: str):
        return None


class PhabricatorHost(object):
    PHABRICATOR_OBJECT_REGEX = '^[DT][0-9]+$'

    def __init__(self):
        pass

    @staticmethod
    def create(url_regex_match: str=None) -> 'PhabricatorHost':
        return PhabricatorHost()

    def get_url(self, git_object: 'GitObject') -> List[str]:
        path = git_object.identifier
        # arc browse requires an object, provide the root object by default
        if git_object.is_root():
            path = '.'
        command = ['arc', 'browse']
        if path:
            command.append(path)
        return command

    def valid_focus_object(self, arg: str) -> Optional['PhabricatorObject']:
        if re.search(self.PHABRICATOR_OBJECT_REGEX, arg):
            return PhabricatorObject(arg)
        return None


class SourcegraphHost(object):
    def __init__(self):
        pass

    @staticmethod
    def create(url_regex_match: str=None) -> 'SourcegraphHost':
        return SourcegraphHost()

    def get_url(self, git_object: 'GitObject') -> List[str]:
        raise NotImplementedError()

    def valid_focus_object(self, arg: str):
        raise NotImplementedError()


HOST_REGEXES = {
    GITHUB_SSH_URL: GithubHost,
    GITHUB_HTTPS_URL: GithubHost,
    UBER_SSH_GITOLITE_URL: PhabricatorHost,
    UBER_SSH_CONFIG_GITOLITE_URL: PhabricatorHost,
    UBER_HTTPS_GITOLITE_URL: PhabricatorHost,
}  # type: Dict[str, Any]


class GitObject(object):
    def __init__(self, identifier: str) -> None:
        self.identifier = identifier

    def is_commit_hash(self) -> bool:
        return False

    def is_root(self) -> bool:
        return False

    def is_directory(self) -> bool:
        return False

{'fraction_non_alphanumeric': 0.11190281509169489, 'fraction_numerical': 0.0021025581123700504, 'mean_word_length': 2.6683804627249357, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 41, 'https://': 6, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '877898', 'n_tokens_mistral': 2840, 'n_tokens_neox': 2757, 'n_words': 562}