2020 'download.html' ,
2121 'chapter1_introduction.html' , 'chapter2_installation.html' , 'chapter3_basics.html' ,
2222 'chapter4_interactive_prompt.html' , 'chapter5_languages.html' , 'chapter6_parsing.html' ,
23- 'chapter7_evaluation.html' , 'chapter8_error_handling.html' , 'chapter9_s_expressions.html' ,
24- 'chapter10_q_expressions.html' , 'chapter11_variables.html' , 'chapter12_functions.html' ,
23+ 'chapter7_evaluation.html' , 'chapter8_error_handling.html' , 'chapter9_s_expressions.html' ,
24+ 'chapter10_q_expressions.html' , 'chapter11_variables.html' , 'chapter12_functions.html' ,
2525 'chapter13_conditionals.html' , 'chapter14_strings.html' , 'chapter15_standard_library.html' ,
2626 'chapter16_bonus_projects.html' ,
27-
27+
2828 'appendix_a_hand_rolled_parser.html' ,
2929]
3030
3737 'Q-Expressions • Chapter 10' , 'Variables • Chapter 11' , 'Functions • Chapter 12' ,
3838 'Conditionals • Chapter 13' , 'Strings • Chapter 14' , 'Standard Library • Chapter 15' ,
3939 'Bonus Projects • Chapter 16' ,
40-
40+
4141 'Hand Rolled Parser • Appendix A'
4242]
4343
6161 <link href="static/css/bootstrap.css" rel="stylesheet">
6262 <link href="static/css/code.css" rel="stylesheet">
6363 <link rel="icon" type="image/png" href="/static/img/favicon.png" />
64-
64+
6565 <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
6666 <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
6767 <!--[if lt IE 9]>
6868 <script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
6969 <script src="https://oss.maxcdn.com/libs/respond.js/1.3.0/respond.min.js"></script>
7070 <![endif]-->
71-
71+
7272 <script>
7373 (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
7474 (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
8686 </head>
8787 <body style="background: url(static/img/halftone.png); margin:0px; padding:0px;">
8888 <div style="background: url(static/img/tiletop.png) repeat-x; height:25px;">
89-
89+
9090 <div class='container' style='max-width:750px; padding-top:10px;'>
9191 <div class='row'>
9292 <div class='col-xs-12'>
93-
93+
9494"""
9595
9696footer = """
9797 </div>
98- </div>
98+ </div>
9999 </div>
100-
100+
101101 <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
102102 <script src="https://code.jquery.com/jquery.js"></script>
103103 <!-- Include all compiled plugins (below), or include individual files as needed -->
108108 <script src="static/js/language/generic.js"></script>
109109 <script src="static/js/language/c.js"></script>
110110 <script src="static/js/language/lispy.js"></script>
111+
112+ <script type="module" src="static/js/main.js"></script>
111113 </div>
112114 </body>
113115</html>
116118try :
117119 cache = MemcachedCache (['127.0.0.1:11211' ])
118120except RuntimeError :
119-
121+
120122 class FakeCache :
121123 def get (self , k ): return None
122124 def set (self , k , v , ** kwargs ): return None
123-
125+
124126 cache = FakeCache ()
125127
126128app = Flask (__name__ )
127-
129+
128130handler = logging .FileHandler (os .path .join (os .path .split (__file__ )[0 ], 'error.log' ))
129131handler .setLevel (logging .INFO )
130132app .logger .addHandler (handler )
@@ -157,85 +159,85 @@ def set(self, k, v, **kwargs): return None
157159"""
158160
159161def code_html (codes ):
160-
162+
161163 string = ('<div class="panel-group alert alert-warning" id="accordion">\n '
162164 ' <div class="panel panel-default">' )
163-
165+
164166 for num , code in zip (('One' , 'Two' , 'Three' , 'Four' , 'Five' ), codes ):
165-
167+
166168 string += code_header % (num , code , num )
167-
169+
168170 if code .endswith ('.lspy' ):
169171 string += '<pre><code data-language=\' lispy\' >'
170172 else :
171173 string += '<pre><code data-language=\' c\' >'
172-
174+
173175 path = os .path .join (os .path .split (__file__ )[0 ], 'src' , code )
174-
176+
175177 with open (path , 'r' ) as f :
176178 contents = f .read ()
177179 contents = contents .replace ('&' , '&' )
178180 contents = contents .replace ('<' , '<' )
179181 contents = contents .replace ('>' , '>' )
180182 string += contents
181-
183+
182184 string = string .rstrip () + '</code></pre>'
183185 string += code_footer + '\n \n '
184-
186+
185187 string += '</div>\n </div>'
186188
187189 return string
188-
190+
189191@app .route ('/<page>' )
190192def route_page (page ):
191193 page = page + '.html'
192194 if not page in pages : page = '404.html'
193195 path = os .path .join (os .path .split (__file__ )[0 ], page )
194-
196+
195197 index = pages .index (page )
196198 title = titles [index ]
197199 codes = sources [index ]
198-
200+
199201 contents = cache .get ("lispy-" + path )
200202 if contents is None :
201203 contents = open (path , 'r' ).read ()
202204 contents = (header % title ) + contents .replace ('<references />' , code_html (codes )) + footer
203205 cache .set ("lispy-" + path , contents , timeout = 5 * 60 )
204-
206+
205207 return contents
206-
208+
207209@app .route ('/' )
208210def route_index ():
209211 return route_page ('splash' )
210-
212+
211213@app .errorhandler (404 )
212214def route_404 (e ):
213215 return redirect (url_for ('route_page' , page = '404' ))
214-
216+
215217@app .route ('/download/<id>/<type>' )
216218@app .route ('/download/<id>/BuildYourOwnLisp.<type>' )
217219def route_download (id , type ):
218-
220+
219221 keys = os .path .join (os .path .split (__file__ )[0 ], 'purchases' )
220-
222+
221223 with open (keys , 'r' ) as keyfile :
222224 keys = map (lambda x : x .strip (), keyfile .readlines ())
223225 keys = map (lambda x : x .split (' ' ), keys )
224- keys = set ([key [1 ] for key in keys if
225- (datetime .datetime .now () -
226- datetime .datetime .strptime (key [0 ], '%Y-%m-%d-%H:%M:%S' ))
226+ keys = set ([key [1 ] for key in keys if
227+ (datetime .datetime .now () -
228+ datetime .datetime .strptime (key [0 ], '%Y-%m-%d-%H:%M:%S' ))
227229 < datetime .timedelta (days = 60 )])
228-
230+
229231 if id in keys :
230232 if type == 'epub' : return send_file ('BuildYourOwnLisp.epub' , mimetype = 'application/epub+zip' )
231233 elif type == 'mobi' : return send_file ('BuildYourOwnLisp.mobi' , mimetype = 'application/x-mobipocket-ebook' )
232234 elif type == 'pdf' : return send_file ('BuildYourOwnLisp.pdf' , mimetype = 'application/pdf' )
233235 elif type == 'tar' : return send_file ('BuildYourOwnLisp.tar.gz' , mimetype = 'application/x-gtar' )
234236 else : return redirect (url_for ('route_page' , page = 'invalid' ))
235-
237+
236238 else : return redirect (url_for ('route_page' , page = 'invalid' ))
237-
238-
239+
240+
239241""" Paypal Stuff """
240242
241243def ordered_storage (f ):
@@ -244,7 +246,7 @@ def decorator(*args, **kwargs):
244246 return f (* args , ** kwargs )
245247 return decorator
246248""" Main """
247-
249+
248250if __name__ == '__main__' :
249251 port = int (os .getenv ('PORT' ) or 5000 )
250252 app .run (port = port , debug = True )
0 commit comments