From 9bc2ab482c42ee3b3f051b1b403713f9f0922a15 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 29 Oct 2021 22:43:35 -0400 Subject: docs: sample HTML report for 6.1 --- doc/sample_html/coverage_html.js | 624 ++- .../d_7b071bdc2a35fa80___init___py.html | 113 +- .../d_7b071bdc2a35fa80___main___py.html | 105 +- .../d_7b071bdc2a35fa80_backward_py.html | 179 +- doc/sample_html/d_7b071bdc2a35fa80_cogapp_py.html | 1715 +++---- .../d_7b071bdc2a35fa80_makefiles_py.html | 187 +- .../d_7b071bdc2a35fa80_test_cogapp_py.html | 5051 ++++++++++---------- .../d_7b071bdc2a35fa80_test_makefiles_py.html | 339 +- .../d_7b071bdc2a35fa80_test_whiteutils_py.html | 297 +- .../d_7b071bdc2a35fa80_whiteutils_py.html | 241 +- doc/sample_html/index.html | 99 +- doc/sample_html/jquery.ba-throttle-debounce.min.js | 9 - doc/sample_html/jquery.hotkeys.js | 99 - doc/sample_html/jquery.isonscreen.js | 53 - doc/sample_html/jquery.min.js | 4 - doc/sample_html/jquery.tablesorter.min.js | 2 - doc/sample_html/status.json | 2 +- doc/sample_html/style.css | 124 +- 18 files changed, 4545 insertions(+), 4698 deletions(-) delete mode 100644 doc/sample_html/jquery.ba-throttle-debounce.min.js delete mode 100644 doc/sample_html/jquery.hotkeys.js delete mode 100644 doc/sample_html/jquery.isonscreen.js delete mode 100644 doc/sample_html/jquery.min.js delete mode 100644 doc/sample_html/jquery.tablesorter.min.js (limited to 'doc/sample_html') diff --git a/doc/sample_html/coverage_html.js b/doc/sample_html/coverage_html.js index 30d3a067..d111289b 100644 --- a/doc/sample_html/coverage_html.js +++ b/doc/sample_html/coverage_html.js @@ -7,227 +7,191 @@ coverage = {}; -// Find all the elements with shortkey_* class, and use them to assign a shortcut key. -coverage.assign_shortkeys = function () { - $("*[class*='shortkey_']").each(function (i, e) { - $.each($(e).attr("class").split(" "), function (i, c) { - if (/^shortkey_/.test(c)) { - $(document).bind('keydown', c.substr(9), function () { - $(e).click(); - }); - } - }); - }); +// General helpers +function debounce(callback, wait) { + let timeoutId = null; + return function(...args) { + clearTimeout(timeoutId); + timeoutId = setTimeout(() => { + callback.apply(this, args); + }, wait); + }; }; -// Create the events for the help panel. -coverage.wire_up_help_panel = function () { - $("#keyboard_icon").click(function () { - // Show the help panel, and position it so the keyboard icon in the - // panel is in the same place as the keyboard icon in the header. - $(".help_panel").show(); - var koff = $("#keyboard_icon").offset(); - var poff = $("#panel_icon").position(); - $(".help_panel").offset({ - top: koff.top-poff.top-1, - left: koff.left-poff.left-1 +function checkVisible(element) { + const rect = element.getBoundingClientRect(); + const viewBottom = Math.max(document.documentElement.clientHeight, window.innerHeight); + const viewTop = 30; + return !(rect.bottom < viewTop || rect.top >= viewBottom); +} + +// Helpers for table sorting +function getCellValue(row, column = 0) { + const cell = row.cells[column] + if (cell.childElementCount == 1) { + const child = cell.firstElementChild + if (child instanceof HTMLTimeElement && child.dateTime) { + return child.dateTime + } else if (child instanceof HTMLDataElement && child.value) { + return child.value + } + } + return cell.innerText || cell.textContent; +} + +function rowComparator(rowA, rowB, column = 0) { + let valueA = getCellValue(rowA, column); + let valueB = getCellValue(rowB, column); + if (!isNaN(valueA) && !isNaN(valueB)) { + return valueA - valueB + } + return valueA.localeCompare(valueB, undefined, {numeric: true}); +} + +function sortColumn(th) { + // Get the current sorting direction of the selected header, + // clear state on other headers and then set the new sorting direction + const currentSortOrder = th.getAttribute("aria-sort"); + [...th.parentElement.cells].forEach(header => header.setAttribute("aria-sort", "none")); + if (currentSortOrder === "none") { + th.setAttribute("aria-sort", th.dataset.defaultSortOrder || "ascending"); + } else { + th.setAttribute("aria-sort", currentSortOrder === "ascending" ? "descending" : "ascending"); + } + + const column = [...th.parentElement.cells].indexOf(th) + + // Sort all rows and afterwards append them in order to move them in the DOM + Array.from(th.closest("table").querySelectorAll("tbody tr")) + .sort((rowA, rowB) => rowComparator(rowA, rowB, column) * (th.getAttribute("aria-sort") === "ascending" ? 1 : -1)) + .forEach(tr => tr.parentElement.appendChild(tr) ); +} + +// Find all the elements with data-shortcut attribute, and use them to assign a shortcut key. +coverage.assign_shortkeys = function () { + document.querySelectorAll("[data-shortcut]").forEach(element => { + document.addEventListener("keypress", event => { + if (event.target.tagName.toLowerCase() === "input") { + return; // ignore keypress from search filter + } + if (event.key === element.dataset.shortcut) { + element.click(); + } }); }); - $("#panel_icon").click(function () { - $(".help_panel").hide(); - }); }; // Create the events for the filter box. coverage.wire_up_filter = function () { // Cache elements. - var table = $("table.index"); - var table_rows = table.find("tbody tr"); - var table_row_names = table_rows.find("td.name a"); - var no_rows = $("#no_rows"); - - // Create a duplicate table footer that we can modify with dynamic summed values. - var table_footer = $("table.index tfoot tr"); - var table_dynamic_footer = table_footer.clone(); - table_dynamic_footer.attr('class', 'total_dynamic hidden'); - table_footer.after(table_dynamic_footer); + const table = document.querySelector("table.index"); + const table_body_rows = table.querySelectorAll("tbody tr"); + const no_rows = document.getElementById("no_rows"); // Observe filter keyevents. - $("#filter").on("keyup change", $.debounce(150, function (event) { - var filter_value = $(this).val(); - - if (filter_value === "") { - // Filter box is empty, remove all filtering. - table_rows.removeClass("hidden"); - - // Show standard footer, hide dynamic footer. - table_footer.removeClass("hidden"); - table_dynamic_footer.addClass("hidden"); - - // Hide placeholder, show table. - if (no_rows.length > 0) { - no_rows.hide(); + document.getElementById("filter").addEventListener("input", debounce(event => { + // Keep running total of each metric, first index contains number of shown rows + const totals = new Array(table.rows[0].cells.length).fill(0); + // Accumulate the percentage as fraction + totals[totals.length - 1] = { "numer": 0, "denom": 0 }; + + // Hide / show elements. + table_body_rows.forEach(row => { + if (!row.cells[0].textContent.includes(event.target.value)) { + // hide + row.classList.add("hidden"); + return; } - table.show(); - } - else { - // Filter table items by value. - var hidden = 0; - var shown = 0; - - // Hide / show elements. - $.each(table_row_names, function () { - var element = $(this).parents("tr"); - - if ($(this).text().indexOf(filter_value) === -1) { - // hide - element.addClass("hidden"); - hidden++; - } - else { - // show - element.removeClass("hidden"); - shown++; - } - }); - - // Show placeholder if no rows will be displayed. - if (no_rows.length > 0) { - if (shown === 0) { - // Show placeholder, hide table. - no_rows.show(); - table.hide(); - } - else { - // Hide placeholder, show table. - no_rows.hide(); - table.show(); + // show + row.classList.remove("hidden"); + totals[0]++; + + for (let column = 1; column < totals.length; column++) { + // Accumulate dynamic totals + cell = row.cells[column] + if (column === totals.length - 1) { + // Last column contains percentage + const [numer, denom] = cell.dataset.ratio.split(" "); + totals[column]["numer"] += parseInt(numer, 10); + totals[column]["denom"] += parseInt(denom, 10); + } else { + totals[column] += parseInt(cell.textContent, 10); } } + }); - // Manage dynamic header: - if (hidden > 0) { - // Calculate new dynamic sum values based on visible rows. - for (var column = 2; column < 20; column++) { - // Calculate summed value. - var cells = table_rows.find('td:nth-child(' + column + ')'); - if (!cells.length) { - // No more columns...! - break; - } - - var sum = 0, numer = 0, denom = 0; - $.each(cells.filter(':visible'), function () { - var ratio = $(this).data("ratio"); - if (ratio) { - var splitted = ratio.split(" "); - numer += parseInt(splitted[0], 10); - denom += parseInt(splitted[1], 10); - } - else { - sum += parseInt(this.innerHTML, 10); - } - }); - - // Get footer cell element. - var footer_cell = table_dynamic_footer.find('td:nth-child(' + column + ')'); - - // Set value into dynamic footer cell element. - if (cells[0].innerHTML.indexOf('%') > -1) { - // Percentage columns use the numerator and denominator, - // and adapt to the number of decimal places. - var match = /\.([0-9]+)/.exec(cells[0].innerHTML); - var places = 0; - if (match) { - places = match[1].length; - } - var pct = numer * 100 / denom; - footer_cell.text(pct.toFixed(places) + '%'); - } - else { - footer_cell.text(sum); - } - } + // Show placeholder if no rows will be displayed. + if (!totals[0]) { + // Show placeholder, hide table. + no_rows.style.display = "block"; + table.style.display = "none"; + return; + } - // Hide standard footer, show dynamic footer. - table_footer.addClass("hidden"); - table_dynamic_footer.removeClass("hidden"); - } - else { - // Show standard footer, hide dynamic footer. - table_footer.removeClass("hidden"); - table_dynamic_footer.addClass("hidden"); + // Hide placeholder, show table. + no_rows.style.display = null; + table.style.display = null; + + const footer = table.tFoot.rows[0]; + // Calculate new dynamic sum values based on visible rows. + for (let column = 1; column < totals.length; column++) { + // Get footer cell element. + const cell = footer.cells[column]; + + // Set value into dynamic footer cell element. + if (column === totals.length - 1) { + // Percentage column uses the numerator and denominator, + // and adapts to the number of decimal places. + const match = /\.([0-9]+)/.exec(cell.textContent); + const places = match ? match[1].length : 0; + const { numer, denom } = totals[column]; + cell.dataset.ratio = `${numer} ${denom}`; + // Check denom to prevent NaN if filtered files contain no statements + cell.textContent = denom + ? `${(numer * 100 / denom).toFixed(places)}%` + : `${(100).toFixed(places)}%`; + } else { + cell.textContent = totals[column]; } } })); // Trigger change event on setup, to force filter on page refresh // (filter value may still be present). - $("#filter").trigger("change"); + document.getElementById("filter").dispatchEvent(new Event("change")); }; +coverage.INDEX_SORT_STORAGE = "COVERAGE_INDEX_SORT_2"; + // Loaded on index.html -coverage.index_ready = function ($) { +coverage.index_ready = function () { + coverage.assign_shortkeys(); + coverage.wire_up_filter(); + document.querySelectorAll("[data-sortable] th[aria-sort]").forEach( + th => th.addEventListener("click", e => sortColumn(e.target)) + ); + // Look for a localStorage item containing previous sort settings: - var sort_list = []; - var storage_name = "COVERAGE_INDEX_SORT"; - var stored_list = undefined; - try { - stored_list = localStorage.getItem(storage_name); - } catch(err) {} + const stored_list = localStorage.getItem(coverage.INDEX_SORT_STORAGE); if (stored_list) { - sort_list = JSON.parse('[[' + stored_list + ']]'); + const {column, direction} = JSON.parse(stored_list); + const th = document.querySelector("[data-sortable]").tHead.rows[0].cells[column]; + th.setAttribute("aria-sort", direction === "ascending" ? "descending" : "ascending"); + th.click() } - // Create a new widget which exists only to save and restore - // the sort order: - $.tablesorter.addWidget({ - id: "persistentSort", - - // Format is called by the widget before displaying: - format: function (table) { - if (table.config.sortList.length === 0 && sort_list.length > 0) { - // This table hasn't been sorted before - we'll use - // our stored settings: - $(table).trigger('sorton', [sort_list]); - } - else { - // This is not the first load - something has - // already defined sorting so we'll just update - // our stored value to match: - sort_list = table.config.sortList; - } - } - }); - - // Configure our tablesorter to handle the variable number of - // columns produced depending on report options: - var headers = []; - var col_count = $("table.index > thead > tr > th").length; - - headers[0] = { sorter: 'text' }; - for (i = 1; i < col_count-1; i++) { - headers[i] = { sorter: 'digit' }; - } - headers[col_count-1] = { sorter: 'percent' }; - - // Enable the table sorter: - $("table.index").tablesorter({ - widgets: ['persistentSort'], - headers: headers - }); - - coverage.assign_shortkeys(); - coverage.wire_up_help_panel(); - coverage.wire_up_filter(); - // Watch for page unload events so we can save the final sort settings: - $(window).on("unload", function () { - try { - localStorage.setItem(storage_name, sort_list.toString()) - } catch(err) {} + window.addEventListener("unload", function () { + const th = document.querySelector('[data-sortable] th[aria-sort="ascending"], [data-sortable] [aria-sort="descending"]'); + if (!th) { + return; + } + localStorage.setItem(coverage.INDEX_SORT_STORAGE, JSON.stringify({ + column: [...th.parentElement.cells].indexOf(th), + direction: th.getAttribute("aria-sort"), + })); }); }; @@ -235,28 +199,25 @@ coverage.index_ready = function ($) { coverage.LINE_FILTERS_STORAGE = "COVERAGE_LINE_FILTERS"; -coverage.pyfile_ready = function ($) { +coverage.pyfile_ready = function () { // If we're directed to a particular line number, highlight the line. var frag = location.hash; if (frag.length > 2 && frag[1] === 't') { - $(frag).addClass('highlight'); + document.querySelector(frag).closest(".n").classList.add("highlight"); coverage.set_sel(parseInt(frag.substr(2), 10)); - } - else { + } else { coverage.set_sel(0); } - $(document) - .bind('keydown', 'j', coverage.to_next_chunk_nicely) - .bind('keydown', 'k', coverage.to_prev_chunk_nicely) - .bind('keydown', '0', coverage.to_top) - .bind('keydown', '1', coverage.to_first_chunk) - ; + document.querySelector(".button_toggle_run").addEventListener("click", coverage.toggle_lines); + document.querySelector(".button_toggle_mis").addEventListener("click", coverage.toggle_lines); + document.querySelector(".button_toggle_exc").addEventListener("click", coverage.toggle_lines); + document.querySelector(".button_toggle_par").addEventListener("click", coverage.toggle_lines); - $(".button_toggle_run").click(function (evt) {coverage.toggle_lines(evt.target, "run");}); - $(".button_toggle_exc").click(function (evt) {coverage.toggle_lines(evt.target, "exc");}); - $(".button_toggle_mis").click(function (evt) {coverage.toggle_lines(evt.target, "mis");}); - $(".button_toggle_par").click(function (evt) {coverage.toggle_lines(evt.target, "par");}); + document.querySelector(".button_next_chunk").addEventListener("click", coverage.to_next_chunk_nicely); + document.querySelector(".button_prev_chunk").addEventListener("click", coverage.to_prev_chunk_nicely); + document.querySelector(".button_top_of_page").addEventListener("click", coverage.to_top); + document.querySelector(".button_first_chunk").addEventListener("click", coverage.to_first_chunk); coverage.filters = undefined; try { @@ -275,40 +236,41 @@ coverage.pyfile_ready = function ($) { } coverage.assign_shortkeys(); - coverage.wire_up_help_panel(); - coverage.init_scroll_markers(); + coverage.wire_up_sticky_header(); // Rebuild scroll markers when the window height changes. - $(window).resize(coverage.build_scroll_markers); + window.addEventListener("resize", coverage.build_scroll_markers); }; -coverage.toggle_lines = function (btn, cls) { - var onoff = !$(btn).hasClass("show_" + cls); - coverage.set_line_visibilty(cls, onoff); +coverage.toggle_lines = function (event) { + const btn = event.target.closest("button"); + const category = btn.value + const show = !btn.classList.contains("show_" + category); + coverage.set_line_visibilty(category, show); coverage.build_scroll_markers(); - coverage.filters[cls] = onoff; + coverage.filters[category] = show; try { localStorage.setItem(coverage.LINE_FILTERS_STORAGE, JSON.stringify(coverage.filters)); } catch(err) {} }; -coverage.set_line_visibilty = function (cls, onoff) { - var show = "show_" + cls; - var btn = $(".button_toggle_" + cls); - if (onoff) { - $("#source ." + cls).addClass(show); - btn.addClass(show); +coverage.set_line_visibilty = function (category, should_show) { + const cls = "show_" + category; + const btn = document.querySelector(".button_toggle_" + category); + if (should_show) { + document.querySelectorAll("#source ." + category).forEach(e => e.classList.add(cls)); + btn.classList.add(cls); } else { - $("#source ." + cls).removeClass(show); - btn.removeClass(show); + document.querySelectorAll("#source ." + category).forEach(e => e.classList.remove(cls)); + btn.classList.remove(cls); } }; // Return the nth line div. coverage.line_elt = function (n) { - return $("#t" + n); + return document.getElementById("t" + n)?.closest("p"); }; // Set the selection. b and e are line numbers. @@ -332,25 +294,26 @@ coverage.to_first_chunk = function () { // Return a string indicating what kind of chunk this line belongs to, // or null if not a chunk. coverage.chunk_indicator = function (line_elt) { - var klass = line_elt.attr('class'); - if (klass) { - var m = klass.match(/\bshow_\w+\b/); - if (m) { - return m[0]; - } + const classes = line_elt?.className; + if (!classes) { + return null; + } + const match = classes.match(/\bshow_\w+\b/); + if (!match) { + return null; } - return null; + return match[0]; }; coverage.to_next_chunk = function () { - var c = coverage; + const c = coverage; // Find the start of the next colored chunk. var probe = c.sel_end; var chunk_indicator, probe_line; while (true) { probe_line = c.line_elt(probe); - if (probe_line.length === 0) { + if (!probe_line) { return; } chunk_indicator = c.chunk_indicator(probe_line); @@ -375,19 +338,19 @@ coverage.to_next_chunk = function () { }; coverage.to_prev_chunk = function () { - var c = coverage; + const c = coverage; // Find the end of the prev colored chunk. var probe = c.sel_begin-1; var probe_line = c.line_elt(probe); - if (probe_line.length === 0) { + if (!probe_line) { return; } var chunk_indicator = c.chunk_indicator(probe_line); - while (probe > 0 && !chunk_indicator) { + while (probe > 1 && !chunk_indicator) { probe--; probe_line = c.line_elt(probe); - if (probe_line.length === 0) { + if (!probe_line) { return; } chunk_indicator = c.chunk_indicator(probe_line); @@ -400,6 +363,9 @@ coverage.to_prev_chunk = function () { var prev_indicator = chunk_indicator; while (prev_indicator === chunk_indicator) { probe--; + if (probe <= 0) { + return; + } probe_line = c.line_elt(probe); prev_indicator = c.chunk_indicator(probe_line); } @@ -407,28 +373,6 @@ coverage.to_prev_chunk = function () { c.show_selection(); }; -// Return the line number of the line nearest pixel position pos -coverage.line_at_pos = function (pos) { - var l1 = coverage.line_elt(1), - l2 = coverage.line_elt(2), - result; - if (l1.length && l2.length) { - var l1_top = l1.offset().top, - line_height = l2.offset().top - l1_top, - nlines = (pos - l1_top) / line_height; - if (nlines < 1) { - result = 1; - } - else { - result = Math.ceil(nlines); - } - } - else { - result = 1; - } - return result; -}; - // Returns 0, 1, or 2: how many of the two ends of the selection are on // the screen right now? coverage.selection_ends_on_screen = function () { @@ -436,31 +380,49 @@ coverage.selection_ends_on_screen = function () { return 0; } - var top = coverage.line_elt(coverage.sel_begin); - var next = coverage.line_elt(coverage.sel_end-1); + const begin = coverage.line_elt(coverage.sel_begin); + const end = coverage.line_elt(coverage.sel_end-1); return ( - (top.isOnScreen() ? 1 : 0) + - (next.isOnScreen() ? 1 : 0) + (checkVisible(begin) ? 1 : 0) + + (checkVisible(end) ? 1 : 0) ); }; coverage.to_next_chunk_nicely = function () { - coverage.finish_scrolling(); if (coverage.selection_ends_on_screen() === 0) { - // The selection is entirely off the screen: select the top line on - // the screen. - var win = $(window); - coverage.select_line_or_chunk(coverage.line_at_pos(win.scrollTop())); + // The selection is entirely off the screen: + // Set the top line on the screen as selection. + + // This will select the top-left of the viewport + // As this is most likely the span with the line number we take the parent + const line = document.elementFromPoint(0, 0).parentElement; + if (line.parentElement !== document.getElementById("source")) { + // The element is not a source line but the header or similar + coverage.select_line_or_chunk(1); + } else { + // We extract the line number from the id + coverage.select_line_or_chunk(parseInt(line.id.substring(1), 10)); + } } coverage.to_next_chunk(); }; coverage.to_prev_chunk_nicely = function () { - coverage.finish_scrolling(); if (coverage.selection_ends_on_screen() === 0) { - var win = $(window); - coverage.select_line_or_chunk(coverage.line_at_pos(win.scrollTop() + win.height())); + // The selection is entirely off the screen: + // Set the lowest line on the screen as selection. + + // This will select the bottom-left of the viewport + // As this is most likely the span with the line number we take the parent + const line = document.elementFromPoint(document.documentElement.clientHeight-1, 0).parentElement; + if (line.parentElement !== document.getElementById("source")) { + // The element is not a source line but the header or similar + coverage.select_line_or_chunk(coverage.lines_len); + } else { + // We extract the line number from the id + coverage.select_line_or_chunk(parseInt(line.id.substring(1), 10)); + } } coverage.to_prev_chunk(); }; @@ -470,7 +432,7 @@ coverage.to_prev_chunk_nicely = function () { coverage.select_line_or_chunk = function (lineno) { var c = coverage; var probe_line = c.line_elt(lineno); - if (probe_line.length === 0) { + if (!probe_line) { return; } var the_indicator = c.chunk_indicator(probe_line); @@ -482,7 +444,7 @@ coverage.select_line_or_chunk = function (lineno) { while (probe > 0 && indicator === the_indicator) { probe--; probe_line = c.line_elt(probe); - if (probe_line.length === 0) { + if (!probe_line) { break; } indicator = c.chunk_indicator(probe_line); @@ -506,106 +468,100 @@ coverage.select_line_or_chunk = function (lineno) { }; coverage.show_selection = function () { - var c = coverage; - // Highlight the lines in the chunk - $("#source .highlight").removeClass("highlight"); - for (var probe = c.sel_begin; probe > 0 && probe < c.sel_end; probe++) { - c.line_elt(probe).addClass("highlight"); + document.querySelectorAll("#source .highlight").forEach(e => e.classList.remove("highlight")); + for (let probe = coverage.sel_begin; probe < coverage.sel_end; probe++) { + coverage.line_elt(probe).querySelector(".n").classList.add("highlight"); } - c.scroll_to_selection(); + coverage.scroll_to_selection(); }; coverage.scroll_to_selection = function () { // Scroll the page if the chunk isn't fully visible. if (coverage.selection_ends_on_screen() < 2) { - // Need to move the page. The html,body trick makes it scroll in all - // browsers, got it from http://stackoverflow.com/questions/3042651 - var top = coverage.line_elt(coverage.sel_begin); - var top_pos = parseInt(top.offset().top, 10); - coverage.scroll_window(top_pos - 30); + const element = coverage.line_elt(coverage.sel_begin); + coverage.scroll_window(element.offsetTop - 60); } }; coverage.scroll_window = function (to_pos) { - $("html,body").animate({scrollTop: to_pos}, 200); -}; - -coverage.finish_scrolling = function () { - $("html,body").stop(true, true); + window.scroll({top: to_pos, behavior: "smooth"}); }; coverage.init_scroll_markers = function () { - var c = coverage; // Init some variables - c.lines_len = $('#source p').length; - c.body_h = $('body').height(); - c.header_h = $('div#header').height(); + coverage.lines_len = document.querySelectorAll('#source > p').length; // Build html - c.build_scroll_markers(); + coverage.build_scroll_markers(); }; coverage.build_scroll_markers = function () { - var c = coverage, - min_line_height = 3, - max_line_height = 10, - visible_window_h = $(window).height(); - - c.lines_to_mark = $('#source').find('p.show_run, p.show_mis, p.show_exc, p.show_exc, p.show_par'); - $('#scroll_marker').remove(); + const temp_scroll_marker = document.getElementById('scroll_marker') + if (temp_scroll_marker) temp_scroll_marker.remove(); // Don't build markers if the window has no scroll bar. - if (c.body_h <= visible_window_h) { + if (document.body.scrollHeight <= window.innerHeight) { return; } - $("body").append("
 
"); - var scroll_marker = $('#scroll_marker'), - marker_scale = scroll_marker.height() / c.body_h, - line_height = scroll_marker.height() / c.lines_len; + const marker_scale = window.innerHeight / document.body.scrollHeight; + const line_height = Math.min(Math.max(3, window.innerHeight / coverage.lines_len), 10); - // Line height must be between the extremes. - if (line_height > min_line_height) { - if (line_height > max_line_height) { - line_height = max_line_height; - } - } - else { - line_height = min_line_height; - } - - var previous_line = -99, - last_mark, - last_top, - offsets = {}; + let previous_line = -99, last_mark, last_top; - // Calculate line offsets outside loop to prevent relayouts - c.lines_to_mark.each(function() { - offsets[this.id] = $(this).offset().top; - }); - c.lines_to_mark.each(function () { - var id_name = $(this).attr('id'), - line_top = Math.round(offsets[id_name] * marker_scale), - line_number = parseInt(id_name.substring(1, id_name.length)); + const scroll_marker = document.createElement("div"); + scroll_marker.id = "scroll_marker"; + document.getElementById('source').querySelectorAll( + 'p.show_run, p.show_mis, p.show_exc, p.show_exc, p.show_par' + ).forEach(element => { + const line_top = Math.floor(element.offsetTop * marker_scale); + const line_number = parseInt(element.id.substr(1)); if (line_number === previous_line + 1) { // If this solid missed block just make previous mark higher. - last_mark.css({ - 'height': line_top + line_height - last_top - }); - } - else { + last_mark.style.height = `${line_top + line_height - last_top}px`; + } else { // Add colored line in scroll_marker block. - scroll_marker.append('
'); - last_mark = $('#m' + line_number); - last_mark.css({ - 'height': line_height, - 'top': line_top - }); + last_mark = document.createElement("div"); + last_mark.id = `m${line_number}`; + last_mark.classList.add("marker"); + last_mark.style.height = `${line_height}px`; + last_mark.style.top = `${line_top}px`; + scroll_marker.append(last_mark); last_top = line_top; } previous_line = line_number; }); + + // Append last to prevent layout calculation + document.body.append(scroll_marker); }; + +coverage.wire_up_sticky_header = function () { + const header = document.querySelector('header'); + const header_bottom = ( + header.querySelector('.content h2').getBoundingClientRect().top - + header.getBoundingClientRect().top + ); + + function updateHeader() { + if (window.scrollY > header_bottom) { + header.classList.add('sticky'); + } else { + header.classList.remove('sticky'); + } + } + + window.addEventListener('scroll', updateHeader); + updateHeader(); +}; + +document.addEventListener("DOMContentLoaded", () => { + if (document.body.classList.contains("indexfile")) { + coverage.index_ready(); + } else { + coverage.pyfile_ready(); + } +}); diff --git a/doc/sample_html/d_7b071bdc2a35fa80___init___py.html b/doc/sample_html/d_7b071bdc2a35fa80___init___py.html index 617fdbef..938496dc 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80___init___py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80___init___py.html @@ -6,70 +6,75 @@ Coverage for cogapp/__init__.py: 100.00% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1""" Cog content generation tool. 

-

2 http://nedbatchelder.com/code/cog 

-

3 

-

4 Copyright 2004-2015, Ned Batchelder. 

-

5""" 

-

6 

-

7from __future__ import absolute_import 

-

8 

-

9from .cogapp import * 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80___main___py.html b/doc/sample_html/d_7b071bdc2a35fa80___main___py.html index 464019fb..f9652ea1 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80___main___py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80___main___py.html @@ -6,66 +6,71 @@ Coverage for cogapp/__main__.py: 0.00% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1"""Make Cog runnable directly from the module.""" 

-

2import sys 

-

3from cogapp import Cog 

-

4 

-

5sys.exit(Cog().main(sys.argv)) 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_backward_py.html b/doc/sample_html/d_7b071bdc2a35fa80_backward_py.html index f997eec8..9a3e9009 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_backward_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_backward_py.html @@ -6,103 +6,108 @@ Coverage for cogapp/backward.py: 69.23% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1"""Compatibility between Py2 and Py3.""" 

-

2 

-

3import sys 

-

4import unittest 

-

5 

-

6PY3 = sys.version_info[0] == 3 

-

7 

-

8if PY3: 8 ↛ 14line 8 didn't jump to line 14, because the condition on line 8 was never false

-

9 string_types = (str,bytes) 

-

10 bytes_types = (bytes,) 

-

11 def to_bytes(s): 

-

12 return s.encode('utf8') 

-

13else: 

-

14 string_types = (basestring,) 

-

15 bytes_types = (str,) 

-

16 def to_bytes(s): 

-

17 return s 

-

18 

-

19# Pythons 2 and 3 differ on where to get StringIO 

-

20try: 

-

21 from cStringIO import StringIO 

-

22except ImportError: 

-

23 from io import StringIO 

-

24 

-

25 

-

26def unittest_has(method): 

-

27 """Does `unittest.TestCase` have `method` defined?""" 

-

28 return hasattr(unittest.TestCase, method) 

-

29 

-

30 

-

31class TestCase(unittest.TestCase): 

-

32 """Just like unittest.TestCase, but with assert methods added. 

-

33 

-

34 Designed to be compatible with 3.1 unittest. Methods are only defined if 

-

35 `unittest` doesn't have them. 

-

36 

-

37 """ 

-

38 # pylint: disable=missing-docstring 

-

39 

-

40 if not unittest_has('assertRaisesRegex'): 40 ↛ 41line 40 didn't jump to line 41, because the condition on line 40 was never true

-

41 def assertRaisesRegex(self, *args, **kwargs): 

-

42 return self.assertRaisesRegexp(*args, **kwargs) 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_cogapp_py.html b/doc/sample_html/d_7b071bdc2a35fa80_cogapp_py.html index 6fe42303..9793f644 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_cogapp_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_cogapp_py.html @@ -6,871 +6,876 @@ Coverage for cogapp/cogapp.py: 49.42% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1# coding: utf8 

-

2""" Cog content generation tool. 

-

3 http://nedbatchelder.com/code/cog 

-

4 

-

5 Copyright 2004-2019, Ned Batchelder. 

-

