coding style: adopt pep8
Change-Id: Ic037f925271c970406284e52a00a6c56d048452e
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
import fileinput
|
||||
|
||||
|
||||
class LineHandler():
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
@ -14,6 +15,7 @@ class LineHandler():
|
||||
'''
|
||||
self.send_line("> " + line)
|
||||
|
||||
|
||||
class LineServer():
|
||||
|
||||
def __init__(self, isfile, lineHandlerClass):
|
||||
|
@ -33,26 +33,37 @@ else:
|
||||
|
||||
|
||||
class SecopError(Exception):
|
||||
|
||||
def __init__(self, message, text):
|
||||
Exception.__init__(self, message, text)
|
||||
|
||||
|
||||
class UnknownDeviceError(SecopError):
|
||||
|
||||
def __init__(self, message, args):
|
||||
SecopError.__init__(self, "NoSuchDevice", args[0])
|
||||
|
||||
|
||||
class UnknownParamError(SecopError):
|
||||
|
||||
def __init__(self, message, args):
|
||||
SecopError.__init__(self, "NoSuchParam", "%s:%s" % args)
|
||||
|
||||
|
||||
class UnknownPropError(SecopError):
|
||||
|
||||
def __init__(self, message, args):
|
||||
SecopError.__init__(self, "NoSuchProperty", "%s:%s:%s" % args)
|
||||
|
||||
|
||||
class SyntaxError(SecopError):
|
||||
|
||||
def __init__(self, message):
|
||||
SecopError.__init__(self, "SyntaxError", message)
|
||||
|
||||
|
||||
class OtherError(SecopError):
|
||||
|
||||
def __init__(self, message):
|
||||
SecopError.__init__(self, "OtherError", message)
|
||||
|
||||
@ -64,12 +75,14 @@ def encode(input):
|
||||
return enc
|
||||
return inp
|
||||
|
||||
|
||||
def gettype(obj):
|
||||
typ = str(type(obj).__name__)
|
||||
if typ == "unicode":
|
||||
typ = "string"
|
||||
return typ
|
||||
|
||||
|
||||
def wildcard(dictionary, pattern):
|
||||
list = []
|
||||
if pattern == "":
|
||||
@ -89,11 +102,14 @@ def wildcard(dictionary, pattern):
|
||||
|
||||
|
||||
class SecopClientProps(object):
|
||||
|
||||
def __init__(self):
|
||||
self.reply_items = {".": "t", "writable": 1}
|
||||
self.compact_output = {".": 0, "writable": 1}
|
||||
|
||||
|
||||
class SecopLineHandler(lineserver.LineHandler):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
lineserver.LineHandler.__init__(self, *args, **kwargs)
|
||||
self.props = SecopClientProps()
|
||||
@ -118,7 +134,6 @@ class SecopLineHandler(lineserver.LineHandler):
|
||||
self.send_line("~%s~ %s" % (e.args[0], e.args[1]))
|
||||
self.send_line("")
|
||||
|
||||
|
||||
def get_device(self, d):
|
||||
if d == "":
|
||||
d = "."
|
||||
@ -193,11 +208,12 @@ class SecopLineHandler(lineserver.LineHandler):
|
||||
try:
|
||||
val = (typ)(value)
|
||||
except ValueError:
|
||||
raise SyntaxError("can not convert '%s' to %s" % (value, gettype(value)))
|
||||
raise SyntaxError("can not convert '%s' to %s" %
|
||||
(value, gettype(value)))
|
||||
parDict["."] = val
|
||||
parDict["t"] = datetime.utcnow()
|
||||
self.send_line(self.output_path(d, p, ".") + "=" + encode(parDict["."]))
|
||||
|
||||
self.send_line(self.output_path(d, p, ".") +
|
||||
"=" + encode(parDict["."]))
|
||||
|
||||
def read(self, pathArg):
|
||||
self.clear_output_path()
|
||||
@ -240,7 +256,8 @@ class SecopLineHandler(lineserver.LineHandler):
|
||||
if path[2] == "":
|
||||
msg = self.output_path(d, p, "") + "=" + encode(paramDict["."])
|
||||
for y in replyitems:
|
||||
if y == ".": continue # do not show the value twice
|
||||
if y == ".":
|
||||
continue # do not show the value twice
|
||||
try:
|
||||
msg += ";" + y + "=" + encode(paramDict[y])
|
||||
except KeyError:
|
||||
@ -296,7 +313,8 @@ else:
|
||||
server = lineserver.LineServer("localhost", port, SecopLineHandler)
|
||||
|
||||
|
||||
secNodeDict=json.load(open("secnode.json", "r"), object_pairs_hook=OrderedDict)
|
||||
secNodeDict = json.load(open("secnode.json", "r"),
|
||||
object_pairs_hook=OrderedDict)
|
||||
#json.dump(secNodeDict, open("secnode_out.json", "w"), indent=2, separators=(",",":"))
|
||||
for d in secNodeDict:
|
||||
devDict = secNodeDict[d]
|
||||
|
@ -1,6 +1,7 @@
|
||||
import asyncore
|
||||
import socket
|
||||
|
||||
|
||||
class LineHandler(asyncore.dispatcher_with_send):
|
||||
|
||||
def __init__(self, sock):
|
||||
@ -34,6 +35,7 @@ class LineHandler(asyncore.dispatcher_with_send):
|
||||
'''
|
||||
self.send_line("> " + line)
|
||||
|
||||
|
||||
class LineServer(asyncore.dispatcher):
|
||||
|
||||
def __init__(self, host, port, lineHandlerClass):
|
||||
|
@ -72,5 +72,3 @@ class Temp(Driveable):
|
||||
|
||||
def write_target(self, target):
|
||||
pass
|
||||
|
||||
|
||||
|
@ -212,5 +212,3 @@ class HelpRequest(Request):
|
||||
|
||||
class HelpReply(Reply):
|
||||
pass
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user