[Python-modules-commits] [python-textile] 02/05: Import python-textile_2.3.2.orig.tar.gz

Dmitry Shachnev mitya57 at moszumanska.debian.org
Wed Jun 22 18:11:52 UTC 2016


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

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

commit 1d5ff1880d1893e02880d4377c2207ce58dc9a9f
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date:   Wed Jun 22 21:04:03 2016 +0300

    Import python-textile_2.3.2.orig.tar.gz
---
 .coveragerc                           |    7 +
 .gitignore                            |   22 +
 .travis.yml                           |   25 +
 CHANGELOG.textile                     |   42 +
 CONTRIBUTORS.txt                      |    8 +
 LICENSE.txt                           |   27 +
 PKG-INFO                              |   18 -
 README.textile                        |   46 +
 TODO.textile                          |    6 +
 pytest.ini                            |    3 +
 requirements.txt                      |    2 +
 setup.cfg                             |   18 +-
 setup.py                              |   26 +-
 tests/test_attributes.py              |   15 +
 tests/test_block.py                   |   49 +
 tests/test_footnoteRef.py             |    8 +
 tests/test_getRefs.py                 |   11 +
 tests/test_getimagesize.py            |    9 +
 tests/test_github_issues.py           |   81 ++
 tests/test_glyphs.py                  |   32 +
 tests/test_image.py                   |   21 +
 tests/test_imagesize.py               |   13 +
 tests/test_lists.py                   |    7 +
 tests/test_retrieve.py                |    6 +
 tests/test_span.py                    |   19 +
 tests/test_subclassing.py             |   17 +
 tests/test_table.py                   |   12 +
 tests/test_textile.py                 |  191 ++++
 tests/test_textilefactory.py          |   28 +
 tests/test_urls.py                    |   53 +
 tests/test_utils.py                   |   30 +
 tests/test_values.py                  |  322 ++++++
 textile.egg-info/PKG-INFO             |   18 -
 textile.egg-info/SOURCES.txt          |   17 -
 textile.egg-info/dependency_links.txt |    1 -
 textile.egg-info/not-zip-safe         |    1 -
 textile.egg-info/requires.txt         |    3 -
 textile.egg-info/top_level.txt        |    1 -
 textile/core.py                       | 1783 ++++++++++++++-------------------
 textile/objects/__init__.py           |    4 +
 textile/objects/block.py              |  123 +++
 textile/objects/table.py              |  227 +++++
 textile/regex_strings.py              |   56 ++
 textile/tests/__init__.py             |  611 -----------
 textile/textilefactory.py             |   43 +-
 textile/tools/doctest_utils.py        |   92 --
 textile/tools/imagesize.py            |   12 -
 textile/utils.py                      |  217 ++++
 textile/version.py                    |    2 +-
 49 files changed, 2488 insertions(+), 1897 deletions(-)

