# Path: pubs/p3.py
# def input():
#     return raw_input().decode(sys.stdin.encoding or 'utf8', 'ignore')
# 
# Path: pubs/content.py
# class UnableToDecodeTextFile(Exception):
#     def __init__(self, path):
#     def __str__(self):
# def _check_system_path_exists(path, fail=True):
# def _check_system_path_is(nature, path, fail=True):
# def system_path(path):
# def _open(path, mode):
# def check_file(path, fail=True):
# def check_directory(path, fail=True):
# def read_text_file(filepath, fail=True):
# def read_binary_file(filepath, fail=True):
# def remove_file(filepath):
# def write_file(filepath, data, mode='w'):
# def content_type(path):
# def url_exists(url):
# def check_content(path):
# def _get_byte_url_content(path, ui=None):
# def _dump_byte_url_content(source, target):
# def get_content(path, ui=None):
# def move_content(source, target, overwrite=False):
# def copy_content(source, target, overwrite=False):
# 
# Path: pubs/filebroker.py
# META_EXT = '.yaml'
# BIB_EXT  = '.bib'
# def filter_filename(filename, ext):
#     def __init__(self, directory, create=False):
#     def _create(self):
#     def bib_path(self, citekey):
#     def meta_path(self, citekey):
#     def pull_cachefile(self, filename):
#     def push_cachefile(self, filename, data):
#     def mtime_metafile(self, citekey):
#     def mtime_bibfile(self, citekey):
#     def pull_metafile(self, citekey):
#     def pull_bibfile(self, citekey):
#     def push_metafile(self, citekey, metadata):
#     def push_bibfile(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def listing(self, filestats=True):
#     def __init__(self, directory, scheme='docsdir', subdir='doc'):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
# class FileBroker(object):
# class DocBroker(object):
# 
# Path: pubs/uis.py
# DEBUG = False  # unhandled exceptions traces are printed
# DEBUG_ALL_TRACES = False  # handled exceptions traces are printed
# def _get_encoding(conf):
# def _get_local_editor():
# def get_ui():
# def init_ui(conf, force_colors=False):
#     def __init__(self, conf, force_colors=False):
#     def message(self, *messages, **kwargs):
#     def info(self, message, **kwargs):
#     def warning(self, message, **kwargs):
#     def error(self, message, **kwargs):
#     def exit(self, error_code=1):
#     def handle_exception(self, exc):
#     def test_handle_exception(self, exc):
#     def __init__(self, conf, force_colors=False):
#     def input(self):
#     def input_choice_ng(self, options, option_chars=None, default=None, question=''):
#     def input_choice(self, options, option_chars, default=None, question=''):
#     def input_yn(self, question='', default='y'):
#     def editor_input(self, initial="", suffix='.tmp'):
#     def edit_file(self, path, temporary):
#     def _call_editor(self, path):
# class PrintUI(object):
# class InputUI(PrintUI):


import sys
import io
import os
import shutil
import glob
import locale
import dotdot
from pyfakefs import fake_filesystem, fake_filesystem_unittest
from pubs.p3 import input
from pubs import content, filebroker, uis
# Test helpers

# automating input
real_input = input


class FakeInput():
    """ Replace the input() command, and mock user input during tests

        Instanciate as :
        input = FakeInput(['yes', 'no'])
        then replace the input command in every module of the package :
        input.as_global()
        Then :
        input() returns 'yes'
        input() returns 'no'
        input() raises IndexError
     """

    class UnexpectedInput(Exception):
        pass

    def __init__(self, inputs, module_list=tuple()):
        self.inputs = list(inputs) or []
        self.module_list = module_list
        self._cursor = 0
        self._original_handler = None

    def as_global(self):
        for md in self.module_list:

