s243a

config-filt-test bottle python

Nov 4th, 2018
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.49 KB | None | 0 0
  1. import bottle
  2. from bottle import route, run, Bottle
  3. import sys, os, re, urllib
  4. #fcpHost = "127.0.0.1"
  5. #import fcp
  6. #node = fcp.FCPNode(host=fcpHost, verbosity=fcp.DETAIL)
  7.  
  8. app = Bottle()
  9.  
  10. #m1="'"
  11.  
  12.  
  13. def delim_filter(config):
  14.     bottle.debug(True)
  15.     print("Entering delim_filter")
  16.     ''' Matches a comma separated list of numbers. '''
  17.     aconfig = config or "%20"
  18.     print ("aconfig=" + aconfig)
  19.     delimiter = urllib.unquote(aconfig).decode('utf8')
  20.     print("delimiter=" + delimiter)  
  21.     regexp = r'(?!{a_delim})+({a_delim}(?!%s)+)*'.format(a_delim=re.escape(delimiter))
  22.  
  23.     def to_python(match):
  24.         print("Converting Match")
  25.         print("Math=" + match)
  26.         ms = map(urllib.unquote(aconfig).decode,match.split())
  27.         print( "ms=" + ms )
  28.         return ms
  29.  
  30.     def to_url(astr):
  31.         print("Converting to URL")
  32.         print ("astr=" + astr)
  33.         astr2 = delimiter.join(map(urllib.unquote(aconfig).decode,astr))
  34.         print("astr2="+astr2)
  35.         print  astr2
  36.         return astr2
  37.  
  38.     return regexp, to_python, to_url
  39.  
  40. app.router.add_filter('delim', delim_filter)
  41.  
  42. @app.route('/<key>/%09/<cmd>/<args:delim:%09>') # %09 == tab
  43. @app.route('/<key>/%20/<cmd>/<args:delim:%20>') # %20 == ' '
  44. @app.route('/<key>/ /<cmd>/<args:delim: >') # %20 == ' '
  45. @app.route('/<key>/%3B/<cmd>/<args:delim:%3B>') # %3B == ';'
  46. @app.route('/<key>/%2C/<cmd>/<args:delim:%2C>') # %2C == ','
  47. def mystery(key,cmd,args,aconfig='%2C'):
  48.     bottle.debug(True)
  49.     if key == '1234': # %2C == ','
  50.         print(key)
  51.         print(cmd)
  52.         print(args)
  53.         delimiter = urllib.unquote(aconfig).decode('utf8')
  54.         print(delimiter)            
  55.         #os.system("IFS=<a_dilim>".format(a_dilim=dilimiter))
  56.         #os.system("cmd" + "delimiter" + delimiter.join(args))
  57.  
  58.         return ('key=' + key + '<br>' +
  59.              'delimiter=' + delimiter + '<br>' +
  60.              'cmd=' + cmd + '<br>' +
  61.              'args='   + args)
  62. #@app.route('/USK@<hashKey:nocomma>,<ecryptionKey:nocomma>,<encryption:nocomma>/<metaData:path>')
  63. #def hello(hashKey,ecryptionKey,encryption,metaData):
  64. #    
  65. #    mimetype, val1 = node.get(uri)
  66. #    return ('hashKey=' + hashKey + '<br>' +
  67. #             'ecryptionKey=' + ecryptionKey + '<br>' +
  68. #             'encryption=' + encryption + '<br>' +
  69. #             'metaData='   + metaData)
  70. #            
  71. #Regular eressions use a seperate filter; https://bottlepy.org/docs/dev/routing.html
  72. app.run(host='localhost', port=8082, debug=True)
Add Comment
Please, Sign In to add comment