Commit f4947f1b authored by Sam Rushing's avatar Sam Rushing

move Sync class into coro.log.asn1

This way log processors don't have to duplicate it.
parent c31e5118
......@@ -3,9 +3,12 @@ from coro.asn1.python import encode
import coro
import struct
# four bytes from os.urandom().
MAGIC = '%\xf1\xbfB'
class Logger:
magic = '%\xf1\xbfB'
magic = MAGIC
def __init__ (self, file):
self.encode = encode
......@@ -21,3 +24,36 @@ class Logger:
)
)
self.file.flush()
class Sync:
magic = MAGIC
def __init__ (self):
self.state = 0
self.last = None
def feed (self, ch):
if ch == self.magic[self.state]:
self.state += 1
if self.state == 4:
return True
else:
return False
else:
self.state = 0
self.last = ch
return False
def resync (self, fdin):
self.state = 0
give_up = 10000
i = 0
while i < give_up:
ch = fdin.read (1)
i += 1
if ch == '':
raise EOFError
else:
if self.feed (ch):
return
raise ValueError ("unable to sync: is this an asn1 log file?")
......@@ -6,37 +6,7 @@ import struct
import sys
import datetime
from coro.asn1.python import decode
class Sync:
magic = '%\xf1\xbfB'
def __init__ (self):
self.state = 0
self.last = None
def feed (self, ch):
if ch == self.magic[self.state]:
self.state += 1
if self.state == 4:
return True
else:
return False
else:
self.state = 0
self.last = ch
return False
def resync (self, fdin):
self.state = 0
give_up = 10000
i = 0
while i < give_up:
ch = fdin.read (1)
i += 1
if ch == '':
raise EOFError
else:
if self.feed (ch):
return
raise ValueError ("unable to sync: is this an asn1 log file?")
from coro.log.asn1 import Sync
def is_binary (ob):
if type(ob) is not bytes:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment