Skip to content

Commit

Permalink
use requests instead of urllib(2); fixes #57
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Jun 6, 2018
1 parent 837305f commit 2d60d1f
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions cicero/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@
import requests
import json

# FIXME: rather use requests.get
if sys.version_info[0] > 2:
from urllib import request
_urlopen = request.urlopen
else:
import urllib2
_urlopen = urllib2.urlopen

blueprint = flask.Blueprint('git', __name__)

URL_BASE = 'CICERO_URL_BASE_is_undefined'
Expand Down Expand Up @@ -90,28 +82,26 @@ def render_github_markdown(path, engine, engine_version):
# if not, we default to empty own css
try:
url = prefix + '/' + file_without_suffix + '.css'
response = _urlopen(url)
own_css = response.read().decode("utf-8")
response = requests.get(url)
own_css = response.text
except IOError:
own_css = ''
own_css = flask.Markup(own_css) # disable autoescaping
# .. do the same for own javascript
# try:
# url = prefix + '/' + file_without_suffix + '.js'
# response = _urlopen(url)
# own_javascript = response.read().decode("utf-8")
# response = requests.get(url)
# own_javascript = response.text
# except IOError:
# own_javascript = ''
# for the moment I am not sure whether the above is not too risky
own_javascript = ''

# use custom configuration for the rendering engine, if available
try:
url = prefix + '/' + file_without_suffix + '.conf'
response = _urlopen(url)
own_conf = ''
for line in response.readlines():
own_conf += line.decode("utf-8").replace('\n', ',\n')
own_conf = own_conf.rstrip('\n')
response = requests.get(url)
own_conf = ',\n'.join(response.text.split('\n'))
except IOError:
own_conf = ''

Expand Down

0 comments on commit 2d60d1f

Please sign in to comment.