forked from amarian12/overblock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
120 lines (64 loc) · 2.46 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from servlet import HttpServer,HttpServlet
import bitcoinrpc
import urlparse
from bitcoinrpc.authproxy import AuthServiceProxy,JSONRPCException
from pprint import pprint
from decimal import Decimal
from pages.RawBlockView import RawBlockView
from pages.RawTransactionView import RawTransactionView
from pages.TransactionView import TransactionView
from pages.BlockView import BlockView
from pages.MainPage import MainPage
from pages.Page import Page
class DemuxServlet(HttpServlet):
def __init__(self,request, client_address, server):
self.init_params = {'request':request,'client_address':client_address,'server':server}
HttpServlet.__init__(self,request,client_address,server)
#print 'request:',request
def service(self,request, response):
#sever.path
#print 'path:',self.path
path = urlparse.urlparse(self.path).path
if path not in self.server.paths:
self.send_error(404)
return
cls = self.server.paths[path]
path_servlet = cls(self)
path_servlet.service(request,response)
class StyleSheet(Page):
def service(self,request, response):
with open('style.css','r') as f:
css = f.read()
response.setContentType('text/css')
writer = response.getWriter()
writer.write(css)
def main():
import yaml
config_file = open('config.yml')
config = None
try:
config = yaml.load(config_file)
except:
print
print "ERROR: parsing configuration"
print
raise
def create_access():
return AuthServiceProxy(config['rpcserverurl'])
HttpServer.allow_reuse_address = True
DemuxServlet.debug(True)
port = config['listen_port']
httpd = HttpServer(('', port), DemuxServlet)
httpd.__debug = True
httpd.paths = { '/': MainPage, '/block': BlockView, '/transaction': TransactionView, '/style.css': StyleSheet, '/rawtransaction': RawTransactionView, '/rawblock': RawBlockView}
httpd.create_access = create_access
httpd.config = config
try:
while True:
httpd.handle_request()
finally:
httpd.socket.close()
pass
pass
if __name__ == "__main__":
main()