6""" 

-

7 

-

8from __future__ import absolute_import, print_function 

-

9 

-

10import copy 

-

11import getopt 

-

12import glob 

-

13import hashlib 

-

14import linecache 

-

15import os 

-

16import re 

-

17import shlex 

-

18import sys 

-

19import traceback 

-

20 

-

21from .backward import PY3, StringIO, string_types, to_bytes 

-

22 

-

23__all__ = ['Cog', 'CogUsageError', 'main'] 

-

24 

-

25__version__ = '3.1.0' 

-

26 

-

27usage = """\ 

-

28cog - generate content with inlined Python code. 

-

29 

-

30cog [OPTIONS] [INFILE | @FILELIST] ... 

-

31 

-

32INFILE is the name of an input file, '-' will read from stdin. 

-

33FILELIST is the name of a text file containing file names or 

-

34 other @FILELISTs. 

-

35 

-

36OPTIONS: 

-

37 -c Checksum the output to protect it against accidental change. 

-

38 -d Delete the generator code from the output file. 

-

39 -D name=val Define a global string available to your generator code. 

-

40 -e Warn if a file has no cog code in it. 

-

41 -I PATH Add PATH to the list of directories for data files and modules. 

-

42 -n ENCODING Use ENCODING when reading and writing files. 

-

43 -o OUTNAME Write the output to OUTNAME. 

-

44 -p PROLOGUE Prepend the generator source with PROLOGUE. Useful to insert an 

-

45 import line. Example: -p "import math" 

-

46 -r Replace the input file with the output. 

-

47 -s STRING Suffix all generated output lines with STRING. 

-

48 -U Write the output with Unix newlines (only LF line-endings). 

-

49 -w CMD Use CMD if the output file needs to be made writable. 

-

50 A %s in the CMD will be filled with the filename. 

-

51 -x Excise all the generated output without running the generators. 

-

52 -z The end-output marker can be omitted, and is assumed at eof. 

-

53 -v Print the version of cog and exit. 

-

54 --verbosity=VERBOSITY 

-

55 Control the amount of output. 2 (the default) lists all files, 

-

56 1 lists only changed files, 0 lists no files. 

-

57 --markers='START END END-OUTPUT' 

-

58 The patterns surrounding cog inline instructions. Should 

-

59 include three values separated by spaces, the start, end, 

-

60 and end-output markers. Defaults to '[[[cog ]]] [[[end]]]'. 

-

61 -h Print this help. 

-

62""" 

-

63 

-

64# Other package modules 

-

65from .whiteutils import * 

-

66 

-

67class CogError(Exception): 

-

68 """ Any exception raised by Cog. 

-

69 """ 

-

70 def __init__(self, msg, file='', line=0): 

-

71 if file: 

-

72 Exception.__init__(self, "%s(%d): %s" % (file, line, msg)) 

-

73 else: 

-

74 Exception.__init__(self, msg) 

-

75 

-

76class CogUsageError(CogError): 

-

77 """ An error in usage of command-line arguments in cog. 

-

78 """ 

-

79 pass 

-

80 

-

81class CogInternalError(CogError): 

-

82 """ An error in the coding of Cog. Should never happen. 

-

83 """ 

-

84 pass 

-

85 

-

86class CogGeneratedError(CogError): 

-

87 """ An error raised by a user's cog generator. 

-

88 """ 

-

89 pass 

-

90 

-

91class CogUserException(CogError): 

-

92 """ An exception caught when running a user's cog generator. 

-

93 The argument is the traceback message to print. 

-

94 """ 

-

95 pass 

-

96 

-

97class Redirectable: 

-

98 """ An object with its own stdout and stderr files. 

-

99 """ 

-

100 def __init__(self): 

-

101 self.stdout = sys.stdout 

-

102 self.stderr = sys.stderr 

-

103 

-

104 def setOutput(self, stdout=None, stderr=None): 

-

105 """ Assign new files for standard out and/or standard error. 

-

106 """ 

-

107 if stdout: 107 ↛ 109line 107 didn't jump to line 109, because the condition on line 107 was never false

-

108 self.stdout = stdout 

-

109 if stderr: 109 ↛ 110line 109 didn't jump to line 110, because the condition on line 109 was never true

-

110 self.stderr = stderr 

-

111 

-

112 def prout(self, s, end="\n"): 

-

113 print(s, file=self.stdout, end=end) 

-

114 

-

115 def prerr(self, s, end="\n"): 

-

116 print(s, file=self.stderr, end=end) 

-

117 

-

118 

-

119class CogGenerator(Redirectable): 

-

120 """ A generator pulled from a source file. 

-

121 """ 

-

122 def __init__(self, options=None): 

-

123 Redirectable.__init__(self) 

-

124 self.markers = [] 

-

125 self.lines = [] 

-

126 self.options = options or CogOptions() 

-

127 

-

128 def parseMarker(self, l): 

-

129 self.markers.append(l) 

-

130 

-

131 def parseLine(self, l): 

-

132 self.lines.append(l.strip('\n')) 

-

133 

-

134 def getCode(self): 

-

135 """ Extract the executable Python code from the generator. 

-

136 """ 

-

137 # If the markers and lines all have the same prefix 

-

138 # (end-of-line comment chars, for example), 

-

139 # then remove it from all the lines. 

-

140 prefIn = commonPrefix(self.markers + self.lines) 

-

141 if prefIn: 

-

142 self.markers = [ l.replace(prefIn, '', 1) for l in self.markers ] 

-

143 self.lines = [ l.replace(prefIn, '', 1) for l in self.lines ] 

-

144 

-

145 return reindentBlock(self.lines, '') 

-

146 

-

147 def evaluate(self, cog, globals, fname): 

-

148 # figure out the right whitespace prefix for the output 

-

149 prefOut = whitePrefix(self.markers) 

-

150 

-

151 intext = self.getCode() 

-

152 if not intext: 

-

153 return '' 

-

154 

-

155 prologue = "import " + cog.cogmodulename + " as cog\n" 

-

156 if self.options.sPrologue: 156 ↛ 157line 156 didn't jump to line 157, because the condition on line 156 was never true

-

157 prologue += self.options.sPrologue + '\n' 

-

158 code = compile(prologue + intext, str(fname), 'exec') 

-

159 

-

160 # Make sure the "cog" module has our state. 

-

161 cog.cogmodule.msg = self.msg 

-

162 cog.cogmodule.out = self.out 

-

163 cog.cogmodule.outl = self.outl 

-

164 cog.cogmodule.error = self.error 

-

165 

-

166 self.outstring = '' 

-

167 try: 

-

168 eval(code, globals) 

-

169 except CogError: 169 ↛ 170line 169 didn't jump to line 170, because the exception caught by line 169 didn't happen

-

170 raise 

-

171 except: 

-

172 typ, err, tb = sys.exc_info() 

-

173 frames = (tuple(fr) for fr in traceback.extract_tb(tb.tb_next)) 

-

174 frames = find_cog_source(frames, prologue) 

-

175 msg = "".join(traceback.format_list(frames)) 

-

176 msg += "{}: {}".format(typ.__name__, err) 

-

177 raise CogUserException(msg) 

-

178 

-

179 # We need to make sure that the last line in the output 

-

180 # ends with a newline, or it will be joined to the 

-

181 # end-output line, ruining cog's idempotency. 

-

182 if self.outstring and self.outstring[-1] != '\n': 

-

183 self.outstring += '\n' 

-

184 

-

185 return reindentBlock(self.outstring, prefOut) 

-

186 

-

187 def msg(self, s): 

-

188 self.prout("Message: "+s) 

-

189 

-

190 def out(self, sOut='', dedent=False, trimblanklines=False): 

-

191 """ The cog.out function. 

-

192 """ 

-

193 if trimblanklines and ('\n' in sOut): 

-

194 lines = sOut.split('\n') 

-

195 if lines[0].strip() == '': 

-

196 del lines[0] 

-

197 if lines and lines[-1].strip() == '': 

-

198 del lines[-1] 

-

199 sOut = '\n'.join(lines)+'\n' 

-

200 if dedent: 

-

201 sOut = reindentBlock(sOut) 

-

202 self.outstring += sOut 

-

203 

-

204 def outl(self, sOut='', **kw): 

-

205 """ The cog.outl function. 

-

206 """ 

-

207 self.out(sOut, **kw) 

-

208 self.out('\n') 

-

209 

-

210 def error(self, msg='Error raised by cog generator.'): 

-

211 """ The cog.error function. 

-

212 Instead of raising standard python errors, cog generators can use 

-

213 this function. It will display the error without a scary Python 

-

214 traceback. 

-

215 """ 

-

216 raise CogGeneratedError(msg) 

-

217 

-

218 

-

219class NumberedFileReader: 

-

220 """ A decorator for files that counts the readline()'s called. 

-

221 """ 

-

222 def __init__(self, f): 

-

223 self.f = f 

-

224 self.n = 0 

-

225 

-

226 def readline(self): 

-

227 l = self.f.readline() 

-

228 if l: 

-

229 self.n += 1 

-

230 return l 

-

231 

-

232 def linenumber(self): 

-

233 return self.n 

-

234 

-

235 

-

236class CogOptions: 

-

237 """ Options for a run of cog. 

-

238 """ 

-

239 def __init__(self): 

-

240 # Defaults for argument values. 

-

241 self.args = [] 

-

242 self.includePath = [] 

-

243 self.defines = {} 

-

244 self.bShowVersion = False 

-

245 self.sMakeWritableCmd = None 

-

246 self.bReplace = False 

-

247 self.bNoGenerate = False 

-

248 self.sOutputName = None 

-

249 self.bWarnEmpty = False 

-

250 self.bHashOutput = False 

-

251 self.bDeleteCode = False 

-

252 self.bEofCanBeEnd = False 

-

253 self.sSuffix = None 

-

254 self.bNewlines = False 

-

255 self.sBeginSpec = '[[[cog' 

-

256 self.sEndSpec = ']]]' 

-

257 self.sEndOutput = '[[[end]]]' 

-

258 self.sEncoding = "utf-8" 

-

259 self.verbosity = 2 

-

260 self.sPrologue = '' 

-

261 

-

262 def __eq__(self, other): 

-

263 """ Comparison operator for tests to use. 

-

264 """ 

-

265 return self.__dict__ == other.__dict__ 

-

266 

-

267 def clone(self): 

-

268 """ Make a clone of these options, for further refinement. 

-

269 """ 

-

270 return copy.deepcopy(self) 

-

271 

-

272 def addToIncludePath(self, dirs): 

-

273 """ Add directories to the include path. 

-

274 """ 

-

275 dirs = dirs.split(os.pathsep) 

-

276 self.includePath.extend(dirs) 

-

277 

-

278 def parseArgs(self, argv): 

-

279 # Parse the command line arguments. 

-

280 try: 

-

281 opts, self.args = getopt.getopt( 

-

282 argv, 

-

283 'cdD:eI:n:o:rs:p:Uvw:xz', 

-

284 [ 

-

285 'markers=', 

-

286 'verbosity=', 

-

287 ] 

-

288 ) 

-

289 except getopt.error as msg: 

-

290 raise CogUsageError(msg) 

-

291 

-

292 # Handle the command line arguments. 

-

293 for o, a in opts: 

-

294 if o == '-c': 

-

295 self.bHashOutput = True 

-

296 elif o == '-d': 

-

297 self.bDeleteCode = True 

-

298 elif o == '-D': 

-

299 if a.count('=') < 1: 

-

300 raise CogUsageError("-D takes a name=value argument") 

-

301 name, value = a.split('=', 1) 

-

302 self.defines[name] = value 

-

303 elif o == '-e': 

-

304 self.bWarnEmpty = True 

-

305 elif o == '-I': 

-

306 self.addToIncludePath(os.path.abspath(a)) 

-

307 elif o == '-n': 

-

308 self.sEncoding = a 

-

309 elif o == '-o': 

-

310 self.sOutputName = a 

-

311 elif o == '-r': 

-

312 self.bReplace = True 

-

313 elif o == '-s': 

-

314 self.sSuffix = a 

-

315 elif o == '-p': 

-

316 self.sPrologue = a 

-

317 elif o == '-U': 

-

318 self.bNewlines = True 

-

319 elif o == '-v': 

-

320 self.bShowVersion = True 

-

321 elif o == '-w': 

-

322 self.sMakeWritableCmd = a 

-

323 elif o == '-x': 

-

324 self.bNoGenerate = True 

-

325 elif o == '-z': 

-

326 self.bEofCanBeEnd = True 

-

327 elif o == '--markers': 

-

328 self._parse_markers(a) 

-

329 elif o == '--verbosity': 

-

330 self.verbosity = int(a) 

-

331 else: 

-

332 # Since getopt.getopt is given a list of possible flags, 

-

333 # this is an internal error. 

-

334 raise CogInternalError("Don't understand argument %s" % o) 

-

335 

-

336 def _parse_markers(self, val): 

-

337 try: 

-

338 self.sBeginSpec, self.sEndSpec, self.sEndOutput = val.split(' ') 

-

339 except ValueError: 

-

340 raise CogUsageError( 

-

341 '--markers requires 3 values separated by spaces, could not parse %r' % val 

-

342 ) 

-

343 

-

344 def validate(self): 

-

345 """ Does nothing if everything is OK, raises CogError's if it's not. 

-

346 """ 

-

347 if self.bReplace and self.bDeleteCode: 

-

348 raise CogUsageError("Can't use -d with -r (or you would delete all your source!)") 

-

349 

-

350 if self.bReplace and self.sOutputName: 

-

351 raise CogUsageError("Can't use -o with -r (they are opposites)") 

-

352 

-

353 

-

354class Cog(Redirectable): 

-

355 """ The Cog engine. 

-

356 """ 

-

357 def __init__(self): 

-

358 Redirectable.__init__(self) 

-

359 self.options = CogOptions() 

-

360 self._fixEndOutputPatterns() 

-

361 self.cogmodulename = "cog" 

-

362 self.createCogModule() 

-

363 

-

364 def _fixEndOutputPatterns(self): 

-

365 end_output = re.escape(self.options.sEndOutput) 

-

366 self.reEndOutput = re.compile(end_output + r'(?P<hashsect> *\(checksum: (?P<hash>[a-f0-9]+)\))') 

-

367 self.sEndFormat = self.options.sEndOutput + ' (checksum: %s)' 

-

368 

-

369 def showWarning(self, msg): 

-

370 self.prout("Warning: "+msg) 

-

371 

-

372 def isBeginSpecLine(self, s): 

-

373 return self.options.sBeginSpec in s 

-

374 

-

375 def isEndSpecLine(self, s): 

-

376 return self.options.sEndSpec in s and not self.isEndOutputLine(s) 

-

377 

-

378 def isEndOutputLine(self, s): 

-

379 return self.options.sEndOutput in s 

-

380 

-

381 def createCogModule(self): 

-

382 """ Make a cog "module" object so that imported Python modules 

-

383 can say "import cog" and get our state. 

-

384 """ 

-

385 class DummyModule(object): 

-

386 """Modules don't have to be anything special, just an object will do.""" 

-

387 pass 

-

388 self.cogmodule = DummyModule() 

-

389 self.cogmodule.path = [] 

-

390 

-

391 def openOutputFile(self, fname): 

-

392 """ Open an output file, taking all the details into account. 

-

393 """ 

-

394 opts = {} 

-

395 mode = "w" 

-

396 if PY3: 

-

397 opts['encoding'] = self.options.sEncoding 

-

398 if self.options.bNewlines: 

-

399 if PY3: 

-

400 opts['newline'] = "\n" 

-

401 else: 

-

402 mode = "wb" 

-

403 fdir = os.path.dirname(fname) 

-

404 if os.path.dirname(fdir) and not os.path.exists(fdir): 

-

405 os.makedirs(fdir) 

-

406 return open(fname, mode, **opts) 

-

407 

-

408 def openInputFile(self, fname): 

-

409 """ Open an input file. """ 

-

410 if fname == "-": 

-

411 return sys.stdin 

-

412 else: 

-

413 opts = {} 

-

414 if PY3: 

-

415 opts['encoding'] = self.options.sEncoding 

-

416 return open(fname, "r", **opts) 

-

417 

-

418 def processFile(self, fIn, fOut, fname=None, globals=None): 

-

419 """ Process an input file object to an output file object. 

-

420 fIn and fOut can be file objects, or file names. 

-

421 """ 

-

422 

-

423 sFileIn = fname or '' 

-

424 sFileOut = fname or '' 

-

425 fInToClose = fOutToClose = None 

-

426 # Convert filenames to files. 

-

427 if isinstance(fIn, string_types): 427 ↛ 429line 427 didn't jump to line 429, because the condition on line 427 was never true

-

428 # Open the input file. 

-

429 sFileIn = fIn 

-

430 fIn = fInToClose = self.openInputFile(fIn) 

-

431 if isinstance(fOut, string_types): 431 ↛ 433line 431 didn't jump to line 433, because the condition on line 431 was never true

-

432 # Open the output file. 

-

433 sFileOut = fOut 

-

434 fOut = fOutToClose = self.openOutputFile(fOut) 

-

435 

-

436 try: 

-

437 fIn = NumberedFileReader(fIn) 

-

438 

-

439 bSawCog = False 

-

440 

-

441 self.cogmodule.inFile = sFileIn 

-

442 self.cogmodule.outFile = sFileOut 

-

443 self.cogmodulename = 'cog_' + hashlib.md5(sFileOut.encode()).hexdigest() 

-

444 sys.modules[self.cogmodulename] = self.cogmodule 

-

445 # if "import cog" explicitly done in code by user, note threading will cause clashes. 

-

446 sys.modules['cog'] = self.cogmodule 

-

447 

-

448 # The globals dict we'll use for this file. 

-

449 if globals is None: 449 ↛ 453line 449 didn't jump to line 453, because the condition on line 449 was never false

-

450 globals = {} 

-

451 

-

452 # If there are any global defines, put them in the globals. 

-

453 globals.update(self.options.defines) 

-

454 

-

455 # loop over generator chunks 

-

456 l = fIn.readline() 

-

457 while l: 

-

458 # Find the next spec begin 

-

459 while l and not self.isBeginSpecLine(l): 

-

460 if self.isEndSpecLine(l): 460 ↛ 461line 460 didn't jump to line 461, because the condition on line 460 was never true

-

461 raise CogError("Unexpected '%s'" % self.options.sEndSpec, 

-

462 file=sFileIn, line=fIn.linenumber()) 

-

463 if self.isEndOutputLine(l): 463 ↛ 464line 463 didn't jump to line 464, because the condition on line 463 was never true

-

464 raise CogError("Unexpected '%s'" % self.options.sEndOutput, 

-

465 file=sFileIn, line=fIn.linenumber()) 

-

466 fOut.write(l) 

-

467 l = fIn.readline() 

-

468 if not l: 

-

469 break 

-

470 if not self.options.bDeleteCode: 470 ↛ 474line 470 didn't jump to line 474, because the condition on line 470 was never false

-

471 fOut.write(l) 

-

472 

-

473 # l is the begin spec 

-

474 gen = CogGenerator(options=self.options) 

-

475 gen.setOutput(stdout=self.stdout) 

-

476 gen.parseMarker(l) 

-

477 firstLineNum = fIn.linenumber() 

-

478 self.cogmodule.firstLineNum = firstLineNum 

-

479 

-

480 # If the spec begin is also a spec end, then process the single 

-

481 # line of code inside. 

-

482 if self.isEndSpecLine(l): 

-

483 beg = l.find(self.options.sBeginSpec) 

-

484 end = l.find(self.options.sEndSpec) 

-

485 if beg > end: 

-

486 raise CogError("Cog code markers inverted", 

-

487 file=sFileIn, line=firstLineNum) 

-

488 else: 

-

489 sCode = l[beg+len(self.options.sBeginSpec):end].strip() 

-

490 gen.parseLine(sCode) 

-

491 else: 

-

492 # Deal with an ordinary code block. 

-

493 l = fIn.readline() 

-

494 

-

495 # Get all the lines in the spec 

-

496 while l and not self.isEndSpecLine(l): 

-

497 if self.isBeginSpecLine(l): 497 ↛ 498line 497 didn't jump to line 498, because the condition on line 497 was never true

-

498 raise CogError("Unexpected '%s'" % self.options.sBeginSpec, 

-

499 file=sFileIn, line=fIn.linenumber()) 

-

500 if self.isEndOutputLine(l): 500 ↛ 501line 500 didn't jump to line 501, because the condition on line 500 was never true

-

501 raise CogError("Unexpected '%s'" % self.options.sEndOutput, 

-

502 file=sFileIn, line=fIn.linenumber()) 

-

503 if not self.options.bDeleteCode: 503 ↛ 505line 503 didn't jump to line 505, because the condition on line 503 was never false

-

504 fOut.write(l) 

-

505 gen.parseLine(l) 

-

506 l = fIn.readline() 

-

507 if not l: 507 ↛ 508line 507 didn't jump to line 508, because the condition on line 507 was never true

-

508 raise CogError( 

-

509 "Cog block begun but never ended.", 

-

510 file=sFileIn, line=firstLineNum) 

-

511 

-

512 if not self.options.bDeleteCode: 512 ↛ 514line 512 didn't jump to line 514, because the condition on line 512 was never false

-

513 fOut.write(l) 

-

514 gen.parseMarker(l) 

-

515 

-

516 l = fIn.readline() 

-

517 

-

518 # Eat all the lines in the output section. While reading past 

-

519 # them, compute the md5 hash of the old output. 

-

520 previous = "" 

-

521 hasher = hashlib.md5() 

-

522 while l and not self.isEndOutputLine(l): 

-

523 if self.isBeginSpecLine(l): 523 ↛ 524line 523 didn't jump to line 524, because the condition on line 523 was never true

-

524 raise CogError("Unexpected '%s'" % self.options.sBeginSpec, 

-

525 file=sFileIn, line=fIn.linenumber()) 

-

526 if self.isEndSpecLine(l): 526 ↛ 527line 526 didn't jump to line 527, because the condition on line 526 was never true

-

527 raise CogError("Unexpected '%s'" % self.options.sEndSpec, 

-

528 file=sFileIn, line=fIn.linenumber()) 

-

529 previous += l 

-

530 hasher.update(to_bytes(l)) 

-

531 l = fIn.readline() 

-

532 curHash = hasher.hexdigest() 

-

533 

-

534 if not l and not self.options.bEofCanBeEnd: 534 ↛ 536line 534 didn't jump to line 536, because the condition on line 534 was never true

-

535 # We reached end of file before we found the end output line. 

-

536 raise CogError("Missing '%s' before end of file." % self.options.sEndOutput, 

-

537 file=sFileIn, line=fIn.linenumber()) 

-

538 

-

539 # Make the previous output available to the current code 

-

540 self.cogmodule.previous = previous 

-

541 

-

542 # Write the output of the spec to be the new output if we're 

-

543 # supposed to generate code. 

-

544 hasher = hashlib.md5() 

-

545 if not self.options.bNoGenerate: 545 ↛ 551line 545 didn't jump to line 551, because the condition on line 545 was never false

-

546 sFile = "<cog %s:%d>" % (sFileIn, firstLineNum) 

-

547 sGen = gen.evaluate(cog=self, globals=globals, fname=sFile) 

-

548 sGen = self.suffixLines(sGen) 

-

549 hasher.update(to_bytes(sGen)) 

-

550 fOut.write(sGen) 

-

551 newHash = hasher.hexdigest() 

-

552 

-

553 bSawCog = True 

-

554 

-

555 # Write the ending output line 

-

556 hashMatch = self.reEndOutput.search(l) 

-

557 if self.options.bHashOutput: 557 ↛ 558line 557 didn't jump to line 558, because the condition on line 557 was never true

-

558 if hashMatch: 

-

559 oldHash = hashMatch.groupdict()['hash'] 

-

560 if oldHash != curHash: 

-

561 raise CogError("Output has been edited! Delete old checksum to unprotect.", 

-

562 file=sFileIn, line=fIn.linenumber()) 

-

563 # Create a new end line with the correct hash. 

-

564 endpieces = l.split(hashMatch.group(0), 1) 

-

565 else: 

-

566 # There was no old hash, but we want a new hash. 

-

567 endpieces = l.split(self.options.sEndOutput, 1) 

-

568 l = (self.sEndFormat % newHash).join(endpieces) 

-

569 else: 

-

570 # We don't want hashes output, so if there was one, get rid of 

-

571 # it. 

-

572 if hashMatch: 572 ↛ 573line 572 didn't jump to line 573, because the condition on line 572 was never true

-

573 l = l.replace(hashMatch.groupdict()['hashsect'], '', 1) 

-

574 

-

575 if not self.options.bDeleteCode: 575 ↛ 577line 575 didn't jump to line 577, because the condition on line 575 was never false

-

576 fOut.write(l) 

-

577 l = fIn.readline() 

-

578 

-

579 if not bSawCog and self.options.bWarnEmpty: 579 ↛ 580line 579 didn't jump to line 580, because the condition on line 579 was never true

-

580 self.showWarning("no cog code found in %s" % sFileIn) 

-

581 finally: 

-

582 if fInToClose: 582 ↛ 583line 582 didn't jump to line 583, because the condition on line 582 was never true

-

583 fInToClose.close() 

-

584 if fOutToClose: 584 ↛ 585line 584 didn't jump to line 585, because the condition on line 584 was never true

-

585 fOutToClose.close() 

-

586 

-

587 

-

588 # A regex for non-empty lines, used by suffixLines. 

-

589 reNonEmptyLines = re.compile(r"^\s*\S+.*$", re.MULTILINE) 

-

590 

-

591 def suffixLines(self, text): 

-

592 """ Add suffixes to the lines in text, if our options desire it. 

-

593 text is many lines, as a single string. 

-

594 """ 

-

595 if self.options.sSuffix: 595 ↛ 597line 595 didn't jump to line 597, because the condition on line 595 was never true

-

596 # Find all non-blank lines, and add the suffix to the end. 

-

597 repl = r"\g<0>" + self.options.sSuffix.replace('\\', '\\\\') 

-

598 text = self.reNonEmptyLines.sub(repl, text) 

-

599 return text 

-

600 

-

601 def processString(self, sInput, fname=None): 

-

602 """ Process sInput as the text to cog. 

-

603 Return the cogged output as a string. 

-

604 """ 

-

605 fOld = StringIO(sInput) 

-

606 fNew = StringIO() 

-

607 self.processFile(fOld, fNew, fname=fname) 

-

608 return fNew.getvalue() 

-

609 

-

610 def replaceFile(self, sOldPath, sNewText): 

-

611 """ Replace file sOldPath with the contents sNewText 

-

612 """ 

-

613 if not os.access(sOldPath, os.W_OK): 

-

614 # Need to ensure we can write. 

-

615 if self.options.sMakeWritableCmd: 

-

616 # Use an external command to make the file writable. 

-

617 cmd = self.options.sMakeWritableCmd.replace('%s', sOldPath) 

-

618 self.stdout.write(os.popen(cmd).read()) 

-

619 if not os.access(sOldPath, os.W_OK): 

-

620 raise CogError("Couldn't make %s writable" % sOldPath) 

-

621 else: 

-

622 # Can't write! 

-

623 raise CogError("Can't overwrite %s" % sOldPath) 

-

624 f = self.openOutputFile(sOldPath) 

-

625 f.write(sNewText) 

-

626 f.close() 

-

627 

-

628 def saveIncludePath(self): 

-

629 self.savedInclude = self.options.includePath[:] 

-

630 self.savedSysPath = sys.path[:] 

-

631 

-

632 def restoreIncludePath(self): 

-

633 self.options.includePath = self.savedInclude 

-

634 self.cogmodule.path = self.options.includePath 

-

635 sys.path = self.savedSysPath 

-

636 

-

637 def addToIncludePath(self, includePath): 

-

638 self.cogmodule.path.extend(includePath) 

-

639 sys.path.extend(includePath) 

-

640 

-

641 def processOneFile(self, sFile): 

-

642 """ Process one filename through cog. 

-

643 """ 

-

644 

-

645 self.saveIncludePath() 

-

646 bNeedNewline = False 

-

647 

-

648 try: 

-

649 self.addToIncludePath(self.options.includePath) 

-

650 # Since we know where the input file came from, 

-

651 # push its directory onto the include path. 

-

652 self.addToIncludePath([os.path.dirname(sFile)]) 

-

653 

-

654 # How we process the file depends on where the output is going. 

-

655 if self.options.sOutputName: 

-

656 self.processFile(sFile, self.options.sOutputName, sFile) 

-

657 elif self.options.bReplace: 

-

658 # We want to replace the cog file with the output, 

-

659 # but only if they differ. 

-

660 if self.options.verbosity >= 2: 

-

661 self.prout("Cogging %s" % sFile, end="") 

-

662 bNeedNewline = True 

-

663 

-

664 try: 

-

665 fOldFile = self.openInputFile(sFile) 

-

666 sOldText = fOldFile.read() 

-

667 fOldFile.close() 

-

668 sNewText = self.processString(sOldText, fname=sFile) 

-

669 if sOldText != sNewText: 

-

670 if self.options.verbosity >= 1: 

-

671 if self.options.verbosity < 2: 

-

672 self.prout("Cogging %s" % sFile, end="") 

-

673 self.prout(" (changed)") 

-

674 bNeedNewline = False 

-

675 self.replaceFile(sFile, sNewText) 

-

676 finally: 

-

677 # The try-finally block is so we can print a partial line 

-

678 # with the name of the file, and print (changed) on the 

-

679 # same line, but also make sure to break the line before 

-

680 # any traceback. 

-

681 if bNeedNewline: 

-

682 self.prout("") 

-

683 else: 

-

684 self.processFile(sFile, self.stdout, sFile) 

-

685 finally: 

-

686 self.restoreIncludePath() 

-

687 

-

688 def processWildcards(self, sFile): 

-

689 files = glob.glob(sFile) 

-

690 if files: 

-

691 for sMatchingFile in files: 

-

692 self.processOneFile(sMatchingFile) 

-

693 else: 

-

694 self.processOneFile(sFile) 

-

695 

-

696 def processFileList(self, sFileList): 

-

697 """ Process the files in a file list. 

-

698 """ 

-

699 flist = self.openInputFile(sFileList) 

-

700 lines = flist.readlines() 

-

701 flist.close() 

-

702 for l in lines: 

-

703 # Use shlex to parse the line like a shell. 

-

704 lex = shlex.shlex(l, posix=True) 

-

705 lex.whitespace_split = True 

-

706 lex.commenters = '#' 

-

707 # No escapes, so that backslash can be part of the path 

-

708 lex.escape = '' 

-

709 args = list(lex) 

-

710 if args: 

-

711 self.processArguments(args) 

-

712 

-

713 def processArguments(self, args): 

-

714 """ Process one command-line. 

-

715 """ 

-

716 saved_options = self.options 

-

717 self.options = self.options.clone() 

-

718 

-

719 self.options.parseArgs(args[1:]) 

-

720 self.options.validate() 

-

721 

-

722 if args[0][0] == '@': 

-

723 if self.options.sOutputName: 

-

724 raise CogUsageError("Can't use -o with @file") 

-

725 self.processFileList(args[0][1:]) 

-

726 else: 

-

727 self.processWildcards(args[0]) 

-

728 

-

729 self.options = saved_options 

-

730 

-

731 def callableMain(self, argv): 

-

732 """ All of command-line cog, but in a callable form. 

-

733 This is used by main. 

-

734 argv is the equivalent of sys.argv. 

-

735 """ 

