print "========" print "LOG TEST" print "========" import pysec from pysec import load from pysec import log log.register_actions('LOG_TEST', 'LOG_MAIN') log.register_errors('IS_FALSE') log.start_log(log.actions.LOG_TEST) log.add_global_emit(log.emit_simple) NUM = 0 with log.ctx(log.actions.LOG_MAIN): if NUM == 0: log.error(log.errors.IS_FALSE, num=NUM) try: load.importlib('test') except ImportError: print "library 'test' doesn't exist"
return func(fd, *args, **kargs) raise NotReadableFD(fd) return _read def write_check(func): """Decorator to control write permission in writer methods""" def _write(fd, *args, **kargs): """*func* wrapped with write check""" if fd.flags & os.O_WRONLY or fd.flags & os.O_APPEND: return func(fd, *args, **kargs) raise NotWriteableFD(fd) return _write log.register_actions('FD_NEW', 'FD_CLOSE') class FD(Object): """FD represents a File Descriptor""" @log.wrap(log.actions.FD_NEW, fields=('fd',), lib=__name__) def __init__(self, fd): fd = int(fd) if fd < 0: raise ValueError("wrong fd value") self.fd = fd def fileno(self): """Return file descriptor's int""" return int(self.fd)
print "========" print "LOG TEST" print "========" import pysec from pysec import load from pysec import log log.register_actions( 'LOG_TEST', 'LOG_MAIN' ) log.register_errors( 'IS_FALSE' ) log.start_log(log.actions.LOG_TEST) log.add_global_emit(log.emit_simple) NUM = 0 with log.ctx(log.actions.LOG_MAIN): if NUM == 0: log.error(log.errors.IS_FALSE, num=NUM) try: load.importlib('test') except ImportError: print "library 'test' doesn't exist"
# imp = <module imp> # os = <module os> import imp import os import hashlib import base64 from types import ModuleType from pysec.io import fd from pysec import log __name__ = 'pysec.load' # set actions log.register_actions('LOAD_TAB', 'IMPORT_LIB') ASCII_LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' DIGITS = '0123456789' HEXDIGITS = '0123456789abcdefABCDEF' _HASHES = { # raise NameError: undefined: getattr 'md5': getattr(hashlib, 'md5'), # raise NameError: undefined: getattr 'sha1': getattr(hashlib, 'sha1'), # raise NameError: undefined: getattr 'sha256': getattr(hashlib, 'sha256'), # raise NameError: undefined: getattr
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # -*- coding: ascii -*- import os import kyotocabinet as kyoto from pysec import log, kv __name__ = 'pysec.kv.kyoto' log.register_actions('KYOTOKV_NEW', 'KYOTOKV_SET', 'KYOTOKV_GET', 'KYOTOKV_DEL', 'KYOTOKV_CLEAR', 'KYOTOKV_POP', 'KYOTOKV_UPDATE', 'KYOTOKV_CLOSE') _OPEN_MODE = kyoto.DB.OWRITER | kyoto.DB.OREADER | kyoto.DB.OCREATE class KyotoKV(kv.HardKV): @log.wrap(log.actions.KYOTOKV_NEW, fields=('path', ), lib=__name__) def __init__(self, path, parse=lambda v: v, unparse=lambda v: v): self.fk = kyoto.DB() if not self.fk.open(path, _OPEN_MODE): raise self.fk.error() self.parse = parse self.unparse = unparse @log.wrap(log.actions.KYOTOKV_CLOSE, lib=__name__)
import errno from functools import partial import select import socket from pysec.core import memory, Object from pysec.xsplit import xbounds from pysec.net.error import TooBigReply, TooManyFlushData from pysec import log __name__ = 'pysec.net.pop' # set actions log.register_actions('POP3_NEW_SESSION', 'POP3_CONNECT', 'POP3_CLOSE', 'POP3_FLUSH', 'POP3_CMD', 'POP3_PUTCMD', 'POP3_SIMPLEREPLY', 'POP3_MULREPLY') EOL = '\r\n' MULTI_END = '.%s' % EOL POP3_PORT = 110 OK_REPLY = 1 ERR_REPLY = 0 UNKNOWN_REPLY = -1
import os import hashlib import base64 from types import ModuleType from pysec.core import Object from pysec.io import fd from pysec import log __name__ = "pysec.load" __all__ = "load_tab", "import_lib", "make_line" # set actions log.register_actions("LOAD_TAB", "IMPORT_LIB") ASCII_LETTERS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" DIGITS = "0123456789" HEXDIGITS = "0123456789abcdefABCDEF" _HASHES = { # raise NameError: undefined: getattr "md5": getattr(hashlib, "md5"), # raise NameError: undefined: getattr "sha1": getattr(hashlib, "sha1"), # raise NameError: undefined: getattr "sha256": getattr(hashlib, "sha256"), # raise NameError: undefined: getattr
import socket import select import errno from pysec.core import memory, Object from pysec.xsplit import xbounds from pysec.net.error import TooBigReply, TooManyFlushData from pysec import log __name__ = 'pysec.net.smtp' # set actions log.register_actions('SMTP_NEW_SESSION', 'SMTP_CONNECT', 'SMTP_CLOSE', 'SMTP_FLUSH', 'SMTP_CMD', 'SMTP_PUTCMD', 'SMTP_REPLY') EOL = '\r\n' SMTP_PORT = 25 CMDS = 'QUIT', 'HELO', 'EHLO', 'HELP', 'NOOP', 'RSET' def is_1xx(reply): return reply[:3].isdigit() and reply[0] == '1'
import socket import select import errno from pysec.core import memory, Object from pysec.xsplit import xbounds from pysec.net.error import TooBigReply, TooManyFlushData from pysec import log __name__ = 'pysec.net.smtp' # set actions log.register_actions('SMTP_NEW_SESSION', 'SMTP_CONNECT', 'SMTP_CLOSE', 'SMTP_FLUSH', 'SMTP_CMD', 'SMTP_PUTCMD', 'SMTP_REPLY') EOL = '\r\n' SMTP_PORT = 25 CMDS = 'QUIT', 'HELO', 'EHLO', 'HELP', 'NOOP', 'RSET' def is_1xx(reply): return reply[:3].isdigit() and reply[0] == '1' def is_2xx(reply): return reply[:3].isdigit() and reply[0] == '2' def is_3xx(reply):
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # # -*- coding: ascii -*- import os import kv import kyotocabinet as kyoto from pysec import log __name__ = 'pysec.kv.kyoto' log.register_actions('KYOTOKV_NEW', 'KYOTOKV_SET', 'KYOTOKV_GET', 'KYOTOKV_DEL', 'KYOTOKV_CLEAR', 'KYOTOKV_POP', 'KYOTOKV_UPDATE', 'KYOTOKV_CLOSE') _OPEN_MODE = kyoto.DB.OWRITER | kyoto.DB.OREADER | kyoto.DB.OCREATE class KyotoKV(kv.HardKV): @log.wrap(log.actions.KYOTOKV_NEW, fields=('path',), lib=__name__) def __init__(self, path, parse=lambda v: v, unparse=lambda v: v): self.fk = kyoto.DB() if not self.fk.open(path, _OPEN_MODE): raise self.fk.error() self.parse = parse self.unparse = unparse
import os import hashlib import base64 from types import ModuleType from pysec.core import Object from pysec.io import fd from pysec import log from pysec import lang __name__ = 'pysec.load' __all__ = 'load_tab', 'importlib', 'make_line' # set actions log.register_actions('LOAD_TAB', 'IMPORT_LIB') ASCII_LETTERS = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' DIGITS = '0123456789' HEXDIGITS = '0123456789abcdefABCDEF' _HASHES = { # raise NameError: undefined: getattr 'md5': getattr(hashlib, 'md5'), # raise NameError: undefined: getattr 'sha1': getattr(hashlib, 'sha1'), # raise NameError: undefined: getattr 'sha256': getattr(hashlib, 'sha256'), # raise NameError: undefined: getattr 'sha512': getattr(hashlib, 'sha512'), }
# # -*- coding: ascii -*- """Implementations of POP protocols""" import errno import select import socket from pysec.core import memory, Object from pysec.xsplit import xbounds from pysec.net.error import TooBigReply, TooManyFlushData from pysec import log __name__ = 'pysec.net.pop' # set actions log.register_actions('POP3_NEW_SESSION', 'POP3_CONNECT', 'POP3_CLOSE', 'POP3_FLUSH', 'POP3_CMD', 'POP3_PUTCMD', 'POP3_SIMPLEREPLY', 'POP3_MULREPLY') EOL = '\r\n' MULTI_END = '.%s' % EOL POP3_PORT = 110 OK_REPLY = 1 ERR_REPLY = 0 UNKNOWN_REPLY = -1 def is_ok(reply): return reply.startswith('+OK')