📄 mpdbpages.py
字号:
#
# This object creates pages for multiple ports from a small database
#
import mx.DateTime as DateTime
import mx.ODBC.Windows
class dbsource:
def __init__(self, source, type, port):
if type == 'mx':
self.conn = mx.ODBC.Windows.connect(source)
else:
raise ValueError, "Illegal data source type %s" % type
self.cursor = self.conn.cursor()
self.port = port
print self.port, self.conn, self.cursor
#
# Build the navigation links
#
def navlinks(self):
self.cursor.execute("SELECT PgName, PgNum from MpPgData WHERE PgPrt = ? AND PgGrp='TopLevel' ORDER BY PgNum", (self.port,))
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, addr, op, path, LOGGING=0):
if LOGGING:
print addr[0], self.port, op, path
try:
self.cursor.execute("INSERT INTO Log (crDateTime, addr, port, op, path) VALUES(?,?,?,?,?)", \
(DateTime.now(), addr[0], self.port, op, path))
except mx.ODBC.Windows.Warning: # grotty date problem?
pass
self.conn.commit()
if op.upper() == "GET":
self.cursor.execute("SELECT PgText FROM MpPgData WHERE PgName=? AND PgPrt=?", (path, self.port))
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 + -