Home | History | Annotate | Download | only in paste
      1 # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
      2 # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php
      3 """
      4 We have a pony and/or a unicorn.
      5 """
      6 from paste.request import construct_url
      7 
      8 PONY = """
      9 eJyFkkFuxCAMRfdzCisbJxK2D5D2JpbMrlI3XXQZDt9PCG0ySgcWIMT79rcN0XClUJlZRB9jVmci
     10 FmV19khjgRFl0RzrKmqzvY8lRUWFlXvCrD7UbAQR/17NUvGhypAF9og16vWtkC8DzUayS6pN3/dR
     11 ki0OnpzKjUBFpmlC7zVFRNL1rwoq6PWXXQSnIm9WoTzlM2//ke21o5g/l1ckRhiPbkDZXsKIR7l1
     12 36hF9uMhnRiVjI8UgYjlsIKCrXXpcA9iX5y7zMmtG0fUpW61Ssttipf6cp3WARfkMVoYFryi2a+w
     13 o/2dhW0OXfcMTnmh53oR9egzPs+qkpY9IKxdUVRP5wHO7UDAuI6moA2N+/z4vtc2k8B+AIBimVU=
     14 """
     15 
     16 UNICORN = """
     17 eJyVVD1vhDAM3e9XeAtIxB5P6qlDx0OMXVBzSpZOHdsxP762E0JAnMgZ8Zn37OePAPC60eV1Dl5b
     18 SS7fB6DmQNGhtegpNlPIQS8HmkYGdSqNqDF9wcMYus4TuBYGsZwIPqXfEoNir5K+R3mbzhlR4JMW
     19 eGpikPpn9wHl2sDgEH1270guZwzKDRf3nTztMvfI5r3fJqEmNxdCyISBcWjNgjPG8Egg2hgT3mJi
     20 KBwNvmPB1hbWJ3TwBfMlqdTzxNyDE2H8zOD5HA4KkqJGPVY/TwnxmPA82kdSJNj7zs+R0d1pB+JO
     21 xn2DKgsdxAfFS2pfTSD0Fb6Uzv7dCQSvE5JmZQEQ90vNjBU1GPuGQpCPS8cGo+dQgjIKqxnJTXbw
     22 ucFzPFVIJXtzk6BXKGPnYsKzvFmGx7A0j6Zqvlvk5rETXbMWTGWj0RFc8QNPYVfhJfMMniCPazWJ
     23 lGtPZecIGJWW6oL2hpbWRZEkChe8eg5Wb7xx/MBZBFjxeZPEss+mRQ3Uhc8WQv684seSRO7i3nb4
     24 7HlKUg8sraz47LmXyh8S0somADvoUpoHjGWl+rUkF0H+EIf/gbyyMg58BBk6L634/fkHUCodMw==
     25 """
     26 
     27 
     28 class PonyMiddleware(object):
     29 
     30     def __init__(self, application):
     31         self.application = application
     32 
     33     def __call__(self, environ, start_response):
     34         path_info = environ.get('PATH_INFO', '')
     35         if path_info == '/pony':
     36             url = construct_url(environ, with_query_string=False)
     37             if 'horn' in environ.get('QUERY_STRING', ''):
     38                 data = UNICORN
     39                 link = 'remove horn!'
     40             else:
     41                 data = PONY
     42                 url += '?horn'
     43                 link = 'add horn!'
     44             msg = data.decode('base64').decode('zlib')
     45             msg = '<pre>%s\n<a href="%s">%s</a></pre>' % (
     46                 msg, url, link)
     47             start_response('200 OK', [('content-type', 'text/html')])
     48             return [msg]
     49         else:
     50             return self.application(environ, start_response)
     51 
     52 def make_pony(app, global_conf):
     53     """
     54     Adds pony power to any application, at /pony
     55     """
     56     return PonyMiddleware(app)
     57 
     58