-

736 argv = argv[1:] 

-

737 

-

738 # Provide help if asked for anywhere in the command line. 

-

739 if '-?' in argv or '-h' in argv: 

-

740 self.prerr(usage, end="") 

-

741 return 

-

742 

-

743 self.options.parseArgs(argv) 

-

744 self.options.validate() 

-

745 self._fixEndOutputPatterns() 

-

746 

-

747 if self.options.bShowVersion: 

-

748 self.prout("Cog version %s" % __version__) 

-

749 return 

-

750 

-

751 if self.options.args: 

-

752 for a in self.options.args: 

-

753 self.processArguments([a]) 

-

754 else: 

-

755 raise CogUsageError("No files to process") 

-

756 

-

757 def main(self, argv): 

-

758 """ Handle the command-line execution for cog. 

-

759 """ 

-

760 

-

761 try: 

-

762 self.callableMain(argv) 

-

763 return 0 

-

764 except CogUsageError as err: 

-

765 self.prerr(err) 

-

766 self.prerr("(for help use -?)") 

-

767 return 2 

-

768 except CogGeneratedError as err: 

-

769 self.prerr("Error: %s" % err) 

-

770 return 3 

-

771 except CogUserException as err: 

-

772 self.prerr("Traceback (most recent call last):") 

-

773 self.prerr(err.args[0]) 

-

774 return 4 

-

775 except CogError as err: 

-

776 self.prerr(err) 

-

777 return 1 

-

778 

-

779 

-

780def find_cog_source(frame_summary, prologue): 

-

781 """Find cog source lines in a frame summary list, for printing tracebacks. 

-

782 

-

783 Arguments: 

-

784 frame_summary: a list of 4-item tuples, as returned by traceback.extract_tb. 

-

785 prologue: the text of the code prologue. 

-

786 

-

787 Returns 

-

788 A list of 4-item tuples, updated to correct the cog entries. 

-

789 

-

790 """ 

-

791 prolines = prologue.splitlines() 

-

792 for filename, lineno, funcname, source in frame_summary: 

-

793 if not source: 793 ↛ 805line 793 didn't jump to line 805, because the condition on line 793 was never false

-

794 m = re.search(r"^<cog ([^:]+):(\d+)>$", filename) 

-

795 if m: 795 ↛ 796line 795 didn't jump to line 796, because the condition on line 795 was never true

-

796 if lineno <= len(prolines): 

-

797 filename = '<prologue>' 

-

798 source = prolines[lineno-1] 

-

799 lineno -= 1 # Because "import cog" is the first line in the prologue 

-

800 else: 

-

801 filename, coglineno = m.groups() 

-

802 coglineno = int(coglineno) 

-

803 lineno += coglineno - len(prolines) 

-

804 source = linecache.getline(filename, lineno).strip() 

-

805 yield filename, lineno, funcname, source 

-

806 

-

807 

-

808def main(): 

-

809 """Main function for entry_points to use.""" 

-

810 return Cog().main(sys.argv) 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_makefiles_py.html b/doc/sample_html/d_7b071bdc2a35fa80_makefiles_py.html index c591fba9..6fc42807 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_makefiles_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_makefiles_py.html @@ -6,107 +6,112 @@ Coverage for cogapp/makefiles.py: 17.07% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1""" Dictionary-to-filetree functions, to create test files for testing. 

-

2 http://nedbatchelder.com/code/cog 

-

3 

-

4 Copyright 2004-2019, Ned Batchelder. 

-

5""" 

-

6 

-

7from __future__ import absolute_import 

-

8 

-

9import os.path 

-

10 

-

11from .backward import string_types, bytes_types 

-

12from .whiteutils import reindentBlock 

-

13 

-

14__all__ = ['makeFiles', 'removeFiles'] 

-

15 

-

16def makeFiles(d, basedir='.', bytes=False): 

-

17 """ Create files from the dictionary `d`, in the directory named by `basedir`. 

-

18 If `bytes` is true, then treat bytestrings as bytes, else as text. 

-

19 """ 

-

20 for name, contents in d.items(): 

-

21 child = os.path.join(basedir, name) 

-

22 if isinstance(contents, string_types): 

-

23 mode = 'w' 

-

24 if bytes and isinstance(contents, bytes_types): 

-

25 mode += "b" 

-

26 f = open(child, mode) 

-

27 contents = reindentBlock(contents) 

-

28 f.write(contents) 

-

29 f.close() 

-

30 else: 

-

31 if not os.path.exists(child): 

-

32 os.mkdir(child) 

-

33 makeFiles(contents, child) 

-

34 

-

35def removeFiles(d, basedir='.'): 

-

36 """ Remove the files created by makeFiles. 

-

37 Directories are removed if they are empty. 

-

38 """ 

-

39 for name, contents in d.items(): 

-

40 child = os.path.join(basedir, name) 

-

41 if isinstance(contents, string_types): 

-

42 os.remove(child) 

-

43 else: 

-

44 removeFiles(contents, child) 

-

45 if not os.listdir(child): 

-

46 os.rmdir(child) 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_test_cogapp_py.html b/doc/sample_html/d_7b071bdc2a35fa80_test_cogapp_py.html index 07e6fa9c..3c78ddee 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_test_cogapp_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_test_cogapp_py.html @@ -6,2539 +6,2544 @@ Coverage for cogapp/test_cogapp.py: 30.07% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1""" Test cogapp. 

-

2 http://nedbatchelder.com/code/cog 

-

3 

-

4 Copyright 2004-2019, Ned Batchelder. 

-

5""" 

-

6 

-

7from __future__ import absolute_import 

-

8 

-

9import os 

-

10import os.path 

-

11import random 

-

12import re 

-

13import shutil 

-

14import stat 

-

15import sys 

-

16import tempfile 

-

17import threading 

-

18 

-

19from .backward import StringIO, to_bytes, TestCase, PY3 

-

20from .cogapp import Cog, CogOptions, CogGenerator 

-

21from .cogapp import CogError, CogUsageError, CogGeneratedError, CogUserException 

-

22from .cogapp import usage, __version__, main 

-

23from .makefiles import * 

-

24from .whiteutils import reindentBlock 

-

25 

-

26 

-

27class CogTestsInMemory(TestCase): 

-

28 """ Test cases for cogapp.Cog() 

-

29 """ 

-

30 

-

31 def testNoCog(self): 

-

32 strings = [ 

-

33 '', 

-

34 ' ', 

-

35 ' \t \t \tx', 

-

36 'hello', 

-

37 'the cat\nin the\nhat.', 

-

38 'Horton\n\tHears A\n\t\tWho' 

-

39 ] 

-

40 for s in strings: 

-

41 self.assertEqual(Cog().processString(s), s) 

-

42 

-

43 def testSimple(self): 

-

44 infile = """\ 

-

45 Some text. 

-

46 //[[[cog 

-

47 import cog 

-

48 cog.outl("This is line one\\n") 

-

49 cog.outl("This is line two") 

-

50 //]]] 

-

51 gobbledegook. 

-

52 //[[[end]]] 

-

53 epilogue. 

-

54 """ 

-

55 

-

56 outfile = """\ 

-

57 Some text. 

-

58 //[[[cog 

-

59 import cog 

-

60 cog.outl("This is line one\\n") 

-

61 cog.outl("This is line two") 

-

62 //]]] 

-

63 This is line one 

-

64 

-

65 This is line two 

-

66 //[[[end]]] 

-

67 epilogue. 

-

68 """ 

-

69 

-

70 self.assertEqual(Cog().processString(infile), outfile) 

-

71 

-

72 def testEmptyCog(self): 

-

73 # The cog clause can be totally empty. Not sure why you'd want it, 

-

74 # but it works. 

-

75 infile = """\ 

-

76 hello 

-

77 //[[[cog 

-

78 //]]] 

-

79 //[[[end]]] 

-

80 goodbye 

-

81 """ 

-

82 

-

83 infile = reindentBlock(infile) 

-

84 self.assertEqual(Cog().processString(infile), infile) 

-

85 

-

86 def testMultipleCogs(self): 

-

87 # One file can have many cog chunks, even abutting each other. 

-

88 infile = """\ 

-

89 //[[[cog 

-

90 cog.out("chunk1") 

-

91 //]]] 

-

92 chunk1 

-

93 //[[[end]]] 

-

94 //[[[cog 

-

95 cog.out("chunk2") 

-

96 //]]] 

-

97 chunk2 

-

98 //[[[end]]] 

-

99 between chunks 

-

100 //[[[cog 

-

101 cog.out("chunk3") 

-

102 //]]] 

-

103 chunk3 

-

104 //[[[end]]] 

-

105 """ 

-

106 

-

107 infile = reindentBlock(infile) 

-

108 self.assertEqual(Cog().processString(infile), infile) 

-

109 

-

110 def testTrimBlankLines(self): 

-

111 infile = """\ 

-

112 //[[[cog 

-

113 cog.out("This is line one\\n", trimblanklines=True) 

-

114 cog.out(''' 

-

115 This is line two 

-

116 ''', dedent=True, trimblanklines=True) 

-

117 cog.outl("This is line three", trimblanklines=True) 

-

118 //]]] 

-

119 This is line one 

-

120 This is line two 

-

121 This is line three 

-

122 //[[[end]]] 

-

123 """ 

-

124 

-

125 infile = reindentBlock(infile) 

-

126 self.assertEqual(Cog().processString(infile), infile) 

-

127 

-

128 def testTrimEmptyBlankLines(self): 

-

129 infile = """\ 

-

130 //[[[cog 

-

131 cog.out("This is line one\\n", trimblanklines=True) 

-

132 cog.out(''' 

-

133 This is line two 

-

134 ''', dedent=True, trimblanklines=True) 

-

135 cog.out('', dedent=True, trimblanklines=True) 

-

136 cog.outl("This is line three", trimblanklines=True) 

-

137 //]]] 

-

138 This is line one 

-

139 This is line two 

-

140 This is line three 

-

141 //[[[end]]] 

-

142 """ 

-

143 

-

144 infile = reindentBlock(infile) 

-

145 self.assertEqual(Cog().processString(infile), infile) 

-

146 

-

147 def testTrimBlankLinesWithLastPartial(self): 

-

148 infile = """\ 

-

149 //[[[cog 

-

150 cog.out("This is line one\\n", trimblanklines=True) 

-

151 cog.out("\\nLine two\\nLine three", trimblanklines=True) 

-

152 //]]] 

-

153 This is line one 

-

154 Line two 

-

155 Line three 

-

156 //[[[end]]] 

-

157 """ 

-

158 

-

159 infile = reindentBlock(infile) 

-

160 self.assertEqual(Cog().processString(infile), infile) 

-

161 

-

162 def testCogOutDedent(self): 

-

163 infile = """\ 

-

164 //[[[cog 

-

165 cog.out("This is the first line\\n") 

-

166 cog.out(''' 

-

167 This is dedent=True 1 

-

168 This is dedent=True 2 

-

169 ''', dedent=True, trimblanklines=True) 

-

170 cog.out(''' 

-

171 This is dedent=False 1 

-

172 This is dedent=False 2 

-

173 ''', dedent=False, trimblanklines=True) 

-

174 cog.out(''' 

-

175 This is dedent=default 1 

-

176 This is dedent=default 2 

-

177 ''', trimblanklines=True) 

-

178 cog.out("This is the last line\\n") 

-

179 //]]] 

-

180 This is the first line 

-

181 This is dedent=True 1 

-

182 This is dedent=True 2 

-

183 This is dedent=False 1 

-

184 This is dedent=False 2 

-

185 This is dedent=default 1 

-

186 This is dedent=default 2 

-

187 This is the last line 

-

188 //[[[end]]] 

-

189 """ 

-

190 

-

191 infile = reindentBlock(infile) 

-

192 self.assertEqual(Cog().processString(infile), infile) 

-

193 

-

194 def test22EndOfLine(self): 

-

195 # In Python 2.2, this cog file was not parsing because the 

-

196 # last line is indented but didn't end with a newline. 

-

197 infile = """\ 

-

198 //[[[cog 

-

199 import cog 

-

200 for i in range(3): 

-

201 cog.out("%d\\n" % i) 

-

202 //]]] 

-

203 0 

-

204 1 

-

205 2 

-

206 //[[[end]]] 

-

207 """ 

-

208 

-

209 infile = reindentBlock(infile) 

-

210 self.assertEqual(Cog().processString(infile), infile) 

-

211 

-

212 def testIndentedCode(self): 

-

213 infile = """\ 

-

214 first line 

-

215 [[[cog 

-

216 import cog 

-

217 for i in range(3): 

-

218 cog.out("xx%d\\n" % i) 

-

219 ]]] 

-

220 xx0 

-

221 xx1 

-

222 xx2 

-

223 [[[end]]] 

-

224 last line 

-

225 """ 

-

226 

-

227 infile = reindentBlock(infile) 

-

228 self.assertEqual(Cog().processString(infile), infile) 

-

229 

-

230 def testPrefixedCode(self): 

-

231 infile = """\ 

-

232 --[[[cog 

-

233 --import cog 

-

234 --for i in range(3): 

-

235 -- cog.out("xx%d\\n" % i) 

-

236 --]]] 

-

237 xx0 

-

238 xx1 

-

239 xx2 

-

240 --[[[end]]] 

-

241 """ 

-

242 

-

243 infile = reindentBlock(infile) 

-

244 self.assertEqual(Cog().processString(infile), infile) 

-

245 

-

246 def testPrefixedIndentedCode(self): 

-

247 infile = """\ 

-

248 prologue 

-

249 --[[[cog 

-

250 -- import cog 

-

251 -- for i in range(3): 

-

252 -- cog.out("xy%d\\n" % i) 

-

253 --]]] 

-

254 xy0 

-

255 xy1 

-

256 xy2 

-

257 --[[[end]]] 

-

258 """ 

-

259 

-

260 infile = reindentBlock(infile) 

-

261 self.assertEqual(Cog().processString(infile), infile) 

-

262 

-

263 def testBogusPrefixMatch(self): 

-

264 infile = """\ 

-

265 prologue 

-

266 #[[[cog 

-

267 import cog 

-

268 # This comment should not be clobbered by removing the pound sign. 

-

269 for i in range(3): 

-

270 cog.out("xy%d\\n" % i) 

-

271 #]]] 

-

272 xy0 

-

273 xy1 

-

274 xy2 

-

275 #[[[end]]] 

-

276 """ 

-

277 

-

278 infile = reindentBlock(infile) 

-

279 self.assertEqual(Cog().processString(infile), infile) 

-

280 

-

281 def testNoFinalNewline(self): 

-

282 # If the cog'ed output has no final newline, 

-

283 # it shouldn't eat up the cog terminator. 

-

284 infile = """\ 

-

285 prologue 

-

286 [[[cog 

-

287 import cog 

-

288 for i in range(3): 

-

289 cog.out("%d" % i) 

-

290 ]]] 

-

291 012 

-

292 [[[end]]] 

-

293 epilogue 

-

294 """ 

-

295 

-

296 infile = reindentBlock(infile) 

-

297 self.assertEqual(Cog().processString(infile), infile) 

-

298 

-

299 def testNoOutputAtAll(self): 

-

300 # If there is absolutely no cog output, that's ok. 

-

301 infile = """\ 

-

302 prologue 

-

303 [[[cog 

-

304 i = 1 

-

305 ]]] 

-

306 [[[end]]] 

-

307 epilogue 

-

308 """ 

-

309 

-

310 infile = reindentBlock(infile) 

-

311 self.assertEqual(Cog().processString(infile), infile) 

-

312 

-

313 def testPurelyBlankLine(self): 

-

314 # If there is a blank line in the cog code with no whitespace 

-

315 # prefix, that should be OK. 

-

316 

-

317 infile = """\ 

-

318 prologue 

-

319 [[[cog 

-

320 import sys 

-

321 cog.out("Hello") 

-

322 $ 

-

323 cog.out("There") 

-

324 ]]] 

-

325 HelloThere 

-

326 [[[end]]] 

-

327 epilogue 

-

328 """ 

-

329 

-

330 infile = reindentBlock(infile.replace('$', '')) 

-

331 self.assertEqual(Cog().processString(infile), infile) 

-

332 

-

333 def testEmptyOutl(self): 

-

334 # Alexander Belchenko suggested the string argument to outl should 

-

335 # be optional. Does it work? 

-

336 

-

337 infile = """\ 

-

338 prologue 

-

339 [[[cog 

-

340 cog.outl("x") 

-

341 cog.outl() 

-

342 cog.outl("y") 

-

343 cog.out() # Also optional, a complete no-op. 

-

344 cog.outl(trimblanklines=True) 

-

345 cog.outl("z") 

-

346 ]]] 

-

347 x 

-

348 

-

349 y 

-

350 

-

351 z 

-

352 [[[end]]] 

-

353 epilogue 

-

354 """ 

-

355 

-

356 infile = reindentBlock(infile) 

-

357 self.assertEqual(Cog().processString(infile), infile) 

-

358 

-

359 def testFirstLineNum(self): 

-

360 infile = """\ 

-

361 fooey 

-

362 [[[cog 

-

363 cog.outl("started at line number %d" % cog.firstLineNum) 

-

364 ]]] 

-

365 started at line number 2 

-

366 [[[end]]] 

-

367 blah blah 

-

368 [[[cog 

-

369 cog.outl("and again at line %d" % cog.firstLineNum) 

-

370 ]]] 

-

371 and again at line 8 

-

372 [[[end]]] 

-

373 """ 

-

374 

-

375 infile = reindentBlock(infile) 

-

376 self.assertEqual(Cog().processString(infile), infile) 

-

377 

-

378 def testCompactOneLineCode(self): 

-

379 infile = """\ 

-

380 first line 

-

381 hey: [[[cog cog.outl("hello %d" % (3*3*3*3)) ]]] looky! 

-

382 get rid of this! 

-

383 [[[end]]] 

-

384 last line 

-

385 """ 

-

386 

-

387 outfile = """\ 

-

388 first line 

-

389 hey: [[[cog cog.outl("hello %d" % (3*3*3*3)) ]]] looky! 

-

390 hello 81 

-

391 [[[end]]] 

-

392 last line 

-

393 """ 

-

394 

-

395 infile = reindentBlock(infile) 

-

396 self.assertEqual(Cog().processString(infile), reindentBlock(outfile)) 

-

397 

-

398 def testInsideOutCompact(self): 

-

399 infile = """\ 

-

400 first line 

-

401 hey?: ]]] what is this? [[[cog strange! 

-

402 get rid of this! 

-

403 [[[end]]] 

-

404 last line 

-

405 """ 

-

406 with self.assertRaisesRegex(CogError, r"^infile.txt\(2\): Cog code markers inverted$"): 

-

407 Cog().processString(reindentBlock(infile), "infile.txt") 

-

408 

-

409 def testSharingGlobals(self): 

-

410 infile = """\ 

-

411 first line 

-

412 hey: [[[cog s="hey there" ]]] looky! 

-

413 [[[end]]] 

-

414 more literal junk. 

-

415 [[[cog cog.outl(s) ]]] 

-

416 [[[end]]] 

-

417 last line 

-

418 """ 

-

419 

-

420 outfile = """\ 

-

421 first line 

-

422 hey: [[[cog s="hey there" ]]] looky! 

-

423 [[[end]]] 

-

424 more literal junk. 

-

425 [[[cog cog.outl(s) ]]] 

-

426 hey there 

-

427 [[[end]]] 

-

428 last line 

-

429 """ 

-

430 

-

431 infile = reindentBlock(infile) 

-

432 self.assertEqual(Cog().processString(infile), reindentBlock(outfile)) 

-

433 

-

434 def testAssertInCogCode(self): 

-

435 # Check that we can test assertions in cog code in the test framework. 

-

436 infile = """\ 

-

437 [[[cog 

-

438 assert 1 == 2, "Oops" 

-

439 ]]] 

-

440 [[[end]]] 

-

441 """ 

-

442 infile = reindentBlock(infile) 

-

443 with self.assertRaisesRegex(CogUserException, "AssertionError: Oops"): 

-

444 Cog().processString(infile) 

-

445 

-

446 def testCogPrevious(self): 

-

447 # Check that we can access the previous run's output. 

-

448 infile = """\ 

-

449 [[[cog 

-

450 assert cog.previous == "Hello there!\\n", "WTF??" 

-

451 cog.out(cog.previous) 

-

452 cog.outl("Ran again!") 

-

453 ]]] 

-

454 Hello there! 

-

455 [[[end]]] 

-

456 """ 

-

457 

-

458 outfile = """\ 

-

459 [[[cog 

-

460 assert cog.previous == "Hello there!\\n", "WTF??" 

-

461 cog.out(cog.previous) 

-

462 cog.outl("Ran again!") 

-

463 ]]] 

-

464 Hello there! 

-

465 Ran again! 

-

466 [[[end]]] 

-

467 """ 

-

468 

-

469 infile = reindentBlock(infile) 

-

470 self.assertEqual(Cog().processString(infile), reindentBlock(outfile)) 

-

471 

-

472 

-

473class CogOptionsTests(TestCase): 

-

474 """ Test the CogOptions class. 

-

475 """ 

-

476 

-

477 def testEquality(self): 

-

478 o = CogOptions() 

-

479 p = CogOptions() 

-

480 self.assertEqual(o, p) 

-

481 o.parseArgs(['-r']) 

-

482 self.assertNotEqual(o, p) 

-

483 p.parseArgs(['-r']) 

-

484 self.assertEqual(o, p) 

-

485 

-

486 def testCloning(self): 

-

487 o = CogOptions() 

-

488 o.parseArgs(['-I', 'fooey', '-I', 'booey', '-s', ' /*x*/']) 

-

489 p = o.clone() 

-

490 self.assertEqual(o, p) 

-

491 p.parseArgs(['-I', 'huey', '-D', 'foo=quux']) 

-

492 self.assertNotEqual(o, p) 

-

493 q = CogOptions() 

-

494 q.parseArgs(['-I', 'fooey', '-I', 'booey', '-s', ' /*x*/', '-I', 'huey', '-D', 'foo=quux']) 

-

495 self.assertEqual(p, q) 

-

496 

-

497 def testCombiningFlags(self): 

-

498 # Single-character flags can be combined. 

-

499 o = CogOptions() 

-

500 o.parseArgs(['-e', '-r', '-z']) 

-

501 p = CogOptions() 

-

502 p.parseArgs(['-erz']) 

-

503 self.assertEqual(o, p) 

-

504 

-

505 def testMarkers(self): 

-

506 o = CogOptions() 

-

507 o._parse_markers('a b c') 

-

508 self.assertEqual('a', o.sBeginSpec) 

-

509 self.assertEqual('b', o.sEndSpec) 

-

510 self.assertEqual('c', o.sEndOutput) 

-

511 

-

512 def testMarkersSwitch(self): 

-

513 o = CogOptions() 

-

514 o.parseArgs(['--markers', 'a b c']) 

-

515 self.assertEqual('a', o.sBeginSpec) 

-

516 self.assertEqual('b', o.sEndSpec) 

-

517 self.assertEqual('c', o.sEndOutput) 

-

518 

-

519 

-

520class FileStructureTests(TestCase): 

-

521 """ Test cases to check that we're properly strict about the structure 

-

522 of files. 

-

523 """ 

-

524 

-

525 def isBad(self, infile, msg=None): 

-

526 infile = reindentBlock(infile) 

-

527 with self.assertRaisesRegex(CogError, "^"+re.escape(msg)+"$"): 

-

528 Cog().processString(infile, 'infile.txt') 

-

529 

-

530 def testBeginNoEnd(self): 

-

531 infile = """\ 

-

532 Fooey 

-

533 #[[[cog 

-

534 cog.outl('hello') 

-

535 """ 

-

536 self.isBad(infile, "infile.txt(2): Cog block begun but never ended.") 

-

537 

-

538 def testNoEoo(self): 

-

539 infile = """\ 

-

540 Fooey 

-

541 #[[[cog 

-

542 cog.outl('hello') 

-

543 #]]] 

-

544 """ 

-

545 self.isBad(infile, "infile.txt(4): Missing '[[[end]]]' before end of file.") 

-

546 

-

547 infile2 = """\ 

-

548 Fooey 

-

549 #[[[cog 

-

550 cog.outl('hello') 

-

551 #]]] 

-

552 #[[[cog 

-

553 cog.outl('goodbye') 

-

554 #]]] 

-

555 """ 

-

556 self.isBad(infile2, "infile.txt(5): Unexpected '[[[cog'") 

-

557 

-

558 def testStartWithEnd(self): 

-

559 infile = """\ 

-

560 #]]] 

-

561 """ 

-

562 self.isBad(infile, "infile.txt(1): Unexpected ']]]'") 

-

563 

-

564 infile2 = """\ 

-

565 #[[[cog 

-

566 cog.outl('hello') 

-

567 #]]] 

-

568 #[[[end]]] 

-

569 #]]] 

-

570 """ 

-

571 self.isBad(infile2, "infile.txt(5): Unexpected ']]]'") 

-

572 

-

573 def testStartWithEoo(self): 

-

574 infile = """\ 

-

575 #[[[end]]] 

-

576 """ 

-

577 self.isBad(infile, "infile.txt(1): Unexpected '[[[end]]]'") 

-

578 

-

579 infile2 = """\ 

-

580 #[[[cog 

-

581 cog.outl('hello') 

-

582 #]]] 

-

583 #[[[end]]] 

-

584 #[[[end]]] 

-

585 """ 

-

586 self.isBad(infile2, "infile.txt(5): Unexpected '[[[end]]]'") 

-

587 

-

588 def testNoEnd(self): 

-

589 infile = """\ 

-

590 #[[[cog 

-

591 cog.outl("hello") 

-

592 #[[[end]]] 

-

593 """ 

-

594 self.isBad(infile, "infile.txt(3): Unexpected '[[[end]]]'") 

-

595 

-

596 infile2 = """\ 

-

597 #[[[cog 

-

598 cog.outl('hello') 

-

599 #]]] 

-

600 #[[[end]]] 

-

601 #[[[cog 

-

602 cog.outl("hello") 

-

603 #[[[end]]] 

-

604 """ 

-

605 self.isBad(infile2, "infile.txt(7): Unexpected '[[[end]]]'") 

-

606 

-

607 def testTwoBegins(self): 

-

608 infile = """\ 

-

609 #[[[cog 

-

610 #[[[cog 

-

611 cog.outl("hello") 

-

612 #]]] 

-

613 #[[[end]]] 

-

614 """ 

-

615 self.isBad(infile, "infile.txt(2): Unexpected '[[[cog'") 

-

616 

-

617 infile2 = """\ 

-

618 #[[[cog 

-

619 cog.outl("hello") 

-

620 #]]] 

-

621 #[[[end]]] 

-

622 #[[[cog 

-

623 #[[[cog 

-

624 cog.outl("hello") 

-

625 #]]] 

-

626 #[[[end]]] 

-

627 """ 

-

628 self.isBad(infile2, "infile.txt(6): Unexpected '[[[cog'") 

-

629 

-

630 def testTwoEnds(self): 

-

631 infile = """\ 

-

632 #[[[cog 

-

633 cog.outl("hello") 

-

634 #]]] 

-

635 #]]] 

-

636 #[[[end]]] 

-

637 """ 

-

638 self.isBad(infile, "infile.txt(4): Unexpected ']]]'") 

-

639 

-

640 infile2 = """\ 

-

641 #[[[cog 

-

642 cog.outl("hello") 

-

643 #]]] 

-

644 #[[[end]]] 

-

645 #[[[cog 

-

646 cog.outl("hello") 

-

647 #]]] 

-

648 #]]] 

-

649 #[[[end]]] 

-

650 """ 

-

651 self.isBad(infile2, "infile.txt(8): Unexpected ']]]'") 

-

652 

-

653 

-

654class CogErrorTests(TestCase): 

-

655 """ Test cases for cog.error(). 

-

656 """ 

-

657 

-

658 def testErrorMsg(self): 

-

659 infile = """\ 

-

660 [[[cog cog.error("This ain't right!")]]] 

-

661 [[[end]]] 

-

662 """ 

-

663 

-

664 infile = reindentBlock(infile) 

-

665 with self.assertRaisesRegex(CogGeneratedError, "^This ain't right!$"): 

-

666 Cog().processString(infile) 

-

667 

-

668 def testErrorNoMsg(self): 

-

669 infile = """\ 

-

670 [[[cog cog.error()]]] 

-

671 [[[end]]] 

-

672 """ 

-

673 

-

674 infile = reindentBlock(infile) 

-

675 with self.assertRaisesRegex(CogGeneratedError, "^Error raised by cog generator.$"): 

-

676 Cog().processString(infile) 

-

677 

-

678 def testNoErrorIfErrorNotCalled(self): 

-

679 infile = """\ 

-

680 --[[[cog 

-

681 --import cog 

-

682 --for i in range(3): 

-

683 -- if i > 10: 

-

684 -- cog.error("Something is amiss!") 

-

685 -- cog.out("xx%d\\n" % i) 

-

686 --]]] 

-

687 xx0 

-

688 xx1 

-

689 xx2 

-

690 --[[[end]]] 

-

691 """ 

-

692 

-

693 infile = reindentBlock(infile) 

-

694 self.assertEqual(Cog().processString(infile), infile) 

-

695 

-

696 

-

697class CogGeneratorGetCodeTests(TestCase): 

-

698 """ Unit tests against CogGenerator to see if its getCode() method works 

-

699 properly. 

-

700 """ 

-

701 

-

702 def setUp(self): 

-

703 """ All tests get a generator to use, and short same-length names for 

-

704 the functions we're going to use. 

-

705 """ 

-

706 self.gen = CogGenerator() 

-

707 self.m = self.gen.parseMarker 

-

708 self.l = self.gen.parseLine 

-

709 

-

710 def testEmpty(self): 

-

711 self.m('// [[[cog') 

-

712 self.m('// ]]]') 

-

713 self.assertEqual(self.gen.getCode(), '') 

-

714 

-

715 def testSimple(self): 

-

716 self.m('// [[[cog') 

-

717 self.l(' print "hello"') 

-

718 self.l(' print "bye"') 

-

719 self.m('// ]]]') 

-

720 self.assertEqual(self.gen.getCode(), 'print "hello"\nprint "bye"') 

-

721 

-

722 def testCompressed1(self): 

-

723 # For a while, I supported compressed code blocks, but no longer. 

-

724 self.m('// [[[cog: print """') 

-

725 self.l('// hello') 

-

726 self.l('// bye') 

-

727 self.m('// """)]]]') 

-

728 self.assertEqual(self.gen.getCode(), 'hello\nbye') 

-

729 

-

730 def testCompressed2(self): 

-

731 # For a while, I supported compressed code blocks, but no longer. 

-

732 self.m('// [[[cog: print """') 

-

733 self.l('hello') 

-

734 self.l('bye') 

-

735 self.m('// """)]]]') 

-

736 self.assertEqual(self.gen.getCode(), 'hello\nbye') 

-

737 

-

738 def testCompressed3(self): 

-

739 # For a while, I supported compressed code blocks, but no longer. 

-

740 self.m('// [[[cog') 

-

741 self.l('print """hello') 

-

742 self.l('bye') 

-

743 self.m('// """)]]]') 

-

744 self.assertEqual(self.gen.getCode(), 'print """hello\nbye') 

-

745 

-

746 def testCompressed4(self): 

-

747 # For a while, I supported compressed code blocks, but no longer. 

