<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

import os
import sys
import argparse
import base58

from .client import DownstreamClient
from downstream_farmer.version import __version__
from downstream_farmer.exc import ConnectError, DownstreamError

try:
    from urllib2 import urlopen, URLError
except ImportError:
    from urllib.request import urlopen
    from urllib.error import URLError


def fail_exit(msg, exit_code=1):
    sys.stderr.write('Error: %s\n' % msg)
    sys.exit(exit_code)


def run_prototype(url, number):
    try:
        # generate a blank address...
        test_address = base58.b58encode_check(b'\x00'+os.urandom(20))
        client = DownstreamClient(test_address)

        print('Connect to server')
        client.connect(url)

        print('Fetching contract')
        client.get_chunk()

        print('Answering challenge 0')
        client.answer_challenge()

        i = 1
        while number == 0 or i < number:
            client.get_challenge()
            print('Answering challenge {0}'.format(i))
            client.answer_challenge()
            i += 1

        print('Verification successful!')

    except DownstreamError as e:
        fail_exit(e.message)


def check_connectivity(url):
        """ Check to see if we even get a connection to the server.
        https://stackoverflow.com/questions/3764291/checking-network-connection
        """
        try:
            urlopen(url, timeout=2)
        except URLError:
            raise ConnectError("Could not connect to server.")


def eval_args(args):
    try:
        check_connectivity(args.node_url)
    except ConnectError as e:
        fail_exit(e.message)

    if args.number < 0:
        fail_exit('Must specify a non-negative number of challenges.')

    run_prototype(args.node_url, args.number)


def parse_args():
    parser = argparse.ArgumentParser('downstream-farmer')
    parser.add_argument('-V', '--version', action='version',
                        version=__version__)
    parser.add_argument('node_url', help='URL of the Downstream node')
    parser.add_argument('-n', '--number', type=int,
                        default=0,
                        help='Number of challenges to perform.  '
                        'If unspecified, perform challenges until killed.')
    return parser.parse_args()


def main():
    args = parse_args()
    eval_args(args)<commit_msg>added default for node_url to verify.driveshare.org<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import print_function

import os
import sys
import argparse
import base58

from .client import DownstreamClient
from downstream_farmer.version import __version__
from downstream_farmer.exc import ConnectError, DownstreamError

try:
    from urllib2 import urlopen, URLError
except ImportError:
    from urllib.request import urlopen
    from urllib.error import URLError


def fail_exit(msg, exit_code=1):
    sys.stderr.write('Error: %s\n' % msg)
    sys.exit(exit_code)


def run_prototype(url, number):
    try:
        # generate a blank address...
        test_address = base58.b58encode_check(b'\x00'+os.urandom(20))
        client = DownstreamClient(test_address)

        print('Connect to server')
        client.connect(url)

        print('Fetching contract')
        client.get_chunk()

        print('Answering challenge 0')
        client.answer_challenge()

        i = 1
        while number == 0 or i < number:
            client.get_challenge()
            print('Answering challenge {0}'.format(i))
            client.answer_challenge()
            i += 1

        print('Verification successful!')

    except DownstreamError as e:
        fail_exit(e.message)


def check_connectivity(url):
        """ Check to see if we even get a connection to the server.
        https://stackoverflow.com/questions/3764291/checking-network-connection
        """
        try:
            urlopen(url, timeout=2)
        except URLError:
            raise ConnectError("Could not connect to server.")


def eval_args(args):
    try:
        check_connectivity(args.node_url)
    except ConnectError as e:
        fail_exit(e.message)

    if args.number < 0:
        fail_exit('Must specify a non-negative number of challenges.')

    run_prototype(args.node_url, args.number)


def parse_args():
    parser = argparse.ArgumentParser('downstream-farmer')
    parser.add_argument('-V', '--version', action='version',
                        version=__version__)
    parser.add_argument('node_url', help='URL of the Downstream node',
                        nargs='?',
                        default='http://verify.driveshare.org')
    parser.add_argument('-n', '--number', type=int,
                        default=0,
                        help='Number of challenges to perform. '
                        'If unspecified, perform challenges until killed.')
    return parser.parse_args()


def main():
    args = parse_args()
    eval_args(args)
{'fraction_non_alphanumeric': 0.10063643595863166, 'fraction_numerical': 0.011137629276054098, 'mean_word_length': 2.4947880472550383, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2853338', 'n_tokens_mistral': 1510, 'n_tokens_neox': 1404, 'n_words': 366}