📄 dbpages.py
字号:
#
# This object creates pages from a small database
#
class dbsource:
def __init__(self, source, type):
if type == 'mx':
import mx.ODBC.Windows as odbc
self.conn = odbc.connect(source)
elif type == 'odbc':
import odbc
self.conn = odbc.odbc(source)
elif type == 'gf':
import gadfly
self.conn = gadfly.gadfly(source, "gadfly")
else:
raise ValueError, "Illegal data source type %s" % type
self.cursor = self.conn.cursor()
#
# Build the navigation links
#
def navlinks(self):
self.cursor.execute("SELECT PgName, PgNum from PgData ORDER BY PgNum")
lnkLst = []
for row in self.cursor.fetchall():
lnkLst.append('<a href="/%s">%s</a><br>' % (row[0], row[0]))
return "\r\n".join(lnkLst)
#
# Build the main page content
#
def page(self, op, path):
if op.upper() == "GET":
self.cursor.execute("SELECT PgText FROM PgData WHERE PgName=?", (path, ))
result = self.cursor.fetchall() # only one, we hope!
if result:
text = result[0][0]
else:
text = "Sorry. No page '%s' in the database" % path
else:
text = "Sorry. The '%s' operation you requested is invalid." % op
return \
"""HTTP/1.0 200 OK Response Follows
Content-Type: text/html
Cache-Control: no-cache
<HTML>
<HEAD>
<TITLE>Operation %s %s</TITLE>
</HEAD>
<BODY>
<TABLE>
<tr>
<td valign="TOP" width="80">%s</td>
<td valign="TOP" width="150"><b>Page <i>%s</i></b><br>%s</td>
</tr>
</TABLE>
</BODY>
""" % (op, path, self.navlinks(), path, text)
#
# Tidy up
#
def close(self):
self.cursor.close()
self.conn.close()
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -