本文整理汇总了Python中CPL类的典型用法代码示例。如果您正苦于以下问题:Python CPL类的具体用法?Python CPL怎么用?Python CPL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CPL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setActorsForProgram
def setActorsForProgram(self, program, actors, cmd=None):
""" Define the list of actors that a program can command.
"""
if self.debug > 3:
CPL.log("auth.setActors", "setting actors for commander %s: %s" % (program, actors))
if not cmd:
cmd = self.defaultCmd
if program not in self.programs:
cmd.fail("permsTxt=%s" % (CPL.qstr("Program %s did not have an authorization entry, so could not be set" % (program))))
return
d = {}
for a in actors:
if a not in self.actors:
cmd.warn("permsTxt=%s" % (CPL.qstr("Actor %s is not subject to permissions." % (a))))
else:
d[a] = True
# Make sure God-like commanders can always command us...
#
if program in self.gods:
d['perms'] = True
self.programs[program] = d
self.genAuthKeys(programs=[program], cmd=cmd)
示例2: dropPrograms
def dropPrograms(self, programs=[], cmd=None):
""" Remove a list of programs from the control list.
Args:
programs - a list of programs to register for authorization. Adds all connected
programs if empty.
cmd - The command to reply to, or .defaultCmd
"""
if not programs:
programs = list(self.programs.keys())
if self.debug > 3:
CPL.log("auth.dropProgram", "dropping programs %s" % (programs))
if not cmd:
cmd = self.defaultCmd
for program in programs:
if program in self.gods:
cmd.warn("permsTxt=%s" % \
(CPL.qstr("Super-%s cannot be removed from the list of authorized programs" % (program))))
self.genAuthKeys([program], cmd)
continue
try:
del self.programs[program]
except:
cmd.warn("permsTxt=%s" % \
(CPL.qstr("Program %s did not have an authorization entry, so could not be deleted" % (program))))
self.genProgramsKey(cmd=cmd)
示例3: encode
def encode(self, cmd):
if self.useCID:
if self.CIDfirst:
ids = "%s %s " % (cmd.actorCid, cmd.actorMid)
else:
ids = "%s %s " % (cmd.actorMid, cmd.actorCid)
else:
ids = "%s " % (cmd.actorMid,)
if self.sendCmdrCID:
cmdrInfo = "%s " % (cmd.cmdrCid)
elif self.sendCmdr:
cmdrInfo = "%s " % (cmd.cmdrName)
else:
cmdrInfo = ""
if self.useTarget:
e = "%s%s %s%s%s" % (cmdrInfo, cmd.actorName, ids, cmd.cmd, self.EOL)
else:
e = "%s%s%s%s" % (cmdrInfo, ids, cmd.cmd, self.EOL)
if self.debug > 5:
CPL.log("ASCIIEncoder", "encoded: %s" % (e))
return e
示例4: addPrograms
def addPrograms(self, programs=[], actors=[], cmd=None):
""" Add a list program to the control list.
Args:
program - a list of program names. Use all connected programs if empty.
actors - an optional list of actors that the commander can command.
"""
if not cmd:
cmd = self.defaultCmd
if not programs:
programs = []
for name, cmdr in g.commanders.items():
if cmdr.needsAuth and name not in self.programs:
programs.append(name)
if self.debug > 3:
CPL.log("auth.addPrograms",
"adding programs %s with actors=%s" % (programs, actors))
for prog in programs:
if prog in self.programs:
cmd.warn("permsTxt=%s" % \
(CPL.qstr("Program %s already has an authorization entry, which will not be modified." % (prog))))
continue
self.programs[prog] = {}
self.setActorsForProgram(prog, actors, cmd=cmd)
self.genProgramsKey(cmd=cmd)
示例5: encode
def encode(self, cmd):
e = "%s%s" % (cmd.cmd, self.EOL)
if self.debug > 5:
CPL.log("RawEncoder", "encoded: %s" % (e))
return e
示例6: lockActors
def lockActors(self, actors, cmd=None):
""" Block non-APO users form commanding a list of actors.
Any actors not in .actors will be ignored with a warning. This may not be the right behavior. We may
actually want to allow actors we do not control to be locked.
"""
if not cmd:
cmd = self.defaultCmd
if not actors:
actors = self.actors
if self.debug > 3:
CPL.log("auth.lockActor", "locking actors %s" % (actors))
for a in actors:
if a in self.lockedActors:
cmd.warn("permsTxt=%s" % (CPL.qstr("Actor %s is already locked" % (a))))
elif a not in self.actors:
cmd.warn("permsTxt=%s" % (CPL.qstr("Actor %s is not subject to permissions and will not be locked" % (a))))
else:
self.lockedActors[a] = True
self.genLockedKey(cmd=cmd)
示例7: genAuthKeys
def genAuthKeys(self, programs=None, cmd=None):
""" Generate keys describing some or all programs.
Args:
cmd - if set, the command to reply to. Otherwise use our .defaultCmd
programs - if set, a list of programs to generate keys for. Otherwise describe all programs.
Notes:
Never finishes the cmd.
"""
if not cmd:
cmd = self.defaultCmd
if not programs:
programs = list(self.programs.keys())
programs.sort()
CPL.log("auth.genAuthKeys", "listing programs: %s" % (programs))
for prog in programs:
try:
pAuth = list(self.programs[prog].keys())
except KeyError as e:
raise Exception("No authorization entry found for program %s" % (prog))
pAuth.sort()
actors = [CPL.qstr(x) for x in pAuth]
cmd.inform("authList=%s,%s" % (CPL.qstr(prog), ','.join(actors)))
示例8: parseKVs
def parseKVs(self, kvl):
""" Convert some form of keys to an OrderedDict.
We are trying to be ridiculously flexible here. Take:
- a string, which we parse as it came from an ICC.
- a list, which we parse either as a list of key=value strings or of (key, value) duples.
"""
if isinstance(kvl, str):
return Parsing.parseKVs(kvl)
od = collections.OrderedDict()
if kvl is not None:
for i in kvl:
if isinstance(i, str):
k, v, junk = Parsing.parseKV(i)
od[k] = v
elif type(i) in (list, tuple) and len(i) == 2:
k, v, junk = Parsing.parseKV("%s=%s" % i)
else:
CPL.log('Reply', 'kvl item is not a string: %r' % (i))
raise Exception("kvl == %r" % (i))
return od
示例9: __init__
def __init__(self, poller, **argv):
CPL.Object.__init__(self, **argv)
self.poller = poller
CPL.log("IOHandler.init", "IOHandler(argv=%s)" % (argv))
# The IO size tweaks would mean something for slow network links.
#
self.tryToRead = argv.get('readSize', 4096)
self.tryToWrite = argv.get('writeSize', 4096)
self.tryToWriteMany = argv.get('writeMany', False)
self.oneAtATime = argv.get('oneAtATime', False)
self.in_f = self.out_f = None
self.in_fd = self.out_fd = None
self.outQueue = []
self.queueLock = CPL.LLock(debug = (argv.get('debug', 0) > 7))
self.setInputFile(argv.get('in_f', None))
self.setOutputFile(argv.get('out_f', None))
# Some stats
#
self.totalReads = 0
self.totalBytesRead = 0
self.largestRead = 0
self.totalQueued = 0
self.maxQueue = 0
self.totalOutputs = 0
self.totalWrites = 0
self.totalBytesWritten = 0
self.largestWrite = 0
示例10: connected
def connected(self):
""" Optionally send a list of commands after the connection has been established.
This is complicated by .grabCID. If that exists, we want to sent a command just to
force the actor to generate our CID. If we send the init comands before that is
established, we will not recognize the replies as replies to our init commands.
So if .grabCID is set and our .cid is not, send the .grabCID command, and let the .grabCID
logic in copeWithInput() call us back when we are _really_ connected. Feh.
"""
if self.grabCID != False and self.cid == None:
if isinstance(self.grabCID, basestring):
initCmds = [self.grabCID]
else:
initCmds = []
doRegister = False
else:
initCmds = self.initCmds
doRegister = True
CPL.log("ActorNub.connected", "sending initCmds to %s (cid=%s)" % (self.ID, self.cid))
for c in initCmds:
CPL.log("ActorNub.connected", "sending initCmd %s" % (c))
self.sendCommand(Command('.hub', '0',
g.hubMIDs.gimme(),
self.name, c),
doRegister=doRegister)
示例11: queueForOutput
def queueForOutput(self, s, timer=None):
""" Append s to the output queue. """
assert s != None, "queueing nothing!"
self.queueLock.acquire(src='queueForOutput')
try:
mustRegister = (self.outQueue == [])
# Keep the output "lines" separate.
#
self.outQueue.append(s)
# Add any timer.
if timer != None:
self.addTimer(timer)
# Bump the stats.
self.totalQueued += 1
if len(self.outQueue) > self.maxQueue:
self.maxQueue = len(self.outQueue)
if self.debug > 4:
CPL.log("IOHandler.queueForOutput",
"appended %r to queue (len=%d) of %s" % \
(s, len(self.outQueue), self))
if mustRegister:
self.poller.addOutput(self)
finally:
self.queueLock.release(src='queueForOutput')
示例12: setOutputFile
def setOutputFile(self, f):
""" Change the output file. Close and unregister any old file. Clear the output queue.
This should be the only method which adjusts output registration.
"""
if self.debug > 2:
CPL.log("IOHandler.setOutput", "%s changing output %s to %s. queue=%s" % \
(self, self.out_f, f, self.outQueue))
if self.out_f != None:
self.poller.removeOutput(self)
if f != self.out_f:
try:
self.out_f.close()
except:
CPL.error("IOHandler.setOutput", "failed to close output for %s", self)
# Establish new .out_f
#
self.out_f = f
if f == None:
self.out_fd = None
else:
self.out_fd = f.fileno()
self.outQueue = []
示例13: reply
def reply(self, r):
# The authentication system want to be able to block all output until
# the connection is established. Let an external agent "intercept" replies.
#
intercepted = False
if hasattr(self, 'interceptReply'):
intercepted = self.interceptReply(r)
if intercepted:
return
# Most replies get sent to all interested commanders. But we allow
# the possibility of only sending to the commander; in that case,
# the commander gets all replies and keys, but other commanders only get told
# about command completion.
# We do this by triaging out replies here, then optionally telling the encoder
# whether to include keys.
#
if r.bcast or r.cmd.cmdrID == self.ID:
er = self.encoder.encode(r, self)
self.queueForOutput(er)
if self.log:
self.log.log(er, note='>')
else:
CPL.log("CommanderNub.reply", "not bcast; rID=%s selfID=%s" % (r.cmd.cmdrID, self.ID))
if r.finishesCommand():
er = self.encoder.encode(r, self, noKeys=True)
self.queueForOutput(er)
if self.log:
self.log.log(er, note='>')
示例14: acquire
def acquire(self, block=True, src="up"):
if self.debug > 0:
CPL.log("LLock.acquiring", "name=%s, block=%s, src=%s" % \
(self.name, block, src))
self.lock.acquire(block)
if self.debug > 0:
CPL.log("LLock.acquired", "name=%s, block=%s, src=%s" % \
(self.name, block, src))
示例15: ioshutdown
def ioshutdown(self, **argv):
""" Unregister ourselves """
why = argv.get('why', "just cuz")
CPL.log("IOhandler.ioshutdown", "what=%s why=%s" % (self, why))
self.setOutputFile(None)
self.setInputFile(None)