Skip to content

Commit

Permalink
Merge pull request #41 from loechel/master
Browse files Browse the repository at this point in the history
Fix case when theme is provided via an remote https source
  • Loading branch information
lrowe committed Apr 8, 2015
2 parents 8235739 + 22ca84b commit 7bb1137
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ dist
*.pyc
*.pyo
*.egg-info
.eggs/
.installed.cfg
.tox
include
Expand Down
2 changes: 2 additions & 0 deletions docs/CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Changelog
------------------

- Nothing changed yet.
* Fixed issue with remote themes via https connections
[loechel]


1.1.1 (2015-03-21)
Expand Down
11 changes: 9 additions & 2 deletions lib/diazo/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from lxml import etree
from six import string_types
from future.moves.urllib.parse import urljoin
from future.moves.urllib.request import urlopen
from diazo.cssrules import convert_css_selectors
from diazo.utils import namespaces, fullname, pkg_xsl, _createOptionParser

Expand Down Expand Up @@ -115,10 +116,16 @@ def expand_themes(rules_doc, parser=None, absolute_prefix=None,
for element in rules_doc.xpath('//diazo:theme[@href]',
namespaces=namespaces):
url = urljoin(base, element.get('href'))
if not read_network and url[:6] in ('ftp://', 'http:/', 'https:'):
if not read_network and \
url.startswith(('ftp://', 'ftps://', 'http://', 'https://')):
raise ValueError("Supplied theme '%s', "
"but network access denied." % url)
theme_doc = etree.parse(url, parser=parser)
elif read_network and \
url.startswith(('ftp://', 'ftps://', 'http://', 'https://')):
theme = urlopen(url)
else:
theme = url
theme_doc = etree.parse(theme, parser=parser, base_url=url)
expand_theme(element, theme_doc, absolute_prefix)
return rules_doc

Expand Down

0 comments on commit 7bb1137

Please sign in to comment.