Browse Source

Fix for Python3

master
Cassowary 2 years ago
parent
commit
989c48166e
3 changed files with 51 additions and 42 deletions
  1. +15
    -9
      bobostatic.py
  2. +33
    -31
      hackersite.wsgi
  3. +3
    -2
      main.py

+ 15
- 9
bobostatic.py View File

@@ -1,21 +1,21 @@
import bobo, mimetypes, os, webob

class Directory:

class Directory:
def __init__(self, root, path=None):
self.root = os.path.abspath(root)+os.path.sep
self.root = os.path.abspath(root) + os.path.sep
self.path = path or root

@bobo.query('')
@bobo.query("")
def base(self, bobo_request):
return bobo.redirect(bobo_request.url+'/')
return bobo.redirect(bobo_request.url + "/")

@bobo.query('/')
@bobo.query("/")
def index(self):
links = []
for name in os.listdir(self.path):
if os.path.isdir(os.path.join(self.path, name)):
name += '/'
name += "/"
links.append('<a href="%s">%s</a>' % (name, name))
return """<html>
<head><title>%s</title></head>
@@ -23,9 +23,12 @@ class Directory:
%s
</body>
</html>
""" % (self.path[len(self.root):], '<br>\n '.join(links))
""" % (
self.path[len(self.root) :],
"<br>\n ".join(links),
)

@bobo.subroute('/:name')
@bobo.subroute("/:name")
def traverse(self, request, name):
path = os.path.abspath(os.path.join(self.path, name))
if not path.startswith(self.root):
@@ -35,13 +38,15 @@ class Directory:
else:
return File(path)


bobo.scan_class(Directory)


class File:
def __init__(self, path):
self.path = path

@bobo.query('')
@bobo.query("")
def base(self, bobo_request):
response = webob.Response()
content_type = mimetypes.guess_type(self.path)[0]
@@ -54,4 +59,5 @@ class File:

return response


bobo.scan_class(File)

+ 33
- 31
hackersite.wsgi View File

@@ -12,44 +12,46 @@ import webob
import mimetypes

try:
config = json.load(file('/srv/dehacker/dehacker.cfg','r'))
config = json.load(file("/srv/dehacker/dehacker.cfg", "r"))
except:
config = dict()
config = dict()
try:
sys.path.append(os.path.dirname(__file__))
except: pass
sys.path.append(os.path.dirname(__file__))
except:
pass

import namegenerators


@bobo.resource('/', content_type="text/html")
def index(request): return file('hackersite.template','r').read()
@bobo.resource("/", content_type="text/html")
def index(request):
return file("hackersite.template", "r").read()


@bobo.query('/namegen',content_type="application/json")
def namegen(bobo_request, govid='Bobby Smith'):
namegenerators.filters.filter_random.seed(govid)
namegenerators.hacker.hacker_random.seed(govid)
name = namegenerators.hacker.hacker_name()
return json.dumps({'govid':govid, 'hackername':name})
@bobo.query("/namegen", content_type="application/json")
def namegen(bobo_request, govid="Bobby Smith"):
namegenerators.filters.filter_random.seed(govid)
namegenerators.hacker.hacker_random.seed(govid)
name = namegenerators.hacker.hacker_name()
return json.dumps({"govid": govid, "hackername": name})


@bobo.resource('/statics/:f')
@bobo.resource('/resources/:f')
@bobo.resource("/statics/:f")
@bobo.resource("/resources/:f")
def statics(bobo_request, f):
f = f.replace('..','fuuuuuuuuuuuuuuuuuuuug')
f = f.replace('/','asssssssssssssssssssss')
pth = os.path.join('resources',f)
response = webob.Response()
content_type = mimetypes.guess_type(pth)[0]
if content_type is not None:
response.content_type = content_type
try:
response.body = file(pth,'r').read()
except IOError:
raise bobo.NotFound
return response



if not __name__ == 'bobo__main__':
application = bobo.Application(bobo_resources=__name__)
f = f.replace("..", "fuuuuuuuuuuuuuuuuuuuug")
f = f.replace("/", "asssssssssssssssssssss")
pth = os.path.join("resources", f)
response = webob.Response()
content_type = mimetypes.guess_type(pth)[0]
if content_type is not None:
response.content_type = content_type
try:
response.body = file(pth, "r").read()
except IOError:
raise bobo.NotFound
return response


if not __name__ == "bobo__main__":
application = bobo.Application(bobo_resources=__name__)

+ 3
- 2
main.py View File

@@ -2,9 +2,10 @@
import boboserver
import sys

args = ['-f','hackersite.wsgi', '-p','8080']
args = ["-f", "hackersite.wsgi", "-p", "8080"]
try:
args.extend(sys.argv[1:])
except: pass
except:
pass

sys.exit(boboserver.server(args=args))

Loading…
Cancel
Save