-

748 self.m('// [[[cog: print """') 

-

749 self.l('hello') 

-

750 self.l('bye""")') 

-

751 self.m('// ]]]') 

-

752 self.assertEqual(self.gen.getCode(), 'hello\nbye""")') 

-

753 

-

754 def testNoCommonPrefixForMarkers(self): 

-

755 # It's important to be able to use #if 0 to hide lines from a 

-

756 # C++ compiler. 

-

757 self.m('#if 0 //[[[cog') 

-

758 self.l('\timport cog, sys') 

-

759 self.l('') 

-

760 self.l('\tprint sys.argv') 

-

761 self.m('#endif //]]]') 

-

762 self.assertEqual(self.gen.getCode(), 'import cog, sys\n\nprint sys.argv') 

-

763 

-

764 

-

765class TestCaseWithTempDir(TestCase): 

-

766 

-

767 def newCog(self): 

-

768 """ Initialize the cog members for another run. 

-

769 """ 

-

770 # Create a cog engine, and catch its output. 

-

771 self.cog = Cog() 

-

772 self.output = StringIO() 

-

773 self.cog.setOutput(stdout=self.output, stderr=self.output) 

-

774 

-

775 def setUp(self): 

-

776 # Create a temporary directory. 

-

777 self.tempdir = os.path.join(tempfile.gettempdir(), 'testcog_tempdir_' + str(random.random())[2:]) 

-

778 os.mkdir(self.tempdir) 

-

779 self.olddir = os.getcwd() 

-

780 os.chdir(self.tempdir) 

-

781 self.newCog() 

-

782 

-

783 def tearDown(self): 

-

784 os.chdir(self.olddir) 

-

785 # Get rid of the temporary directory. 

-

786 shutil.rmtree(self.tempdir) 

-

787 

-

788 def assertFilesSame(self, sFName1, sFName2): 

-

789 text1 = open(os.path.join(self.tempdir, sFName1), 'rb').read() 

-

790 text2 = open(os.path.join(self.tempdir, sFName2), 'rb').read() 

-

791 self.assertEqual(text1, text2) 

-

792 

-

793 def assertFileContent(self, sFName, sContent): 

-

794 sAbsName = os.path.join(self.tempdir, sFName) 

-

795 f = open(sAbsName, 'rb') 

-

796 try: 

-

797 sFileContent = f.read() 

-

798 finally: 

-

799 f.close() 

-

800 self.assertEqual(sFileContent, to_bytes(sContent)) 

-

801 

-

802 

-

803class ArgumentHandlingTests(TestCaseWithTempDir): 

-

804 

-

805 def testArgumentFailure(self): 

-

806 # Return value 2 means usage problem. 

-

807 self.assertEqual(self.cog.main(['argv0', '-j']), 2) 

-

808 output = self.output.getvalue() 

-

809 self.assertIn("option -j not recognized", output) 

-

810 with self.assertRaisesRegex(CogUsageError, r"^No files to process$"): 

-

811 self.cog.callableMain(['argv0']) 

-

812 with self.assertRaisesRegex(CogUsageError, r"^option -j not recognized$"): 

-

813 self.cog.callableMain(['argv0', '-j']) 

-

814 

-

815 def testNoDashOAndAtFile(self): 

-

816 d = { 

-

817 'cogfiles.txt': """\ 

-

818 # Please run cog 

-

819 """ 

-

820 } 

-

821 

-

822 makeFiles(d) 

-

823 with self.assertRaisesRegex(CogUsageError, r"^Can't use -o with @file$"): 

-

824 self.cog.callableMain(['argv0', '-o', 'foo', '@cogfiles.txt']) 

-

825 

-

826 def testDashV(self): 

-

827 self.assertEqual(self.cog.main(['argv0', '-v']), 0) 

-

828 output = self.output.getvalue() 

-

829 self.assertEqual('Cog version %s\n' % __version__, output) 

-

830 

-

831 def producesHelp(self, args): 

-

832 self.newCog() 

-

833 argv = ['argv0'] + args.split() 

-

834 self.assertEqual(self.cog.main(argv), 0) 

-

835 self.assertEqual(usage, self.output.getvalue()) 

-

836 

-

837 def testDashH(self): 

-

838 # -h or -? anywhere on the command line should just print help. 

-

839 self.producesHelp("-h") 

-

840 self.producesHelp("-?") 

-

841 self.producesHelp("fooey.txt -h") 

-

842 self.producesHelp("-o -r @fooey.txt -? @booey.txt") 

-

843 

-

844 def testDashOAndDashR(self): 

-

845 d = { 

-

846 'cogfile.txt': """\ 

-

847 # Please run cog 

-

848 """ 

-

849 } 

-

850 

-

851 makeFiles(d) 

-

852 with self.assertRaisesRegex(CogUsageError, r"^Can't use -o with -r \(they are opposites\)$"): 

-

853 self.cog.callableMain(['argv0', '-o', 'foo', '-r', 'cogfile.txt']) 

-

854 

-

855 def testDashZ(self): 

-

856 d = { 

-

857 'test.cog': """\ 

-

858 // This is my C++ file. 

-

859 //[[[cog 

-

860 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

861 for fn in fnames: 

-

862 cog.outl("void %s();" % fn) 

-

863 //]]] 

-

864 """, 

-

865 

-

866 'test.out': """\ 

-

867 // This is my C++ file. 

-

868 //[[[cog 

-

869 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

870 for fn in fnames: 

-

871 cog.outl("void %s();" % fn) 

-

872 //]]] 

-

873 void DoSomething(); 

-

874 void DoAnotherThing(); 

-

875 void DoLastThing(); 

-

876 """, 

-

877 } 

-

878 

-

879 makeFiles(d) 

-

880 with self.assertRaisesRegex(CogError, r"^test.cog\(6\): Missing '\[\[\[end\]\]\]' before end of file.$"): 

-

881 self.cog.callableMain(['argv0', '-r', 'test.cog']) 

-

882 self.newCog() 

-

883 self.cog.callableMain(['argv0', '-r', '-z', 'test.cog']) 

-

884 self.assertFilesSame('test.cog', 'test.out') 

-

885 

-

886 def testBadDashD(self): 

-

887 with self.assertRaisesRegex(CogUsageError, r"^-D takes a name=value argument$"): 

-

888 self.cog.callableMain(['argv0', '-Dfooey', 'cog.txt']) 

-

889 with self.assertRaisesRegex(CogUsageError, r"^-D takes a name=value argument$"): 

-

890 self.cog.callableMain(['argv0', '-D', 'fooey', 'cog.txt']) 

-

891 

-

892 def testBadMarkers(self): 

-

893 with self.assertRaisesRegex(CogUsageError, r"^--markers requires 3 values separated by spaces, could not parse 'X'$"): 

-

894 self.cog.callableMain(['argv0', '--markers=X']) 

-

895 with self.assertRaisesRegex(CogUsageError, r"^--markers requires 3 values separated by spaces, could not parse 'A B C D'$"): 

-

896 self.cog.callableMain(['argv0', '--markers=A B C D']) 

-

897 

-

898 

-

899class TestMain(TestCaseWithTempDir): 

-

900 def setUp(self): 

-

901 super(TestMain, self).setUp() 

-

902 self.old_argv = sys.argv[:] 

-

903 self.old_stderr = sys.stderr 

-

904 sys.stderr = StringIO() 

-

905 

-

906 def tearDown(self): 

-

907 sys.stderr = self.old_stderr 

-

908 sys.argv = self.old_argv 

-

909 sys.modules.pop('mycode', None) 

-

910 super(TestMain, self).tearDown() 

-

911 

-

912 def test_main_function(self): 

-

913 sys.argv = ["argv0", "-Z"] 

-

914 ret = main() 

-

915 self.assertEqual(ret, 2) 

-

916 stderr = sys.stderr.getvalue() 

-

917 self.assertEqual(stderr, 'option -Z not recognized\n(for help use -?)\n') 

-

918 

-

919 files = { 

-

920 'test.cog': """\ 

-

921 //[[[cog 

-

922 def func(): 

-

923 import mycode 

-

924 mycode.boom() 

-

925 //]]] 

-

926 //[[[end]]] 

-

927 ----- 

-

928 //[[[cog 

-

929 func() 

-

930 //]]] 

-

931 //[[[end]]] 

-

932 """, 

-

933 

-

934 'mycode.py': """\ 

-

935 def boom(): 

-

936 [][0] 

-

937 """, 

-

938 } 

-

939 

-

940 def test_error_report(self): 

-

941 self.check_error_report() 

-

942 

-

943 def test_error_report_with_prologue(self): 

-

944 self.check_error_report("-p", "#1\n#2") 

-

945 

-

946 def check_error_report(self, *args): 

-

947 """Check that the error report is right.""" 

-

948 makeFiles(self.files) 

-

949 sys.argv = ["argv0"] + list(args) + ["-r", "test.cog"] 

-

950 main() 

-

951 expected = reindentBlock("""\ 

-

952 Traceback (most recent call last): 

-

953 File "test.cog", line 9, in <module> 

-

954 func() 

-

955 File "test.cog", line 4, in func 

-

956 mycode.boom() 

-

957 File "MYCODE", line 2, in boom 

-

958 [][0] 

-

959 IndexError: list index out of range 

-

960 """) 

-

961 if PY3: 

-

962 expected = expected.replace("MYCODE", os.path.abspath("mycode.py")) 

-

963 else: 

-

964 expected = expected.replace("MYCODE", "mycode.py") 

-

965 assert expected == sys.stderr.getvalue() 

-

966 

-

967 def test_error_in_prologue(self): 

-

968 makeFiles(self.files) 

-

969 sys.argv = ["argv0", "-p", "import mycode; mycode.boom()", "-r", "test.cog"] 

-

970 main() 

-

971 expected = reindentBlock("""\ 

-

972 Traceback (most recent call last): 

-

973 File "<prologue>", line 1, in <module> 

-

974 import mycode; mycode.boom() 

-

975 File "MYCODE", line 2, in boom 

-

976 [][0] 

-

977 IndexError: list index out of range 

-

978 """) 

-

979 if PY3: 

-

980 expected = expected.replace("MYCODE", os.path.abspath("mycode.py")) 

-

981 else: 

-

982 expected = expected.replace("MYCODE", "mycode.py") 

-

983 assert expected == sys.stderr.getvalue() 

-

984 

-

985 

-

986 

-

987class TestFileHandling(TestCaseWithTempDir): 

-

988 

-

989 def testSimple(self): 

-

990 d = { 

-

991 'test.cog': """\ 

-

992 // This is my C++ file. 

-

993 //[[[cog 

-

994 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

995 for fn in fnames: 

-

996 cog.outl("void %s();" % fn) 

-

997 //]]] 

-

998 //[[[end]]] 

-

999 """, 

-

1000 

-

1001 'test.out': """\ 

-

1002 // This is my C++ file. 

-

1003 //[[[cog 

-

1004 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1005 for fn in fnames: 

-

1006 cog.outl("void %s();" % fn) 

-

1007 //]]] 

-

1008 void DoSomething(); 

-

1009 void DoAnotherThing(); 

-

1010 void DoLastThing(); 

-

1011 //[[[end]]] 

-

1012 """, 

-

1013 } 

-

1014 

-

1015 makeFiles(d) 

-

1016 self.cog.callableMain(['argv0', '-r', 'test.cog']) 

-

1017 self.assertFilesSame('test.cog', 'test.out') 

-

1018 output = self.output.getvalue() 

-

1019 self.assertIn("(changed)", output) 

-

1020 

-

1021 def testWildcards(self): 

-

1022 d = { 

-

1023 'test.cog': """\ 

-

1024 // This is my C++ file. 

-

1025 //[[[cog 

-

1026 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1027 for fn in fnames: 

-

1028 cog.outl("void %s();" % fn) 

-

1029 //]]] 

-

1030 //[[[end]]] 

-

1031 """, 

-

1032 

-

1033 'test2.cog': """\ 

-

1034 // This is my C++ file. 

-

1035 //[[[cog 

-

1036 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1037 for fn in fnames: 

-

1038 cog.outl("void %s();" % fn) 

-

1039 //]]] 

-

1040 //[[[end]]] 

-

1041 """, 

-

1042 

-

1043 'test.out': """\ 

-

1044 // This is my C++ file. 

-

1045 //[[[cog 

-

1046 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1047 for fn in fnames: 

-

1048 cog.outl("void %s();" % fn) 

-

1049 //]]] 

-

1050 void DoSomething(); 

-

1051 void DoAnotherThing(); 

-

1052 void DoLastThing(); 

-

1053 //[[[end]]] 

-

1054 """, 

-

1055 

-

1056 'not_this_one.cog': """\ 

-

1057 // This is my C++ file. 

-

1058 //[[[cog 

-

1059 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1060 for fn in fnames: 

-

1061 cog.outl("void %s();" % fn) 

-

1062 //]]] 

-

1063 //[[[end]]] 

-

1064 """, 

-

1065 

-

1066 'not_this_one.out': """\ 

-

1067 // This is my C++ file. 

-

1068 //[[[cog 

-

1069 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1070 for fn in fnames: 

-

1071 cog.outl("void %s();" % fn) 

-

1072 //]]] 

-

1073 //[[[end]]] 

-

1074 """, 

-

1075 } 

-

1076 

-

1077 makeFiles(d) 

-

1078 self.cog.callableMain(['argv0', '-r', 't*.cog']) 

-

1079 self.assertFilesSame('test.cog', 'test.out') 

-

1080 self.assertFilesSame('test2.cog', 'test.out') 

-

1081 self.assertFilesSame('not_this_one.cog', 'not_this_one.out') 

-

1082 output = self.output.getvalue() 

-

1083 self.assertIn("(changed)", output) 

-

1084 

-

1085 def testOutputFile(self): 

-

1086 # -o sets the output file. 

-

1087 d = { 

-

1088 'test.cog': """\ 

-

1089 // This is my C++ file. 

-

1090 //[[[cog 

-

1091 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1092 for fn in fnames: 

-

1093 cog.outl("void %s();" % fn) 

-

1094 //]]] 

-

1095 //[[[end]]] 

-

1096 """, 

-

1097 

-

1098 'test.out': """\ 

-

1099 // This is my C++ file. 

-

1100 //[[[cog 

-

1101 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

1102 for fn in fnames: 

-

1103 cog.outl("void %s();" % fn) 

-

1104 //]]] 

-

1105 void DoSomething(); 

-

1106 void DoAnotherThing(); 

-

1107 void DoLastThing(); 

-

1108 //[[[end]]] 

-

1109 """, 

-

1110 } 

-

1111 

-

1112 makeFiles(d) 

-

1113 self.cog.callableMain(['argv0', '-o', 'in/a/dir/test.cogged', 'test.cog']) 

-

1114 self.assertFilesSame('in/a/dir/test.cogged', 'test.out') 

-

1115 

-

1116 def testAtFile(self): 

-

1117 d = { 

-

1118 'one.cog': """\ 

-

1119 //[[[cog 

-

1120 cog.outl("hello world") 

-

1121 //]]] 

-

1122 //[[[end]]] 

-

1123 """, 

-

1124 

-

1125 'one.out': """\ 

-

1126 //[[[cog 

-

1127 cog.outl("hello world") 

-

1128 //]]] 

-

1129 hello world 

-

1130 //[[[end]]] 

-

1131 """, 

-

1132 

-

1133 'two.cog': """\ 

-

1134 //[[[cog 

-

1135 cog.outl("goodbye cruel world") 

-

1136 //]]] 

-

1137 //[[[end]]] 

-

1138 """, 

-

1139 

-

1140 'two.out': """\ 

-

1141 //[[[cog 

-

1142 cog.outl("goodbye cruel world") 

-

1143 //]]] 

-

1144 goodbye cruel world 

-

1145 //[[[end]]] 

-

1146 """, 

-

1147 

-

1148 'cogfiles.txt': """\ 

-

1149 # Please run cog 

-

1150 one.cog 

-

1151 

-

1152 two.cog 

-

1153 """ 

-

1154 } 

-

1155 

-

1156 makeFiles(d) 

-

1157 self.cog.callableMain(['argv0', '-r', '@cogfiles.txt']) 

-

1158 self.assertFilesSame('one.cog', 'one.out') 

-

1159 self.assertFilesSame('two.cog', 'two.out') 

-

1160 output = self.output.getvalue() 

-

1161 self.assertIn("(changed)", output) 

-

1162 

-

1163 def testNestedAtFile(self): 

-

1164 d = { 

-

1165 'one.cog': """\ 

-

1166 //[[[cog 

-

1167 cog.outl("hello world") 

-

1168 //]]] 

-

1169 //[[[end]]] 

-

1170 """, 

-

1171 

-

1172 'one.out': """\ 

-

1173 //[[[cog 

-

1174 cog.outl("hello world") 

-

1175 //]]] 

-

1176 hello world 

-

1177 //[[[end]]] 

-

1178 """, 

-

1179 

-

1180 'two.cog': """\ 

-

1181 //[[[cog 

-

1182 cog.outl("goodbye cruel world") 

-

1183 //]]] 

-

1184 //[[[end]]] 

-

1185 """, 

-

1186 

-

1187 'two.out': """\ 

-

1188 //[[[cog 

-

1189 cog.outl("goodbye cruel world") 

-

1190 //]]] 

-

1191 goodbye cruel world 

-

1192 //[[[end]]] 

-

1193 """, 

-

1194 

-

1195 'cogfiles.txt': """\ 

-

1196 # Please run cog 

-

1197 one.cog 

-

1198 @cogfiles2.txt 

-

1199 """, 

-

1200 

-

1201 'cogfiles2.txt': """\ 

-

1202 # This one too, please. 

-

1203 two.cog 

-

1204 """, 

-

1205 } 

-

1206 

-

1207 makeFiles(d) 

-

1208 self.cog.callableMain(['argv0', '-r', '@cogfiles.txt']) 

-

1209 self.assertFilesSame('one.cog', 'one.out') 

-

1210 self.assertFilesSame('two.cog', 'two.out') 

-

1211 output = self.output.getvalue() 

-

1212 self.assertIn("(changed)", output) 

-

1213 

-

1214 def testAtFileWithArgs(self): 

-

1215 d = { 

-

1216 'both.cog': """\ 

-

1217 //[[[cog 

-

1218 cog.outl("one: %s" % ('one' in globals())) 

-

1219 cog.outl("two: %s" % ('two' in globals())) 

-

1220 //]]] 

-

1221 //[[[end]]] 

-

1222 """, 

-

1223 

-

1224 'one.out': """\ 

-

1225 //[[[cog 

-

1226 cog.outl("one: %s" % ('one' in globals())) 

-

1227 cog.outl("two: %s" % ('two' in globals())) 

-

1228 //]]] 

-

1229 one: True // ONE 

-

1230 two: False // ONE 

-

1231 //[[[end]]] 

-

1232 """, 

-

1233 

-

1234 'two.out': """\ 

-

1235 //[[[cog 

-

1236 cog.outl("one: %s" % ('one' in globals())) 

-

1237 cog.outl("two: %s" % ('two' in globals())) 

-

1238 //]]] 

-

1239 one: False // TWO 

-

1240 two: True // TWO 

-

1241 //[[[end]]] 

-

1242 """, 

-

1243 

-

1244 'cogfiles.txt': """\ 

-

1245 # Please run cog 

-

1246 both.cog -o in/a/dir/both.one -s ' // ONE' -D one=x 

-

1247 both.cog -o in/a/dir/both.two -s ' // TWO' -D two=x 

-

1248 """ 

-

1249 } 

-

1250 

-

1251 makeFiles(d) 

-

1252 self.cog.callableMain(['argv0', '@cogfiles.txt']) 

-

1253 self.assertFilesSame('in/a/dir/both.one', 'one.out') 

-

1254 self.assertFilesSame('in/a/dir/both.two', 'two.out') 

-

1255 

-

1256 def testAtFileWithBadArgCombo(self): 

-

1257 d = { 

-

1258 'both.cog': """\ 

-

1259 //[[[cog 

-

1260 cog.outl("one: %s" % ('one' in globals())) 

-

1261 cog.outl("two: %s" % ('two' in globals())) 

-

1262 //]]] 

-

1263 //[[[end]]] 

-

1264 """, 

-

1265 

-

1266 'cogfiles.txt': """\ 

-

1267 # Please run cog 

-

1268 both.cog 

-

1269 both.cog -d # This is bad: -r and -d 

-

1270 """ 

-

1271 } 

-

1272 

-

1273 makeFiles(d) 

-

1274 with self.assertRaisesRegex(CogUsageError, r"^Can't use -d with -r \(or you would delete all your source!\)$"): 

-

1275 self.cog.callableMain(['argv0', '-r', '@cogfiles.txt']) 

-

1276 

-

1277 def testAtFileWithTrickyFilenames(self): 

-

1278 def fix_backslashes(files_txt): 

-

1279 """Make the contents of a files.txt sensitive to the platform.""" 

-

1280 if sys.platform != "win32": 

-

1281 files_txt = files_txt.replace("\\", "/") 

-

1282 return files_txt 

-

1283 

-

1284 d = { 

-

1285 'one 1.cog': """\ 

-

1286 //[[[cog cog.outl("hello world") ]]] 

-

1287 """, 

-

1288 

-

1289 'one.out': """\ 

-

1290 //[[[cog cog.outl("hello world") ]]] 

-

1291 hello world //xxx 

-

1292 """, 

-

1293 

-

1294 'subdir': { 

-

1295 'subback.cog': """\ 

-

1296 //[[[cog cog.outl("down deep with backslashes") ]]] 

-

1297 """, 

-

1298 

-

1299 'subfwd.cog': """\ 

-

1300 //[[[cog cog.outl("down deep with slashes") ]]] 

-

1301 """, 

-

1302 }, 

-

1303 

-

1304 'subback.out': """\ 

-

1305 //[[[cog cog.outl("down deep with backslashes") ]]] 

-

1306 down deep with backslashes //yyy 

-

1307 """, 

-

1308 

-

1309 'subfwd.out': """\ 

-

1310 //[[[cog cog.outl("down deep with slashes") ]]] 

-

1311 down deep with slashes //zzz 

-

1312 """, 

-

1313 

-

1314 'cogfiles.txt': fix_backslashes("""\ 

-

1315 # Please run cog 

-

1316 'one 1.cog' -s ' //xxx' 

-

1317 subdir\\subback.cog -s ' //yyy' 

-

1318 subdir/subfwd.cog -s ' //zzz' 

-

1319 """) 

-

1320 } 

-

1321 

-

1322 makeFiles(d) 

-

1323 self.cog.callableMain(['argv0', '-z', '-r', '@cogfiles.txt']) 

-

1324 self.assertFilesSame('one 1.cog', 'one.out') 

-

1325 self.assertFilesSame('subdir/subback.cog', 'subback.out') 

-

1326 self.assertFilesSame('subdir/subfwd.cog', 'subfwd.out') 

-

1327 

-

1328 def run_with_verbosity(self, verbosity): 

-

1329 d = { 

-

1330 'unchanged.cog': """\ 

-

1331 //[[[cog 

-

1332 cog.outl("hello world") 

-

1333 //]]] 

-

1334 hello world 

-

1335 //[[[end]]] 

-

1336 """, 

-

1337 

-

1338 'changed.cog': """\ 

-

1339 //[[[cog 

-

1340 cog.outl("goodbye cruel world") 

-

1341 //]]] 

-

1342 //[[[end]]] 

-

1343 """, 

-

1344 

-

1345 'cogfiles.txt': """\ 

-

1346 unchanged.cog 

-

1347 changed.cog 

-

1348 """ 

-

1349 } 

-

1350 

-

1351 makeFiles(d) 

-

1352 self.cog.callableMain(['argv0', '-r', '--verbosity='+verbosity, '@cogfiles.txt']) 

-

1353 output = self.output.getvalue() 

-

1354 return output 

-

1355 

-

1356 def test_verbosity0(self): 

-

1357 output = self.run_with_verbosity("0") 

-

1358 self.assertEqual(output, "") 

-

1359 

-

1360 def test_verbosity1(self): 

-

1361 output = self.run_with_verbosity("1") 

-

1362 self.assertEqual(output, "Cogging changed.cog (changed)\n") 

-

1363 

-

1364 def test_verbosity2(self): 

-

1365 output = self.run_with_verbosity("2") 

-

1366 self.assertEqual(output, "Cogging unchanged.cog\nCogging changed.cog (changed)\n") 

-

1367 

-

1368 

-

1369class CogTestLineEndings(TestCaseWithTempDir): 

-

1370 """Tests for -U option (force LF line-endings in output).""" 

-

1371 

-

1372 lines_in = ['Some text.', 

-

1373 '//[[[cog', 

-

1374 'cog.outl("Cog text")', 

-

1375 '//]]]', 

-

1376 'gobbledegook.', 

-

1377 '//[[[end]]]', 

-

1378 'epilogue.', 

-

1379 ''] 

-

1380 

-

1381 lines_out = ['Some text.', 

-

1382 '//[[[cog', 

-

1383 'cog.outl("Cog text")', 

-

1384 '//]]]', 

-

1385 'Cog text', 

-

1386 '//[[[end]]]', 

-

1387 'epilogue.', 

-

1388 ''] 

-

1389 

-

1390 def testOutputNativeEol(self): 

-

1391 makeFiles({'infile': '\n'.join(self.lines_in)}) 

-

1392 self.cog.callableMain(['argv0', '-o', 'outfile', 'infile']) 

-

1393 self.assertFileContent('outfile', os.linesep.join(self.lines_out)) 

-

1394 

-

1395 def testOutputLfEol(self): 

-

1396 makeFiles({'infile': '\n'.join(self.lines_in)}) 

-

1397 self.cog.callableMain(['argv0', '-U', '-o', 'outfile', 'infile']) 

-

1398 self.assertFileContent('outfile', '\n'.join(self.lines_out)) 

-

1399 

-

1400 def testReplaceNativeEol(self): 

-

1401 makeFiles({'test.cog': '\n'.join(self.lines_in)}) 

-

1402 self.cog.callableMain(['argv0', '-r', 'test.cog']) 

-

1403 self.assertFileContent('test.cog', os.linesep.join(self.lines_out)) 

-

1404 

-

1405 def testReplaceLfEol(self): 

-

1406 makeFiles({'test.cog': '\n'.join(self.lines_in)}) 

-

1407 self.cog.callableMain(['argv0', '-U', '-r', 'test.cog']) 

-

1408 self.assertFileContent('test.cog', '\n'.join(self.lines_out)) 

-

1409 

-

1410 

-

1411class CogTestCharacterEncoding(TestCaseWithTempDir): 

-

1412 

-

1413 def testSimple(self): 

-

1414 d = { 

-

1415 'test.cog': b"""\ 

-

1416 // This is my C++ file. 

-

1417 //[[[cog 

-

1418 cog.outl("// Unicode: \xe1\x88\xb4 (U+1234)") 

-

1419 //]]] 

-

1420 //[[[end]]] 

-

1421 """, 

-

1422 

-

1423 'test.out': b"""\ 

-

1424 // This is my C++ file. 

-

1425 //[[[cog 

-

1426 cog.outl("// Unicode: \xe1\x88\xb4 (U+1234)") 

-

1427 //]]] 

-

1428 // Unicode: \xe1\x88\xb4 (U+1234) 

-

1429 //[[[end]]] 

-

1430 """.replace(b"\n", os.linesep.encode()), 

-

1431 } 

-

1432 

-

1433 makeFiles(d, bytes=True) 

-

1434 self.cog.callableMain(['argv0', '-r', 'test.cog']) 

-

1435 self.assertFilesSame('test.cog', 'test.out') 

-

1436 output = self.output.getvalue() 

-

1437 self.assertIn("(changed)", output) 

-

1438 

-

1439 def testFileEncodingOption(self): 

-

1440 d = { 

-

1441 'test.cog': b"""\ 

-

1442 // \xca\xee\xe4\xe8\xf0\xe2\xea\xe0 Windows 

-

1443 //[[[cog 

-

1444 cog.outl("\xd1\xfa\xe5\xf8\xfc \xe5\xf9\xb8 \xfd\xf2\xe8\xf5 \xec\xff\xe3\xea\xe8\xf5 \xf4\xf0\xe0\xed\xf6\xf3\xe7\xf1\xea\xe8\xf5 \xe1\xf3\xeb\xee\xea \xe4\xe0 \xe2\xfb\xef\xe5\xe9 \xf7\xe0\xfe") 

-

1445 //]]] 

-

1446 //[[[end]]] 

-

1447 """, 

-

1448 

-

1449 'test.out': b"""\ 

-

1450 // \xca\xee\xe4\xe8\xf0\xe2\xea\xe0 Windows 

-

1451 //[[[cog 

-

1452 cog.outl("\xd1\xfa\xe5\xf8\xfc \xe5\xf9\xb8 \xfd\xf2\xe8\xf5 \xec\xff\xe3\xea\xe8\xf5 \xf4\xf0\xe0\xed\xf6\xf3\xe7\xf1\xea\xe8\xf5 \xe1\xf3\xeb\xee\xea \xe4\xe0 \xe2\xfb\xef\xe5\xe9 \xf7\xe0\xfe") 

-

1453 //]]] 

-

1454 \xd1\xfa\xe5\xf8\xfc \xe5\xf9\xb8 \xfd\xf2\xe8\xf5 \xec\xff\xe3\xea\xe8\xf5 \xf4\xf0\xe0\xed\xf6\xf3\xe7\xf1\xea\xe8\xf5 \xe1\xf3\xeb\xee\xea \xe4\xe0 \xe2\xfb\xef\xe5\xe9 \xf7\xe0\xfe 

-

1455 //[[[end]]] 

-

1456 """.replace(b"\n", os.linesep.encode()), 

-

1457 } 

-

1458 

-

1459 makeFiles(d, bytes=True) 

-

1460 self.cog.callableMain(['argv0', '-n', 'cp1251', '-r', 'test.cog']) 

-

1461 self.assertFilesSame('test.cog', 'test.out') 

-

1462 output = self.output.getvalue() 

-

1463 self.assertIn("(changed)", output) 

-

1464 

-

1465 

-

1466class TestCaseWithImports(TestCaseWithTempDir): 

-

1467 """ When running tests which import modules, the sys.modules list 

-

1468 leaks from one test to the next. This test case class scrubs 

-

1469 the list after each run to keep the tests isolated from each other. 

-

1470 """ 

-

1471 

-

1472 def setUp(self): 

-

1473 super(TestCaseWithImports, self).setUp() 

-

1474 self.sysmodulekeys = list(sys.modules) 

-

1475 

-

1476 def tearDown(self): 

-

1477 modstoscrub = [ 

-

1478 modname 

-

1479 for modname in sys.modules 

-

1480 if modname not in self.sysmodulekeys 

-

1481 ] 

-

1482 for modname in modstoscrub: 

-

1483 del sys.modules[modname] 

-

1484 super(TestCaseWithImports, self).tearDown() 

-

1485 

-

1486 

-

1487class CogIncludeTests(TestCaseWithImports): 

-

