# Path: cutplace/_compat.py
# def text_repr(text):
# def token_io_readline(text):
# def csv_reader(source_text_stream, dialect=csv.excel, **keywords):
# def csv_writer(target_text_stream, dialect=csv.excel, **keywords):


import logging
import os
import token
import tokenize
from cutplace import _compat
def validated_python_name(name, value):
    """
    Validated and cleaned up ``value`` that represents a Python name with any
    whitespace removed. If validation fails, raise :py:exc:`NameError` with
    mentioning ``name`` as the name under which ``value`` is known to the
    user.
    """
    assert name
    assert value is not None

    toky = generated_tokens(value.strip())
    next_token = next(toky)
    next_type = next_token[0]
    result = next_token[1]
    if tokenize.ISEOF(next_type):
        raise NameError("%s must not be empty but was: %r" % (name, value))
    if next_type != token.NAME:
        raise NameError("%s must contain only ASCII letters, digits and underscore (_) but is: %r" % (name, value))
    second_token = next(toky)
    second_token_type = second_token[0]
    if second_token_type == token.NEWLINE and second_token[1] == "":
        # HACK: In Python 3.x a newline seems to be added either by generate_tokens() or readline().
        second_token = next(toky)
        second_token_type = second_token[0]
    if not tokenize.ISEOF(second_token_type):
        raise NameError("%s must be a single word, but after %r there also is %r" % (name, result, second_token[1]))
    return result


def generated_tokens(text):

# Path: cutplace/_compat.py
# def text_repr(text):
# def token_io_readline(text):
# def csv_reader(source_text_stream, dialect=csv.excel, **keywords):
# def csv_writer(target_text_stream, dialect=csv.excel, **keywords):


# Path: cutplace/_tools.py
import logging
import os
import token
import tokenize
from cutplace import _compat

def validated_python_name(name, value):
    """
    Validated and cleaned up ``value`` that represents a Python name with any
    whitespace removed. If validation fails, raise :py:exc:`NameError` with
    mentioning ``name`` as the name under which ``value`` is known to the
    user.
    """
    assert name
    assert value is not None

    toky = generated_tokens(value.strip())
    next_token = next(toky)
    next_type = next_token[0]
    result = next_token[1]
    if tokenize.ISEOF(next_type):
        raise NameError("%s must not be empty but was: %r" % (name, value))
    if next_type != token.NAME:
        raise NameError("%s must contain only ASCII letters, digits and underscore (_) but is: %r" % (name, value))
    second_token = next(toky)
    second_token_type = second_token[0]
    if second_token_type == token.NEWLINE and second_token[1] == "":
        # HACK: In Python 3.x a newline seems to be added either by generate_tokens() or readline().
        second_token = next(toky)
        second_token_type = second_token[0]
    if not tokenize.ISEOF(second_token_type):
        raise NameError("%s must be a single word, but after %r there also is %r" % (name, result, second_token[1]))
    return result


def generated_tokens(text):

    toky = list(tokenize.generate_tokens(_compat.token_io_readline(text)))