Skip to content

Commit

Permalink
restore remote serving on python 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Mar 16, 2017
1 parent 9462b24 commit bfa3748
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions cicero/git.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import flask
import sys

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

Expand All @@ -20,14 +21,21 @@ def home():


def render_github_markdown(namespace, repo, branch, file_name):
from urllib import request
from .title import extract_title
from .images import fix_images

if sys.version_info[0] > 2:
from urllib import request
else:
import urllib2

try:
url = 'https://raw.githubusercontent.com/{}/{}/{}/{}'.format(namespace, repo, branch, file_name)

response = request.urlopen(url)
if sys.version_info[0] > 2:
response = request.urlopen(url)
else:
response = urllib2.urlopen(url)

markdown = response.read().decode("utf-8")
if markdown == 'Not Found':
Expand All @@ -48,7 +56,10 @@ def render_github_markdown(namespace, repo, branch, file_name):

try:
url = 'https://raw.githubusercontent.com/{}/{}/{}/{}'.format(namespace, repo, branch, 'remark.html')
response = request.urlopen(url)
if sys.version_info[0] > 2:
response = request.urlopen(url)
else:
response = urllib2.urlopen(url)
template = response.read().decode("utf-8")
return flask.render_template_string(template,
title=title,
Expand Down

0 comments on commit bfa3748

Please sign in to comment.