1488 dincludes = { 

-

1489 'test.cog': """\ 

-

1490 //[[[cog 

-

1491 import mymodule 

-

1492 //]]] 

-

1493 //[[[end]]] 

-

1494 """, 

-

1495 

-

1496 'test.out': """\ 

-

1497 //[[[cog 

-

1498 import mymodule 

-

1499 //]]] 

-

1500 Hello from mymodule 

-

1501 //[[[end]]] 

-

1502 """, 

-

1503 

-

1504 'test2.out': """\ 

-

1505 //[[[cog 

-

1506 import mymodule 

-

1507 //]]] 

-

1508 Hello from mymodule in inc2 

-

1509 //[[[end]]] 

-

1510 """, 

-

1511 

-

1512 'include': { 

-

1513 'mymodule.py': """\ 

-

1514 import cog 

-

1515 cog.outl("Hello from mymodule") 

-

1516 """ 

-

1517 }, 

-

1518 

-

1519 'inc2': { 

-

1520 'mymodule.py': """\ 

-

1521 import cog 

-

1522 cog.outl("Hello from mymodule in inc2") 

-

1523 """ 

-

1524 }, 

-

1525 

-

1526 'inc3': { 

-

1527 'someothermodule.py': """\ 

-

1528 import cog 

-

1529 cog.outl("This is some other module.") 

-

1530 """ 

-

1531 }, 

-

1532 } 

-

1533 

-

1534 def testNeedIncludePath(self): 

-

1535 # Try it without the -I, to see that an ImportError happens. 

-

1536 makeFiles(self.dincludes) 

-

1537 msg = "(ImportError|ModuleNotFoundError): No module named '?mymodule'?" 

-

1538 with self.assertRaisesRegex(CogUserException, msg): 

-

1539 self.cog.callableMain(['argv0', '-r', 'test.cog']) 

-

1540 

-

1541 def testIncludePath(self): 

-

1542 # Test that -I adds include directories properly. 

-

1543 makeFiles(self.dincludes) 

-

1544 self.cog.callableMain(['argv0', '-r', '-I', 'include', 'test.cog']) 

-

1545 self.assertFilesSame('test.cog', 'test.out') 

-

1546 

-

1547 def testTwoIncludePaths(self): 

-

1548 # Test that two -I's add include directories properly. 

-

1549 makeFiles(self.dincludes) 

-

1550 self.cog.callableMain(['argv0', '-r', '-I', 'include', '-I', 'inc2', 'test.cog']) 

-

1551 self.assertFilesSame('test.cog', 'test.out') 

-

1552 

-

1553 def testTwoIncludePaths2(self): 

-

1554 # Test that two -I's add include directories properly. 

-

1555 makeFiles(self.dincludes) 

-

1556 self.cog.callableMain(['argv0', '-r', '-I', 'inc2', '-I', 'include', 'test.cog']) 

-

1557 self.assertFilesSame('test.cog', 'test2.out') 

-

1558 

-

1559 def testUselessIncludePath(self): 

-

1560 # Test that the search will continue past the first directory. 

-

1561 makeFiles(self.dincludes) 

-

1562 self.cog.callableMain(['argv0', '-r', '-I', 'inc3', '-I', 'include', 'test.cog']) 

-

1563 self.assertFilesSame('test.cog', 'test.out') 

-

1564 

-

1565 def testSysPathIsUnchanged(self): 

-

1566 d = { 

-

1567 'bad.cog': """\ 

-

1568 //[[[cog cog.error("Oh no!") ]]] 

-

1569 //[[[end]]] 

-

1570 """, 

-

1571 'good.cog': """\ 

-

1572 //[[[cog cog.outl("Oh yes!") ]]] 

-

1573 //[[[end]]] 

-

1574 """, 

-

1575 } 

-

1576 

-

1577 makeFiles(d) 

-

1578 # Is it unchanged just by creating a cog engine? 

-

1579 oldsyspath = sys.path[:] 

-

1580 self.newCog() 

-

1581 self.assertEqual(oldsyspath, sys.path) 

-

1582 # Is it unchanged for a successful run? 

-

1583 self.newCog() 

-

1584 self.cog.callableMain(['argv0', '-r', 'good.cog']) 

-

1585 self.assertEqual(oldsyspath, sys.path) 

-

1586 # Is it unchanged for a successful run with includes? 

-

1587 self.newCog() 

-

1588 self.cog.callableMain(['argv0', '-r', '-I', 'xyzzy', 'good.cog']) 

-

1589 self.assertEqual(oldsyspath, sys.path) 

-

1590 # Is it unchanged for a successful run with two includes? 

-

1591 self.newCog() 

-

1592 self.cog.callableMain(['argv0', '-r', '-I', 'xyzzy', '-I', 'quux', 'good.cog']) 

-

1593 self.assertEqual(oldsyspath, sys.path) 

-

1594 # Is it unchanged for a failed run? 

-

1595 self.newCog() 

-

1596 with self.assertRaisesRegex(CogError, r"^Oh no!$"): 

-

1597 self.cog.callableMain(['argv0', '-r', 'bad.cog']) 

-

1598 self.assertEqual(oldsyspath, sys.path) 

-

1599 # Is it unchanged for a failed run with includes? 

-

1600 self.newCog() 

-

1601 with self.assertRaisesRegex(CogError, r"^Oh no!$"): 

-

1602 self.cog.callableMain(['argv0', '-r', '-I', 'xyzzy', 'bad.cog']) 

-

1603 self.assertEqual(oldsyspath, sys.path) 

-

1604 # Is it unchanged for a failed run with two includes? 

-

1605 self.newCog() 

-

1606 with self.assertRaisesRegex(CogError, r"^Oh no!$"): 

-

1607 self.cog.callableMain(['argv0', '-r', '-I', 'xyzzy', '-I', 'quux', 'bad.cog']) 

-

1608 self.assertEqual(oldsyspath, sys.path) 

-

1609 

-

1610 def testSubDirectories(self): 

-

1611 # Test that relative paths on the command line work, with includes. 

-

1612 

-

1613 d = { 

-

1614 'code': { 

-

1615 'test.cog': """\ 

-

1616 //[[[cog 

-

1617 import mysubmodule 

-

1618 //]]] 

-

1619 //[[[end]]] 

-

1620 """, 

-

1621 

-

1622 'test.out': """\ 

-

1623 //[[[cog 

-

1624 import mysubmodule 

-

1625 //]]] 

-

1626 Hello from mysubmodule 

-

1627 //[[[end]]] 

-

1628 """, 

-

1629 

-

1630 'mysubmodule.py': """\ 

-

1631 import cog 

-

1632 cog.outl("Hello from mysubmodule") 

-

1633 """ 

-

1634 } 

-

1635 } 

-

1636 

-

1637 makeFiles(d) 

-

1638 # We should be able to invoke cog without the -I switch, and it will 

-

1639 # auto-include the current directory 

-

1640 self.cog.callableMain(['argv0', '-r', 'code/test.cog']) 

-

1641 self.assertFilesSame('code/test.cog', 'code/test.out') 

-

1642 

-

1643 

-

1644class CogTestsInFiles(TestCaseWithTempDir): 

-

1645 

-

1646 def testWarnIfNoCogCode(self): 

-

1647 # Test that the -e switch warns if there is no Cog code. 

-

1648 d = { 

-

1649 'with.cog': """\ 

-

1650 //[[[cog 

-

1651 cog.outl("hello world") 

-

1652 //]]] 

-

1653 hello world 

-

1654 //[[[end]]] 

-

1655 """, 

-

1656 

-

1657 'without.cog': """\ 

-

1658 There's no cog 

-

1659 code in this file. 

-

1660 """, 

-

1661 } 

-

1662 

-

1663 makeFiles(d) 

-

1664 self.cog.callableMain(['argv0', '-e', 'with.cog']) 

-

1665 output = self.output.getvalue() 

-

1666 self.assertNotIn("Warning", output) 

-

1667 self.newCog() 

-

1668 self.cog.callableMain(['argv0', '-e', 'without.cog']) 

-

1669 output = self.output.getvalue() 

-

1670 self.assertIn("Warning: no cog code found in without.cog", output) 

-

1671 self.newCog() 

-

1672 self.cog.callableMain(['argv0', 'without.cog']) 

-

1673 output = self.output.getvalue() 

-

1674 self.assertNotIn("Warning", output) 

-

1675 

-

1676 def testFileNameProps(self): 

-

1677 d = { 

-

1678 'cog1.txt': """\ 

-

1679 //[[[cog 

-

1680 cog.outl("This is %s in, %s out" % (cog.inFile, cog.outFile)) 

-

1681 //]]] 

-

1682 this is cog1.txt in, cog1.txt out 

-

1683 [[[end]]] 

-

1684 """, 

-

1685 

-

1686 'cog1.out': """\ 

-

1687 //[[[cog 

-

1688 cog.outl("This is %s in, %s out" % (cog.inFile, cog.outFile)) 

-

1689 //]]] 

-

1690 This is cog1.txt in, cog1.txt out 

-

1691 [[[end]]] 

-

1692 """, 

-

1693 

-

1694 'cog1out.out': """\ 

-

1695 //[[[cog 

-

1696 cog.outl("This is %s in, %s out" % (cog.inFile, cog.outFile)) 

-

1697 //]]] 

-

1698 This is cog1.txt in, cog1out.txt out 

-

1699 [[[end]]] 

-

1700 """, 

-

1701 } 

-

1702 

-

1703 makeFiles(d) 

-

1704 self.cog.callableMain(['argv0', '-r', 'cog1.txt']) 

-

1705 self.assertFilesSame('cog1.txt', 'cog1.out') 

-

1706 self.newCog() 

-

1707 self.cog.callableMain(['argv0', '-o', 'cog1out.txt', 'cog1.txt']) 

-

1708 self.assertFilesSame('cog1out.txt', 'cog1out.out') 

-

1709 

-

1710 def testGlobalsDontCrossFiles(self): 

-

1711 # Make sure that global values don't get shared between files. 

-

1712 d = { 

-

1713 'one.cog': """\ 

-

1714 //[[[cog s = "This was set in one.cog" ]]] 

-

1715 //[[[end]]] 

-

1716 //[[[cog cog.outl(s) ]]] 

-

1717 //[[[end]]] 

-

1718 """, 

-

1719 

-

1720 'one.out': """\ 

-

1721 //[[[cog s = "This was set in one.cog" ]]] 

-

1722 //[[[end]]] 

-

1723 //[[[cog cog.outl(s) ]]] 

-

1724 This was set in one.cog 

-

1725 //[[[end]]] 

-

1726 """, 

-

1727 

-

1728 'two.cog': """\ 

-

1729 //[[[cog 

-

1730 try: 

-

1731 cog.outl(s) 

-

1732 except NameError: 

-

1733 cog.outl("s isn't set!") 

-

1734 //]]] 

-

1735 //[[[end]]] 

-

1736 """, 

-

1737 

-

1738 'two.out': """\ 

-

1739 //[[[cog 

-

1740 try: 

-

1741 cog.outl(s) 

-

1742 except NameError: 

-

1743 cog.outl("s isn't set!") 

-

1744 //]]] 

-

1745 s isn't set! 

-

1746 //[[[end]]] 

-

1747 """, 

-

1748 

-

1749 'cogfiles.txt': """\ 

-

1750 # Please run cog 

-

1751 one.cog 

-

1752 

-

1753 two.cog 

-

1754 """ 

-

1755 } 

-

1756 

-

1757 makeFiles(d) 

-

1758 self.cog.callableMain(['argv0', '-r', '@cogfiles.txt']) 

-

1759 self.assertFilesSame('one.cog', 'one.out') 

-

1760 self.assertFilesSame('two.cog', 'two.out') 

-

1761 output = self.output.getvalue() 

-

1762 self.assertIn("(changed)", output) 

-

1763 

-

1764 def testRemoveGeneratedOutput(self): 

-

1765 d = { 

-

1766 'cog1.txt': """\ 

-

1767 //[[[cog 

-

1768 cog.outl("This line was generated.") 

-

1769 //]]] 

-

1770 This line was generated. 

-

1771 //[[[end]]] 

-

1772 This line was not. 

-

1773 """, 

-

1774 

-

1775 'cog1.out': """\ 

-

1776 //[[[cog 

-

1777 cog.outl("This line was generated.") 

-

1778 //]]] 

-

1779 //[[[end]]] 

-

1780 This line was not. 

-

1781 """, 

-

1782 

-

1783 'cog1.out2': """\ 

-

1784 //[[[cog 

-

1785 cog.outl("This line was generated.") 

-

1786 //]]] 

-

1787 This line was generated. 

-

1788 //[[[end]]] 

-

1789 This line was not. 

-

1790 """, 

-

1791 } 

-

1792 

-

1793 makeFiles(d) 

-

1794 # Remove generated output. 

-

1795 self.cog.callableMain(['argv0', '-r', '-x', 'cog1.txt']) 

-

1796 self.assertFilesSame('cog1.txt', 'cog1.out') 

-

1797 self.newCog() 

-

1798 # Regenerate the generated output. 

-

1799 self.cog.callableMain(['argv0', '-r', 'cog1.txt']) 

-

1800 self.assertFilesSame('cog1.txt', 'cog1.out2') 

-

1801 self.newCog() 

-

1802 # Remove the generated output again. 

-

1803 self.cog.callableMain(['argv0', '-r', '-x', 'cog1.txt']) 

-

1804 self.assertFilesSame('cog1.txt', 'cog1.out') 

-

1805 

-

1806 def testMsgCall(self): 

-

1807 infile = """\ 

-

1808 #[[[cog 

-

1809 cog.msg("Hello there!") 

-

1810 #]]] 

-

1811 #[[[end]]] 

-

1812 """ 

-

1813 infile = reindentBlock(infile) 

-

1814 self.assertEqual(self.cog.processString(infile), infile) 

-

1815 output = self.output.getvalue() 

-

1816 self.assertEqual(output, "Message: Hello there!\n") 

-

1817 

-

1818 def testErrorMessageHasNoTraceback(self): 

-

1819 # Test that a Cog error is printed to stderr with no traceback. 

-

1820 

-

1821 d = { 

-

1822 'cog1.txt': """\ 

-

1823 //[[[cog 

-

1824 cog.outl("This line was newly") 

-

1825 cog.outl("generated by cog") 

-

1826 cog.outl("blah blah.") 

-

1827 //]]] 

-

1828 Xhis line was newly 

-

1829 generated by cog 

-

1830 blah blah. 

-

1831 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

1832 """, 

-

1833 } 

-

1834 

-

1835 makeFiles(d) 

-

1836 stderr = StringIO() 

-

1837 self.cog.setOutput(stderr=stderr) 

-

1838 self.cog.main(['argv0', '-c', '-r', "cog1.txt"]) 

-

1839 self.assertEqual(self.output.getvalue(), "Cogging cog1.txt\n") 

-

1840 self.assertEqual(stderr.getvalue(), "cog1.txt(9): Output has been edited! Delete old checksum to unprotect.\n") 

-

1841 

-

1842 def testDashD(self): 

-

1843 d = { 

-

1844 'test.cog': """\ 

-

1845 --[[[cog cog.outl("Defined fooey as " + fooey) ]]] 

-

1846 --[[[end]]] 

-

1847 """, 

-

1848 

-

1849 'test.kablooey': """\ 

-

1850 --[[[cog cog.outl("Defined fooey as " + fooey) ]]] 

-

1851 Defined fooey as kablooey 

-

1852 --[[[end]]] 

-

1853 """, 

-

1854 

-

1855 'test.einstein': """\ 

-

1856 --[[[cog cog.outl("Defined fooey as " + fooey) ]]] 

-

1857 Defined fooey as e=mc2 

-

1858 --[[[end]]] 

-

1859 """, 

-

1860 } 

-

1861 

-

1862 makeFiles(d) 

-

1863 self.cog.callableMain(['argv0', '-r', '-D', 'fooey=kablooey', 'test.cog']) 

-

1864 self.assertFilesSame('test.cog', 'test.kablooey') 

-

1865 makeFiles(d) 

-

1866 self.cog.callableMain(['argv0', '-r', '-Dfooey=kablooey', 'test.cog']) 

-

1867 self.assertFilesSame('test.cog', 'test.kablooey') 

-

1868 makeFiles(d) 

-

1869 self.cog.callableMain(['argv0', '-r', '-Dfooey=e=mc2', 'test.cog']) 

-

1870 self.assertFilesSame('test.cog', 'test.einstein') 

-

1871 makeFiles(d) 

-

1872 self.cog.callableMain(['argv0', '-r', '-Dbar=quux', '-Dfooey=kablooey', 'test.cog']) 

-

1873 self.assertFilesSame('test.cog', 'test.kablooey') 

-

1874 makeFiles(d) 

-

1875 self.cog.callableMain(['argv0', '-r', '-Dfooey=kablooey', '-Dbar=quux', 'test.cog']) 

-

1876 self.assertFilesSame('test.cog', 'test.kablooey') 

-

1877 makeFiles(d) 

-

1878 self.cog.callableMain(['argv0', '-r', '-Dfooey=gooey', '-Dfooey=kablooey', 'test.cog']) 

-

1879 self.assertFilesSame('test.cog', 'test.kablooey') 

-

1880 

-

1881 def testOutputToStdout(self): 

-

1882 d = { 

-

1883 'test.cog': """\ 

-

1884 --[[[cog cog.outl('Hey there!') ]]] 

-

1885 --[[[end]]] 

-

1886 """ 

-

1887 } 

-

1888 

-

1889 makeFiles(d) 

-

1890 stderr = StringIO() 

-

1891 self.cog.setOutput(stderr=stderr) 

-

1892 self.cog.callableMain(['argv0', 'test.cog']) 

-

1893 output = self.output.getvalue() 

-

1894 outerr = stderr.getvalue() 

-

1895 self.assertEqual(output, "--[[[cog cog.outl('Hey there!') ]]]\nHey there!\n--[[[end]]]\n") 

-

1896 self.assertEqual(outerr, "") 

-

1897 

-

1898 def testReadFromStdin(self): 

-

1899 stdin = StringIO("--[[[cog cog.outl('Wow') ]]]\n--[[[end]]]\n") 

-

1900 def restore_stdin(old_stdin): 

-

1901 sys.stdin = old_stdin 

-

1902 self.addCleanup(restore_stdin, sys.stdin) 

-

1903 sys.stdin = stdin 

-

1904 

-

1905 stderr = StringIO() 

-

1906 self.cog.setOutput(stderr=stderr) 

-

1907 self.cog.callableMain(['argv0', '-']) 

-

1908 output = self.output.getvalue() 

-

1909 outerr = stderr.getvalue() 

-

1910 self.assertEqual(output, "--[[[cog cog.outl('Wow') ]]]\nWow\n--[[[end]]]\n") 

-

1911 self.assertEqual(outerr, "") 

-

1912 

-

1913 def testSuffixOutputLines(self): 

-

1914 d = { 

-

1915 'test.cog': """\ 

-

1916 Hey there. 

-

1917 ;[[[cog cog.outl('a\\nb\\n \\nc') ]]] 

-

1918 ;[[[end]]] 

-

1919 Good bye. 

-

1920 """, 

-

1921 

-

1922 'test.out': """\ 

-

1923 Hey there. 

-

1924 ;[[[cog cog.outl('a\\nb\\n \\nc') ]]] 

-

1925 a (foo) 

-

1926 b (foo) 

-

1927 """ # These three trailing spaces are important. 

-

1928 # The suffix is not applied to completely blank lines. 

-

1929 """ 

-

1930 c (foo) 

-

1931 ;[[[end]]] 

-

1932 Good bye. 

-

1933 """, 

-

1934 } 

-

1935 

-

1936 makeFiles(d) 

-

1937 self.cog.callableMain(['argv0', '-r', '-s', ' (foo)', 'test.cog']) 

-

1938 self.assertFilesSame('test.cog', 'test.out') 

-

1939 

-

1940 def testEmptySuffix(self): 

-

1941 d = { 

-

1942 'test.cog': """\ 

-

1943 ;[[[cog cog.outl('a\\nb\\nc') ]]] 

-

1944 ;[[[end]]] 

-

1945 """, 

-

1946 

-

1947 'test.out': """\ 

-

1948 ;[[[cog cog.outl('a\\nb\\nc') ]]] 

-

1949 a 

-

1950 b 

-

1951 c 

-

1952 ;[[[end]]] 

-

1953 """, 

-

1954 } 

-

1955 

-

1956 makeFiles(d) 

-

1957 self.cog.callableMain(['argv0', '-r', '-s', '', 'test.cog']) 

-

1958 self.assertFilesSame('test.cog', 'test.out') 

-

1959 

-

1960 def testHellishSuffix(self): 

-

1961 d = { 

-

1962 'test.cog': """\ 

-

1963 ;[[[cog cog.outl('a\\n\\nb') ]]] 

-

1964 """, 

-

1965 

-

1966 'test.out': """\ 

-

1967 ;[[[cog cog.outl('a\\n\\nb') ]]] 

-

1968 a /\\n*+([)]>< 

-

1969 

-

1970 b /\\n*+([)]>< 

-

1971 """, 

-

1972 } 

-

1973 

-

1974 makeFiles(d) 

-

1975 self.cog.callableMain(['argv0', '-z', '-r', '-s', r' /\n*+([)]><', 'test.cog']) 

-

1976 self.assertFilesSame('test.cog', 'test.out') 

-

1977 

-

1978 def testPrologue(self): 

-

1979 d = { 

-

1980 'test.cog': """\ 

-

1981 Some text. 

-

1982 //[[[cog cog.outl(str(math.sqrt(2))[:12])]]] 

-

1983 //[[[end]]] 

-

1984 epilogue. 

-

1985 """, 

-

1986 

-

1987 'test.out': """\ 

-

1988 Some text. 

-

1989 //[[[cog cog.outl(str(math.sqrt(2))[:12])]]] 

-

1990 1.4142135623 

-

1991 //[[[end]]] 

-

1992 epilogue. 

-

1993 """, 

-

1994 } 

-

1995 

-

1996 makeFiles(d) 

-

1997 self.cog.callableMain(['argv0', '-r', '-p', 'import math', 'test.cog']) 

-

1998 self.assertFilesSame('test.cog', 'test.out') 

-

1999 

-

2000 def testThreads(self): 

-

2001 # Test that the implicitly imported cog module is actually different for 

-

2002 # different threads. 

-

2003 numthreads = 20 

-

2004 

-

2005 d = {} 

-

2006 for i in range(numthreads): 

-

2007 d['f{}.cog'.format(i)] = ( 

-

2008 "x\n" * i + 

-

2009 "[[[cog\n" + 

-

2010 "assert cog.firstLineNum == int(FIRST) == {}\n".format(i+1) + 

-

2011 "]]]\n" + 

-

2012 "[[[end]]]\n" 

-

2013 ) 

-

2014 makeFiles(d) 

-

2015 

-

2016 results = [] 

-

2017 

-

2018 def thread_main(num): 

-

2019 try: 

-

2020 ret = Cog().main( 

-

2021 ['cog.py', '-r', '-D', 'FIRST={}'.format(num+1), 'f{}.cog'.format(num)] 

-

2022 ) 

-

2023 assert ret == 0 

-

2024 except Exception as exc: # pragma: no cover (only happens on test failure) 

-

2025 results.append(exc) 

-

2026 else: 

-

2027 results.append(None) 

-

2028 

-

2029 ts = [threading.Thread(target=thread_main, args=(i,)) for i in range(numthreads)] 

-

2030 for t in ts: 

-

2031 t.start() 

-

2032 for t in ts: 

-

2033 t.join() 

-

2034 assert results == [None] * numthreads 

-

2035 

-

2036 

-

2037class WritabilityTests(TestCaseWithTempDir): 

-

2038 

-

2039 d = { 

-

2040 'test.cog': """\ 

-

2041 //[[[cog 

-

2042 for fn in ['DoSomething', 'DoAnotherThing', 'DoLastThing']: 

-

2043 cog.outl("void %s();" % fn) 

-

2044 //]]] 

-

2045 //[[[end]]] 

-

2046 """, 

-

2047 

-

2048 'test.out': """\ 

-

2049 //[[[cog 

-

2050 for fn in ['DoSomething', 'DoAnotherThing', 'DoLastThing']: 

-

2051 cog.outl("void %s();" % fn) 

-

2052 //]]] 

-

2053 void DoSomething(); 

-

2054 void DoAnotherThing(); 

-

2055 void DoLastThing(); 

-

2056 //[[[end]]] 

-

2057 """, 

-

2058 } 

-

2059 

-

2060 if os.name == 'nt': #pragma: no cover 

-

2061 # for Windows 

-

2062 cmd_w_args = 'attrib -R %s' 

-

2063 cmd_w_asterisk = 'attrib -R *' 

-

2064 else: #pragma: no cover 

-

2065 # for unix-like 

-

2066 cmd_w_args = 'chmod +w %s' 

-

2067 cmd_w_asterisk = 'chmod +w *' 

-

2068 

-

2069 def setUp(self): 

-

2070 super(WritabilityTests, self).setUp() 

-

2071 makeFiles(self.d) 

-

2072 self.testcog = os.path.join(self.tempdir, 'test.cog') 

-

2073 os.chmod(self.testcog, stat.S_IREAD) # Make the file readonly. 

-

2074 assert not os.access(self.testcog, os.W_OK) 

-

2075 

-

2076 def tearDown(self): 

-

2077 os.chmod(self.testcog, stat.S_IWRITE) # Make the file writable again. 

-

2078 super(WritabilityTests, self).tearDown() 

-

2079 

-

2080 def testReadonlyNoCommand(self): 

-

2081 with self.assertRaisesRegex(CogError, "^Can't overwrite test.cog$"): 

-

2082 self.cog.callableMain(['argv0', '-r', 'test.cog']) 

-

2083 assert not os.access(self.testcog, os.W_OK) 

-

2084 

-

2085 def testReadonlyWithCommand(self): 

-

2086 self.cog.callableMain(['argv0', '-r', '-w', self.cmd_w_args, 'test.cog']) 

-

2087 self.assertFilesSame('test.cog', 'test.out') 

-

2088 assert os.access(self.testcog, os.W_OK) 

-

2089 

-

2090 def testReadonlyWithCommandWithNoSlot(self): 

-

2091 self.cog.callableMain(['argv0', '-r', '-w', self.cmd_w_asterisk, 'test.cog']) 

-

2092 self.assertFilesSame('test.cog', 'test.out') 

-

2093 assert os.access(self.testcog, os.W_OK) 

-

2094 

-

2095 def testReadonlyWithIneffectualCommand(self): 

-

2096 with self.assertRaisesRegex(CogError, "^Couldn't make test.cog writable$"): 

-

2097 self.cog.callableMain(['argv0', '-r', '-w', 'echo %s', 'test.cog']) 

-

2098 assert not os.access(self.testcog, os.W_OK) 

-

2099 

-

2100 

-

2101class ChecksumTests(TestCaseWithTempDir): 

-

2102 

-

2103 def testCreateChecksumOutput(self): 

-

2104 d = { 

-

2105 'cog1.txt': """\ 

-

2106 //[[[cog 

-

2107 cog.outl("This line was generated.") 

-

2108 //]]] 

-

2109 This line was generated. 

-

2110 //[[[end]]] 

-

2111 This line was not. 

-

2112 """, 

-

2113 

-

2114 'cog1.out': """\ 

-

2115 //[[[cog 

-

2116 cog.outl("This line was generated.") 

-

2117 //]]] 

-

2118 This line was generated. 

-

2119 //[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893) 

-

2120 This line was not. 

-

2121 """, 

-

2122 } 

-

2123 

-

2124 makeFiles(d) 

-

2125 self.cog.callableMain(['argv0', '-r', '-c', 'cog1.txt']) 

-

2126 self.assertFilesSame('cog1.txt', 'cog1.out') 

-

2127 

-

2128 def testCheckChecksumOutput(self): 

-

2129 d = { 

-

2130 'cog1.txt': """\ 

-

2131 //[[[cog 

-

2132 cog.outl("This line was newly") 

-

2133 cog.outl("generated by cog") 

-

2134 cog.outl("blah blah.") 

-

2135 //]]] 

-

2136 This line was generated. 

-

2137 //[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893) 

-

2138 """, 

-

2139 

-

2140 'cog1.out': """\ 

-

2141 //[[[cog 

-

2142 cog.outl("This line was newly") 

-

2143 cog.outl("generated by cog") 

-

2144 cog.outl("blah blah.") 

-

2145 //]]] 

-

2146 This line was newly 

-

2147 generated by cog 

-

2148 blah blah. 

-

2149 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2150 """, 

-

2151 } 

-

2152 

-

2153 makeFiles(d) 

-

2154 self.cog.callableMain(['argv0', '-r', '-c', 'cog1.txt']) 

-

2155 self.assertFilesSame('cog1.txt', 'cog1.out') 

-

2156 

-

2157 def testRemoveChecksumOutput(self): 

-

2158 d = { 

-

2159 'cog1.txt': """\ 

-

2160 //[[[cog 

-

2161 cog.outl("This line was newly") 

-

2162 cog.outl("generated by cog") 

-

2163 cog.outl("blah blah.") 

-

2164 //]]] 

-

2165 This line was generated. 

-

2166 //[[[end]]] (checksum: 8adb13fb59b996a1c7f0065ea9f3d893) fooey 

-

2167 """, 

-

2168 

-

2169 'cog1.out': """\ 

-

2170 //[[[cog 

-

2171 cog.outl("This line was newly") 

-

2172 cog.outl("generated by cog") 

-

2173 cog.outl("blah blah.") 

-

2174 //]]] 

-

2175 This line was newly 

-

2176 generated by cog 

-

2177 blah blah. 

-

2178 //[[[end]]] fooey 

-

2179 """, 

-

2180 } 

-

2181 

-

2182 makeFiles(d) 

-

2183 self.cog.callableMain(['argv0', '-r', 'cog1.txt']) 

-

2184 self.assertFilesSame('cog1.txt', 'cog1.out') 

-

2185 

-

2186 def testTamperedChecksumOutput(self): 

-

2187 d = { 

-

2188 'cog1.txt': """\ 

-

2189 //[[[cog 

-

2190 cog.outl("This line was newly") 

-

2191 cog.outl("generated by cog") 

-

2192 cog.outl("blah blah.") 

-

2193 //]]] 

-

2194 Xhis line was newly 

-

2195 generated by cog 

-

2196 blah blah. 

-

2197 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2198 """, 

-

2199 

-

2200 'cog2.txt': """\ 

-

2201 //[[[cog 

-

2202 cog.outl("This line was newly") 

-

2203 cog.outl("generated by cog") 

-

2204 cog.outl("blah blah.") 

-

2205 //]]] 

-

2206 This line was newly 

-

2207 generated by cog 

-

2208 blah blah! 

-

2209 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2210 """, 

-

2211 

-

2212 'cog3.txt': """\ 

-

2213 //[[[cog 

-

2214 cog.outl("This line was newly") 

-

2215 cog.outl("generated by cog") 

-

2216 cog.outl("blah blah.") 

-

2217 //]]] 

-

2218 

-

2219 This line was newly 

-

2220 generated by cog 

-

2221 blah blah. 

-

2222 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2223 """, 

-

2224 

-

2225 'cog4.txt': """\ 

-

2226 //[[[cog 

-

2227 cog.outl("This line was newly") 

-

2228 cog.outl("generated by cog") 

-

2229 cog.outl("blah blah.") 

-

2230 //]]] 

-

2231 This line was newly 

-

2232 generated by cog 

-

2233 blah blah.. 

-

2234 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2235 """, 

-

2236 

-

2237 'cog5.txt': """\ 

-

2238 //[[[cog 

-

2239 cog.outl("This line was newly") 

-

2240 cog.outl("generated by cog") 

-

2241 cog.outl("blah blah.") 

-

2242 //]]] 

-

2243 This line was newly 

-

2244 generated by cog 

-

2245 blah blah. 

-

2246 extra 

-

2247 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2248 """, 

-

2249 

-

2250 'cog6.txt': """\ 

-

2251 //[[[cog 

-

2252 cog.outl("This line was newly") 

-

2253 cog.outl("generated by cog") 

-

2254 cog.outl("blah blah.") 

-

2255 //]]] 

-

2256 //[[[end]]] (checksum: a8540982e5ad6b95c9e9a184b26f4346) 

-

2257 """, 

-

2258 } 