# Path: pubs/p3.py
# def input():
#     return raw_input().decode(sys.stdin.encoding or 'utf8', 'ignore')
# 
# Path: pubs/content.py
# class UnableToDecodeTextFile(Exception):
#     def __init__(self, path):
#     def __str__(self):
# def _check_system_path_exists(path, fail=True):
# def _check_system_path_is(nature, path, fail=True):
# def system_path(path):
# def _open(path, mode):
# def check_file(path, fail=True):
# def check_directory(path, fail=True):
# def read_text_file(filepath, fail=True):
# def read_binary_file(filepath, fail=True):
# def remove_file(filepath):
# def write_file(filepath, data, mode='w'):
# def content_type(path):
# def url_exists(url):
# def check_content(path):
# def _get_byte_url_content(path, ui=None):
# def _dump_byte_url_content(source, target):
# def get_content(path, ui=None):
# def move_content(source, target, overwrite=False):
# def copy_content(source, target, overwrite=False):
# 
# Path: pubs/filebroker.py
# META_EXT = '.yaml'
# BIB_EXT  = '.bib'
# def filter_filename(filename, ext):
#     def __init__(self, directory, create=False):
#     def _create(self):
#     def bib_path(self, citekey):
#     def meta_path(self, citekey):
#     def pull_cachefile(self, filename):
#     def push_cachefile(self, filename, data):
#     def mtime_metafile(self, citekey):
#     def mtime_bibfile(self, citekey):
#     def pull_metafile(self, citekey):
#     def pull_bibfile(self, citekey):
#     def push_metafile(self, citekey, metadata):
#     def push_bibfile(self, citekey, bibdata):
#     def push(self, citekey, metadata, bibdata):
#     def remove(self, citekey):
#     def exists(self, citekey, meta_check=False):
#     def listing(self, filestats=True):
#     def __init__(self, directory, scheme='docsdir', subdir='doc'):
#     def in_docsdir(self, docpath):
#     def real_docpath(self, docpath):
#     def add_doc(self, citekey, source_path, overwrite=False):
#     def remove_doc(self, docpath, silent=True):
#     def rename_doc(self, docpath, new_citekey):
# class FileBroker(object):
# class DocBroker(object):
# 
# Path: pubs/uis.py
# DEBUG = False  # unhandled exceptions traces are printed
# DEBUG_ALL_TRACES = False  # handled exceptions traces are printed
# def _get_encoding(conf):
# def _get_local_editor():
# def get_ui():
# def init_ui(conf, force_colors=False):
#     def __init__(self, conf, force_colors=False):
#     def message(self, *messages, **kwargs):
#     def info(self, message, **kwargs):
#     def warning(self, message, **kwargs):
#     def error(self, message, **kwargs):
#     def exit(self, error_code=1):
#     def handle_exception(self, exc):
#     def test_handle_exception(self, exc):
#     def __init__(self, conf, force_colors=False):
#     def input(self):
#     def input_choice_ng(self, options, option_chars=None, default=None, question=''):
#     def input_choice(self, options, option_chars, default=None, question=''):
#     def input_yn(self, question='', default='y'):
#     def editor_input(self, initial="", suffix='.tmp'):
#     def edit_file(self, path, temporary):
#     def _call_editor(self, path):
# class PrintUI(object):
# class InputUI(PrintUI):


# Path: tests/fake_env.py
import sys
import io
import os
import shutil
import glob
import locale
import dotdot
from pyfakefs import fake_filesystem, fake_filesystem_unittest
from pubs.p3 import input
from pubs import content, filebroker, uis

# Test helpers

# automating input
real_input = input


class FakeInput():
    """ Replace the input() command, and mock user input during tests

        Instanciate as :
        input = FakeInput(['yes', 'no'])
        then replace the input command in every module of the package :
        input.as_global()
        Then :
        input() returns 'yes'
        input() returns 'no'
        input() raises IndexError
     """

    class UnexpectedInput(Exception):
        pass

    def __init__(self, inputs, module_list=tuple()):
        self.inputs = list(inputs) or []
        self.module_list = module_list
        self._cursor = 0
        self._original_handler = None

    def as_global(self):
        for md in self.module_list:

            md.input = self