clear out leo comments + cruft

This commit is contained in:
Jeremy Penner 2011-04-12 08:37:52 -07:00
parent 5d61e939aa
commit e0abeabb0c
9 changed files with 29 additions and 303 deletions

View file

@ -1,13 +1,5 @@
#@+leo-ver=4-thin
#@+node:jpenner.20091215224421.2:@thin ansi.py
import config import config
if config.USE_CYTHON: if config.USE_CYTHON:
from ansi_cython import * from ansi_cython import *
else: else:
from ansi_python import * from ansi_python import *
#@+others
#@-others
#@nonl
#@-node:jpenner.20091215224421.2:@thin ansi.py
#@-leo

View file

@ -1,6 +1,3 @@
#@+leo-ver=4-thin
#@+node:jpenner.20091212133112.2:@thin ansi_cython.pyx
#@@language python
import config import config
cdef extern from "stdio.h": cdef extern from "stdio.h":
@ -15,8 +12,6 @@ cdef extern from "stdlib.h":
size_t strlen(char *s) size_t strlen(char *s)
char *strcpy(char *dest, char *src) char *strcpy(char *dest, char *src)
#@+others
#@+node:jpenner.20091212133112.3:Codes
esc = '%s['%chr(27) esc = '%s['%chr(27)
reset = '%s0m'%esc reset = '%s0m'%esc
cls = '%s2j'%esc cls = '%s2j'%esc
@ -62,10 +57,6 @@ def Ctrl(ch):
def FEnter(key): def FEnter(key):
return key == "\n" or key == "\r" return key == "\n" or key == "\r"
#@nonl
#@-node:jpenner.20091212133112.3:Codes
#@+node:jpenner.20091212133112.4:Ach
# ANSI Character - contains prop and character
cdef struct SAch: cdef struct SAch:
unsigned char ch unsigned char ch
@ -162,8 +153,6 @@ cdef inline AstFromAch(int ach, int achPrev = achInvdI):
assert csgr >= 0 and csgr <= 4, "more sgr possibilities, please handle" assert csgr >= 0 and csgr <= 4, "more sgr possibilities, please handle"
return ast return ast
#@-node:jpenner.20091212133112.4:Ach
#@+node:jpenner.20091212133112.5:HTML
mpch_entity = [0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668, 8597, 8252, mpch_entity = [0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668, 8597, 8252,
182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, 9660, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, 9660, 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, 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,
@ -202,8 +191,6 @@ cdef HstFromAch(int ach, int achPrev = achInvdI):
rgst.append("&#" + str(entity) + ";") rgst.append("&#" + str(entity) + ";")
return ''.join(rgst) return ''.join(rgst)
#@-node:jpenner.20091212133112.5:HTML
#@+node:jpenner.20091212133112.6:Pos
class Pos(object): class Pos(object):
def __init__(self, int w=config.W, int h=config.H, int x=1, int y=1): def __init__(self, int w=config.W, int h=config.H, int x=1, int y=1):
self.i = PosI(w, h, x, y) self.i = PosI(w, h, x, y)
@ -271,9 +258,6 @@ cdef class PosI(object):
return True return True
cdef ToPos(self): cdef ToPos(self):
return Pos(self.w, self.h, self.X(), self.Y()) return Pos(self.w, self.h, self.X(), self.Y())
#@nonl
#@-node:jpenner.20091212133112.6:Pos
#@+node:jpenner.20100105170222.1:Ascr
class Ascr(object): class Ascr(object):
def __init__(self, int w=config.W, int h=config.H, int achFill = achBlankI): def __init__(self, int w=config.W, int h=config.H, int achFill = achBlankI):
@ -313,8 +297,6 @@ class Ascr(object):
cdef AscrI ascrI = self.i cdef AscrI ascrI = self.i
return ascrI.ZPos(xz, yz) return ascrI.ZPos(xz, yz)
#@ @+others
#@+node:jpenner.20100105170222.2:Put
def PutAch(self, int ach, int x, int y): def PutAch(self, int ach, int x, int y):
cdef AscrI ascrI = self.i cdef AscrI ascrI = self.i
ascrI.PutAch(ach, x, y) ascrI.PutAch(ach, x, y)
@ -338,9 +320,7 @@ class Ascr(object):
def PutAscr(self, ascr, int x=1, int y=1): def PutAscr(self, ascr, int x=1, int y=1):
cdef AscrI ascrI = self.i cdef AscrI ascrI = self.i
ascrI.PutAscr(ascr.i, x, y) ascrI.PutAscr(ascr.i, x, y)
#@nonl
#@-node:jpenner.20100105170222.2:Put
#@+node:jpenner.20100105170222.3:Diff
def AstDiff(self, ascr): def AstDiff(self, ascr):
cdef AscrI ascrI = self.i cdef AscrI ascrI = self.i
return ascrI.AstDiff(ascr.i) return ascrI.AstDiff(ascr.i)
@ -348,15 +328,9 @@ class Ascr(object):
def Hst(self): def Hst(self):
cdef AscrI ascrI = self.i cdef AscrI ascrI = self.i
return ascrI.Hst() return ascrI.Hst()
#@-node:jpenner.20100105170222.3:Diff
#@+node:jpenner.20091212133112.10:Ast
def Ast(self): def Ast(self):
return Ascr(self.W(), self.H(), achInvdI).AstDiff(self) #stupid implementation return Ascr(self.W(), self.H(), achInvdI).AstDiff(self) #stupid implementation
#@nonl
#@-node:jpenner.20091212133112.10:Ast
#@-others
#@-node:jpenner.20100105170222.1:Ascr
#@+node:jpenner.20091212133112.7:AscrI
# ANSI Screen # ANSI Screen
cdef class AscrI(object): cdef class AscrI(object):
@ -376,8 +350,6 @@ cdef class AscrI(object):
cdef Zpos(self, int xz, int yz): cdef Zpos(self, int xz, int yz):
return Pos(self.w, self.h, xz + 1, yz + 1) return Pos(self.w, self.h, xz + 1, yz + 1)
#@ @+others
#@+node:jpenner.20091212133112.8:Put
cdef inline IAch(self, int xz, int yz): cdef inline IAch(self, int xz, int yz):
return xz + (self.w * yz) return xz + (self.w * yz)
@ -461,8 +433,7 @@ cdef class AscrI(object):
iach = iach + 1 iach = iach + 1
iachOther = iachOther + 1 iachOther = iachOther + 1
yzOther = yzOther + 1 yzOther = yzOther + 1
#@-node:jpenner.20091212133112.8:Put
#@+node:jpenner.20091212133112.9:AstDiff
cdef AstDiff(self, AscrI ascr): cdef AstDiff(self, AscrI ascr):
assert self.w == ascr.w and self.h == ascr.h assert self.w == ascr.w and self.h == ascr.h
cdef int xz = 0 cdef int xz = 0
@ -508,8 +479,7 @@ cdef class AscrI(object):
xzPred = -1 xzPred = -1
yz = yz + 1 yz = yz + 1
return "".join(rgast) return "".join(rgast)
#@-node:jpenner.20091212133112.9:AstDiff
#@+node:jpenner.20091212133112.11:Hst
cdef Hst(self): cdef Hst(self):
rgst = ["<pre style='font-family:\"Courier New\", Courier, System, monospace'>"] rgst = ["<pre style='font-family:\"Courier New\", Courier, System, monospace'>"]
cdef int achPrev = achInvdI cdef int achPrev = achInvdI
@ -526,15 +496,6 @@ cdef class AscrI(object):
rgst.append("</span></pre>") rgst.append("</span></pre>")
return ''.join(rgst) return ''.join(rgst)
#@-node:jpenner.20091212133112.11:Hst
#@-others
#@-node:jpenner.20091212133112.7:AscrI
#@+node:jpenner.20091212133112.12:FKeyPrintable
def FKeyPrintable(key): def FKeyPrintable(key):
return type(key) == str and (ord(key) >= 32 and ord(key) <= 126) return type(key) == str and (ord(key) >= 32 and ord(key) <= 126)
#@-node:jpenner.20091212133112.12:FKeyPrintable
#@-others
#@nonl
#@-node:jpenner.20091212133112.2:@thin ansi_cython.pyx
#@-leo

View file

@ -1,11 +1,6 @@
#@+leo-ver=4-thin
#@+node:jpenner.20090510085557.4:@thin ansi_python.py
#@@language python
import config import config
import numpy import numpy
#@+others
#@+node:jpenner.20091212133112.3:Codes
esc = '%s['%chr(27) esc = '%s['%chr(27)
reset = '%s0m'%esc reset = '%s0m'%esc
cls = '%s2j'%esc cls = '%s2j'%esc
@ -51,9 +46,7 @@ def Ctrl(ch):
def FEnter(key): def FEnter(key):
return key == "\n" or key == "\r" return key == "\n" or key == "\r"
#@nonl
#@-node:jpenner.20091212133112.3:Codes
#@+node:jpenner.20090510085557.6:Ach
# ANSI Character - contains prop and character # ANSI Character - contains prop and character
class Ach(object): class Ach(object):
def __init__(self, ch, fgcol=WHITE, bgcol=BLACK): def __init__(self, ch, fgcol=WHITE, bgcol=BLACK):
@ -99,8 +92,6 @@ def AstFromAch(ach, achPrev = None):
dtAch = numpy.dtype(object) dtAch = numpy.dtype(object)
#@-node:jpenner.20090510085557.6:Ach
#@+node:jpenner.20091016050502.2:HTML
mpch_entity = [0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668, 8597, 8252, mpch_entity = [0, 9786, 9787, 9829, 9830, 9827, 9824, 8226, 9688, 9675, 9689, 9794, 9792, 9834, 9835, 9788, 9658, 9668, 8597, 8252,
182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, 9660, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 182, 167, 9644, 8616, 8593, 8595, 8594, 8592, 8735, 8596, 9650, 9660, 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, 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,
@ -133,9 +124,7 @@ def HstFromAch(ach, achPrev = None):
else: else:
rgst.append("&#" + str(mpch_entity[ord(ach.ch)]) + ";") rgst.append("&#" + str(mpch_entity[ord(ach.ch)]) + ";")
return ''.join(rgst) return ''.join(rgst)
#@nonl
#@-node:jpenner.20091016050502.2:HTML
#@+node:jpenner.20090510085557.7:Pos
class Pos(object): class Pos(object):
def __init__(self, w=config.W, h=config.H, x=1, y=1): def __init__(self, w=config.W, h=config.H, x=1, y=1):
self.w = w self.w = w
@ -166,8 +155,7 @@ class Pos(object):
def Right(self): def Right(self):
if self.xz < self.w - 1: if self.xz < self.w - 1:
self.xz = self.xz + 1 self.xz = self.xz + 1
#@-node:jpenner.20090510085557.7:Pos
#@+node:jpenner.20090510085557.8:Ascr
# ANSI Screen # ANSI Screen
class Ascr(object): class Ascr(object):
def __init__(self, w=config.W, h=config.H, achFill = None): def __init__(self, w=config.W, h=config.H, achFill = None):
@ -182,8 +170,6 @@ class Ascr(object):
def W(self): return self.w def W(self): return self.w
def H(self): return self.h def H(self): return self.h
#@ @+others
#@+node:jpenner.20090526105844.8:Put
def PutAch(self, ach, x, y): def PutAch(self, ach, x, y):
if not (x < 1 or y < 1 or x > self.w or y > self.h): #clip if not (x < 1 or y < 1 or x > self.w or y > self.h): #clip
self.mpyzxz_ach[y-1][x-1] = ach self.mpyzxz_ach[y-1][x-1] = ach
@ -226,8 +212,7 @@ class Ascr(object):
if iachPut >= 0: if iachPut >= 0:
self.PutRgach(rgachRow[iachPut:], x + iachPut, y + irow) self.PutRgach(rgachRow[iachPut:], x + iachPut, y + irow)
iachPut = -1 iachPut = -1
#@-node:jpenner.20090526105844.8:Put
#@+node:jpenner.20090527144214.3:Diff
def AstDiff(self, ascr): def AstDiff(self, ascr):
assert self.w == ascr.w and self.h == ascr.h assert self.w == ascr.w and self.h == ascr.h
rgast = [] rgast = []
@ -261,14 +246,10 @@ class Ascr(object):
xz = xz + 1 xz = xz + 1
yz = yz + 1 yz = yz + 1
return "".join(rgast) return "".join(rgast)
#@nonl
#@-node:jpenner.20090527144214.3:Diff
#@+node:jpenner.20090529173104.26:Ast
def Ast(self): def Ast(self):
return Ascr(self.w, self.h, achInvd).AstDiff(self) #stupid implementation return Ascr(self.w, self.h, achInvd).AstDiff(self) #stupid implementation
#@nonl
#@-node:jpenner.20090529173104.26:Ast
#@+node:jpenner.20091016050502.3:Hst
def Hst(self): def Hst(self):
rgst = ["<pre>"] rgst = ["<pre>"]
achPrev = None achPrev = None
@ -279,16 +260,6 @@ class Ascr(object):
rgst.append("<br>") rgst.append("<br>")
rgst.append("</span></pre>") rgst.append("</span></pre>")
return ''.join(rgst) return ''.join(rgst)
#@nonl
#@-node:jpenner.20091016050502.3:Hst
#@-others
#@-node:jpenner.20090510085557.8:Ascr
#@+node:jpenner.20090521203229.341:FKeyPrintable
def FKeyPrintable(key): def FKeyPrintable(key):
return type(key) == str and (ord(key) >= 32 and ord(key) <= 126) return type(key) == str and (ord(key) >= 32 and ord(key) <= 126)
#@-node:jpenner.20090521203229.341:FKeyPrintable
#@-others
#@nonl
#@-node:jpenner.20090510085557.4:@thin ansi_python.py
#@-leo

View file

@ -1,5 +1,3 @@
#@+leo-ver=4-thin
#@+node:jpenner.20090607135901.1:@thin auth.py
import MySQLdb import MySQLdb
import hashlib import hashlib
import config import config
@ -22,6 +20,3 @@ class DrupalAuth(object):
return False return False
finally: finally:
conn.close() conn.close()
#@-node:jpenner.20090607135901.1:@thin auth.py
#@-leo

View file

@ -1,5 +1,3 @@
#@+leo-ver=4-thin
#@+node:jpenner.20091016050502.1:@thin build_entity.py
import re import re
reEnt = re.compile(r"^.*&#(\d+);.*$"); reEnt = re.compile(r"^.*&#(\d+);.*$");
@ -11,6 +9,3 @@ with open("cp437_html.txt") as fp:
mpch_entity.append(int(ent)) mpch_entity.append(int(ent))
print "mpch_entity = ", mpch_entity print "mpch_entity = ", mpch_entity
#@nonl
#@-node:jpenner.20091016050502.1:@thin build_entity.py
#@-leo

View file

@ -1,14 +1,8 @@
#@+leo-ver=4-thin
#@+node:jpenner.20090526212048.3:@thin haxor.py
from engine import * from engine import *
from basetoken import * from basetoken import *
import telnet import telnet
#@<<IntroTerm>>
#@+node:jpenner.20090526212048.6:<<IntroTerm>>
class IntroTerm(Terminal): class IntroTerm(Terminal):
#@ @+others
#@+node:jpenner.20090526212048.5:run
def run(self): def run(self):
self.newLine(3, 300) self.newLine(3, 300)
self.type("Logon Please: ") self.type("Logon Please: ")
@ -50,11 +44,6 @@ class IntroTerm(Terminal):
self.printSt("NO CARRIER") self.printSt("NO CARRIER")
self.newLine() self.newLine()
self.client.quit() self.client.quit()
#@-node:jpenner.20090526212048.5:run
#@-others
#@nonl
#@-node:jpenner.20090526212048.6:<<IntroTerm>>
#@nl
class Haxor(object): class Haxor(object):
def __init__(self): def __init__(self):
@ -66,6 +55,3 @@ class Haxor(object):
if __name__ == "__main__": if __name__ == "__main__":
Haxor().RunServer() Haxor().RunServer()
#@nonl
#@-node:jpenner.20090526212048.3:@thin haxor.py
#@-leo

View file

@ -1,6 +1,3 @@
#@+leo-ver=4-thin
#@+node:jpenner.20090510085557.10:@thin telnet.py
#@@language python
from twisted.protocols import basic from twisted.protocols import basic
from twisted.conch import telnet from twisted.conch import telnet
from twisted.internet.protocol import Factory,ServerFactory from twisted.internet.protocol import Factory,ServerFactory
@ -12,8 +9,6 @@ import engine
import sys import sys
import config import config
#@<<Server>>
#@+node:jpenner.20090513213413.1:<<Server>>
class AnsiTelnet(protocol.Protocol): class AnsiTelnet(protocol.Protocol):
implements(telnet.ITelnetProtocol) implements(telnet.ITelnetProtocol)
@ -58,8 +53,6 @@ class AnsiTelnet(protocol.Protocol):
print "end: ", len(rgdefr) print "end: ", len(rgdefr)
self.Hello() self.Hello()
#@ <<Options>>
#@+node:jpenner.20090514181656.118:<<Options>>
def enableLocal(self, option): def enableLocal(self, option):
print "enableLocal", ord(option) print "enableLocal", ord(option)
return option in self.rgoptLocal return option in self.rgoptLocal
@ -73,9 +66,6 @@ class AnsiTelnet(protocol.Protocol):
def disableRemote(self, option): def disableRemote(self, option):
print "disableRemote", option print "disableRemote", option
pass pass
#@nonl
#@-node:jpenner.20090514181656.118:<<Options>>
#@nl
def dataReceived(self, data): def dataReceived(self, data):
if self.ast != None: if self.ast != None:
@ -113,8 +103,6 @@ class AnsiTelnet(protocol.Protocol):
if ichSplit < ich: if ichSplit < ich:
self.RcvText(data[ichSplit:ich]) self.RcvText(data[ichSplit:ich])
#@ @+others
#@+node:jpenner.20090526105844.6:Hello
def Hello(self): def Hello(self):
print "negotiated!" print "negotiated!"
self.transport.write(ansi.esc + "2J") #cls self.transport.write(ansi.esc + "2J") #cls
@ -122,9 +110,7 @@ class AnsiTelnet(protocol.Protocol):
self.client.dgJoinGame = self.CreateEvents self.client.dgJoinGame = self.CreateEvents
self.client.addDgQuit(self.transport.loseConnection) self.client.addDgQuit(self.transport.loseConnection)
self.client.go(self.factory.fnRun, self) self.client.go(self.factory.fnRun, self)
#@nonl
#@-node:jpenner.20090526105844.6:Hello
#@+node:jpenner.20090526212048.1:Keys
def RcvText(self, text): def RcvText(self, text):
if self.client.evKey: if self.client.evKey:
for ch in text: for ch in text:
@ -142,9 +128,7 @@ class AnsiTelnet(protocol.Protocol):
def CreateEvents(self, client, game): def CreateEvents(self, client, game):
client.evKey = engine.Event(game) client.evKey = engine.Event(game)
#@nonl
#@-node:jpenner.20090526212048.1:Keys
#@+node:jpenner.20090527144214.1:Draw
def Draw(self, ascr): def Draw(self, ascr):
self.transport.write(self.ascr.AstDiff(ascr)) self.transport.write(self.ascr.AstDiff(ascr))
self.transport.write(ansi.esc + "H") #cursor stays in top-left corner? ascr should contain a cursor pos? self.transport.write(ansi.esc + "H") #cursor stays in top-left corner? ascr should contain a cursor pos?
@ -152,21 +136,12 @@ class AnsiTelnet(protocol.Protocol):
def Refresh(self): def Refresh(self):
self.ascr = ansi.Ascr(config.W, config.H, ansi.achInvd) self.ascr = ansi.Ascr(config.W, config.H, ansi.achInvd)
#@nonl
#@-node:jpenner.20090527144214.1:Draw
#@+node:jpenner.20090529173104.4:connectionLost
def connectionLost(self, reason): def connectionLost(self, reason):
print "lost connection" print "lost connection"
self.client.removeDgQuit(self.transport.loseConnection) self.client.removeDgQuit(self.transport.loseConnection)
self.client.quit() self.client.quit()
#@nonl
#@-node:jpenner.20090529173104.4:connectionLost
#@-others
#@nonl
#@-node:jpenner.20090513213413.1:<<Server>>
#@nl
#@<<factory>>
#@+node:jpenner.20090515161650.1:<<factory>>
class AnsiFactory(ServerFactory): class AnsiFactory(ServerFactory):
def __init__(self, fnRun): def __init__(self, fnRun):
self.fnRun = fnRun self.fnRun = fnRun
@ -175,21 +150,14 @@ class AnsiFactory(ServerFactory):
p.factory = self p.factory = self
print "built protocol for ", addr print "built protocol for ", addr
return p return p
#@-node:jpenner.20090515161650.1:<<factory>>
#@nl
#@<<Flash Policy>>
#@+node:jpenner.20090518103251.118:<<Flash Policy>>
class FlashPolicy(basic.LineReceiver): class FlashPolicy(basic.LineReceiver):
delimiter = '\0' delimiter = '\0'
def lineReceived(self,line): def lineReceived(self,line):
if line == "<policy-file-request/>": if line == "<policy-file-request/>":
self.sendLine("<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"" + str(config.PORT_TELNET) + "\" /></cross-domain-policy>") self.sendLine("<?xml version=\"1.0\"?><cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"" + str(config.PORT_TELNET) + "\" /></cross-domain-policy>")
#@-node:jpenner.20090518103251.118:<<Flash Policy>>
#@nl
#@<<Command server>>
#@+node:jpenner.20090914034457.2:<<Command server>>
class CmdProtocol(basic.LineReceiver): class CmdProtocol(basic.LineReceiver):
def connectionMade(self): def connectionMade(self):
if self.transport.getHost().host != "127.0.0.1": if self.transport.getHost().host != "127.0.0.1":
@ -207,11 +175,7 @@ class CmdFactory(ServerFactory):
p.factory = self p.factory = self
print "built cmd protocol for ", addr print "built cmd protocol for ", addr
return p return p
#@-node:jpenner.20090914034457.2:<<Command server>>
#@nl
#@<<runner>>
#@+node:jpenner.20090513213413.2:<<runner>>
def RunServer(fnRun): def RunServer(fnRun):
log.startLogging(sys.stdout) log.startLogging(sys.stdout)
@ -226,8 +190,3 @@ def RunServer(fnRun):
def RunCmdServer(fnCmd): def RunCmdServer(fnCmd):
if config.PORT_CMDSERVER: if config.PORT_CMDSERVER:
reactor.listenTCP(config.PORT_CMDSERVER, CmdFactory(fnCmd), 50, "localhost") reactor.listenTCP(config.PORT_CMDSERVER, CmdFactory(fnCmd), 50, "localhost")
#@nonl
#@-node:jpenner.20090513213413.2:<<runner>>
#@nl
#@-node:jpenner.20090510085557.10:@thin telnet.py
#@-leo

View file

@ -1,103 +0,0 @@
#@+leo-ver=4-thin
#@+node:jpenner.20090714203921.6:@thin tpers_old.py
import ZODB
import persistent
#@+others
#@+node:jpenner.20090714203921.7:def MkTransparent
def MkTransparent(value):
if type(value) == list:
return TPL(value)
elif type(value) == dict:
return TPM(value)
elif type(value) == set:
return TPS(value)
elif type(value) == tuple:
return TPT(value)
else:
return value
#@-node:jpenner.20090714203921.7:def MkTransparent
#@+node:jpenner.20090714203921.10:def RgTransparent
def RgTransparent(rg):
if rg == None: return []
return [MkTransparent(x) for x in rg]
#@-node:jpenner.20090714203921.10:def RgTransparent
#@+node:jpenner.20090714203921.11:def MpTransparent
def MpTransparent(mp):
if isinstance(mp, TPM): return mp
mpNew = {}
if mp != None:
for k,v in mp.iteritems():
mpNew[k] = MkTransparent(v)
return mpNew
#@-node:jpenner.20090714203921.11:def MpTransparent
#@+node:jpenner.20090714203921.8:class TPrs
class TPrs(persistent.Persistent):
__prs_setattr = persistent.Persistent.__setattr__
def __setattr__(self, name, value):
self.__prs_setattr(name, MkTransparent(value))
#@-node:jpenner.20090714203921.8:class TPrs
#@+node:jpenner.20090714203921.9:class TPL
class TPL(clsList):
__pl_setitem = clsList.__setitem__
__pl_setslice = clsList.__setslice__
__pl_iadd = clsList.__iadd__
__pl_append = clsList.append
__pl_insert = clsList.insert
__pl_extend = clsList.extend
def __init__(self, rg = None):
clsList.__init__(self, RgTransparent(rg))
def __setitem__(self, i, item):
return self.__pl_setitem(i, MkTransparent(item))
def __setslice__(self, i, j, other):
return self.__pl_setslice(i, j, RgTransparent(other))
def __iadd__(self, other):
return self.__pl_iadd(RgTransparent(other))
def append(self, item):
return self.__pl_append(MkTransparent(item))
def insert(self, i, item):
return self.__pl_insert(i, MkTransparent(item))
def extend(self, other):
return self.__pl_extend(RgTransparent(other))
def __reduce__(self):
return (MkTransparent, ([MkPersistable(x) for x in self],))
# Strip weak references rather than replacing them with None
class TPLS(TPL):
def __reduce__(self):
return (MkTransparent, ([x for x in self if FPersist(x)],))
#@-node:jpenner.20090714203921.9:class TPL
#@+node:jpenner.20090714203921.12:class TPM
class TPM(clsDict):
__pm_setitem = clsDict.__setitem__
__pm_update = clsDict.update
def __init__(self, *rgarg, **kwarg):
clsDict.__init__(self, MpTransparent(dict(*rgarg, **kwarg)))
def __setitem__(self, k, v):
return self.__pm_setitem(k, MkTransparent(v))
def update(self, other, **kwargs):
return self.__pm_update(MpTransparent(other), **MpTransparent(kwargs))
def __reduce__(self):
mp = {}
for k, v in self.iteritems():
if FPersist(k):
mp[k] = MkPersistable(v)
return (MkTransparent, (mp,))
#@-node:jpenner.20090714203921.12:class TPM
#@-others
#@-node:jpenner.20090714203921.6:@thin tpers_old.py
#@-leo

View file

@ -1,5 +1,3 @@
#@+leo-ver=4-thin
#@+node:jpenner.20090528201601.6:@thin whiteboard.py
from engine import * from engine import *
from basetoken import * from basetoken import *
from tpers import * from tpers import *
@ -10,8 +8,6 @@ import time
import login import login
import weakref import weakref
#@<<Whiteboard>>
#@+node:jpenner.20090528201601.9:<<Whiteboard>>
class Layer(TPrs): class Layer(TPrs):
def InitPersistent(self, ascr, stName): def InitPersistent(self, ascr, stName):
self.ascr = ascr self.ascr = ascr
@ -82,8 +78,7 @@ class Board(Ownable):
def draw(self, ascr): def draw(self, ascr):
for layer in reversed(self.rglayer): for layer in reversed(self.rglayer):
layer.Draw(ascr) layer.Draw(ascr)
#@ @+others
#@+node:jpenner.20090602154503.5:Save
def Save(self): def Save(self):
fn = config.DIR_ANSI + "/" + "_".join([str(x) for x in time.localtime()]) fn = config.DIR_ANSI + "/" + "_".join([str(x) for x in time.localtime()])
ascr = ansi.Ascr(self.W(), self.H()) ascr = ansi.Ascr(self.W(), self.H())
@ -94,9 +89,7 @@ class Board(Ownable):
fl.write("</center></body></html>") fl.write("</center></body></html>")
with open(fn + ".ans", "w") as fl: with open(fn + ".ans", "w") as fl:
fl.write(ascr.Ast()) fl.write(ascr.Ast())
#@nonl
#@-node:jpenner.20090602154503.5:Save
#@-others
def UpgradeFrom(self, versionOld): def UpgradeFrom(self, versionOld):
if versionOld < 2: if versionOld < 2:
gameWB = [gameWB for gameWB in self.owner.rggameWB if gameWB.rgtoken("whiteboard")[0].board == self][0] gameWB = [gameWB for gameWB in self.owner.rggameWB if gameWB.rgtoken("whiteboard")[0].board == self][0]
@ -127,10 +120,10 @@ class Whiteboard(Token):
del self.rglayer del self.rglayer
if versionOld < 5: if versionOld < 5:
self.board = Board(self.game.gameLobby, self.game.stName, self.game.user, rglayer, dt) self.board = Board(self.game.gameLobby, self.game.stName, self.game.user, rglayer, dt)
#@-node:jpenner.20090528201601.9:<<Whiteboard>>
#@nl
#@<<Chat>>
#@+node:jpenner.20090918200439.1:<<Chat>>
class Chl(object): class Chl(object):
def __init__(self, client, st): def __init__(self, client, st):
self.user = client.cld.user self.user = client.cld.user
@ -215,10 +208,7 @@ class Chat(TPrs):
while yDraw < y + h: while yDraw < y + h:
ascr.PutSt("{0:{1}}".format("", w), x, yDraw, ansi.WHITE, colBg) ascr.PutSt("{0:{1}}".format("", w), x, yDraw, ansi.WHITE, colBg)
yDraw = yDraw + 1 yDraw = yDraw + 1
#@-node:jpenner.20090918200439.1:<<Chat>>
#@nl
#@<<Cursor>>
#@+node:jpenner.20090528201601.10:<<Cursor>>
class Cursor(TokenClient): class Cursor(TokenClient):
def InitPersistent(self, game, client): def InitPersistent(self, game, client):
TokenClient.InitPersistent(self, game, client, "drawable", "cursor") TokenClient.InitPersistent(self, game, client, "drawable", "cursor")
@ -413,12 +403,7 @@ class CursorBlinker(Token):
def BlinkAllCursors(self, fBlink): def BlinkAllCursors(self, fBlink):
for tok in self.game.rgtoken("cursor"): for tok in self.game.rgtoken("cursor"):
tok.blinkCursor(fBlink) tok.blinkCursor(fBlink)
#@-node:jpenner.20090528201601.10:<<Cursor>>
#@nl
#@<<Overlay>>
#@+node:jpenner.20090614150414.1:<<Overlay>>
#@+others
#@+node:jpenner.20090529173104.19:MiColour
class MiColour(MiList): class MiColour(MiList):
def InitPersistent(self, stName, rgcolor, col): def InitPersistent(self, stName, rgcolor, col):
self.rgcolor = rgcolor self.rgcolor = rgcolor
@ -432,8 +417,7 @@ class MiColour(MiList):
for icol in range(len(self.rgcolor)): for icol in range(len(self.rgcolor)):
col = self.rgcolor[icol] col = self.rgcolor[icol]
ascr.PutAch(ansi.MkAch(chr(219) if icol != self.ival else chr(254), col, ansi.BLACK if col != ansi.BLACK else ansi.WHITE), x + icol, y) ascr.PutAch(ansi.MkAch(chr(219) if icol != self.ival else chr(254), col, ansi.BLACK if col != ansi.BLACK else ansi.WHITE), x + icol, y)
#@-node:jpenner.20090529173104.19:MiColour
#@+node:jpenner.20090529173104.20:MiChars
class MiChars(MiList): class MiChars(MiList):
def InitPersistent(self, rgchar, miFg, miBg): def InitPersistent(self, rgchar, miFg, miBg):
MiList.InitPersistent(self, rgchar) MiList.InitPersistent(self, rgchar)
@ -456,9 +440,7 @@ def IchFromCh(ch):
if ch == '0': if ch == '0':
return 9 return 9
return int(ch) - 1 return int(ch) - 1
#@nonl
#@-node:jpenner.20090529173104.20:MiChars
#@+node:jpenner.20090926091308.1:MiChat
class MiChat(Mi): class MiChat(Mi):
KWNDMSG = 0 KWNDMSG = 0
KWNDUSERS = 1 KWNDUSERS = 1
@ -528,13 +510,7 @@ class MiChat(Mi):
ascr.PutAch(ansi.MkAch("A", ansi.RED, ansi.WHITE), xBar, yBar) ascr.PutAch(ansi.MkAch("A", ansi.RED, ansi.WHITE), xBar, yBar)
ascr.PutAch(ansi.MkAch(chr(186), ansi.RED, ansi.WHITE), xBar, yBar + 1) ascr.PutAch(ansi.MkAch(chr(186), ansi.RED, ansi.WHITE), xBar, yBar + 1)
ascr.PutAch(ansi.MkAch("Z", ansi.RED, ansi.WHITE), xBar, yBar + 2) ascr.PutAch(ansi.MkAch("Z", ansi.RED, ansi.WHITE), xBar, yBar + 2)
#@-node:jpenner.20090926091308.1:MiChat
#@-others
#@nonl
#@-node:jpenner.20090614150414.1:<<Overlay>>
#@nl
#@<<Joiner>>
#@+node:jpenner.20090529173104.3:<<Joiner>>
class Joiner(Token): class Joiner(Token):
def InitPersistent(self, owner): def InitPersistent(self, owner):
Token.InitPersistent(self, owner) Token.InitPersistent(self, owner)
@ -560,11 +536,6 @@ class Joiner(Token):
while True: while True:
with self.game.evJoin.oob(self, self.OnJoin): with self.game.evJoin.oob(self, self.OnJoin):
self.OnLeave(self.game.evLeave.receive(self)) self.OnLeave(self.game.evLeave.receive(self))
#@-node:jpenner.20090529173104.3:<<Joiner>>
#@nl
#@+others
#@+node:jpenner.20091003162445.1:Lobby
class Lobby(TokenClient): class Lobby(TokenClient):
def InitPersistent(self, owner, client): def InitPersistent(self, owner, client):
@ -586,8 +557,7 @@ class Lobby(TokenClient):
def Goto(self, board): def Goto(self, board):
self.client.leaveGame(board) self.client.leaveGame(board)
#@-node:jpenner.20091003162445.1:Lobby
#@+node:jpenner.20090529173104.25:Runner
class RunnerWB(Runner): class RunnerWB(Runner):
def InitPersistent(self): def InitPersistent(self):
self.gameLobby = GameLobby() self.gameLobby = GameLobby()