-

2259 

-

2260 makeFiles(d) 

-

2261 with self.assertRaisesRegex(CogError, 

-

2262 r"^cog1.txt\(9\): Output has been edited! Delete old checksum to unprotect.$"): 

-

2263 self.cog.callableMain(['argv0', '-c', "cog1.txt"]) 

-

2264 with self.assertRaisesRegex(CogError, 

-

2265 r"^cog2.txt\(9\): Output has been edited! Delete old checksum to unprotect.$"): 

-

2266 self.cog.callableMain(['argv0', '-c', "cog2.txt"]) 

-

2267 with self.assertRaisesRegex(CogError, 

-

2268 r"^cog3.txt\(10\): Output has been edited! Delete old checksum to unprotect.$"): 

-

2269 self.cog.callableMain(['argv0', '-c', "cog3.txt"]) 

-

2270 with self.assertRaisesRegex(CogError, 

-

2271 r"^cog4.txt\(9\): Output has been edited! Delete old checksum to unprotect.$"): 

-

2272 self.cog.callableMain(['argv0', '-c', "cog4.txt"]) 

-

2273 with self.assertRaisesRegex(CogError, 

-

2274 r"^cog5.txt\(10\): Output has been edited! Delete old checksum to unprotect.$"): 

-

2275 self.cog.callableMain(['argv0', '-c', "cog5.txt"]) 

-

2276 with self.assertRaisesRegex(CogError, 

-

2277 r"^cog6.txt\(6\): Output has been edited! Delete old checksum to unprotect.$"): 

-

2278 self.cog.callableMain(['argv0', '-c', "cog6.txt"]) 

-

2279 

-

2280 def testArgvIsntModified(self): 

-

2281 argv = ['argv0', '-v'] 

-

2282 orig_argv = argv[:] 

-

2283 self.cog.callableMain(argv) 

-

2284 self.assertEqual(argv, orig_argv) 

-

2285 

-

2286 

-

2287class CustomMarkerTests(TestCaseWithTempDir): 

-

2288 

-

2289 def testCustomerMarkers(self): 

-

2290 d = { 

-

2291 'test.cog': """\ 

-

2292 //{{ 

-

2293 cog.outl("void %s();" % "MyFunction") 

-

2294 //}} 

-

2295 //{{end}} 

-

2296 """, 

-

2297 

-

2298 'test.out': """\ 

-

2299 //{{ 

-

2300 cog.outl("void %s();" % "MyFunction") 

-

2301 //}} 

-

2302 void MyFunction(); 

-

2303 //{{end}} 

-

2304 """, 

-

2305 } 

-

2306 

-

2307 makeFiles(d) 

-

2308 self.cog.callableMain([ 

-

2309 'argv0', '-r', 

-

2310 '--markers={{ }} {{end}}', 

-

2311 'test.cog' 

-

2312 ]) 

-

2313 self.assertFilesSame('test.cog', 'test.out') 

-

2314 

-

2315 def testTrulyWackyMarkers(self): 

-

2316 # Make sure the markers are properly re-escaped. 

-

2317 d = { 

-

2318 'test.cog': """\ 

-

2319 //**( 

-

2320 cog.outl("void %s();" % "MyFunction") 

-

2321 //**) 

-

2322 //**(end)** 

-

2323 """, 

-

2324 

-

2325 'test.out': """\ 

-

2326 //**( 

-

2327 cog.outl("void %s();" % "MyFunction") 

-

2328 //**) 

-

2329 void MyFunction(); 

-

2330 //**(end)** 

-

2331 """, 

-

2332 } 

-

2333 

-

2334 makeFiles(d) 

-

2335 self.cog.callableMain([ 

-

2336 'argv0', '-r', 

-

2337 '--markers=**( **) **(end)**', 

-

2338 'test.cog' 

-

2339 ]) 

-

2340 self.assertFilesSame('test.cog', 'test.out') 

-

2341 

-

2342 def testChangeJustOneMarker(self): 

-

2343 d = { 

-

2344 'test.cog': """\ 

-

2345 //**( 

-

2346 cog.outl("void %s();" % "MyFunction") 

-

2347 //]]] 

-

2348 //[[[end]]] 

-

2349 """, 

-

2350 

-

2351 'test.out': """\ 

-

2352 //**( 

-

2353 cog.outl("void %s();" % "MyFunction") 

-

2354 //]]] 

-

2355 void MyFunction(); 

-

2356 //[[[end]]] 

-

2357 """, 

-

2358 } 

-

2359 

-

2360 makeFiles(d) 

-

2361 self.cog.callableMain([ 

-

2362 'argv0', '-r', 

-

2363 '--markers=**( ]]] [[[end]]]', 

-

2364 'test.cog' 

-

2365 ]) 

-

2366 self.assertFilesSame('test.cog', 'test.out') 

-

2367 

-

2368 

-

2369class BlakeTests(TestCaseWithTempDir): 

-

2370 

-

2371 # Blake Winton's contributions. 

-

2372 def testDeleteCode(self): 

-

2373 # -o sets the output file. 

-

2374 d = { 

-

2375 'test.cog': """\ 

-

2376 // This is my C++ file. 

-

2377 //[[[cog 

-

2378 fnames = ['DoSomething', 'DoAnotherThing', 'DoLastThing'] 

-

2379 for fn in fnames: 

-

2380 cog.outl("void %s();" % fn) 

-

2381 //]]] 

-

2382 Some Sample Code Here 

-

2383 //[[[end]]]Data Data 

-

2384 And Some More 

-

2385 """, 

-

2386 

-

2387 'test.out': """\ 

-

2388 // This is my C++ file. 

-

2389 void DoSomething(); 

-

2390 void DoAnotherThing(); 

-

2391 void DoLastThing(); 

-

2392 And Some More 

-

2393 """, 

-

2394 } 

-

2395 

-

2396 makeFiles(d) 

-

2397 self.cog.callableMain(['argv0', '-d', '-o', 'test.cogged', 'test.cog']) 

-

2398 self.assertFilesSame('test.cogged', 'test.out') 

-

2399 

-

2400 def testDeleteCodeWithDashRFails(self): 

-

2401 d = { 

-

2402 'test.cog': """\ 

-

2403 // This is my C++ file. 

-

2404 """ 

-

2405 } 

-

2406 

-

2407 makeFiles(d) 

-

2408 with self.assertRaisesRegex(CogUsageError, r"^Can't use -d with -r \(or you would delete all your source!\)$"): 

-

2409 self.cog.callableMain(['argv0', '-r', '-d', 'test.cog']) 

-

2410 

-

2411 def testSettingGlobals(self): 

-

2412 # Blake Winton contributed a way to set the globals that will be used in 

-

2413 # processFile(). 

-

2414 d = { 

-

2415 'test.cog': """\ 

-

2416 // This is my C++ file. 

-

2417 //[[[cog 

-

2418 for fn in fnames: 

-

2419 cog.outl("void %s();" % fn) 

-

2420 //]]] 

-

2421 Some Sample Code Here 

-

2422 //[[[end]]]""", 

-

2423 

-

2424 'test.out': """\ 

-

2425 // This is my C++ file. 

-

2426 void DoBlake(); 

-

2427 void DoWinton(); 

-

2428 void DoContribution(); 

-

2429 """, 

-

2430 } 

-

2431 

-

2432 makeFiles(d) 

-

2433 globals = {} 

-

2434 globals['fnames'] = ['DoBlake', 'DoWinton', 'DoContribution'] 

-

2435 self.cog.options.bDeleteCode = True 

-

2436 self.cog.processFile('test.cog', 'test.cogged', globals=globals) 

-

2437 self.assertFilesSame('test.cogged', 'test.out') 

-

2438 

-

2439 

-

2440class ErrorCallTests(TestCaseWithTempDir): 

-

2441 

-

2442 def testErrorCallHasNoTraceback(self): 

-

2443 # Test that cog.error() doesn't show a traceback. 

-

2444 d = { 

-

2445 'error.cog': """\ 

-

2446 //[[[cog 

-

2447 cog.error("Something Bad!") 

-

2448 //]]] 

-

2449 //[[[end]]] 

-

2450 """, 

-

2451 } 

-

2452 

-

2453 makeFiles(d) 

-

2454 self.cog.main(['argv0', '-r', 'error.cog']) 

-

2455 output = self.output.getvalue() 

-

2456 self.assertEqual(output, "Cogging error.cog\nError: Something Bad!\n") 

-

2457 

-

2458 def testRealErrorHasTraceback(self): 

-

2459 # Test that a genuine error does show a traceback. 

-

2460 d = { 

-

2461 'error.cog': """\ 

-

2462 //[[[cog 

-

2463 raise RuntimeError("Hey!") 

-

2464 //]]] 

-

2465 //[[[end]]] 

-

2466 """, 

-

2467 } 

-

2468 

-

2469 makeFiles(d) 

-

2470 self.cog.main(['argv0', '-r', 'error.cog']) 

-

2471 output = self.output.getvalue() 

-

2472 msg = 'Actual output:\n' + output 

-

2473 self.assertTrue(output.startswith("Cogging error.cog\nTraceback (most recent"), msg) 

-

2474 self.assertIn("RuntimeError: Hey!", output) 

-

2475 

-

2476 

-

2477# Things not yet tested: 

-

2478# - A bad -w command (currently fails silently). 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_test_makefiles_py.html b/doc/sample_html/d_7b071bdc2a35fa80_test_makefiles_py.html index 3d9602b6..da37bdf0 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_test_makefiles_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_test_makefiles_py.html @@ -6,183 +6,188 @@ Coverage for cogapp/test_makefiles.py: 23.38% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1""" Test the cogapp.makefiles modules 

-

2 http://nedbatchelder.com/code/cog 

-

3 

-

4 Copyright 2004-2019, Ned Batchelder. 

-

5""" 

-

6 

-

7from __future__ import absolute_import 

-

8 

-

9import shutil 

-

10import os 

-

11import random 

-

12import tempfile 

-

13 

-

14from . import makefiles 

-

15from .backward import TestCase 

-

16 

-

17 

-

18class SimpleTests(TestCase): 

-

19 

-

20 def setUp(self): 

-

21 # Create a temporary directory. 

-

22 my_dir = 'testmakefiles_tempdir_' + str(random.random())[2:] 

-

23 self.tempdir = os.path.join(tempfile.gettempdir(), my_dir) 

-

24 os.mkdir(self.tempdir) 

-

25 

-

26 def tearDown(self): 

-

27 # Get rid of the temporary directory. 

-

28 shutil.rmtree(self.tempdir) 

-

29 

-

30 def exists(self, dname, fname): 

-

31 return os.path.exists(os.path.join(dname, fname)) 

-

32 

-

33 def checkFilesExist(self, d, dname): 

-

34 for fname in d.keys(): 

-

35 assert(self.exists(dname, fname)) 

-

36 if type(d[fname]) == type({}): 

-

37 self.checkFilesExist(d[fname], os.path.join(dname, fname)) 

-

38 

-

39 def checkFilesDontExist(self, d, dname): 

-

40 for fname in d.keys(): 

-

41 assert(not self.exists(dname, fname)) 

-

42 

-

43 def testOneFile(self): 

-

44 fname = 'foo.txt' 

-

45 notfname = 'not_here.txt' 

-

46 d = { fname: "howdy" } 

-

47 assert(not self.exists(self.tempdir, fname)) 

-

48 assert(not self.exists(self.tempdir, notfname)) 

-

49 

-

50 makefiles.makeFiles(d, self.tempdir) 

-

51 assert(self.exists(self.tempdir, fname)) 

-

52 assert(not self.exists(self.tempdir, notfname)) 

-

53 

-

54 makefiles.removeFiles(d, self.tempdir) 

-

55 assert(not self.exists(self.tempdir, fname)) 

-

56 assert(not self.exists(self.tempdir, notfname)) 

-

57 

-

58 def testManyFiles(self): 

-

59 d = { 

-

60 'top1.txt': "howdy", 

-

61 'top2.txt': "hello", 

-

62 'sub': { 

-

63 'sub1.txt': "inside", 

-

64 'sub2.txt': "inside2", 

-

65 }, 

-

66 } 

-

67 

-

68 self.checkFilesDontExist(d, self.tempdir) 

-

69 makefiles.makeFiles(d, self.tempdir) 

-

70 self.checkFilesExist(d, self.tempdir) 

-

71 makefiles.removeFiles(d, self.tempdir) 

-

72 self.checkFilesDontExist(d, self.tempdir) 

-

73 

-

74 def testOverlapping(self): 

-

75 d1 = { 

-

76 'top1.txt': "howdy", 

-

77 'sub': { 

-

78 'sub1.txt': "inside", 

-

79 }, 

-

80 } 

-

81 

-

82 d2 = { 

-

83 'top2.txt': "hello", 

-

84 'sub': { 

-

85 'sub2.txt': "inside2", 

-

86 }, 

-

87 } 

-

88 

-

89 self.checkFilesDontExist(d1, self.tempdir) 

-

90 self.checkFilesDontExist(d2, self.tempdir) 

-

91 makefiles.makeFiles(d1, self.tempdir) 

-

92 makefiles.makeFiles(d2, self.tempdir) 

-

93 self.checkFilesExist(d1, self.tempdir) 

-

94 self.checkFilesExist(d2, self.tempdir) 

-

95 makefiles.removeFiles(d1, self.tempdir) 

-

96 makefiles.removeFiles(d2, self.tempdir) 

-

97 self.checkFilesDontExist(d1, self.tempdir) 

-

98 self.checkFilesDontExist(d2, self.tempdir) 

-

99 

-

100 def testContents(self): 

-

101 fname = 'bar.txt' 

-

102 cont0 = "I am bar.txt" 

-

103 d = { fname: cont0 } 

-

104 makefiles.makeFiles(d, self.tempdir) 

-

105 fcont1 = open(os.path.join(self.tempdir, fname)) 

-

106 assert(fcont1.read() == cont0) 

-

107 fcont1.close() 

-

108 

-

109 def testDedent(self): 

-

110 fname = 'dedent.txt' 

-

111 d = { 

-

112 fname: """\ 

-

113 This is dedent.txt 

-

114 \tTabbed in. 

-

115 spaced in. 

-

116 OK. 

-

117 """, 

-

118 } 

-

119 makefiles.makeFiles(d, self.tempdir) 

-

120 fcont = open(os.path.join(self.tempdir, fname)) 

-

121 assert(fcont.read() == "This is dedent.txt\n\tTabbed in.\n spaced in.\nOK.\n") 

-

122 fcont.close() 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_test_whiteutils_py.html b/doc/sample_html/d_7b071bdc2a35fa80_test_whiteutils_py.html index c311ee37..6d8e91f1 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_test_whiteutils_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_test_whiteutils_py.html @@ -6,162 +6,167 @@ Coverage for cogapp/test_whiteutils.py: 27.54% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1""" Test the cogapp.whiteutils module. 

-

2 http://nedbatchelder.com/code/cog 

-

3 

-

4 Copyright 2004-2019, Ned Batchelder. 

-

5""" 

-

6 

-

7from __future__ import absolute_import 

-

8 

-

9from .backward import TestCase 

-

10from .whiteutils import * 

-

11 

-

12 

-

13class WhitePrefixTests(TestCase): 

-

14 """ Test cases for cogapp.whiteutils. 

-

15 """ 

-

16 def testSingleLine(self): 

-

17 self.assertEqual(whitePrefix(['']), '') 

-

18 self.assertEqual(whitePrefix([' ']), '') 

-

19 self.assertEqual(whitePrefix(['x']), '') 

-

20 self.assertEqual(whitePrefix([' x']), ' ') 

-

21 self.assertEqual(whitePrefix(['\tx']), '\t') 

-

22 self.assertEqual(whitePrefix([' x']), ' ') 

-

23 self.assertEqual(whitePrefix([' \t \tx ']), ' \t \t') 

-

24 

-

25 def testMultiLine(self): 

-

26 self.assertEqual(whitePrefix([' x',' x',' x']), ' ') 

-

27 self.assertEqual(whitePrefix([' y',' y',' y']), ' ') 

-

28 self.assertEqual(whitePrefix([' y',' y',' y']), ' ') 

-

29 

-

30 def testBlankLinesAreIgnored(self): 

-

31 self.assertEqual(whitePrefix([' x',' x','',' x']), ' ') 

-

32 self.assertEqual(whitePrefix(['',' x',' x',' x']), ' ') 

-

33 self.assertEqual(whitePrefix([' x',' x',' x','']), ' ') 

-

34 self.assertEqual(whitePrefix([' x',' x',' ',' x']), ' ') 

-

35 

-

36 def testTabCharacters(self): 

-

37 self.assertEqual(whitePrefix(['\timport sys', '', '\tprint sys.argv']), '\t') 

-

38 

-

39 def testDecreasingLengths(self): 

-

40 self.assertEqual(whitePrefix([' x',' x',' x']), ' ') 

-

41 self.assertEqual(whitePrefix([' x',' x',' x']), ' ') 

-

42 

-

43 

-

44class ReindentBlockTests(TestCase): 

-

45 """ Test cases for cogapp.reindentBlock. 

-

46 """ 

-

47 def testNonTermLine(self): 

-

48 self.assertEqual(reindentBlock(''), '') 

-

49 self.assertEqual(reindentBlock('x'), 'x') 

-

50 self.assertEqual(reindentBlock(' x'), 'x') 

-

51 self.assertEqual(reindentBlock(' x'), 'x') 

-

52 self.assertEqual(reindentBlock('\tx'), 'x') 

-

53 self.assertEqual(reindentBlock('x', ' '), ' x') 

-

54 self.assertEqual(reindentBlock('x', '\t'), '\tx') 

-

55 self.assertEqual(reindentBlock(' x', ' '), ' x') 

-

56 self.assertEqual(reindentBlock(' x', '\t'), '\tx') 

-

57 self.assertEqual(reindentBlock(' x', ' '), ' x') 

-

58 

-

59 def testSingleLine(self): 

-

60 self.assertEqual(reindentBlock('\n'), '\n') 

-

61 self.assertEqual(reindentBlock('x\n'), 'x\n') 

-

62 self.assertEqual(reindentBlock(' x\n'), 'x\n') 

-

63 self.assertEqual(reindentBlock(' x\n'), 'x\n') 

-

64 self.assertEqual(reindentBlock('\tx\n'), 'x\n') 

-

65 self.assertEqual(reindentBlock('x\n', ' '), ' x\n') 

-

66 self.assertEqual(reindentBlock('x\n', '\t'), '\tx\n') 

-

67 self.assertEqual(reindentBlock(' x\n', ' '), ' x\n') 

-

68 self.assertEqual(reindentBlock(' x\n', '\t'), '\tx\n') 

-

69 self.assertEqual(reindentBlock(' x\n', ' '), ' x\n') 

-

70 

-

71 def testRealBlock(self): 

-

72 self.assertEqual( 

-

73 reindentBlock('\timport sys\n\n\tprint sys.argv\n'), 

-

74 'import sys\n\nprint sys.argv\n' 

-

75 ) 

-

76 

-

77 

-

78class CommonPrefixTests(TestCase): 

-

79 """ Test cases for cogapp.commonPrefix. 

-

80 """ 

-

81 def testDegenerateCases(self): 

-

82 self.assertEqual(commonPrefix([]), '') 

-

83 self.assertEqual(commonPrefix(['']), '') 

-

84 self.assertEqual(commonPrefix(['','','','','']), '') 

-

85 self.assertEqual(commonPrefix(['cat in the hat']), 'cat in the hat') 

-

86 

-

87 def testNoCommonPrefix(self): 

-

88 self.assertEqual(commonPrefix(['a','b']), '') 

-

89 self.assertEqual(commonPrefix(['a','b','c','d','e','f']), '') 

-

90 self.assertEqual(commonPrefix(['a','a','a','a','a','x']), '') 

-

91 

-

92 def testUsualCases(self): 

-

93 self.assertEqual(commonPrefix(['ab', 'ac']), 'a') 

-

94 self.assertEqual(commonPrefix(['aab', 'aac']), 'aa') 

-

95 self.assertEqual(commonPrefix(['aab', 'aab', 'aab', 'aac']), 'aa') 

-

96 

-

97 def testBlankLine(self): 

-

98 self.assertEqual(commonPrefix(['abc', 'abx', '', 'aby']), '') 

-

99 

-

100 def testDecreasingLengths(self): 

-

101 self.assertEqual(commonPrefix(['abcd', 'abc', 'ab']), 'ab') 

-
- + diff --git a/doc/sample_html/d_7b071bdc2a35fa80_whiteutils_py.html b/doc/sample_html/d_7b071bdc2a35fa80_whiteutils_py.html index 8be3ebd6..6c784697 100644 --- a/doc/sample_html/d_7b071bdc2a35fa80_whiteutils_py.html +++ b/doc/sample_html/d_7b071bdc2a35fa80_whiteutils_py.html @@ -6,134 +6,139 @@ Coverage for cogapp/whiteutils.py: 88.61% - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- r - m - x - p   toggle line displays -

-

- j - k   next/prev highlighted chunk -

-

- 0   (zero) top of page -

-

- 1   (one) first highlighted chunk -

-
-
-
-

1""" Indentation utilities for Cog. 

-

2 http://nedbatchelder.com/code/cog 

-

3 

-

4 Copyright 2004-2019, Ned Batchelder. 

-

5""" 

-

6 

-

7from __future__ import absolute_import 

-

8 

-

9import re 

-

10 

-

11from .backward import string_types, bytes_types, to_bytes 

-

12 

-

13def whitePrefix(strings): 

-

14 """ Determine the whitespace prefix common to all non-blank lines 

-

15 in the argument list. 

-

16 """ 

-

17 # Remove all blank lines from the list 

-

18 strings = [s for s in strings if s.strip() != ''] 

-

19 

-

20 if not strings: return '' 

-

21 

-

22 # Find initial whitespace chunk in the first line. 

-

23 # This is the best prefix we can hope for. 

-

24 pat = r'\s*' 

-

25 if isinstance(strings[0], bytes_types): 25 ↛ 26line 25 didn't jump to line 26, because the condition on line 25 was never true

-

26 pat = to_bytes(pat) 

-

27 prefix = re.match(pat, strings[0]).group(0) 

-

28 

-

29 # Loop over the other strings, keeping only as much of 

-

30 # the prefix as matches each string. 

-

31 for s in strings: 

-

32 for i in range(len(prefix)): 

-

33 if prefix[i] != s[i]: 33 ↛ 34line 33 didn't jump to line 34, because the condition on line 33 was never true

-

34 prefix = prefix[:i] 

-

35 break 

-

36 return prefix 

-

37 

-

38def reindentBlock(lines, newIndent=''): 

-

39 """ Take a block of text as a string or list of lines. 

-

40 Remove any common whitespace indentation. 

-

41 Re-indent using newIndent, and return it as a single string. 

-

42 """ 

-

43 sep, nothing = '\n', '' 

-

44 if isinstance(lines, bytes_types): 44 ↛ 45line 44 didn't jump to line 45, because the condition on line 44 was never true

-

45 sep, nothing = b'\n', b'' 

-

46 if isinstance(lines, string_types): 

-

47 lines = lines.split(sep) 

-

48 oldIndent = whitePrefix(lines) 

-

49 outLines = [] 

-

50 for l in lines: 

-

51 if oldIndent: 

-

52 l = l.replace(oldIndent, nothing, 1) 

-

53 if l and newIndent: 

-

54 l = newIndent + l 

-

55 outLines.append(l) 

-

56 return sep.join(outLines) 

-

57 

-

58def commonPrefix(strings): 

-

59 """ Find the longest string that is a prefix of all the strings. 

-

