Permalink
Browse files

Code cleanup, more flexible location/path handling

  • Loading branch information...
1 parent aa0a4b6 commit 82c73099e6613ca75a6385b9c0d8e2711c2c88f6 @robertkrimen robertkrimen committed May 31, 2011
Showing with 17 additions and 8 deletions.
  1. +9 −8 app.py
  2. +8 −0 t/01-basic.t
View
17 app.py
@@ -11,6 +11,7 @@
import wsgiref.handlers
import re
import posixpath
+import urllib
from google.appengine.api import urlfetch
from google.appengine.ext import db
@@ -59,11 +60,10 @@ def get( self ):
self.render_template( 'index.jinja.html' )
class dispatch_gist_it( RequestHandler ):
- def get( self ):
- url_parse = urlparse.urlparse( self.request.url )
- base = urlparse.urlunparse( ( url_parse.scheme, url_parse.netloc, '', '', '', '' ) )
- path = os.environ[ 'PATH_INFO' ]
- match = gist_it.Gist.match( path )
+ def get( self, location ):
+ base = self.url_for()
+ location = urllib.unquote( location )
+ match = gist_it.Gist.match( location )
self.response.headers['Content-Type'] = 'text/plain';
if not match:
self.response.set_status( 404 )
@@ -72,10 +72,10 @@ def get( self ):
return
else:
- gist = gist_it.Gist.parse( path )
+ gist = gist_it.Gist.parse( location )
if not gist:
self.response.set_status( 500 )
- self.response.out.write( "Unable to parse \"%s\": Not a valid repository path?" % ( path ) )
+ self.response.out.write( "Unable to parse \"%s\": Not a valid repository path?" % ( location ) )
self.response.out.write( "\n" )
return
@@ -114,7 +114,8 @@ def get( self ):
wsgi_application = webapp.WSGIApplication( [
( r'/', dispatch_index ),
- ( r'.*', dispatch_gist_it ),
+ ( r'/xyzzy/(.*)', dispatch_gist_it ),
+ ( r'(.*)', dispatch_gist_it ),
], debug=_DEBUG_ )
def main():
View
@@ -139,4 +139,12 @@ for (qw[
$test->status_code_is( 200, $_ );
}
+$test->get( "$base/xyzzy/github/robertkrimen/gist-it-example/blob/master" );
+$test->status_code_is( 500 );
+$test->body_like( qr{\QUnable to parse "github/robertkrimen/gist-it-example/blob/master": Not a valid repository path?\E} );
+
+$test->get( "$base/xyzzy/github/miyagawa/CPAN-Any/blob/master/README" );
+$test->status_code_is( 200 );
+$test->body_like( qr/CPAN::Any/ );
+
done_testing;

0 comments on commit 82c7309

Please sign in to comment.