[Python-modules-commits] [python-textile] 01/01: Import python-textile_2.3.5.orig.tar.gz

Dmitry Shachnev mitya57 at moszumanska.debian.org
Wed Nov 9 17:39:33 UTC 2016


This is an automated email from the git hooks/post-receive script.

mitya57 pushed a commit to branch upstream
in repository python-textile.

commit d58be00ec960e3f250402f28ea47cfe756fac9f4
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date:   Wed Nov 9 20:38:43 2016 +0300

    Import python-textile_2.3.5.orig.tar.gz
---
 CHANGELOG.textile           | 10 ++++++++++
 MANIFEST.in                 | 11 +++++++++++
 README.textile              |  6 +-----
 setup.py                    |  5 +++++
 tests/fixtures/README.txt   | 46 +++++++++++++++++++++++++++++++++++++++++++++
 tests/test_block.py         | 21 ++++++++++++++++++---
 tests/test_cli.py           | 16 ++++++++++++++++
 tests/test_github_issues.py |  6 ++++++
 tests/test_values.py        |  8 ++++----
 textile/__main__.py         | 31 ++++++++++++++++++++++++++++++
 textile/core.py             | 19 +++++++++++++++----
 textile/objects/block.py    |  6 ++++--
 textile/regex_strings.py    |  1 -
 textile/utils.py            |  2 +-
 textile/version.py          |  2 +-
 15 files changed, 169 insertions(+), 21 deletions(-)

diff --git a/CHANGELOG.textile b/CHANGELOG.textile
index 9f8ffcd..c822ed1 100644
--- a/CHANGELOG.textile
+++ b/CHANGELOG.textile
@@ -1,5 +1,15 @@
 h1. Textile Changelog
 