diff --git a/.coveragerc b/.coveragerc
new file mode 100644
index 0000000..48226e5
--- /dev/null
+++ b/.coveragerc
@@ -0,0 +1,7 @@
+[run]
+branch = True
+
+[report]
+show_missing = True
+omit = 
+	textile/tests/*
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..d459988
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,22 @@
+*.pyc
+*.orig
+*.rej
+*~
+*.pyo
+*.egg-info
+.cache/
+.coverage
+.eggs/
+.noseids*
+docs/build
+docs/coverage
+build
+bin
+dist
+eggs
+htmlcov
+parts
+develop-eggs
+.DS_Store
+*.swp
+.tox
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..7f40ce9
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,25 @@
+language: python
+env:
+  - REQUIREMENTS=true
+  - REQUIREMENTS=false
+python:
+  - "2.6"
+  - "2.7"
+  - "3.2"
+  - "3.3"
+  - "3.4"
+  - "3.5"
+  - "pypy"
+# command to install dependencies
+install:
+  - if [[ $REQUIREMENTS == true ]] ; then pip install -r requirements.txt ; fi
+  - if [[ $TRAVIS_PYTHON_VERSION == '3.2' ]] ; then pip install coverage==3.7.1; fi
+  - pip install coveralls pytest pytest-cov coverage codecov
+  - pip install -e .
+  - if [[ ! $TRAVIS_PYTHON_VERSION == 'pypy' ]] ; then pip install regex; fi
+# command to run tests
+script: py.test
+sudo: false
+after_success:
+  - coveralls
+  - codecov
diff --git a/CHANGELOG.textile b/CHANGELOG.textile
new file mode 100644
index 0000000..06f8e8d
--- /dev/null
+++ b/CHANGELOG.textile
@@ -0,0 +1,42 @@
+h1. Textile Changelog
+
+h2. Version 2.3.2
+* Bugfix: properly handle @":"@ as text, not a link.
+
+h2. Version 2.3.1
+* Regression bugfix: empty string input returns empty string again.
+
+h2. Version 2.3.0
+
+* Bugfixes:
+** Support data URIs in img tags
+** Fix autolink urls with image references ("#17":https://github.com/textile/python-textile/issues/17)
+** Fix textile links containing parentheses ("#20":https://github.com/textile/python-textile/issues/20)
+** Fix double-encoding of code blocks ("#21":https://github.com/textile/python-textile/issues/21)
+** Fix handling of scheme in self-linked URLs ("#16":https://github.com/textile/python-textile/issues/16)
+** Fix Markup not parsed if followed by certain characters ("#22":Markup not parsed if followed by certain characters)
+* Convert testing over to "py.test":http://pytest.org/, improving unicode testing
+* Update functionality for tables, notelists, and footnotes.  This involved a major reworking of parts of the code, but it should now match php-textile and txstyle.org precisely.  Please file an issue for any bugs you come across.
+* Remove @head_offset@ option from parse.  I'm not sure it ever existed in php-textile.
+
+h2. Version 2.2.2
+
+* bugfix: "regex":https://pypi.python.org/pypi/regex is now an optional dependency
+
+h2. Version 2.2.1
+
+* drop textilefactory support for html.
+* Various development-related bugfixes.
+* Added this changelog.
+
+h2. Version 2.2.0
+
+* Started refactoring the code to be less repetitive.  @textile.Textile().parse()@ is a little more friendly than @textile.Textile().textile()@  There may be more work to be done on this front to make the flow a little smoother.
+* We now support versions 2.6 - 3.4 (including 3.2) using the same codebase.  Many thanks to Radek Czajka for this.
+* Drop support for html4.  We now only output xhtml or html5.
+* Various development-related bugfixes.
+
+h2. Version 2.1.8
+
+* Add support for html5 output.
+* Lots of new functionality added bringing us in line with the official Textile 2.4
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
new file mode 100644
index 0000000..5addb2b
--- /dev/null
+++ b/CONTRIBUTORS.txt
@@ -0,0 +1,8 @@
+Dennis Burke
+Radek Czajka
+Roberto A. F. De Almeida
+Matt Layman
+Mark Pilgrim
+Alex Shiels
+Jason Samsa
+Kurt Raschke
\ No newline at end of file
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 0000000..d6c526a
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,27 @@
+L I C E N S E
+=============
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice,
+  this list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+  this list of conditions and the following disclaimer in the documentation
+  and/or other materials provided with the distribution.
+
+* Neither the name Textile nor the names of its contributors may be used to
+  endorse or promote products derived from this software without specific
+  prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
\ No newline at end of file
diff --git a/PKG-INFO b/PKG-INFO
deleted file mode 100644
index dbf3933..0000000
--- a/PKG-INFO
+++ /dev/null
@@ -1,18 +0,0 @@
-Metadata-Version: 1.1
-Name: textile
-Version: 2.2.2
-Summary: Textile processing for python.
-Home-page: http://github.com/textile/python-textile
-Author: UNKNOWN
-Author-email: UNKNOWN
-License: UNKNOWN
-Description: UNKNOWN
-Keywords: textile,text
-Platform: UNKNOWN
-Classifier: Development Status :: 5 - Production/Stable
-Classifier: Environment :: Web Environment
-Classifier: Intended Audience :: Developers
-Classifier: License :: OSI Approved :: BSD License
-Classifier: Operating System :: OS Independent
-Classifier: Programming Language :: Python
-Classifier: Topic :: Software Development :: Libraries :: Python Modules
diff --git a/README.textile b/README.textile
new file mode 100644
index 0000000..e645e34
--- /dev/null
+++ b/README.textile
@@ -0,0 +1,46 @@
+!https://travis-ci.org/textile/python-textile.svg!:https://travis-ci.org/textile/python-textile !https://coveralls.io/repos/github/textile/python-textile/badge.svg!:https://coveralls.io/github/textile/python-textile?branch=master !https://codecov.io/github/textile/python-textile/coverage.svg!:https://codecov.io/github/textile/python-textile
+
+h1. python-textile
+
+python-textile is a Python port of "Textile":http://txstyle.org/, Dean Allen's humane web text generator.
+
+h2. Installation
+
+ at pip install textile@
+
+Optional dependencies include:
+* "PIL/Pillow":http://python-pillow.github.io/ (for checking images size)
+* "regex":https://pypi.python.org/pypi/regex (for faster unicode-aware string matching).
+
+h2. Usage
+
+<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:
+
+* Active development supports Python 2.6 or later (including Python 3.2+).
diff --git a/TODO.textile b/TODO.textile
new file mode 100644
index 0000000..8b5cfac
--- /dev/null
+++ b/TODO.textile
@@ -0,0 +1,6 @@
+TODO
+
+* Improve documentation, both of the code and Textile syntax.
+** Not all functions have docstrings or adequate docstrings.
+** Because the Textile syntax implemented by PyTextile has deviated from the syntax implemented by other implementations of Textile, PyTextile-specific documentation needs to be produced for end-users.
+* Update to comply with Textile 2.5
diff --git a/pytest.ini b/pytest.ini
new file mode 100644
index 0000000..882527b
--- /dev/null
+++ b/pytest.ini
@@ -0,0 +1,3 @@
+[pytest]
+testpaths = tests
+addopts = --cov=textile --cov-report=html --cov-append --cov-report=term-missing
\ No newline at end of file
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..5cfb442
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1,2 @@
+html5lib==0.999
+Pillow==3.0.0
\ No newline at end of file
diff --git a/setup.cfg b/setup.cfg
index 2829b29..3a3405b 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,16 +1,4 @@
-[nosetests]
-detailed-errors = 1
-with-coverage = 1
-cover-package = textile
-cover-erase = 1
-with-doctest = 1
-with-id = 1
-
+[aliases]
+test=pytest
 [bdist_wheel]
-universal = 1
-
-[egg_info]
-tag_build = 
-tag_date = 0
-tag_svn_revision = 0
-
+universal=1
diff --git a/setup.py b/setup.py
index 386c774..897f07d 100644
--- a/setup.py
+++ b/setup.py
@@ -2,14 +2,6 @@ from setuptools import setup, find_packages
 import os
 import sys
 
-install_requires = []
-
-
-if 'develop' in sys.argv:
-    install_requires.extend([
-        'tox',
-    ])
-
 def get_version():
     basedir = os.path.dirname(__file__)
     with open(os.path.join(basedir, 'textile/version.py')) as f:
@@ -32,14 +24,24 @@ setup(
         'Operating System :: OS Independent',
         'Programming Language :: Python',
         'Topic :: Software Development :: Libraries :: Python Modules',
+        'Programming Language :: Python',
+        'Programming Language :: Python :: 2',
+        'Programming Language :: Python :: 2.6',
+        'Programming Language :: Python :: 2.7',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.2',
+        'Programming Language :: Python :: 3.3',
+        'Programming Language :: Python :: 3.4',
+        'Programming Language :: Python :: 3.5',
     ],
-    keywords='textile,text',
-    install_requires=install_requires,
+    keywords='textile,text,html markup',
+    install_requires=['six',],
     extras_require={
         ':python_version=="2.6"': ['ordereddict>=1.1'],
+        'develop': ['regex', 'pytest', 'pytest-cov'],
     },
-    test_suite='nose.collector',
-    tests_require=['nose'],
+    setup_requires=['pytest-runner'],
+    tests_require=['pytest', 'pytest-cov'],
     include_package_data=True,
     zip_safe=False,
 )
diff --git a/tests/test_attributes.py b/tests/test_attributes.py
new file mode 100644
index 0000000..70da842
--- /dev/null
+++ b/tests/test_attributes.py
@@ -0,0 +1,15 @@
+from textile.utils import parse_attributes
+import re
+
+def test_parse_attributes():
+    assert parse_attributes('\\1', element='td') == {'colspan': '1'}
+    assert parse_attributes('/1', element='td') == {'rowspan': '1'}
+    assert parse_attributes('^', element='td') == {'style': 'vertical-align:top;'}
+    assert parse_attributes('{color: blue}') == {'style': 'color: blue;'}
+    assert parse_attributes('[en]') == {'lang': 'en'}
+    assert parse_attributes('(cssclass)') == {'class': 'cssclass'}
+    assert parse_attributes('(') == {'style': 'padding-left:1em;'}
+    assert parse_attributes(')') == {'style': 'padding-right:1em;'}
+    assert parse_attributes('<') == {'style': 'text-align:left;'}
+    assert parse_attributes('(c#i)') == {'class': 'c', 'id': 'i'}
+    assert parse_attributes('\\2 100', element='col') == {'span': '2', 'width': '100'}
diff --git a/tests/test_block.py b/tests/test_block.py
new file mode 100644
index 0000000..1687300
--- /dev/null
+++ b/tests/test_block.py
@@ -0,0 +1,49 @@
+from __future__ import unicode_literals
+
+from textile import Textile
+from textile.objects import Block
+
+try:
+    from collections import OrderedDict
+except ImportError:
+    from ordereddict import OrderedDict
+
+def test_block():
+    t = Textile()
+    result = t.block('h1. foobar baby')
+    expect = '\t<h1>foobar baby</h1>'
+    assert result == expect
+
+    b = Block(t, "bq", "", None, "", "Hello BlockQuote")
+    expect = ('blockquote', OrderedDict(), 'p', OrderedDict(),
+            'Hello BlockQuote')
+    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts, b.content)
+    assert result == expect
+
+    b = Block(t, "bq", "", None, "http://google.com", "Hello BlockQuote")
+    citation = '{0}1:url'.format(t.uid)
+    expect = ('blockquote', OrderedDict([('cite',
+        '{0.uid}{0.refIndex}:url'.format(t))]), 'p', OrderedDict(),
+        'Hello BlockQuote')
+    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts, b.content)
+    assert result == expect
+
+    b = Block(t, "bc", "", None, "", 'printf "Hello, World";')
+    # the content of text will be turned shelved, so we'll asert only the
+    # deterministic portions of the expected values, below
+    expect = ('pre', OrderedDict(), 'code', OrderedDict())
+    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts)
+    assert result == expect
+
+    b = Block(t, "h1", "", None, "", "foobar")
+    expect = ('h1', OrderedDict(), '', OrderedDict(), 'foobar')
+    result = (b.outer_tag, b.outer_atts, b.inner_tag, b.inner_atts, b.content)
+    assert result == expect
+
+def test_block_tags_false():
+    t = Textile(block_tags=False)
+    assert t.block_tags is False
+
+    result = t.parse('test')
+    expect = 'test'
+    assert result == expect
diff --git a/tests/test_footnoteRef.py b/tests/test_footnoteRef.py
new file mode 100644
index 0000000..b773ad2
--- /dev/null
+++ b/tests/test_footnoteRef.py
@@ -0,0 +1,8 @@
+from textile import Textile
+import re
+
+def test_footnoteRef():
+    t = Textile()
+    result = t.footnoteRef('foo[1]')
+    expect = 'foo<sup class="footnote" id="fnrev{0}1"><a href="#fn{0}1">1</a></sup>'.format(t.linkPrefix)
+    assert expect == result
diff --git a/tests/test_getRefs.py b/tests/test_getRefs.py
new file mode 100644
index 0000000..f6e0ae4
--- /dev/null
+++ b/tests/test_getRefs.py
@@ -0,0 +1,11 @@
+from textile import Textile
+
+def test_getRefs():
+    t = Textile()
+    result = t.getRefs("some text [Google]http://www.google.com")
+    expect = 'some text '
+    assert result == expect
+
+    result = t.urlrefs
+    expect = {'Google': 'http://www.google.com'}
+    assert result == expect
diff --git a/tests/test_getimagesize.py b/tests/test_getimagesize.py
new file mode 100644
index 0000000..43f85e3
--- /dev/null
+++ b/tests/test_getimagesize.py
@@ -0,0 +1,9 @@
+from textile.tools.imagesize import getimagesize
+import pytest
+
+PIL = pytest.importorskip('PIL')
+
+def test_imagesize():
+    assert getimagesize("http://www.google.com/intl/en_ALL/images/logo.gif") == (276, 110)
+    assert getimagesize("http://bad.domain/") == ''
+    assert getimagesize("http://www.google.com/robots.txt") is None
diff --git a/tests/test_github_issues.py b/tests/test_github_issues.py
new file mode 100644
index 0000000..fa14237
--- /dev/null
+++ b/tests/test_github_issues.py
@@ -0,0 +1,81 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+
+import textile
+
+def test_github_issue_16():
+    result = textile.textile('"$":http://google.com "$":https://google.com "$":mailto:blackhole at sun.comet')
+    expect = '\t<p><a href="http://google.com">google.com</a> <a href="https://google.com">google.com</a> <a href="mailto:blackhole%40sun.comet">blackhole at sun.comet</a></p>'
+    assert result == expect
+
+def test_github_issue_17():
+    result = textile.textile('!http://www.ox.ac.uk/favicon.ico!')
+    expect = '\t<p><img alt="" src="http://www.ox.ac.uk/favicon.ico" /></p>'
+    assert result == expect
+
+def test_github_issue_20():
+    text = 'This is a link to a ["Wikipedia article about Textile":http://en.wikipedia.org/wiki/Textile_(markup_language)].'
+    result = textile.textile(text)
+    expect = '\t<p>This is a link to a <a href="http://en.wikipedia.org/wiki/Textile_%28markup_language%29">Wikipedia article about Textile</a>.</p>'
+    assert result == expect
+
+def test_github_issue_21():
+    text = '''h1. xml example
+
+bc. 
+<foo>
+  bar
+</foo>'''
+    result = textile.textile(text)
+    expect = '\t<h1>xml example</h1>\n\n<pre><code>\n<foo>\n  bar\n</foo>\n</code></pre>'
+    assert result == expect
+
+def test_github_issue_22():
+    text = '''_(artist-name)Ty Segall_’s'''
+    result = textile.textile(text)
+    expect = '\t<p><em class="artist-name">Ty Segall</em>’s</p>'
+    assert result == expect
+
+def test_github_issue_26():
+    text = ''
+    result = textile.textile(text)
+    expect = ''
+    assert result == expect
+
+def test_github_issue_27():
+    test = """* Folders with ":" in their names are displayed with a forward slash "/" instead. (Filed as "#4581709":/test/link, which was considered "normal behaviour" - quote: "Please note that Finder presents the 'Carbon filesystem' view, regardless of the underlying filesystem.")"""
+    result = textile.textile(test)
+    expect = """\t<ul>\n\t\t<li>Folders with “:” in their names are displayed with a forward slash “/” instead. (Filed as <a href="/test/link">#4581709</a>, which was considered “normal behaviour” – quote: “Please note that Finder presents the ‘Carbon filesystem’ view, regardless of the underlying filesystem.”)</li>\n\t</ul>"""
+    assert result == expect
+
+def test_github_issue_28():
+    test = """So here I am porting my ancient "newspipe":newspipe "front-end":blog/2006/09/30/0950 to "Snakelets":Snakelets and "Python":Python, and I've just trimmed down over 20 lines of "PHP":PHP down to essentially one line of "BeautifulSoup":BeautifulSoup retrieval:
+
+<pre>
+def parseWapProfile(self, url):
+  result = fetch.fetchURL(url)
+  soup = BeautifulStoneSoup(result['data'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
+  try:
+    width, height = soup('prf:screensize')[0].contents[0].split('x')
+  except:
+    width = height = None
+  return {"width": width, "height": height}
+</pre>
+
+Of course there's a lot more error handling to do (and useful data to glean off the "XML":XML), but being able to cut through all the usual parsing crap is immensely gratifying."""
+    result = textile.textile(test)
+    expect = ("""\t<p>So here I am porting my ancient <a href="newspipe">newspipe</a> <a href="blog/2006/09/30/0950">front-end</a> to <a href="Snakelets">Snakelets</a> and <a href="Python">Python</a>, and I’ve just trimmed down over 20 lines of <a href="PHP"><span class="caps">PHP</span></a> down to essentially one line of <a href="BeautifulSoup">BeautifulSoup</a> retrieval:</p>
+
+<pre>
+def parseWapProfile(self, url):
+  result = fetch.fetchURL(url)
+  soup = BeautifulStoneSoup(result['data'], convertEntities=BeautifulStoneSoup.HTML_ENTITIES)
+  try:
+    width, height = soup('prf:screensize')[0].contents[0].split('x')
+  except:
+    width = height = None
+  return {"width": width, "height": height}
+</pre>
+
+\t<p>Of course there’s a lot more error handling to do (and useful data to glean off the <a href="XML"><span class="caps">XML</span></a>), but being able to cut through all the usual parsing crap is immensely gratifying.</p>""")
+    assert result == expect
diff --git a/tests/test_glyphs.py b/tests/test_glyphs.py
new file mode 100644
index 0000000..fcf2636
--- /dev/null
+++ b/tests/test_glyphs.py
@@ -0,0 +1,32 @@
+from textile import Textile
+
+def test_glyphs():
+    t = Textile()
+
+    result = t.glyphs("apostrophe's")
+    expect = 'apostrophe’s'
+    assert result == expect
+
+    result = t.glyphs("back in '88")
+    expect = 'back in ’88'
+    assert result == expect
+
+    result = t.glyphs('foo ...')
+    expect = 'foo …'
+    assert result == expect
+
+    result = t.glyphs('--')
+    expect = '—'
+    assert result == expect
+
+    result = t.glyphs('FooBar[tm]')
+    expect = 'FooBar™'
+    assert result == expect
+
+    result = t.glyphs("<p><cite>Cat's Cradle</cite> by Vonnegut</p>")
+    expect = '<p><cite>Cat’s Cradle</cite> by Vonnegut</p>'
+    assert result == expect
+
+    result = t.glyphs('test"')
+    expect = 'test” '
+    assert result == expect
diff --git a/tests/test_image.py b/tests/test_image.py
new file mode 100644
index 0000000..aad39e2
--- /dev/null
+++ b/tests/test_image.py
@@ -0,0 +1,21 @@
+from textile import Textile
+
+def test_image():
+    t = Textile()
+    result = t.image('!/imgs/myphoto.jpg!:http://jsamsa.com')
+    expect = ('<a href="{0}1:url"><img alt="" src="{0}2:url" /></a>'.format(
+        t.uid))
+    assert result == expect
+    assert t.refCache[1] == 'http://jsamsa.com'
+    assert t.refCache[2] == '/imgs/myphoto.jpg'
+
+    result = t.image('!</imgs/myphoto.jpg!')
+    expect = '<img align="left" alt="" src="{0}3:url" />'.format(t.uid)
+    assert result == expect
+    assert t.refCache[3] == '/imgs/myphoto.jpg'
+
+    t = Textile(rel='nofollow')
+    result = t.image('!/imgs/myphoto.jpg!:http://jsamsa.com')
+    expect = ('<a href="{0}1:url" rel="nofollow"><img alt="" src="{0}2:url" '
+            '/></a>'.format(t.uid))
+    assert result == expect
diff --git a/tests/test_imagesize.py b/tests/test_imagesize.py
new file mode 100644
index 0000000..112989e
--- /dev/null
+++ b/tests/test_imagesize.py
@@ -0,0 +1,13 @@
+import textile
+
+def test_imagesize():
+    imgurl = 'http://www.google.com/intl/en_ALL/images/srpr/logo1w.png'
+    result = textile.tools.imagesize.getimagesize(imgurl)
+    try:
+        import PIL
+
+        expect = (275, 95)
+        assert result == expect
+    except ImportError:
+        expect = ''
+        assert result == expect
diff --git a/tests/test_lists.py b/tests/test_lists.py
new file mode 100644
index 0000000..4e85f4c
--- /dev/null
+++ b/tests/test_lists.py
@@ -0,0 +1,7 @@
+from textile import Textile
+
+def test_lists():
+    t = Textile()
+    result = t.textileLists("* one\n* two\n* three")
+    expect = '\t<ul>\n\t\t<li>one</li>\n\t\t<li>two</li>\n\t\t<li>three</li>\n\t</ul>'
+    assert result == expect
diff --git a/tests/test_retrieve.py b/tests/test_retrieve.py
new file mode 100644
index 0000000..10bd173
--- /dev/null
+++ b/tests/test_retrieve.py
@@ -0,0 +1,6 @@
+from textile import Textile
+
+def test_retrieve():
+    t = Textile()
+    id = t.shelve("foobar")
+    assert t.retrieve(id) == 'foobar'
diff --git a/tests/test_span.py b/tests/test_span.py
new file mode 100644
index 0000000..d83530d
--- /dev/null
+++ b/tests/test_span.py
@@ -0,0 +1,19 @@
+from textile import Textile
+
+def test_span():
+    t = Textile()
+    result = t.span("hello %(bob)span *strong* and **bold**% goodbye")
+    expect = ('hello <span class="bob">span <strong>strong</strong> and '
+            '<b>bold</b></span> goodbye')
+    assert result == expect
+
+    result = t.span('%:http://domain.tld test%')
+    expect = '<span cite="http://domain.tld">test</span>'
+    assert result == expect
+
+    t = Textile()
+    # cover the partial branch where we exceed the max_span_depth.
+    t.max_span_depth = 2
+    result = t.span('_-*test*-_')
+    expect = '<em><del>*test*</del></em>'
+    assert result == expect
diff --git a/tests/test_subclassing.py b/tests/test_subclassing.py
new file mode 100644
index 0000000..9235e03
--- /dev/null
+++ b/tests/test_subclassing.py
@@ -0,0 +1,17 @@
+import textile
+
+def test_change_glyphs():
+    class TextilePL(textile.Textile):
+        glyph_definitions = dict(textile.Textile.glyph_definitions,
+            quote_double_open = '„'
+        )
+
+    test = 'Test "quotes".'
+    expect = '\t<p>Test „quotes”.</p>'
+    result = TextilePL().parse(test)
+    assert expect == result
+
+    # Base Textile is unchanged.
+    expect = '\t<p>Test “quotes”.</p>'
+    result = textile.textile(test)
+    assert expect == result
diff --git a/tests/test_table.py b/tests/test_table.py
new file mode 100644
index 0000000..0a3cb0d
--- /dev/null
+++ b/tests/test_table.py
@@ -0,0 +1,12 @@
+from textile import Textile
+
+def test_table():
+    t = Textile()
+    result = t.table('(rowclass). |one|two|three|\n|a|b|c|')
+    expect = '\t<table>\n\t\t<tr class="rowclass">\n\t\t\t<td>one</td>\n\t\t\t<td>two</td>\n\t\t\t<td>three</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>a</td>\n\t\t\t<td>b</td>\n\t\t\t<td>c</td>\n\t\t</tr>\n\t</table>\n\n'
+    assert result == expect
+
+    t = Textile(lite=True)
+    result = t.table('(lite). |one|two|three|\n|a|b|c|\n| * test\n* test|1|2|')
+    expect = '\t<table>\n\t\t<tr class="lite">\n\t\t\t<td>one</td>\n\t\t\t<td>two</td>\n\t\t\t<td>three</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td>a</td>\n\t\t\t<td>b</td>\n\t\t\t<td>c</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td> * test\n* test</td>\n\t\t\t<td>1</td>\n\t\t\t<td>2</td>\n\t\t</tr>\n\t</table>\n\n'
+    assert result == expect
diff --git a/tests/test_textile.py b/tests/test_textile.py
new file mode 100644
index 0000000..dd069fb
--- /dev/null
+++ b/tests/test_textile.py
@@ -0,0 +1,191 @@
+# -*- coding: utf-8 -*-
+from __future__ import unicode_literals
+import pytest
+import re
+import textile
+
+def test_FootnoteReference():
+    html = textile.textile('YACC[1]')
+    assert re.search(r'^\t<p><span class="caps">YACC</span><sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">1</a></sup></p>', html) is not None
+
+def test_Footnote():
+    html = textile.textile('This is covered elsewhere[1].\n\nfn1. Down here, in fact.\n\nfn2. Here is another footnote.')
+    assert re.search(r'^\t<p>This is covered elsewhere<sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">1</a></sup>.</p>\n\n\t<p class="footnote" id="fn\1-1"><sup>1</sup> Down here, in fact.</p>\n\n\t<p class="footnote" id="fn\1-2"><sup>2</sup> Here is another footnote.</p>$', html) is not None
+
+    html = textile.textile('''See[1] for details -- or perhaps[100] at a push.\n\nfn1. Here are the details.\n\nfn100(footy#otherid). A totally unrelated footnote.''')
+    assert re.search(r'^\t<p>See<sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">1</a></sup> for details — or perhaps<sup class="footnote" id="fnrev\1-2"><a href="#fn\1-2">100</a></sup> at a push.</p>\n\n\t<p class="footnote" id="fn\1-1"><sup>1</sup> Here are the details.</p>\n\n\t<p class="footy" id="otherid"><sup id="fn\1-2">100</sup> A totally unrelated footnote.</p>$', html) is not None
+
+    html = textile.textile('''See[2] for details, and later, reference it again[2].\n\nfn2^(footy#otherid)[en]. Here are the details.''')
+    assert re.search(r'^\t<p>See<sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">2</a></sup> for details, and later, reference it again<sup class="footnote"><a href="#fn\1-1">2</a></sup>.</p>\n\n\t<p class="footy" id="otherid" lang="en"><sup id="fn\1-1"><a href="#fnrev\1-1">2</a></sup> Here are the details.</p>$', html) is not None
+
+    html = textile.textile('''See[3!] for details.\n\nfn3. Here are the details.''')
+    assert re.search(r'^\t<p>See<sup class="footnote" id="fnrev([a-f0-9]{32})-1">3</sup> for details.</p>\n\n\t<p class="footnote" id="fn\1-1"><sup>3</sup> Here are the details.</p>$', html) is not None
+
+    html = textile.textile('''See[4!] for details.\n\nfn4^. Here are the details.''')
+    assert re.search(r'^\t<p>See<sup class="footnote" id="fnrev([a-f0-9]{32})-1">4</sup> for details.</p>\n\n\t<p class="footnote" id="fn\1-1"><sup><a href="#fnrev\1-1">4</a></sup> Here are the details.</p>$', html) is not None
+
+def test_issue_35():
+    result = textile.textile('"z"')
+    expect = '\t<p>“z” </p>'
+    assert result == expect
+
+    result = textile.textile('" z"')
+    expect = '\t<p>“ z” </p>'
+    assert result == expect
+
+def test_restricted():
+    #Note that the HTML is escaped, thus rendering the <script> tag harmless.
+    test = "Here is some text.\n<script>alert('hello world')</script>"
+    result = textile.textile_restricted(test)
+    expect = "\t<p>Here is some text.<br />\n<script>alert(‘hello world’)</script></p>"
+
+    assert result == expect
+
+    test = "Here's some <!-- commented *out* --> text."
+    result = textile.textile_restricted(test)
+    expect = "\t<p>Here’s some <!— commented <strong>out</strong> —> text.</p>"
+
+    assert result == expect
+
+    test = "p[fr]. Partir, c'est toujours mourir un peu."
+    result = textile.textile_restricted(test)
+    expect = '\t<p lang="fr">Partir, c’est toujours mourir un peu.</p>'
+
+    assert result == expect
+
+def test_unicode_footnote():
+    html = textile.textile('текст[1]')
+    assert re.compile(r'^\t<p>текст<sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">1</a></sup></p>$', re.U).search(html) is not None
+
+def test_autolinking():
+    test = """some text "test":http://www.google.com http://www.google.com "$":http://www.google.com"""
+    result = """\t<p>some text <a href="http://www.google.com">test</a> http://www.google.com <a href="http://www.google.com">www.google.com</a></p>"""
+    expect = textile.textile(test)
+
+    assert result == expect
+
+def test_sanitize():
+    test = "a paragraph of benign text"
+    result = "\t<p>a paragraph of benign text</p>"
+    try:
+        expect = textile.Textile().parse(test, sanitize=True)
+        assert result == expect
+
+        test = """<p style="width: expression(alert('evil'));">a paragraph of evil text</p>"""
+        result = '<p style="">a paragraph of evil text</p>'
+        expect = textile.Textile().parse(test, sanitize=True)
+        assert result == expect
+
+        test = """<p>a paragraph of benign text<br />and more text</p>"""
+        result = '<p>a paragraph of benign text<br />\nand more text</p>'
+        expect = textile.Textile(html_type='html5').parse(test, sanitize=True)
+        assert result == expect
+    except Exception as e:
+        message = '{0}'.format(e)
+        assert "html5lib not available" in message
+
+def test_imagesize():
+    PIL = pytest.importorskip('PIL')
+
+    test = "!http://www.google.com/intl/en_ALL/images/srpr/logo1w.png!"
+    result = '\t<p><img alt="" height="95" src="http://www.google.com/intl/en_ALL/images/srpr/logo1w.png" width="275" /></p>'
+    expect = textile.Textile(get_sizes=True).parse(test)
+    assert result == expect
+
+def test_endnotes_simple():
+    test = """Scientists say the moon is slowly shrinking[#my_first_label].\n\nnotelist!.\n\nnote#my_first_label Over the past billion years, about a quarter of the moon's 4.5 billion-year lifespan, it has shrunk about 200 meters (700 feet) in diameter."""
+    html = textile.textile(test)
+    result_pattern = r"""\t<p>Scientists say the moon is slowly shrinking<sup><a href="#note([a-f0-9]{32})-2"><span id="noteref\1-1">1</span></a></sup>.</p>\n\n\t<ol>\n\t\t<li><span id="note\1-2"> </span>Over the past billion years, about a quarter of the moon’s 4.5 billion-year lifespan, it has shrunk about 200 meters \(700 feet\) in diameter.</li>\n\t</ol>$"""
+    result_re = re.compile(result_pattern)
+    assert result_re.search(html) is not None
+
+def test_endnotes_complex():
+    test = """Tim Berners-Lee is one of the pioneer voices in favour of Net Neutrality[#netneutral] and has expressed the view that ISPs should supply "connectivity with no strings attached"[#netneutral!] [#tbl_quote]\n\nBerners-Lee admitted that the forward slashes ("//") in a web address were actually unnecessary.  He told the newspaper that he could easily have designed URLs not to have the forward slashes.  "... it seemed like a good idea at the time,"[#slashes]\n\nnote#netneutral. " [...]
+    html = textile.textile(test)
+    result_pattern = r"""\t<p>Tim Berners-Lee is one of the pioneer voices in favour of Net Neutrality<sup><a href="#note([a-f0-9]{32})-2"><span id="noteref\1-1">1</span></a></sup> and has expressed the view that <span class="caps">ISP</span>s should supply “connectivity with no strings attached”<sup><span id="noteref\1-3">1</span></sup> <sup><a href="#note\1-5"><span id="noteref\1-4">2</span></a></sup></p>\n\n\t<p>Berners-Lee admitted that the forward slashes \(“//&#82 [...]
+    result_re = re.compile(result_pattern)
+    assert result_re.search(html) is not None
+
+def test_endnotes_unreferenced_note():
+    test = """Scientists say[#lavader] the moon is quite small. But I, for one, don't believe them. Others claim it to be made of cheese[#aardman]. If this proves true I suspect we are in for troubled times[#apollo13] as people argue over their "share" of the moon's cheese. In the end, its limited size[#lavader] may prove problematic.\n\nnote#lavader(noteclass). "Proof of the small moon hypothesis":http://antwrp.gsfc.nasa.gov/apod/ap080801.html. Copyright(c) Laurent Laveder\n\nnote#aardm [...]
+    html = textile.textile(test)
+    result_pattern = r"""\t<p>Scientists say<sup><a href="#note([a-f0-9]{32})-2"><span id="noteref\1-1">1</span></a></sup> the moon is quite small. But I, for one, don’t believe them. Others claim it to be made of cheese<sup><a href="#note\1-4"><span id="noteref\1-3">2</span></a></sup>. If this proves true I suspect we are in for troubled times<sup><a href="#note\1-6"><span id="noteref\1-5">3</span></a></sup> as people argue over their “share” of the moon’s cheese [...]
+    result_re = re.compile(result_pattern, re.U)
+    assert result_re.search(html) is not None
+
+def test_endnotes_malformed():
+    test = """Scientists say[#lavader] the moon is quite small. But I, for one, don't believe them. Others claim it to be made of cheese[#aardman]. If this proves true I suspect we are in for troubled times[#apollo13!] as people argue over their "share" of the moon's cheese. In the end, its limited size[#lavader] may prove problematic.\n\nnote#unused An unreferenced note.\n\nnote#lavader^ "Proof of the small moon hypothesis":http://antwrp.gsfc.nasa.gov/apod/ap080801.html. Copyright(c) La [...]
+    html = textile.textile(test)
+    result_pattern = r"""^\t<p>Scientists say<sup><a href="#note([a-f0-9]{32})-2"><span id="noteref\1-1">1</span></a></sup> the moon is quite small. But I, for one, don’t believe them. Others claim it to be made of cheese<sup><a href="#note\1-4"><span id="noteref\1-3">2</span></a></sup>. If this proves true I suspect we are in for troubled times<sup><span id="noteref\1-5">3</span></sup> as people argue over their “share” of the moon’s cheese. In the end, its limit [...]
+    result_re = re.compile(result_pattern, re.U)
+    assert result_re.search(html) is not None
+
+def test_endnotes_undefined_note():
+    test = """Scientists say the moon is slowly shrinking[#my_first_label].\n\nnotelist!."""
+    html = textile.textile(test)
+    result_pattern = r"""\t<p>Scientists say the moon is slowly shrinking<sup><a href="#note([a-f0-9]{32})-2"><span id="noteref\1-1">1</span></a></sup>.</p>\n\n\t<ol>\n\t\t<li> Undefined Note \[#my_first_label\].<li>\n\t</ol>$"""
+    result_re = re.compile(result_pattern)
+    assert result_re.search(html) is not None
+
+def test_encode_url():
+    # I tried adding these as doctests, but the unicode tests weren't
+    # returning the correct results.
+    t = textile.Textile()
+
+    url = 'http://www.example.local'
+    result = 'http://www.example.local'
+    eurl = t.encode_url(url)
+    assert eurl == result
+
+    url = 'http://user@www.example.local'
+    result = 'http://user@www.example.local'
+    eurl = t.encode_url(url)
+    assert eurl == result
+
+    url = 'http://user:password@www.example.local'
+    result = 'http://user:password@www.example.local'
+    eurl = t.encode_url(url)
+    assert eurl == result
+
+    url = 'http://user:password@www.example.local/Ubermensch'
+    result = 'http://user:password@www.example.local/Ubermensch'
+    eurl = t.encode_url(url)
+    assert eurl == result
+
+    url = "http://user:password@www.example.local/Übermensch"
+    result = "http://user:password@www.example.local/%C3%9Cbermensch"
+    eurl = t.encode_url(url)
+    assert eurl == result
+
+    url = 'http://user:password@www.example.local:8080/Übermensch'
+    result = 'http://user:password@www.example.local:8080/%C3%9Cbermensch'
+    eurl = t.encode_url(url)
+    assert eurl == result
+
+def test_footnote_crosslink():
+    html = textile.textile('''See[2] for details, and later, reference it again[2].\n\nfn2^(footy#otherid)[en]. Here are the details.''')
+    searchstring = r'\t<p>See<sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">2</a></sup> for details, and later, reference it again<sup class="footnote"><a href="#fn\1-1">2</a></sup>.</p>\n\n\t<p class="footy" id="otherid" lang="en"><sup id="fn\1-1"><a href="#fnrev\1-1">2</a></sup> Here are the details.</p>$'
+    assert re.compile(searchstring).search(html) is not None
+
+def test_footnote_without_reflink():
+    html = textile.textile('''See[3!] for details.\n\nfn3. Here are the details.''')
+    searchstring = r'^\t<p>See<sup class="footnote" id="fnrev([a-f0-9]{32})-1">3</sup> for details.</p>\n\n\t<p class="footnote" id="fn\1-1"><sup>3</sup> Here are the details.</p>$'
+    assert re.compile(searchstring).search(html) is not None
+
+def testSquareBrackets():
+    html = textile.textile("""1[^st^], 2[^nd^], 3[^rd^]. 2 log[~n~]\n\nA close[!http://textpattern.com/favicon.ico!]image.\nA tight["text":http://textpattern.com/]link.\nA ["footnoted link":http://textpattern.com/][182].""")
+    searchstring = r'^\t<p>1<sup>st</sup>, 2<sup>nd</sup>, 3<sup>rd</sup>. 2 log<sub>n</sub></p>\n\n\t<p>A close<img alt="" src="http://textpattern.com/favicon.ico" />image.<br />\nA tight<a href="http://textpattern.com/">text</a>link.<br />\nA <a href="http://textpattern.com/">footnoted link</a><sup class="footnote" id="fnrev([a-f0-9]{32})-1"><a href="#fn\1-1">182</a></sup>.</p>'
+    assert re.compile(searchstring).search(html) is not None
+
+def test_html5():
+    """docstring for testHTML5"""
+
+    test = 'We use CSS(Cascading Style Sheets).'
+    result = '\t<p>We use <abbr title="Cascading Style Sheets"><span class="caps">CSS</span></abbr>.</p>'
+    expect = textile.textile(test, html_type="html5")
+    assert result == expect
+
+def test_relURL():
+    t = textile.Textile()
+    t.restricted = True
+    assert t.relURL("gopher://gopher.com/") == '#'
diff --git a/tests/test_textilefactory.py b/tests/test_textilefactory.py
new file mode 100644
index 0000000..846b927
--- /dev/null
+++ b/tests/test_textilefactory.py
@@ -0,0 +1,28 @@
+from textile import textilefactory
+import pytest
+
+def test_TextileFactory():
+    f = textilefactory.TextileFactory()
+    result = f.process("some text here")
+    expect = '\t<p>some text here</p>'
... 4294 lines suppressed ...

-- 
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