60 """ 

-

61 if not strings: 61 ↛ 62line 61 didn't jump to line 62, because the condition on line 61 was never true

-

62 return '' 

-

63 prefix = strings[0] 

-

64 for s in strings: 

-

65 if len(s) < len(prefix): 

-

66 prefix = prefix[:len(s)] 

-

67 if not prefix: 

-

68 return '' 

-

69 for i in range(len(prefix)): 

-

70 if prefix[i] != s[i]: 

-

71 prefix = prefix[:i] 

-

72 break 

-

73 return prefix 

-
- + diff --git a/doc/sample_html/index.html b/doc/sample_html/index.html index 7a7a63f1..a43f85e3 100644 --- a/doc/sample_html/index.html +++ b/doc/sample_html/index.html @@ -5,66 +5,52 @@ Coverage report - - - - - - + - -
- Hide keyboard shortcuts -

Hot-keys on this page

-
-

- n - s - m - x - b - p - c   change column sorting -

-
-
-
- + +
+
- - - - - - - + + + + + + + - - - - - - - - - - - @@ -148,18 +134,29 @@ + + + + + + + + + + +
ModulestatementsmissingexcludedbranchespartialcoverageModulestatementsmissingexcludedbranchespartialcoverage
Total151389992783439.98%
cogapp/__init__.py88.61%
Total151389992783439.98%

No items found using the specified filter.

-
- + diff --git a/doc/sample_html/jquery.ba-throttle-debounce.min.js b/doc/sample_html/jquery.ba-throttle-debounce.min.js deleted file mode 100644 index 648fe5d3..00000000 --- a/doc/sample_html/jquery.ba-throttle-debounce.min.js +++ /dev/null @@ -1,9 +0,0 @@ -/* - * jQuery throttle / debounce - v1.1 - 3/7/2010 - * http://benalman.com/projects/jquery-throttle-debounce-plugin/ - * - * Copyright (c) 2010 "Cowboy" Ben Alman - * Dual licensed under the MIT and GPL licenses. - * http://benalman.com/about/license/ - */ -(function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this); diff --git a/doc/sample_html/jquery.hotkeys.js b/doc/sample_html/jquery.hotkeys.js deleted file mode 100644 index 09b21e03..00000000 --- a/doc/sample_html/jquery.hotkeys.js +++ /dev/null @@ -1,99 +0,0 @@ -/* - * jQuery Hotkeys Plugin - * Copyright 2010, John Resig - * Dual licensed under the MIT or GPL Version 2 licenses. - * - * Based upon the plugin by Tzury Bar Yochay: - * http://github.com/tzuryby/hotkeys - * - * Original idea by: - * Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/ -*/ - -(function(jQuery){ - - jQuery.hotkeys = { - version: "0.8", - - specialKeys: { - 8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause", - 20: "capslock", 27: "esc", 32: "space", 33: "pageup", 34: "pagedown", 35: "end", 36: "home", - 37: "left", 38: "up", 39: "right", 40: "down", 45: "insert", 46: "del", - 96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7", - 104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/", - 112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8", - 120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta" - }, - - shiftNums: { - "`": "~", "1": "!", "2": "@", "3": "#", "4": "$", "5": "%", "6": "^", "7": "&", - "8": "*", "9": "(", "0": ")", "-": "_", "=": "+", ";": ": ", "'": "\"", ",": "<", - ".": ">", "/": "?", "\\": "|" - } - }; - - function keyHandler( handleObj ) { - // Only care when a possible input has been specified - if ( typeof handleObj.data !== "string" ) { - return; - } - - var origHandler = handleObj.handler, - keys = handleObj.data.toLowerCase().split(" "); - - handleObj.handler = function( event ) { - // Don't fire in text-accepting inputs that we didn't directly bind to - if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) || - event.target.type === "text") ) { - return; - } - - // Keypress represents characters, not special keys - var special = event.type !== "keypress" && jQuery.hotkeys.specialKeys[ event.which ], - character = String.fromCharCode( event.which ).toLowerCase(), - key, modif = "", possible = {}; - - // check combinations (alt|ctrl|shift+anything) - if ( event.altKey && special !== "alt" ) { - modif += "alt+"; - } - - if ( event.ctrlKey && special !== "ctrl" ) { - modif += "ctrl+"; - } - - // TODO: Need to make sure this works consistently across platforms - if ( event.metaKey && !event.ctrlKey && special !== "meta" ) { - modif += "meta+"; - } - - if ( event.shiftKey && special !== "shift" ) { - modif += "shift+"; - } - - if ( special ) { - possible[ modif + special ] = true; - - } else { - possible[ modif + character ] = true; - possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true; - - // "$" can be triggered as "Shift+4" or "Shift+$" or just "$" - if ( modif === "shift+" ) { - possible[ jQuery.hotkeys.shiftNums[ character ] ] = true; - } - } - - for ( var i = 0, l = keys.length; i < l; i++ ) { - if ( possible[ keys[i] ] ) { - return origHandler.apply( this, arguments ); - } - } - }; - } - - jQuery.each([ "keydown", "keyup", "keypress" ], function() { - jQuery.event.special[ this ] = { add: keyHandler }; - }); - -})( jQuery ); diff --git a/doc/sample_html/jquery.isonscreen.js b/doc/sample_html/jquery.isonscreen.js deleted file mode 100644 index 28fb99bc..00000000 --- a/doc/sample_html/jquery.isonscreen.js +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (c) 2010 - * @author Laurence Wheway - * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) - * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses. - * - * @version 1.2.0 - */ -(function($) { - jQuery.extend({ - isOnScreen: function(box, container) { - //ensure numbers come in as integers (not strings) and remove 'px' is it's there - for(var i in box){box[i] = parseFloat(box[i])}; - for(var i in container){container[i] = parseFloat(container[i])}; - - if(!container){ - container = { - left: $(window).scrollLeft(), - top: $(window).scrollTop(), - width: $(window).width(), - height: $(window).height() - } - } - - if( box.left+box.width-container.left > 0 && - box.left < container.width+container.left && - box.top+box.height-container.top > 0 && - box.top < container.height+container.top - ) return true; - return false; - } - }) - - - jQuery.fn.isOnScreen = function (container) { - for(var i in container){container[i] = parseFloat(container[i])}; - - if(!container){ - container = { - left: $(window).scrollLeft(), - top: $(window).scrollTop(), - width: $(window).width(), - height: $(window).height() - } - } - - if( $(this).offset().left+$(this).width()-container.left > 0 && - $(this).offset().left < container.width+container.left && - $(this).offset().top+$(this).height()-container.top > 0 && - $(this).offset().top < container.height+container.top - ) return true; - return false; - } -})(jQuery); diff --git a/doc/sample_html/jquery.min.js b/doc/sample_html/jquery.min.js deleted file mode 100644 index d1608e37..00000000 --- a/doc/sample_html/jquery.min.js +++ /dev/null @@ -1,4 +0,0 @@ -/*! jQuery v1.11.1 | (c) 2005, 2014 jQuery Foundation, Inc. | jquery.org/license */ -!function(a,b){"object"==typeof module&&"object"==typeof module.exports?module.exports=a.document?b(a,!0):function(a){if(!a.document)throw new Error("jQuery requires a window with a document");return b(a)}:b(a)}("undefined"!=typeof window?window:this,function(a,b){var c=[],d=c.slice,e=c.concat,f=c.push,g=c.indexOf,h={},i=h.toString,j=h.hasOwnProperty,k={},l="1.11.1",m=function(a,b){return new m.fn.init(a,b)},n=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,o=/^-ms-/,p=/-([\da-z])/gi,q=function(a,b){return b.toUpperCase()};m.fn=m.prototype={jquery:l,constructor:m,selector:"",length:0,toArray:function(){return d.call(this)},get:function(a){return null!=a?0>a?this[a+this.length]:this[a]:d.call(this)},pushStack:function(a){var b=m.merge(this.constructor(),a);return b.prevObject=this,b.context=this.context,b},each:function(a,b){return m.each(this,a,b)},map:function(a){return this.pushStack(m.map(this,function(b,c){return a.call(b,c,b)}))},slice:function(){return this.pushStack(d.apply(this,arguments))},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},eq:function(a){var b=this.length,c=+a+(0>a?b:0);return this.pushStack(c>=0&&b>c?[this[c]]:[])},end:function(){return this.prevObject||this.constructor(null)},push:f,sort:c.sort,splice:c.splice},m.extend=m.fn.extend=function(){var a,b,c,d,e,f,g=arguments[0]||{},h=1,i=arguments.length,j=!1;for("boolean"==typeof g&&(j=g,g=arguments[h]||{},h++),"object"==typeof g||m.isFunction(g)||(g={}),h===i&&(g=this,h--);i>h;h++)if(null!=(e=arguments[h]))for(d in e)a=g[d],c=e[d],g!==c&&(j&&c&&(m.isPlainObject(c)||(b=m.isArray(c)))?(b?(b=!1,f=a&&m.isArray(a)?a:[]):f=a&&m.isPlainObject(a)?a:{},g[d]=m.extend(j,f,c)):void 0!==c&&(g[d]=c));return g},m.extend({expando:"jQuery"+(l+Math.random()).replace(/\D/g,""),isReady:!0,error:function(a){throw new Error(a)},noop:function(){},isFunction:function(a){return"function"===m.type(a)},isArray:Array.isArray||function(a){return"array"===m.type(a)},isWindow:function(a){return null!=a&&a==a.window},isNumeric:function(a){return!m.isArray(a)&&a-parseFloat(a)>=0},isEmptyObject:function(a){var b;for(b in a)return!1;return!0},isPlainObject:function(a){var b;if(!a||"object"!==m.type(a)||a.nodeType||m.isWindow(a))return!1;try{if(a.constructor&&!j.call(a,"constructor")&&!j.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}if(k.ownLast)for(b in a)return j.call(a,b);for(b in a);return void 0===b||j.call(a,b)},type:function(a){return null==a?a+"":"object"==typeof a||"function"==typeof a?h[i.call(a)]||"object":typeof a},globalEval:function(b){b&&m.trim(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(o,"ms-").replace(p,q)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toLowerCase()===b.toLowerCase()},each:function(a,b,c){var d,e=0,f=a.length,g=r(a);if(c){if(g){for(;f>e;e++)if(d=b.apply(a[e],c),d===!1)break}else for(e in a)if(d=b.apply(a[e],c),d===!1)break}else if(g){for(;f>e;e++)if(d=b.call(a[e],e,a[e]),d===!1)break}else for(e in a)if(d=b.call(a[e],e,a[e]),d===!1)break;return a},trim:function(a){return null==a?"":(a+"").replace(n,"")},makeArray:function(a,b){var c=b||[];return null!=a&&(r(Object(a))?m.merge(c,"string"==typeof a?[a]:a):f.call(c,a)),c},inArray:function(a,b,c){var d;if(b){if(g)return g.call(b,a,c);for(d=b.length,c=c?0>c?Math.max(0,d+c):c:0;d>c;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,b){var c=+b.length,d=0,e=a.length;while(c>d)a[e++]=b[d++];if(c!==c)while(void 0!==b[d])a[e++]=b[d++];return a.length=e,a},grep:function(a,b,c){for(var d,e=[],f=0,g=a.length,h=!c;g>f;f++)d=!b(a[f],f),d!==h&&e.push(a[f]);return e},map:function(a,b,c){var d,f=0,g=a.length,h=r(a),i=[];if(h)for(;g>f;f++)d=b(a[f],f,c),null!=d&&i.push(d);else for(f in a)d=b(a[f],f,c),null!=d&&i.push(d);return e.apply([],i)},guid:1,proxy:function(a,b){var c,e,f;return"string"==typeof b&&(f=a[b],b=a,a=f),m.isFunction(a)?(c=d.call(arguments,2),e=function(){return a.apply(b||this,c.concat(d.call(arguments)))},e.guid=a.guid=a.guid||m.guid++,e):void 0},now:function(){return+new Date},support:k}),m.each("Boolean Number String Function Array Date RegExp Object Error".split(" "),function(a,b){h["[object "+b+"]"]=b.toLowerCase()});function r(a){var b=a.length,c=m.type(a);return"function"===c||m.isWindow(a)?!1:1===a.nodeType&&b?!0:"array"===c||0===b||"number"==typeof b&&b>0&&b-1 in a}var s=function(a){var b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u="sizzle"+-new Date,v=a.document,w=0,x=0,y=gb(),z=gb(),A=gb(),B=function(a,b){return a===b&&(l=!0),0},C="undefined",D=1<<31,E={}.hasOwnProperty,F=[],G=F.pop,H=F.push,I=F.push,J=F.slice,K=F.indexOf||function(a){for(var b=0,c=this.length;c>b;b++)if(this[b]===a)return b;return-1},L="checked|selected|async|autofocus|autoplay|controls|defer|disabled|hidden|ismap|loop|multiple|open|readonly|required|scoped",M="[\\x20\\t\\r\\n\\f]",N="(?:\\\\.|[\\w-]|[^\\x00-\\xa0])+",O=N.replace("w","w#"),P="\\["+M+"*("+N+")(?:"+M+"*([*^$|!~]?=)"+M+"*(?:'((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\"|("+O+"))|)"+M+"*\\]",Q=":("+N+")(?:\\((('((?:\\\\.|[^\\\\'])*)'|\"((?:\\\\.|[^\\\\\"])*)\")|((?:\\\\.|[^\\\\()[\\]]|"+P+")*)|.*)\\)|)",R=new RegExp("^"+M+"+|((?:^|[^\\\\])(?:\\\\.)*)"+M+"+$","g"),S=new RegExp("^"+M+"*,"+M+"*"),T=new RegExp("^"+M+"*([>+~]|"+M+")"+M+"*"),U=new RegExp("="+M+"*([^\\]'\"]*?)"+M+"*\\]","g"),V=new RegExp(Q),W=new RegExp("^"+O+"$"),X={ID:new RegExp("^#("+N+")"),CLASS:new RegExp("^\\.("+N+")"),TAG:new RegExp("^("+N.replace("w","w*")+")"),ATTR:new RegExp("^"+P),PSEUDO:new RegExp("^"+Q),CHILD:new RegExp("^:(only|first|last|nth|nth-last)-(child|of-type)(?:\\("+M+"*(even|odd|(([+-]|)(\\d*)n|)"+M+"*(?:([+-]|)"+M+"*(\\d+)|))"+M+"*\\)|)","i"),bool:new RegExp("^(?:"+L+")$","i"),needsContext:new RegExp("^"+M+"*[>+~]|:(even|odd|eq|gt|lt|nth|first|last)(?:\\("+M+"*((?:-\\d)?\\d*)"+M+"*\\)|)(?=[^-]|$)","i")},Y=/^(?:input|select|textarea|button)$/i,Z=/^h\d$/i,$=/^[^{]+\{\s*\[native \w/,_=/^(?:#([\w-]+)|(\w+)|\.([\w-]+))$/,ab=/[+~]/,bb=/'|\\/g,cb=new RegExp("\\\\([\\da-f]{1,6}"+M+"?|("+M+")|.)","ig"),db=function(a,b,c){var d="0x"+b-65536;return d!==d||c?b:0>d?String.fromCharCode(d+65536):String.fromCharCode(d>>10|55296,1023&d|56320)};try{I.apply(F=J.call(v.childNodes),v.childNodes),F[v.childNodes.length].nodeType}catch(eb){I={apply:F.length?function(a,b){H.apply(a,J.call(b))}:function(a,b){var c=a.length,d=0;while(a[c++]=b[d++]);a.length=c-1}}}function fb(a,b,d,e){var f,h,j,k,l,o,r,s,w,x;if((b?b.ownerDocument||b:v)!==n&&m(b),b=b||n,d=d||[],!a||"string"!=typeof a)return d;if(1!==(k=b.nodeType)&&9!==k)return[];if(p&&!e){if(f=_.exec(a))if(j=f[1]){if(9===k){if(h=b.getElementById(j),!h||!h.parentNode)return d;if(h.id===j)return d.push(h),d}else if(b.ownerDocument&&(h=b.ownerDocument.getElementById(j))&&t(b,h)&&h.id===j)return d.push(h),d}else{if(f[2])return I.apply(d,b.getElementsByTagName(a)),d;if((j=f[3])&&c.getElementsByClassName&&b.getElementsByClassName)return I.apply(d,b.getElementsByClassName(j)),d}if(c.qsa&&(!q||!q.test(a))){if(s=r=u,w=b,x=9===k&&a,1===k&&"object"!==b.nodeName.toLowerCase()){o=g(a),(r=b.getAttribute("id"))?s=r.replace(bb,"\\$&"):b.setAttribute("id",s),s="[id='"+s+"'] ",l=o.length;while(l--)o[l]=s+qb(o[l]);w=ab.test(a)&&ob(b.parentNode)||b,x=o.join(",")}if(x)try{return I.apply(d,w.querySelectorAll(x)),d}catch(y){}finally{r||b.removeAttribute("id")}}}return i(a.replace(R,"$1"),b,d,e)}function gb(){var a=[];function b(c,e){return a.push(c+" ")>d.cacheLength&&delete b[a.shift()],b[c+" "]=e}return b}function hb(a){return a[u]=!0,a}function ib(a){var b=n.createElement("div");try{return!!a(b)}catch(c){return!1}finally{b.parentNode&&b.parentNode.removeChild(b),b=null}}function jb(a,b){var c=a.split("|"),e=a.length;while(e--)d.attrHandle[c[e]]=b}function kb(a,b){var c=b&&a,d=c&&1===a.nodeType&&1===b.nodeType&&(~b.sourceIndex||D)-(~a.sourceIndex||D);if(d)return d;if(c)while(c=c.nextSibling)if(c===b)return-1;return a?1:-1}function lb(a){return function(b){var c=b.nodeName.toLowerCase();return"input"===c&&b.type===a}}function mb(a){return function(b){var c=b.nodeName.toLowerCase();return("input"===c||"button"===c)&&b.type===a}}function nb(a){return hb(function(b){return b=+b,hb(function(c,d){var e,f=a([],c.length,b),g=f.length;while(g--)c[e=f[g]]&&(c[e]=!(d[e]=c[e]))})})}function ob(a){return a&&typeof a.getElementsByTagName!==C&&a}c=fb.support={},f=fb.isXML=function(a){var b=a&&(a.ownerDocument||a).documentElement;return b?"HTML"!==b.nodeName:!1},m=fb.setDocument=function(a){var b,e=a?a.ownerDocument||a:v,g=e.defaultView;return e!==n&&9===e.nodeType&&e.documentElement?(n=e,o=e.documentElement,p=!f(e),g&&g!==g.top&&(g.addEventListener?g.addEventListener("unload",function(){m()},!1):g.attachEvent&&g.attachEvent("onunload",function(){m()})),c.attributes=ib(function(a){return a.className="i",!a.getAttribute("className")}),c.getElementsByTagName=ib(function(a){return a.appendChild(e.createComment("")),!a.getElementsByTagName("*").length}),c.getElementsByClassName=$.test(e.getElementsByClassName)&&ib(function(a){return a.innerHTML="
",a.firstChild.className="i",2===a.getElementsByClassName("i").length}),c.getById=ib(function(a){return o.appendChild(a).id=u,!e.getElementsByName||!e.getElementsByName(u).length}),c.getById?(d.find.ID=function(a,b){if(typeof b.getElementById!==C&&p){var c=b.getElementById(a);return c&&c.parentNode?[c]:[]}},d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){return a.getAttribute("id")===b}}):(delete d.find.ID,d.filter.ID=function(a){var b=a.replace(cb,db);return function(a){var c=typeof a.getAttributeNode!==C&&a.getAttributeNode("id");return c&&c.value===b}}),d.find.TAG=c.getElementsByTagName?function(a,b){return typeof b.getElementsByTagName!==C?b.getElementsByTagName(a):void 0}:function(a,b){var c,d=[],e=0,f=b.getElementsByTagName(a);if("*"===a){while(c=f[e++])1===c.nodeType&&d.push(c);return d}return f},d.find.CLASS=c.getElementsByClassName&&function(a,b){return typeof b.getElementsByClassName!==C&&p?b.getElementsByClassName(a):void 0},r=[],q=[],(c.qsa=$.test(e.querySelectorAll))&&(ib(function(a){a.innerHTML="",a.querySelectorAll("[msallowclip^='']").length&&q.push("[*^$]="+M+"*(?:''|\"\")"),a.querySelectorAll("[selected]").length||q.push("\\["+M+"*(?:value|"+L+")"),a.querySelectorAll(":checked").length||q.push(":checked")}),ib(function(a){var b=e.createElement("input");b.setAttribute("type","hidden"),a.appendChild(b).setAttribute("name","D"),a.querySelectorAll("[name=d]").length&&q.push("name"+M+"*[*^$|!~]?="),a.querySelectorAll(":enabled").length||q.push(":enabled",":disabled"),a.querySelectorAll("*,:x"),q.push(",.*:")})),(c.matchesSelector=$.test(s=o.matches||o.webkitMatchesSelector||o.mozMatchesSelector||o.oMatchesSelector||o.msMatchesSelector))&&ib(function(a){c.disconnectedMatch=s.call(a,"div"),s.call(a,"[s!='']:x"),r.push("!=",Q)}),q=q.length&&new RegExp(q.join("|")),r=r.length&&new RegExp(r.join("|")),b=$.test(o.compareDocumentPosition),t=b||$.test(o.contains)?function(a,b){var c=9===a.nodeType?a.documentElement:a,d=b&&b.parentNode;return a===d||!(!d||1!==d.nodeType||!(c.contains?c.contains(d):a.compareDocumentPosition&&16&a.compareDocumentPosition(d)))}:function(a,b){if(b)while(b=b.parentNode)if(b===a)return!0;return!1},B=b?function(a,b){if(a===b)return l=!0,0;var d=!a.compareDocumentPosition-!b.compareDocumentPosition;return d?d:(d=(a.ownerDocument||a)===(b.ownerDocument||b)?a.compareDocumentPosition(b):1,1&d||!c.sortDetached&&b.compareDocumentPosition(a)===d?a===e||a.ownerDocument===v&&t(v,a)?-1:b===e||b.ownerDocument===v&&t(v,b)?1:k?K.call(k,a)-K.call(k,b):0:4&d?-1:1)}:function(a,b){if(a===b)return l=!0,0;var c,d=0,f=a.parentNode,g=b.parentNode,h=[a],i=[b];if(!f||!g)return a===e?-1:b===e?1:f?-1:g?1:k?K.call(k,a)-K.call(k,b):0;if(f===g)return kb(a,b);c=a;while(c=c.parentNode)h.unshift(c);c=b;while(c=c.parentNode)i.unshift(c);while(h[d]===i[d])d++;return d?kb(h[d],i[d]):h[d]===v?-1:i[d]===v?1:0},e):n},fb.matches=function(a,b){return fb(a,null,null,b)},fb.matchesSelector=function(a,b){if((a.ownerDocument||a)!==n&&m(a),b=b.replace(U,"='$1']"),!(!c.matchesSelector||!p||r&&r.test(b)||q&&q.test(b)))try{var d=s.call(a,b);if(d||c.disconnectedMatch||a.document&&11!==a.document.nodeType)return d}catch(e){}return fb(b,n,null,[a]).length>0},fb.contains=function(a,b){return(a.ownerDocument||a)!==n&&m(a),t(a,b)},fb.attr=function(a,b){(a.ownerDocument||a)!==n&&m(a);var e=d.attrHandle[b.toLowerCase()],f=e&&E.call(d.attrHandle,b.toLowerCase())?e(a,b,!p):void 0;return void 0!==f?f:c.attributes||!p?a.getAttribute(b):(f=a.getAttributeNode(b))&&f.specified?f.value:null},fb.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)},fb.uniqueSort=function(a){var b,d=[],e=0,f=0;if(l=!c.detectDuplicates,k=!c.sortStable&&a.slice(0),a.sort(B),l){while(b=a[f++])b===a[f]&&(e=d.push(f));while(e--)a.splice(d[e],1)}return k=null,a},e=fb.getText=function(a){var b,c="",d=0,f=a.nodeType;if(f){if(1===f||9===f||11===f){if("string"==typeof a.textContent)return a.textContent;for(a=a.firstChild;a;a=a.nextSibling)c+=e(a)}else if(3===f||4===f)return a.nodeValue}else while(b=a[d++])c+=e(b);return c},d=fb.selectors={cacheLength:50,createPseudo:hb,match:X,attrHandle:{},find:{},relative:{">":{dir:"parentNode",first:!0}," ":{dir:"parentNode"},"+":{dir:"previousSibling",first:!0},"~":{dir:"previousSibling"}},preFilter:{ATTR:function(a){return a[1]=a[1].replace(cb,db),a[3]=(a[3]||a[4]||a[5]||"").replace(cb,db),"~="===a[2]&&(a[3]=" "+a[3]+" "),a.slice(0,4)},CHILD:function(a){return a[1]=a[1].toLowerCase(),"nth"===a[1].slice(0,3)?(a[3]||fb.error(a[0]),a[4]=+(a[4]?a[5]+(a[6]||1):2*("even"===a[3]||"odd"===a[3])),a[5]=+(a[7]+a[8]||"odd"===a[3])):a[3]&&fb.error(a[0]),a},PSEUDO:function(a){var b,c=!a[6]&&a[2];return X.CHILD.test(a[0])?null:(a[3]?a[2]=a[4]||a[5]||"":c&&V.test(c)&&(b=g(c,!0))&&(b=c.indexOf(")",c.length-b)-c.length)&&(a[0]=a[0].slice(0,b),a[2]=c.slice(0,b)),a.slice(0,3))}},filter:{TAG:function(a){var b=a.replace(cb,db).toLowerCase();return"*"===a?function(){return!0}:function(a){return a.nodeName&&a.nodeName.toLowerCase()===b}},CLASS:function(a){var b=y[a+" "];return b||(b=new RegExp("(^|"+M+")"+a+"("+M+"|$)"))&&y(a,function(a){return b.test("string"==typeof a.className&&a.className||typeof a.getAttribute!==C&&a.getAttribute("class")||"")})},ATTR:function(a,b,c){return function(d){var e=fb.attr(d,a);return null==e?"!="===b:b?(e+="","="===b?e===c:"!="===b?e!==c:"^="===b?c&&0===e.indexOf(c):"*="===b?c&&e.indexOf(c)>-1:"$="===b?c&&e.slice(-c.length)===c:"~="===b?(" "+e+" ").indexOf(c)>-1:"|="===b?e===c||e.slice(0,c.length+1)===c+"-":!1):!0}},CHILD:function(a,b,c,d,e){var f="nth"!==a.slice(0,3),g="last"!==a.slice(-4),h="of-type"===b;return 1===d&&0===e?function(a){return!!a.parentNode}:function(b,c,i){var j,k,l,m,n,o,p=f!==g?"nextSibling":"previousSibling",q=b.parentNode,r=h&&b.nodeName.toLowerCase(),s=!i&&!h;if(q){if(f){while(p){l=b;while(l=l[p])if(h?l.nodeName.toLowerCase()===r:1===l.nodeType)return!1;o=p="only"===a&&!o&&"nextSibling"}return!0}if(o=[g?q.firstChild:q.lastChild],g&&s){k=q[u]||(q[u]={}),j=k[a]||[],n=j[0]===w&&j[1],m=j[0]===w&&j[2],l=n&&q.childNodes[n];while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if(1===l.nodeType&&++m&&l===b){k[a]=[w,n,m];break}}else if(s&&(j=(b[u]||(b[u]={}))[a])&&j[0]===w)m=j[1];else while(l=++n&&l&&l[p]||(m=n=0)||o.pop())if((h?l.nodeName.toLowerCase()===r:1===l.nodeType)&&++m&&(s&&((l[u]||(l[u]={}))[a]=[w,m]),l===b))break;return m-=e,m===d||m%d===0&&m/d>=0}}},PSEUDO:function(a,b){var c,e=d.pseudos[a]||d.setFilters[a.toLowerCase()]||fb.error("unsupported pseudo: "+a);return e[u]?e(b):e.length>1?(c=[a,a,"",b],d.setFilters.hasOwnProperty(a.toLowerCase())?hb(function(a,c){var d,f=e(a,b),g=f.length;while(g--)d=K.call(a,f[g]),a[d]=!(c[d]=f[g])}):function(a){return e(a,0,c)}):e}},pseudos:{not:hb(function(a){var b=[],c=[],d=h(a.replace(R,"$1"));return d[u]?hb(function(a,b,c,e){var f,g=d(a,null,e,[]),h=a.length;while(h--)(f=g[h])&&(a[h]=!(b[h]=f))}):function(a,e,f){return b[0]=a,d(b,null,f,c),!c.pop()}}),has:hb(function(a){return function(b){return fb(a,b).length>0}}),contains:hb(function(a){return function(b){return(b.textContent||b.innerText||e(b)).indexOf(a)>-1}}),lang:hb(function(a){return W.test(a||"")||fb.error("unsupported lang: "+a),a=a.replace(cb,db).toLowerCase(),function(b){var c;do if(c=p?b.lang:b.getAttribute("xml:lang")||b.getAttribute("lang"))return c=c.toLowerCase(),c===a||0===c.indexOf(a+"-");while((b=b.parentNode)&&1===b.nodeType);return!1}}),target:function(b){var c=a.location&&a.location.hash;return c&&c.slice(1)===b.id},root:function(a){return a===o},focus:function(a){return a===n.activeElement&&(!n.hasFocus||n.hasFocus())&&!!(a.type||a.href||~a.tabIndex)},enabled:function(a){return a.disabled===!1},disabled:function(a){return a.disabled===!0},checked:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&!!a.checked||"option"===b&&!!a.selected},selected:function(a){return a.parentNode&&a.parentNode.selectedIndex,a.selected===!0},empty:function(a){for(a=a.firstChild;a;a=a.nextSibling)if(a.nodeType<6)return!1;return!0},parent:function(a){return!d.pseudos.empty(a)},header:function(a){return Z.test(a.nodeName)},input:function(a){return Y.test(a.nodeName)},button:function(a){var b=a.nodeName.toLowerCase();return"input"===b&&"button"===a.type||"button"===b},text:function(a){var b;return"input"===a.nodeName.toLowerCase()&&"text"===a.type&&(null==(b=a.getAttribute("type"))||"text"===b.toLowerCase())},first:nb(function(){return[0]}),last:nb(function(a,b){return[b-1]}),eq:nb(function(a,b,c){return[0>c?c+b:c]}),even:nb(function(a,b){for(var c=0;b>c;c+=2)a.push(c);return a}),odd:nb(function(a,b){for(var c=1;b>c;c+=2)a.push(c);return a}),lt:nb(function(a,b,c){for(var d=0>c?c+b:c;--d>=0;)a.push(d);return a}),gt:nb(function(a,b,c){for(var d=0>c?c+b:c;++db;b++)d+=a[b].value;return d}function rb(a,b,c){var d=b.dir,e=c&&"parentNode"===d,f=x++;return b.first?function(b,c,f){while(b=b[d])if(1===b.nodeType||e)return a(b,c,f)}:function(b,c,g){var h,i,j=[w,f];if(g){while(b=b[d])if((1===b.nodeType||e)&&a(b,c,g))return!0}else while(b=b[d])if(1===b.nodeType||e){if(i=b[u]||(b[u]={}),(h=i[d])&&h[0]===w&&h[1]===f)return j[2]=h[2];if(i[d]=j,j[2]=a(b,c,g))return!0}}}function sb(a){return a.length>1?function(b,c,d){var e=a.length;while(e--)if(!a[e](b,c,d))return!1;return!0}:a[0]}function tb(a,b,c){for(var d=0,e=b.length;e>d;d++)fb(a,b[d],c);return c}function ub(a,b,c,d,e){for(var f,g=[],h=0,i=a.length,j=null!=b;i>h;h++)(f=a[h])&&(!c||c(f,d,e))&&(g.push(f),j&&b.push(h));return g}function vb(a,b,c,d,e,f){return d&&!d[u]&&(d=vb(d)),e&&!e[u]&&(e=vb(e,f)),hb(function(f,g,h,i){var j,k,l,m=[],n=[],o=g.length,p=f||tb(b||"*",h.nodeType?[h]:h,[]),q=!a||!f&&b?p:ub(p,m,a,h,i),r=c?e||(f?a:o||d)?[]:g:q;if(c&&c(q,r,h,i),d){j=ub(r,n),d(j,[],h,i),k=j.length;while(k--)(l=j[k])&&(r[n[k]]=!(q[n[k]]=l))}if(f){if(e||a){if(e){j=[],k=r.length;while(k--)(l=r[k])&&j.push(q[k]=l);e(null,r=[],j,i)}k=r.length;while(k--)(l=r[k])&&(j=e?K.call(f,l):m[k])>-1&&(f[j]=!(g[j]=l))}}else r=ub(r===g?r.splice(o,r.length):r),e?e(null,g,r,i):I.apply(g,r)})}function wb(a){for(var b,c,e,f=a.length,g=d.relative[a[0].type],h=g||d.relative[" "],i=g?1:0,k=rb(function(a){return a===b},h,!0),l=rb(function(a){return K.call(b,a)>-1},h,!0),m=[function(a,c,d){return!g&&(d||c!==j)||((b=c).nodeType?k(a,c,d):l(a,c,d))}];f>i;i++)if(c=d.relative[a[i].type])m=[rb(sb(m),c)];else{if(c=d.filter[a[i].type].apply(null,a[i].matches),c[u]){for(e=++i;f>e;e++)if(d.relative[a[e].type])break;return vb(i>1&&sb(m),i>1&&qb(a.slice(0,i-1).concat({value:" "===a[i-2].type?"*":""})).replace(R,"$1"),c,e>i&&wb(a.slice(i,e)),f>e&&wb(a=a.slice(e)),f>e&&qb(a))}m.push(c)}return sb(m)}function xb(a,b){var c=b.length>0,e=a.length>0,f=function(f,g,h,i,k){var l,m,o,p=0,q="0",r=f&&[],s=[],t=j,u=f||e&&d.find.TAG("*",k),v=w+=null==t?1:Math.random()||.1,x=u.length;for(k&&(j=g!==n&&g);q!==x&&null!=(l=u[q]);q++){if(e&&l){m=0;while(o=a[m++])if(o(l,g,h)){i.push(l);break}k&&(w=v)}c&&((l=!o&&l)&&p--,f&&r.push(l))}if(p+=q,c&&q!==p){m=0;while(o=b[m++])o(r,s,g,h);if(f){if(p>0)while(q--)r[q]||s[q]||(s[q]=G.call(i));s=ub(s)}I.apply(i,s),k&&!f&&s.length>0&&p+b.length>1&&fb.uniqueSort(i)}return k&&(w=v,j=t),r};return c?hb(f):f}return h=fb.compile=function(a,b){var c,d=[],e=[],f=A[a+" "];if(!f){b||(b=g(a)),c=b.length;while(c--)f=wb(b[c]),f[u]?d.push(f):e.push(f);f=A(a,xb(e,d)),f.selector=a}return f},i=fb.select=function(a,b,e,f){var i,j,k,l,m,n="function"==typeof a&&a,o=!f&&g(a=n.selector||a);if(e=e||[],1===o.length){if(j=o[0]=o[0].slice(0),j.length>2&&"ID"===(k=j[0]).type&&c.getById&&9===b.nodeType&&p&&d.relative[j[1].type]){if(b=(d.find.ID(k.matches[0].replace(cb,db),b)||[])[0],!b)return e;n&&(b=b.parentNode),a=a.slice(j.shift().value.length)}i=X.needsContext.test(a)?0:j.length;while(i--){if(k=j[i],d.relative[l=k.type])break;if((m=d.find[l])&&(f=m(k.matches[0].replace(cb,db),ab.test(j[0].type)&&ob(b.parentNode)||b))){if(j.splice(i,1),a=f.length&&qb(j),!a)return I.apply(e,f),e;break}}}return(n||h(a,o))(f,b,!p,e,ab.test(a)&&ob(b.parentNode)||b),e},c.sortStable=u.split("").sort(B).join("")===u,c.detectDuplicates=!!l,m(),c.sortDetached=ib(function(a){return 1&a.compareDocumentPosition(n.createElement("div"))}),ib(function(a){return a.innerHTML="","#"===a.firstChild.getAttribute("href")})||jb("type|href|height|width",function(a,b,c){return c?void 0:a.getAttribute(b,"type"===b.toLowerCase()?1:2)}),c.attributes&&ib(function(a){return a.innerHTML="",a.firstChild.setAttribute("value",""),""===a.firstChild.getAttribute("value")})||jb("value",function(a,b,c){return c||"input"!==a.nodeName.toLowerCase()?void 0:a.defaultValue}),ib(function(a){return null==a.getAttribute("disabled")})||jb(L,function(a,b,c){var d;return c?void 0:a[b]===!0?b.toLowerCase():(d=a.getAttributeNode(b))&&d.specified?d.value:null}),fb}(a);m.find=s,m.expr=s.selectors,m.expr[":"]=m.expr.pseudos,m.unique=s.uniqueSort,m.text=s.getText,m.isXMLDoc=s.isXML,m.contains=s.contains;var t=m.expr.match.needsContext,u=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,v=/^.[^:#\[\.,]*$/;function w(a,b,c){if(m.isFunction(b))return m.grep(a,function(a,d){return!!b.call(a,d,a)!==c});if(b.nodeType)return m.grep(a,function(a){return a===b!==c});if("string"==typeof b){if(v.test(b))return m.filter(b,a,c);b=m.filter(b,a)}return m.grep(a,function(a){return m.inArray(a,b)>=0!==c})}m.filter=function(a,b,c){var d=b[0];return c&&(a=":not("+a+")"),1===b.length&&1===d.nodeType?m.find.matchesSelector(d,a)?[d]:[]:m.find.matches(a,m.grep(b,function(a){return 1===a.nodeType}))},m.fn.extend({find:function(a){var b,c=[],d=this,e=d.length;if("string"!=typeof a)return this.pushStack(m(a).filter(function(){for(b=0;e>b;b++)if(m.contains(d[b],this))return!0}));for(b=0;e>b;b++)m.find(a,d[b],c);return c=this.pushStack(e>1?m.unique(c):c),c.selector=this.selector?this.selector+" "+a:a,c},filter:function(a){return this.pushStack(w(this,a||[],!1))},not:function(a){return this.pushStack(w(this,a||[],!0))},is:function(a){return!!w(this,"string"==typeof a&&t.test(a)?m(a):a||[],!1).length}});var x,y=a.document,z=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,A=m.fn.init=function(a,b){var c,d;if(!a)return this;if("string"==typeof a){if(c="<"===a.charAt(0)&&">"===a.charAt(a.length-1)&&a.length>=3?[null,a,null]:z.exec(a),!c||!c[1]&&b)return!b||b.jquery?(b||x).find(a):this.constructor(b).find(a);if(c[1]){if(b=b instanceof m?b[0]:b,m.merge(this,m.parseHTML(c[1],b&&b.nodeType?b.ownerDocument||b:y,!0)),u.test(c[1])&&m.isPlainObject(b))for(c in b)m.isFunction(this[c])?this[c](b[c]):this.attr(c,b[c]);return this}if(d=y.getElementById(c[2]),d&&d.parentNode){if(d.id!==c[2])return x.find(a);this.length=1,this[0]=d}return this.context=y,this.selector=a,this}return a.nodeType?(this.context=this[0]=a,this.length=1,this):m.isFunction(a)?"undefined"!=typeof x.ready?x.ready(a):a(m):(void 0!==a.selector&&(this.selector=a.selector,this.context=a.context),m.makeArray(a,this))};A.prototype=m.fn,x=m(y);var B=/^(?:parents|prev(?:Until|All))/,C={children:!0,contents:!0,next:!0,prev:!0};m.extend({dir:function(a,b,c){var d=[],e=a[b];while(e&&9!==e.nodeType&&(void 0===c||1!==e.nodeType||!m(e).is(c)))1===e.nodeType&&d.push(e),e=e[b];return d},sibling:function(a,b){for(var c=[];a;a=a.nextSibling)1===a.nodeType&&a!==b&&c.push(a);return c}}),m.fn.extend({has:function(a){var b,c=m(a,this),d=c.length;return this.filter(function(){for(b=0;d>b;b++)if(m.contains(this,c[b]))return!0})},closest:function(a,b){for(var c,d=0,e=this.length,f=[],g=t.test(a)||"string"!=typeof a?m(a,b||this.context):0;e>d;d++)for(c=this[d];c&&c!==b;c=c.parentNode)if(c.nodeType<11&&(g?g.index(c)>-1:1===c.nodeType&&m.find.matchesSelector(c,a))){f.push(c);break}return this.pushStack(f.length>1?m.unique(f):f)},index:function(a){return a?"string"==typeof a?m.inArray(this[0],m(a)):m.inArray(a.jquery?a[0]:a,this):this[0]&&this[0].parentNode?this.first().prevAll().length:-1},add:function(a,b){return this.pushStack(m.unique(m.merge(this.get(),m(a,b))))},addBack:function(a){return this.add(null==a?this.prevObject:this.prevObject.filter(a))}});function D(a,b){do a=a[b];while(a&&1!==a.nodeType);return a}m.each({parent:function(a){var b=a.parentNode;return b&&11!==b.nodeType?b:null},parents:function(a){return m.dir(a,"parentNode")},parentsUntil:function(a,b,c){return m.dir(a,"parentNode",c)},next:function(a){return D(a,"nextSibling")},prev:function(a){return D(a,"previousSibling")},nextAll:function(a){return m.dir(a,"nextSibling")},prevAll:function(a){return m.dir(a,"previousSibling")},nextUntil:function(a,b,c){return m.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return m.dir(a,"previousSibling",c)},siblings:function(a){return m.sibling((a.parentNode||{}).firstChild,a)},children:function(a){return m.sibling(a.firstChild)},contents:function(a){return m.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:m.merge([],a.childNodes)}},function(a,b){m.fn[a]=function(c,d){var e=m.map(this,b,c);return"Until"!==a.slice(-5)&&(d=c),d&&"string"==typeof d&&(e=m.filter(d,e)),this.length>1&&(C[a]||(e=m.unique(e)),B.test(a)&&(e=e.reverse())),this.pushStack(e)}});var E=/\S+/g,F={};function G(a){var b=F[a]={};return m.each(a.match(E)||[],function(a,c){b[c]=!0}),b}m.Callbacks=function(a){a="string"==typeof a?F[a]||G(a):m.extend({},a);var b,c,d,e,f,g,h=[],i=!a.once&&[],j=function(l){for(c=a.memory&&l,d=!0,f=g||0,g=0,e=h.length,b=!0;h&&e>f;f++)if(h[f].apply(l[0],l[1])===!1&&a.stopOnFalse){c=!1;break}b=!1,h&&(i?i.length&&j(i.shift()):c?h=[]:k.disable())},k={add:function(){if(h){var d=h.length;!function f(b){m.each(b,function(b,c){var d=m.type(c);"function"===d?a.unique&&k.has(c)||h.push(c):c&&c.length&&"string"!==d&&f(c)})}(arguments),b?e=h.length:c&&(g=d,j(c))}return this},remove:function(){return h&&m.each(arguments,function(a,c){var d;while((d=m.inArray(c,h,d))>-1)h.splice(d,1),b&&(e>=d&&e--,f>=d&&f--)}),this},has:function(a){return a?m.inArray(a,h)>-1:!(!h||!h.length)},empty:function(){return h=[],e=0,this},disable:function(){return h=i=c=void 0,this},disabled:function(){return!h},lock:function(){return i=void 0,c||k.disable(),this},locked:function(){return!i},fireWith:function(a,c){return!h||d&&!i||(c=c||[],c=[a,c.slice?c.slice():c],b?i.push(c):j(c)),this},fire:function(){return k.fireWith(this,arguments),this},fired:function(){return!!d}};return k},m.extend({Deferred:function(a){var b=[["resolve","done",m.Callbacks("once memory"),"resolved"],["reject","fail",m.Callbacks("once memory"),"rejected"],["notify","progress",m.Callbacks("memory")]],c="pending",d={state:function(){return c},always:function(){return e.done(arguments).fail(arguments),this},then:function(){var a=arguments;return m.Deferred(function(c){m.each(b,function(b,f){var g=m.isFunction(a[b])&&a[b];e[f[1]](function(){var a=g&&g.apply(this,arguments);a&&m.isFunction(a.promise)?a.promise().done(c.resolve).fail(c.reject).progress(c.notify):c[f[0]+"With"](this===d?c.promise():this,g?[a]:arguments)})}),a=null}).promise()},promise:function(a){return null!=a?m.extend(a,d):d}},e={};return d.pipe=d.then,m.each(b,function(a,f){var g=f[2],h=f[3];d[f[1]]=g.add,h&&g.add(function(){c=h},b[1^a][2].disable,b[2][2].lock),e[f[0]]=function(){return e[f[0]+"With"](this===e?d:this,arguments),this},e[f[0]+"With"]=g.fireWith}),d.promise(e),a&&a.call(e,e),e},when:function(a){var b=0,c=d.call(arguments),e=c.length,f=1!==e||a&&m.isFunction(a.promise)?e:0,g=1===f?a:m.Deferred(),h=function(a,b,c){return function(e){b[a]=this,c[a]=arguments.length>1?d.call(arguments):e,c===i?g.notifyWith(b,c):--f||g.resolveWith(b,c)}},i,j,k;if(e>1)for(i=new Array(e),j=new Array(e),k=new Array(e);e>b;b++)c[b]&&m.isFunction(c[b].promise)?c[b].promise().done(h(b,k,c)).fail(g.reject).progress(h(b,j,i)):--f;return f||g.resolveWith(k,c),g.promise()}});var H;m.fn.ready=function(a){return m.ready.promise().done(a),this},m.extend({isReady:!1,readyWait:1,holdReady:function(a){a?m.readyWait++:m.ready(!0)},ready:function(a){if(a===!0?!--m.readyWait:!m.isReady){if(!y.body)return setTimeout(m.ready);m.isReady=!0,a!==!0&&--m.readyWait>0||(H.resolveWith(y,[m]),m.fn.triggerHandler&&(m(y).triggerHandler("ready"),m(y).off("ready")))}}});function I(){y.addEventListener?(y.removeEventListener("DOMContentLoaded",J,!1),a.removeEventListener("load",J,!1)):(y.detachEvent("onreadystatechange",J),a.detachEvent("onload",J))}function J(){(y.addEventListener||"load"===event.type||"complete"===y.readyState)&&(I(),m.ready())}m.ready.promise=function(b){if(!H)if(H=m.Deferred(),"complete"===y.readyState)setTimeout(m.ready);else if(y.addEventListener)y.addEventListener("DOMContentLoaded",J,!1),a.addEventListener("load",J,!1);else{y.attachEvent("onreadystatechange",J),a.attachEvent("onload",J);var c=!1;try{c=null==a.frameElement&&y.documentElement}catch(d){}c&&c.doScroll&&!function e(){if(!m.isReady){try{c.doScroll("left")}catch(a){return setTimeout(e,50)}I(),m.ready()}}()}return H.promise(b)};var K="undefined",L;for(L in m(k))break;k.ownLast="0"!==L,k.inlineBlockNeedsLayout=!1,m(function(){var a,b,c,d;c=y.getElementsByTagName("body")[0],c&&c.style&&(b=y.createElement("div"),d=y.createElement("div"),d.style.cssText="position:absolute;border:0;width:0;height:0;top:0;left:-9999px",c.appendChild(d).appendChild(b),typeof b.style.zoom!==K&&(b.style.cssText="display:inline;margin:0;border:0;padding:1px;width:1px;zoom:1",k.inlineBlockNeedsLayout=a=3===b.offsetWidth,a&&(c.style.zoom=1)),c.removeChild(d))}),function(){var a=y.createElement("div");if(null==k.deleteExpando){k.deleteExpando=!0;try{delete a.test}catch(b){k.deleteExpando=!1}}a=null}(),m.acceptData=function(a){var b=m.noData[(a.nodeName+" ").toLowerCase()],c=+a.nodeType||1;return 1!==c&&9!==c?!1:!b||b!==!0&&a.getAttribute("classid")===b};var M=/^(?:\{[\w\W]*\}|\[[\w\W]*\])$/,N=/([A-Z])/g;function O(a,b,c){if(void 0===c&&1===a.nodeType){var d="data-"+b.replace(N,"-$1").toLowerCase();if(c=a.getAttribute(d),"string"==typeof c){try{c="true"===c?!0:"false"===c?!1:"null"===c?null:+c+""===c?+c:M.test(c)?m.parseJSON(c):c}catch(e){}m.data(a,b,c)}else c=void 0}return c}function P(a){var b;for(b in a)if(("data"!==b||!m.isEmptyObject(a[b]))&&"toJSON"!==b)return!1;return!0}function Q(a,b,d,e){if(m.acceptData(a)){var f,g,h=m.expando,i=a.nodeType,j=i?m.cache:a,k=i?a[h]:a[h]&&h; -if(k&&j[k]&&(e||j[k].data)||void 0!==d||"string"!=typeof b)return k||(k=i?a[h]=c.pop()||m.guid++:h),j[k]||(j[k]=i?{}:{toJSON:m.noop}),("object"==typeof b||"function"==typeof b)&&(e?j[k]=m.extend(j[k],b):j[k].data=m.extend(j[k].data,b)),g=j[k],e||(g.data||(g.data={}),g=g.data),void 0!==d&&(g[m.camelCase(b)]=d),"string"==typeof b?(f=g[b],null==f&&(f=g[m.camelCase(b)])):f=g,f}}function R(a,b,c){if(m.acceptData(a)){var d,e,f=a.nodeType,g=f?m.cache:a,h=f?a[m.expando]:m.expando;if(g[h]){if(b&&(d=c?g[h]:g[h].data)){m.isArray(b)?b=b.concat(m.map(b,m.camelCase)):b in d?b=[b]:(b=m.camelCase(b),b=b in d?[b]:b.split(" ")),e=b.length;while(e--)delete d[b[e]];if(c?!P(d):!m.isEmptyObject(d))return}(c||(delete g[h].data,P(g[h])))&&(f?m.cleanData([a],!0):k.deleteExpando||g!=g.window?delete g[h]:g[h]=null)}}}m.extend({cache:{},noData:{"applet ":!0,"embed ":!0,"object ":"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"},hasData:function(a){return a=a.nodeType?m.cache[a[m.expando]]:a[m.expando],!!a&&!P(a)},data:function(a,b,c){return Q(a,b,c)},removeData:function(a,b){return R(a,b)},_data:function(a,b,c){return Q(a,b,c,!0)},_removeData:function(a,b){return R(a,b,!0)}}),m.fn.extend({data:function(a,b){var c,d,e,f=this[0],g=f&&f.attributes;if(void 0===a){if(this.length&&(e=m.data(f),1===f.nodeType&&!m._data(f,"parsedAttrs"))){c=g.length;while(c--)g[c]&&(d=g[c].name,0===d.indexOf("data-")&&(d=m.camelCase(d.slice(5)),O(f,d,e[d])));m._data(f,"parsedAttrs",!0)}return e}return"object"==typeof a?this.each(function(){m.data(this,a)}):arguments.length>1?this.each(function(){m.data(this,a,b)}):f?O(f,a,m.data(f,a)):void 0},removeData:function(a){return this.each(function(){m.removeData(this,a)})}}),m.extend({queue:function(a,b,c){var d;return a?(b=(b||"fx")+"queue",d=m._data(a,b),c&&(!d||m.isArray(c)?d=m._data(a,b,m.makeArray(c)):d.push(c)),d||[]):void 0},dequeue:function(a,b){b=b||"fx";var c=m.queue(a,b),d=c.length,e=c.shift(),f=m._queueHooks(a,b),g=function(){m.dequeue(a,b)};"inprogress"===e&&(e=c.shift(),d--),e&&("fx"===b&&c.unshift("inprogress"),delete f.stop,e.call(a,g,f)),!d&&f&&f.empty.fire()},_queueHooks:function(a,b){var c=b+"queueHooks";return m._data(a,c)||m._data(a,c,{empty:m.Callbacks("once memory").add(function(){m._removeData(a,b+"queue"),m._removeData(a,c)})})}}),m.fn.extend({queue:function(a,b){var c=2;return"string"!=typeof a&&(b=a,a="fx",c--),arguments.lengthh;h++)b(a[h],c,g?d:d.call(a[h],h,b(a[h],c)));return e?a:j?b.call(a):i?b(a[0],c):f},W=/^(?:checkbox|radio)$/i;!function(){var a=y.createElement("input"),b=y.createElement("div"),c=y.createDocumentFragment();if(b.innerHTML="
a",k.leadingWhitespace=3===b.firstChild.nodeType,k.tbody=!b.getElementsByTagName("tbody").length,k.htmlSerialize=!!b.getElementsByTagName("link").length,k.html5Clone="<:nav>"!==y.createElement("nav").cloneNode(!0).outerHTML,a.type="checkbox",a.checked=!0,c.appendChild(a),k.appendChecked=a.checked,b.innerHTML="",k.noCloneChecked=!!b.cloneNode(!0).lastChild.defaultValue,c.appendChild(b),b.innerHTML="",k.checkClone=b.cloneNode(!0).cloneNode(!0).lastChild.checked,k.noCloneEvent=!0,b.attachEvent&&(b.attachEvent("onclick",function(){k.noCloneEvent=!1}),b.cloneNode(!0).click()),null==k.deleteExpando){k.deleteExpando=!0;try{delete b.test}catch(d){k.deleteExpando=!1}}}(),function(){var b,c,d=y.createElement("div");for(b in{submit:!0,change:!0,focusin:!0})c="on"+b,(k[b+"Bubbles"]=c in a)||(d.setAttribute(c,"t"),k[b+"Bubbles"]=d.attributes[c].expando===!1);d=null}();var X=/^(?:input|select|textarea)$/i,Y=/^key/,Z=/^(?:mouse|pointer|contextmenu)|click/,$=/^(?:focusinfocus|focusoutblur)$/,_=/^([^.]*)(?:\.(.+)|)$/;function ab(){return!0}function bb(){return!1}function cb(){try{return y.activeElement}catch(a){}}m.event={global:{},add:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m._data(a);if(r){c.handler&&(i=c,c=i.handler,e=i.selector),c.guid||(c.guid=m.guid++),(g=r.events)||(g=r.events={}),(k=r.handle)||(k=r.handle=function(a){return typeof m===K||a&&m.event.triggered===a.type?void 0:m.event.dispatch.apply(k.elem,arguments)},k.elem=a),b=(b||"").match(E)||[""],h=b.length;while(h--)f=_.exec(b[h])||[],o=q=f[1],p=(f[2]||"").split(".").sort(),o&&(j=m.event.special[o]||{},o=(e?j.delegateType:j.bindType)||o,j=m.event.special[o]||{},l=m.extend({type:o,origType:q,data:d,handler:c,guid:c.guid,selector:e,needsContext:e&&m.expr.match.needsContext.test(e),namespace:p.join(".")},i),(n=g[o])||(n=g[o]=[],n.delegateCount=0,j.setup&&j.setup.call(a,d,p,k)!==!1||(a.addEventListener?a.addEventListener(o,k,!1):a.attachEvent&&a.attachEvent("on"+o,k))),j.add&&(j.add.call(a,l),l.handler.guid||(l.handler.guid=c.guid)),e?n.splice(n.delegateCount++,0,l):n.push(l),m.event.global[o]=!0);a=null}},remove:function(a,b,c,d,e){var f,g,h,i,j,k,l,n,o,p,q,r=m.hasData(a)&&m._data(a);if(r&&(k=r.events)){b=(b||"").match(E)||[""],j=b.length;while(j--)if(h=_.exec(b[j])||[],o=q=h[1],p=(h[2]||"").split(".").sort(),o){l=m.event.special[o]||{},o=(d?l.delegateType:l.bindType)||o,n=k[o]||[],h=h[2]&&new RegExp("(^|\\.)"+p.join("\\.(?:.*\\.|)")+"(\\.|$)"),i=f=n.length;while(f--)g=n[f],!e&&q!==g.origType||c&&c.guid!==g.guid||h&&!h.test(g.namespace)||d&&d!==g.selector&&("**"!==d||!g.selector)||(n.splice(f,1),g.selector&&n.delegateCount--,l.remove&&l.remove.call(a,g));i&&!n.length&&(l.teardown&&l.teardown.call(a,p,r.handle)!==!1||m.removeEvent(a,o,r.handle),delete k[o])}else for(o in k)m.event.remove(a,o+b[j],c,d,!0);m.isEmptyObject(k)&&(delete r.handle,m._removeData(a,"events"))}},trigger:function(b,c,d,e){var f,g,h,i,k,l,n,o=[d||y],p=j.call(b,"type")?b.type:b,q=j.call(b,"namespace")?b.namespace.split("."):[];if(h=l=d=d||y,3!==d.nodeType&&8!==d.nodeType&&!$.test(p+m.event.triggered)&&(p.indexOf(".")>=0&&(q=p.split("."),p=q.shift(),q.sort()),g=p.indexOf(":")<0&&"on"+p,b=b[m.expando]?b:new m.Event(p,"object"==typeof b&&b),b.isTrigger=e?2:3,b.namespace=q.join("."),b.namespace_re=b.namespace?new RegExp("(^|\\.)"+q.join("\\.(?:.*\\.|)")+"(\\.|$)"):null,b.result=void 0,b.target||(b.target=d),c=null==c?[b]:m.makeArray(c,[b]),k=m.event.special[p]||{},e||!k.trigger||k.trigger.apply(d,c)!==!1)){if(!e&&!k.noBubble&&!m.isWindow(d)){for(i=k.delegateType||p,$.test(i+p)||(h=h.parentNode);h;h=h.parentNode)o.push(h),l=h;l===(d.ownerDocument||y)&&o.push(l.defaultView||l.parentWindow||a)}n=0;while((h=o[n++])&&!b.isPropagationStopped())b.type=n>1?i:k.bindType||p,f=(m._data(h,"events")||{})[b.type]&&m._data(h,"handle"),f&&f.apply(h,c),f=g&&h[g],f&&f.apply&&m.acceptData(h)&&(b.result=f.apply(h,c),b.result===!1&&b.preventDefault());if(b.type=p,!e&&!b.isDefaultPrevented()&&(!k._default||k._default.apply(o.pop(),c)===!1)&&m.acceptData(d)&&g&&d[p]&&!m.isWindow(d)){l=d[g],l&&(d[g]=null),m.event.triggered=p;try{d[p]()}catch(r){}m.event.triggered=void 0,l&&(d[g]=l)}return b.result}},dispatch:function(a){a=m.event.fix(a);var b,c,e,f,g,h=[],i=d.call(arguments),j=(m._data(this,"events")||{})[a.type]||[],k=m.event.special[a.type]||{};if(i[0]=a,a.delegateTarget=this,!k.preDispatch||k.preDispatch.call(this,a)!==!1){h=m.event.handlers.call(this,a,j),b=0;while((f=h[b++])&&!a.isPropagationStopped()){a.currentTarget=f.elem,g=0;while((e=f.handlers[g++])&&!a.isImmediatePropagationStopped())(!a.namespace_re||a.namespace_re.test(e.namespace))&&(a.handleObj=e,a.data=e.data,c=((m.event.special[e.origType]||{}).handle||e.handler).apply(f.elem,i),void 0!==c&&(a.result=c)===!1&&(a.preventDefault(),a.stopPropagation()))}return k.postDispatch&&k.postDispatch.call(this,a),a.result}},handlers:function(a,b){var c,d,e,f,g=[],h=b.delegateCount,i=a.target;if(h&&i.nodeType&&(!a.button||"click"!==a.type))for(;i!=this;i=i.parentNode||this)if(1===i.nodeType&&(i.disabled!==!0||"click"!==a.type)){for(e=[],f=0;h>f;f++)d=b[f],c=d.selector+" ",void 0===e[c]&&(e[c]=d.needsContext?m(c,this).index(i)>=0:m.find(c,this,null,[i]).length),e[c]&&e.push(d);e.length&&g.push({elem:i,handlers:e})}return h]","i"),hb=/^\s+/,ib=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/gi,jb=/<([\w:]+)/,kb=/\s*$/g,rb={option:[1,""],legend:[1,"
","
"],area:[1,"",""],param:[1,"",""],thead:[1,"","
"],tr:[2,"","
"],col:[2,"","
"],td:[3,"","
"],_default:k.htmlSerialize?[0,"",""]:[1,"X
","
"]},sb=db(y),tb=sb.appendChild(y.createElement("div"));rb.optgroup=rb.option,rb.tbody=rb.tfoot=rb.colgroup=rb.caption=rb.thead,rb.th=rb.td;function ub(a,b){var c,d,e=0,f=typeof a.getElementsByTagName!==K?a.getElementsByTagName(b||"*"):typeof a.querySelectorAll!==K?a.querySelectorAll(b||"*"):void 0;if(!f)for(f=[],c=a.childNodes||a;null!=(d=c[e]);e++)!b||m.nodeName(d,b)?f.push(d):m.merge(f,ub(d,b));return void 0===b||b&&m.nodeName(a,b)?m.merge([a],f):f}function vb(a){W.test(a.type)&&(a.defaultChecked=a.checked)}function wb(a,b){return m.nodeName(a,"table")&&m.nodeName(11!==b.nodeType?b:b.firstChild,"tr")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function xb(a){return a.type=(null!==m.find.attr(a,"type"))+"/"+a.type,a}function yb(a){var b=pb.exec(a.type);return b?a.type=b[1]:a.removeAttribute("type"),a}function zb(a,b){for(var c,d=0;null!=(c=a[d]);d++)m._data(c,"globalEval",!b||m._data(b[d],"globalEval"))}function Ab(a,b){if(1===b.nodeType&&m.hasData(a)){var c,d,e,f=m._data(a),g=m._data(b,f),h=f.events;if(h){delete g.handle,g.events={};for(c in h)for(d=0,e=h[c].length;e>d;d++)m.event.add(b,c,h[c][d])}g.data&&(g.data=m.extend({},g.data))}}function Bb(a,b){var c,d,e;if(1===b.nodeType){if(c=b.nodeName.toLowerCase(),!k.noCloneEvent&&b[m.expando]){e=m._data(b);for(d in e.events)m.removeEvent(b,d,e.handle);b.removeAttribute(m.expando)}"script"===c&&b.text!==a.text?(xb(b).text=a.text,yb(b)):"object"===c?(b.parentNode&&(b.outerHTML=a.outerHTML),k.html5Clone&&a.innerHTML&&!m.trim(b.innerHTML)&&(b.innerHTML=a.innerHTML)):"input"===c&&W.test(a.type)?(b.defaultChecked=b.checked=a.checked,b.value!==a.value&&(b.value=a.value)):"option"===c?b.defaultSelected=b.selected=a.defaultSelected:("input"===c||"textarea"===c)&&(b.defaultValue=a.defaultValue)}}m.extend({clone:function(a,b,c){var d,e,f,g,h,i=m.contains(a.ownerDocument,a);if(k.html5Clone||m.isXMLDoc(a)||!gb.test("<"+a.nodeName+">")?f=a.cloneNode(!0):(tb.innerHTML=a.outerHTML,tb.removeChild(f=tb.firstChild)),!(k.noCloneEvent&&k.noCloneChecked||1!==a.nodeType&&11!==a.nodeType||m.isXMLDoc(a)))for(d=ub(f),h=ub(a),g=0;null!=(e=h[g]);++g)d[g]&&Bb(e,d[g]);if(b)if(c)for(h=h||ub(a),d=d||ub(f),g=0;null!=(e=h[g]);g++)Ab(e,d[g]);else Ab(a,f);return d=ub(f,"script"),d.length>0&&zb(d,!i&&ub(a,"script")),d=h=e=null,f},buildFragment:function(a,b,c,d){for(var e,f,g,h,i,j,l,n=a.length,o=db(b),p=[],q=0;n>q;q++)if(f=a[q],f||0===f)if("object"===m.type(f))m.merge(p,f.nodeType?[f]:f);else if(lb.test(f)){h=h||o.appendChild(b.createElement("div")),i=(jb.exec(f)||["",""])[1].toLowerCase(),l=rb[i]||rb._default,h.innerHTML=l[1]+f.replace(ib,"<$1>")+l[2],e=l[0];while(e--)h=h.lastChild;if(!k.leadingWhitespace&&hb.test(f)&&p.push(b.createTextNode(hb.exec(f)[0])),!k.tbody){f="table"!==i||kb.test(f)?""!==l[1]||kb.test(f)?0:h:h.firstChild,e=f&&f.childNodes.length;while(e--)m.nodeName(j=f.childNodes[e],"tbody")&&!j.childNodes.length&&f.removeChild(j)}m.merge(p,h.childNodes),h.textContent="";while(h.firstChild)h.removeChild(h.firstChild);h=o.lastChild}else p.push(b.createTextNode(f));h&&o.removeChild(h),k.appendChecked||m.grep(ub(p,"input"),vb),q=0;while(f=p[q++])if((!d||-1===m.inArray(f,d))&&(g=m.contains(f.ownerDocument,f),h=ub(o.appendChild(f),"script"),g&&zb(h),c)){e=0;while(f=h[e++])ob.test(f.type||"")&&c.push(f)}return h=null,o},cleanData:function(a,b){for(var d,e,f,g,h=0,i=m.expando,j=m.cache,l=k.deleteExpando,n=m.event.special;null!=(d=a[h]);h++)if((b||m.acceptData(d))&&(f=d[i],g=f&&j[f])){if(g.events)for(e in g.events)n[e]?m.event.remove(d,e):m.removeEvent(d,e,g.handle);j[f]&&(delete j[f],l?delete d[i]:typeof d.removeAttribute!==K?d.removeAttribute(i):d[i]=null,c.push(f))}}}),m.fn.extend({text:function(a){return V(this,function(a){return void 0===a?m.text(this):this.empty().append((this[0]&&this[0].ownerDocument||y).createTextNode(a))},null,a,arguments.length)},append:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.appendChild(a)}})},prepend:function(){return this.domManip(arguments,function(a){if(1===this.nodeType||11===this.nodeType||9===this.nodeType){var b=wb(this,a);b.insertBefore(a,b.firstChild)}})},before:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this)})},after:function(){return this.domManip(arguments,function(a){this.parentNode&&this.parentNode.insertBefore(a,this.nextSibling)})},remove:function(a,b){for(var c,d=a?m.filter(a,this):this,e=0;null!=(c=d[e]);e++)b||1!==c.nodeType||m.cleanData(ub(c)),c.parentNode&&(b&&m.contains(c.ownerDocument,c)&&zb(ub(c,"script")),c.parentNode.removeChild(c));return this},empty:function(){for(var a,b=0;null!=(a=this[b]);b++){1===a.nodeType&&m.cleanData(ub(a,!1));while(a.firstChild)a.removeChild(a.firstChild);a.options&&m.nodeName(a,"select")&&(a.options.length=0)}return this},clone:function(a,b){return a=null==a?!1:a,b=null==b?a:b,this.map(function(){return m.clone(this,a,b)})},html:function(a){return V(this,function(a){var b=this[0]||{},c=0,d=this.length;if(void 0===a)return 1===b.nodeType?b.innerHTML.replace(fb,""):void 0;if(!("string"!=typeof a||mb.test(a)||!k.htmlSerialize&&gb.test(a)||!k.leadingWhitespace&&hb.test(a)||rb[(jb.exec(a)||["",""])[1].toLowerCase()])){a=a.replace(ib,"<$1>");try{for(;d>c;c++)b=this[c]||{},1===b.nodeType&&(m.cleanData(ub(b,!1)),b.innerHTML=a);b=0}catch(e){}}b&&this.empty().append(a)},null,a,arguments.length)},replaceWith:function(){var a=arguments[0];return this.domManip(arguments,function(b){a=this.parentNode,m.cleanData(ub(this)),a&&a.replaceChild(b,this)}),a&&(a.length||a.nodeType)?this:this.remove()},detach:function(a){return this.remove(a,!0)},domManip:function(a,b){a=e.apply([],a);var c,d,f,g,h,i,j=0,l=this.length,n=this,o=l-1,p=a[0],q=m.isFunction(p);if(q||l>1&&"string"==typeof p&&!k.checkClone&&nb.test(p))return this.each(function(c){var d=n.eq(c);q&&(a[0]=p.call(this,c,d.html())),d.domManip(a,b)});if(l&&(i=m.buildFragment(a,this[0].ownerDocument,!1,this),c=i.firstChild,1===i.childNodes.length&&(i=c),c)){for(g=m.map(ub(i,"script"),xb),f=g.length;l>j;j++)d=i,j!==o&&(d=m.clone(d,!0,!0),f&&m.merge(g,ub(d,"script"))),b.call(this[j],d,j);if(f)for(h=g[g.length-1].ownerDocument,m.map(g,yb),j=0;f>j;j++)d=g[j],ob.test(d.type||"")&&!m._data(d,"globalEval")&&m.contains(h,d)&&(d.src?m._evalUrl&&m._evalUrl(d.src):m.globalEval((d.text||d.textContent||d.innerHTML||"").replace(qb,"")));i=c=null}return this}}),m.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){m.fn[a]=function(a){for(var c,d=0,e=[],g=m(a),h=g.length-1;h>=d;d++)c=d===h?this:this.clone(!0),m(g[d])[b](c),f.apply(e,c.get());return this.pushStack(e)}});var Cb,Db={};function Eb(b,c){var d,e=m(c.createElement(b)).appendTo(c.body),f=a.getDefaultComputedStyle&&(d=a.getDefaultComputedStyle(e[0]))?d.display:m.css(e[0],"display");return e.detach(),f}function Fb(a){var b=y,c=Db[a];return c||(c=Eb(a,b),"none"!==c&&c||(Cb=(Cb||m("