# Path: common/ws_utils.py
# def split_page_text(text):
# 
# Path: common/utils.py
# def read_file(filename):
# def write_file(filename, text):
# def save_obj(filename, data):
# def load_obj(filename):
# def sha1(filename):
# def write_sha1(sha1, filename):
# def url_opener():
# def copy_file_from_url(url, out_file, expect_sha1 = None, max_retry = 4):
# def compress_file_data(out_filename, data, compress_type):
# def compress_file(out_filename, in_filename, compress_type):
# def uncompress_file(filename, compress_type):
# def _retry_on_eintr(func, *args):
# def safe_read(fd):
# def safe_write(fd, text):
# def print_traceback(*kwargs):
# def readline_backward(filename, buf_size=8192):


import sys
import os
import re
import tempfile
import os
import pywikibot
from ws_namespaces import page as page_prefixes, index as index_prefixes
from common import ws_utils
from common import utils
from pywikibot import pagegenerators as pagegen
    from match_and_split import align
    diff = re.sub(u'^\+\+\+ /[^\n]+/[^\n]+\n', '', diff)

    diff = re.split(u'(?ms)@@.*?@@\n', diff)
    diff = [x for x in diff if x]

    return diff

def filter_diff(diff, opt):
    result = []
    for d in diff:
        if check_diff(d, opt):
            result.append(d)

    return result

def do_transform(text, ocr_text, opt):
    text = common_transform(text)
    text = transform_text(text, opt)
    ocr_text = common_transform(ocr_text)
    ocr_text = transform_ocr_text(ocr_text, opt)
    return text, ocr_text

def verify_match(page_name, ocr_text, text, opt):
    has_nr = has_nr_template(text)

    if opt.do_transform:
        text, ocr_text = do_transform(text, ocr_text, opt)

    diff = do_diff(ocr_text, text, opt)
    if False and not has_nr:

# Path: common/ws_utils.py
# def split_page_text(text):
# 
# Path: common/utils.py
# def read_file(filename):
# def write_file(filename, text):
# def save_obj(filename, data):
# def load_obj(filename):
# def sha1(filename):
# def write_sha1(sha1, filename):
# def url_opener():
# def copy_file_from_url(url, out_file, expect_sha1 = None, max_retry = 4):
# def compress_file_data(out_filename, data, compress_type):
# def compress_file(out_filename, in_filename, compress_type):
# def uncompress_file(filename, compress_type):
# def _retry_on_eintr(func, *args):
# def safe_read(fd):
# def safe_write(fd, text):
# def print_traceback(*kwargs):
# def readline_backward(filename, buf_size=8192):


# Path: verify_match/verify_match.py
import sys
import os
import re
import tempfile
import os
import pywikibot
from ws_namespaces import page as page_prefixes, index as index_prefixes
from common import ws_utils
from common import utils
from pywikibot import pagegenerators as pagegen
    from match_and_split import align

    diff = re.sub(u'^\+\+\+ /[^\n]+/[^\n]+\n', '', diff)

    diff = re.split(u'(?ms)@@.*?@@\n', diff)
    diff = [x for x in diff if x]

    return diff

def filter_diff(diff, opt):
    result = []
    for d in diff:
        if check_diff(d, opt):
            result.append(d)

    return result

def do_transform(text, ocr_text, opt):
    text = common_transform(text)
    text = transform_text(text, opt)
    ocr_text = common_transform(ocr_text)
    ocr_text = transform_ocr_text(ocr_text, opt)
    return text, ocr_text

def verify_match(page_name, ocr_text, text, opt):
    has_nr = has_nr_template(text)

    if opt.do_transform:
        text, ocr_text = do_transform(text, ocr_text, opt)

    diff = do_diff(ocr_text, text, opt)
    if False and not has_nr:

        ocr_text = ocr_text.split(u'\n')