Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for XML parsing #61

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
/venv
/dist
/docs/html
.vscode/
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
language: python
python:
- "2.6"
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
# command to run tests
script: python setup.py test
8 changes: 7 additions & 1 deletion pynliner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class Pynliner(object):
output = False

def __init__(self, log=None, allow_conditional_comments=False,
preserve_entities=True):
preserve_entities=True, is_xml=False):
self.log = log
cssutils.log.enabled = False if log is None else True
self.extra_style_strings = []
Expand All @@ -73,6 +73,7 @@ def __init__(self, log=None, allow_conditional_comments=False,
self.root_url = None
self.relative_url = None
self._substitutions = None
self.is_xml = is_xml

def from_url(self, url):
"""Gets remote HTML page for conversion
Expand Down Expand Up @@ -179,9 +180,14 @@ def _unsubstitute_output(self):
def _get_soup(self):
"""Convert source string to BeautifulSoup object. Sets it to self.soup.

If parsing xml (i.e. self.is_xml = True), then use xml parser.

If using mod_wgsi, use html5 parsing to prevent BeautifulSoup
incompatibility.
"""
if self.is_xml:
self.soup = BeautifulSoup(self.source_string.encode('utf-8'), "xml")
return
# Check if mod_wsgi is running
# - see http://code.google.com/p/modwsgi/wiki/TipsAndTricks
try:
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
install_requires=[
'BeautifulSoup4 >= 4.4.1',
'cssutils >=0.9.7',
'lxml',
],
tests_require=[
'mock'
Expand Down