+h2. Version 2.3.5
+* Bugfix: Correctly handle unicode text in url query-strings. ("#36":https://github.com/textile/python-textile/issues/36)
+
+h2. Version 2.3.4
+* Bugfix: fix an issue with extended block code
+* Remove misplaced shebang on non-callable files.
+* Packaging: Add test-command to setup.py directly.
+* Packaging: Included the tests/ directory for source-tarballs, useful for packaging checks. ("#33":https://github.com/textile/python-textile/issues/33)
+* Add a cli tool `pytextile` which takes textile input and prints html output.  See `pytextile -h` for details.
+
 h2. Version 2.3.3
 * Bugfix: Unicode in URL titles no longer break everything ("#30":https://github.com/textile/python-textile/issues/30)
 * Display DeprecationWarning when using textile on Python 2.6.
diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..b0f4cab
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,11 @@
+exclude .gitignore
+exclude TODO.textile
+exclude .travis.yml
+include CHANGELOG.textile
+include CONTRIBUTORS.txt
+include .coveragerc
+include LICENSE.txt
+include MANIFEST.in
+include pytest.ini
+include README.textile
+include requirements.txt
diff --git a/README.textile b/README.textile
index e645e34..a363721 100644
--- a/README.textile
+++ b/README.textile
@@ -14,9 +14,7 @@ Optional dependencies include:
 
 h2. Usage
 
-<pre>
-<code>
->>> import textile
+bc.. import textile
 >>> s = """
 ... _This_ is a *test.*
 ...
@@ -38,8 +36,6 @@ h2. Usage
 
 	<p>Link to <a href="http://slashdot.org/">Slashdot</a></p>
 >>>
-</code>
-</pre>
 
 h3. Notes:
 
diff --git a/setup.py b/setup.py
index 897f07d..b28294c 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,7 @@
 from setuptools import setup, find_packages
 import os
 import sys
+import pytest
 
 def get_version():
     basedir = os.path.dirname(__file__)
@@ -13,6 +14,8 @@ def get_version():
 setup(
     name='textile',
     version=get_version(),
+    author='Dennis Burke',
+    author_email='ikirudennis at gmail.com',
     description='Textile processing for python.',
     url='http://github.com/textile/python-textile',
     packages=find_packages(),
@@ -40,8 +43,10 @@ setup(
         ':python_version=="2.6"': ['ordereddict>=1.1'],
         'develop': ['regex', 'pytest', 'pytest-cov'],
     },
+    entry_points={'console_scripts': ['pytextile=textile.__main__:main']},
     setup_requires=['pytest-runner'],
     tests_require=['pytest', 'pytest-cov'],
+    cmdclass = {'test': pytest},
     include_package_data=True,
     zip_safe=False,
 )
diff --git a/tests/fixtures/README.txt b/tests/fixtures/README.txt
new file mode 100644
index 0000000..426c9aa
--- /dev/null
+++ b/tests/fixtures/README.txt
@@ -0,0 +1,46 @@
+	<p><a href="https://travis-ci.org/textile/python-textile"><img alt="" src="https://travis-ci.org/textile/python-textile.svg" /></a> <a href="https://coveralls.io/github/textile/python-textile?branch=master"><img alt="" src="https://coveralls.io/repos/github/textile/python-textile/badge.svg" /></a> <a href="https://codecov.io/github/textile/python-textile"><img alt="" src="https://codecov.io/github/textile/python-textile/coverage.svg" /></a></p>
+
+	<h1>python-textile</h1>
+
+	<p>python-textile is a Python port of <a href="http://txstyle.org/">Textile</a>, Dean Allen’s humane web text generator.</p>
+
+	<h2>Installation</h2>
+
+	<p><code>pip install textile</code></p>
+
+	<p>Optional dependencies include:
+	<ul>
+		<li><a href="http://python-pillow.github.io/"><span class="caps">PIL</span>/Pillow</a> (for checking images size)</li>
+		<li><a href="https://pypi.python.org/pypi/regex">regex</a> (for faster unicode-aware string matching).</li>
+	</ul></p>
+
+	<h2>Usage</h2>
+
+<pre><code>import textile
+>>> s = """
+... _This_ is a *test.*
+...
+... * One
+... * Two
+... * Three
+...
+... Link to "Slashdot":http://slashdot.org/
+... """
+>>> html = textile.textile(s)
+>>> print html
+	<p><em>This</em> is a <strong>test.</strong></p>
+
+	<ul>
+		<li>One</li>
+		<li>Two</li>
+		<li>Three</li>
+	</ul>
+
+	<p>Link to <a href="http://slashdot.org/">Slashdot</a></p>
+>>></code></pre>
+
+	<h3>Notes:</h3>
+
+	<ul>
+		<li>Active development supports Python 2.6 or later (including Python 3.2+).</li>
+	</ul>
\ No newline at end of file
diff --git a/tests/test_block.py b/tests/test_block.py
index 1687300..0e6dc14 100644
--- a/tests/test_block.py
+++ b/tests/test_block.py
@@ -1,6 +1,6 @@
 from __future__ import unicode_literals
 
-from textile import Textile
+import textile
 from textile.objects import Block
 
 try:
@@ -9,7 +9,7 @@ except ImportError:
     from ordereddict import OrderedDict
 
 def test_block():
-    t = Textile()
+    t = textile.Textile()
     result = t.block('h1. foobar baby')
     expect = '\t<h1>foobar baby</h1>'
     assert result == expect
@@ -41,9 +41,24 @@ def test_block():
     assert result == expect
 
 def test_block_tags_false():
-    t = Textile(block_tags=False)
+    t = textile.Textile(block_tags=False)
     assert t.block_tags is False
 
     result = t.parse('test')
     expect = 'test'
     assert result == expect
+
+def test_blockcode_extended():
+    input = 'bc.. text\nmoretext\n\nevenmoretext\n\nmoremoretext\n\np. test'
+    expect = '<pre><code>text\nmoretext\n\nevenmoretext\n\nmoremoretext</code></pre>\n\n\t<p>test</p>'
+    t = textile.Textile()
+    result = t.parse(input)
+    assert result == expect
+
+def test_blockcode_in_README():
+    with open('README.textile') as f:
+        readme = ''.join(f.readlines())
+    result = textile.textile(readme)
+    with open('tests/fixtures/README.txt') as f:
+        expect = ''.join(f.readlines())
+    assert result == expect
diff --git a/tests/test_cli.py b/tests/test_cli.py
new file mode 100644
index 0000000..bc1e28d
--- /dev/null
+++ b/tests/test_cli.py
@@ -0,0 +1,16 @@
+import six
+import subprocess
+
+def test_console_script():
+    command = ['python', '-m', 'textile', 'README.textile']
+    try:
+        result = subprocess.check_output(command)
+    except AttributeError:
+        command[2] = 'textile.__main__'
+        result = subprocess.Popen(command,
+                stdout=subprocess.PIPE).communicate()[0]
+    with open('tests/fixtures/README.txt') as f:
+        expect = ''.join(f.readlines())
+    if type(result) == bytes:
+        result = result.decode('utf-8')
+    assert result == expect
diff --git a/tests/test_github_issues.py b/tests/test_github_issues.py
index 20448c7..bf9c339 100644
--- a/tests/test_github_issues.py
+++ b/tests/test_github_issues.py
@@ -85,3 +85,9 @@ def test_github_issue_30():
     result = textile.textile(text)
     expect = '\t<p><a href="http://lala.com" title="Tëxtíle">Tëxtíle</a></p>'
     assert result == expect
+
+def test_github_issue_36():
+    text = '"Chögyam Trungpa":https://www.google.com/search?q=Chögyam+Trungpa'
+    result = textile.textile(text)
+    expect = '\t<p><a href="https://www.google.com/search?q=Chögyam+Trungpa">Chögyam Trungpa</a></p>'
+    assert result == expect
diff --git a/tests/test_values.py b/tests/test_values.py
index 4a6fe60..a67cfa6 100644
--- a/tests/test_values.py
+++ b/tests/test_values.py
@@ -150,7 +150,7 @@ xhtml_known_values = (
 
     ('<script>alert("hello");</script>', '\t<p><script>alert(“hello”);</script></p>'),
 
-    ('pre.. Hello\n\nHello Again\n\np. normal text', '<pre>Hello\n\nHello Again\n</pre>\n\n\t<p>normal text</p>'),
+    ('pre.. Hello\n\nHello Again\n\np. normal text', '<pre>Hello\n\nHello Again</pre>\n\n\t<p>normal text</p>'),
 
     ('<pre>this is in a pre tag</pre>', '<pre>this is in a pre tag</pre>'),
 
@@ -180,7 +180,7 @@ xhtml_known_values = (
 
     ('h2. A header\n\n\n\n\n\nsome text', '\t<h2>A header</h2>\n\n\t<p>some text</p>'),
 
-    ('pre.. foo bar baz\nquux', '<pre>foo bar baz\nquux\n</pre>'),
+    ('pre.. foo bar baz\nquux', '<pre>foo bar baz\nquux</pre>'),
 
     ('line of text\n\n    leading spaces',
      '\t<p>line of text</p>\n\n    leading spaces'),
@@ -286,11 +286,11 @@ html_known_values = (
     # issue 2 escaping
     ('"foo ==(bar)==":#foobar', '\t<p><a href="#foobar">foo (bar)</a></p>'),
     # issue 14 newlines in extended pre blocks
-    ("pre.. Hello\n\nAgain\n\np. normal text", '<pre>Hello\n\nAgain\n</pre>\n\n\t<p>normal text</p>'),
+    ("pre.. Hello\n\nAgain\n\np. normal text", '<pre>Hello\n\nAgain</pre>\n\n\t<p>normal text</p>'),
     # url with parentheses
     ('"python":http://en.wikipedia.org/wiki/Python_(programming_language)', '\t<p><a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29">python</a></p>'),
     # table with hyphen styles
-    ('table(linkblog-thumbnail).\n|(linkblog-thumbnail-cell). apple|bear|', '\t<table class="linkblog-thumbnail">\n\t\t<tr>\n\t\t\t<td class="linkblog-thumbnail-cell" style="vertical-align:middle;">apple</td>\n\t\t\t<td>bear</td>\n\t\t</tr>\n\t</table>'),
+    ('table(linkblog-thumbnail).\n|(linkblog-thumbnail-cell). apple|bear|', '\t<table class="linkblog-thumbnail">\n\t\t<tr>\n\t\t\t<td class="linkblog-thumbnail-cell">apple</td>\n\t\t\t<td>bear</td>\n\t\t</tr>\n\t</table>'),
     # issue 32 empty table cells
     ("|thing|||otherthing|", "\t<table>\n\t\t<tr>\n\t\t\t<td>thing</td>\n\t\t\t<td></td>\n\t\t\t<td></td>\n\t\t\t<td>otherthing</td>\n\t\t</tr>\n\t</table>"),
     # issue 36 link reference names http and https
diff --git a/textile/__main__.py b/textile/__main__.py
new file mode 100644
index 0000000..481b976
--- /dev/null
+++ b/textile/__main__.py
@@ -0,0 +1,31 @@
+import argparse
+import sys
+import textile
+
+
+def main():
+    """A CLI tool in the style of python's json.tool.  In fact, this is mostly
+    copied directly from that module.  This allows us to create a stand-alone
+    tool as well as invoking it via `python -m textile`."""
+    prog = 'textile'
+    description = ('A simple command line interface for textile module '
+                   'to convert textile input to HTML output.  This script '
+                   'accepts input as a file or stdin and can write out to '
+                   'a file or stdout.')
+    parser = argparse.ArgumentParser(prog=prog, description=description)
+    parser.add_argument('infile', nargs='?', type=argparse.FileType(),
+                        help='a textile file to be converted')
+    parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'),
+                        help='write the output of infile to outfile')
+    options = parser.parse_args()
+
+    infile = options.infile or sys.stdin
+    outfile = options.outfile or sys.stdout
+    with infile:
+        output = textile.textile(''.join(infile.readlines()))
+    with outfile:
+        outfile.write(output)
+
+
+if __name__ == '__main__': #pragma: no cover
+    main()
diff --git a/textile/core.py b/textile/core.py
index 7cc7439..692cca4 100644
--- a/textile/core.py
+++ b/textile/core.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
@@ -421,6 +420,7 @@ class Textile(object):
         tag = 'p'
         atts = cite = graf = ext = ''
 
+        last_item_is_a_shelf = False
         out = []
 
         for line in text:
@@ -430,6 +430,16 @@ class Textile(object):
             match = re.search(pattern, line, flags=re.S | re.U)
             # tag specified on this line.
             if match:
+                # if we had a previous extended tag but not this time, close up
+                # the tag
+                if out:
+                    last_item_is_a_shelf = out[-1] in self.shelf
+                if ext and match.group('tag') and last_item_is_a_shelf:
+                    content = out.pop()
+                    content = generate_tag(block.inner_tag, content,
+                            block.inner_atts)
+                    out.append(generate_tag(block.outer_tag, content,
+                        block.outer_atts))
                 tag, atts, ext, cite, content = match.groups()
                 block = Block(self, **match.groupdict())
                 inner_block = generate_tag(block.inner_tag, block.content,
@@ -450,7 +460,7 @@ class Textile(object):
                 # if we're inside an extended block, add the text from the
                 # previous extension to the front
                 if ext:
-                    line = '{0}\n{1}'.format(out.pop(), line)
+                    line = '{0}\n\n{1}'.format(out.pop(), line)
                 whitespace = ' \t\n\r\f\v'
                 if ext or not line[0] in whitespace:
                     block = Block(self, tag, atts, ext, cite, line)
@@ -459,6 +469,8 @@ class Textile(object):
                     else:
                         line = generate_tag(block.outer_tag, block.content,
                                 block.outer_atts)
+                        if block.inner_tag == 'code':
+                            line = block.content
                         if block.outer_tag != 'pre' and not has_raw_text(line):
                             line = "\t{0}".format(line)
                 else:
@@ -926,7 +938,6 @@ class Textile(object):
             quote(unquote(pce).encode('utf8'), b'')
             for pce in parsed.path.split('/')
         )
-        query = quote(unquote(parsed.query), b'=&?/')
         fragment = quote(unquote(parsed.fragment))
 
         # put it back together
@@ -939,7 +950,7 @@ class Textile(object):
         netloc = '{0}{1}'.format(netloc, host)
         if port:
             netloc = '{0}:{1}'.format(netloc, port)
-        return urlunsplit((scheme, netloc, path, query, fragment))
+        return urlunsplit((scheme, netloc, path, parsed.query, fragment))
 
     def span(self, text):
         qtags = (r'\*\*', r'\*', r'\?\?', r'\-', r'__',
diff --git a/textile/objects/block.py b/textile/objects/block.py
index 7b46bc1..920147a 100644
--- a/textile/objects/block.py
+++ b/textile/objects/block.py
@@ -99,8 +99,10 @@ class Block(object):
             i_tag = ''
             if self.tag == 'bc':
                 i_tag = 'code'
-            self.content = self.textile.shelve(encode_html('{0}\n'.format(
-                self.content.rstrip("\n"))))
+            content = encode_html(self.content)
+            if not self.ext:
+                content = '{0}\n'.format(content)
+            self.content = self.textile.shelve(content)
             self.outer_tag = 'pre'
             self.outer_atts = self.attributes
             self.inner_tag = i_tag
diff --git a/textile/regex_strings.py b/textile/regex_strings.py
index 23c1569..a152072 100644
--- a/textile/regex_strings.py
+++ b/textile/regex_strings.py
@@ -1,4 +1,3 @@
-#!/usr/bin/env python
 # -*- coding: utf-8 -*-
 from __future__ import unicode_literals
 
diff --git a/textile/utils.py b/textile/utils.py
index 89e35e8..00da831 100644
--- a/textile/utils.py
+++ b/textile/utils.py
@@ -143,7 +143,7 @@ def parse_attributes(block_attributes, element=None, include_id=True):
             rowspan = m.group(1)
 
     if element == 'td' or element == 'tr':
-        m = re.search(r'({0})'.format(valign_re_s), matched)
+        m = re.search(r'(^{0})'.format(valign_re_s), matched)
         if m:
             style.append("vertical-align:{0}".format(vAlign[m.group(1)]))
 
diff --git a/textile/version.py b/textile/version.py
index 47cb28f..b4ab188 100644
--- a/textile/version.py
+++ b/textile/version.py
@@ -1 +1 @@
-VERSION = '2.3.3'
+VERSION = '2.3.5'

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-textile.git



More information about the Python-modules-commits mailing list