Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
shrapnel
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
shrapnel
Commits
f4947f1b
Commit
f4947f1b
authored
Feb 19, 2015
by
Sam Rushing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
move Sync class into coro.log.asn1
This way log processors don't have to duplicate it.
parent
c31e5118
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
32 deletions
+38
-32
coro/log/asn1.py
coro/log/asn1.py
+37
-1
coro/log/catlog
coro/log/catlog
+1
-31
No files found.
coro/log/asn1.py
View file @
f4947f1b
...
@@ -3,9 +3,12 @@ from coro.asn1.python import encode
...
@@ -3,9 +3,12 @@ from coro.asn1.python import encode
import
coro
import
coro
import
struct
import
struct
# four bytes from os.urandom().
MAGIC
=
'%
\
xf1
\
xbf
B'
class
Logger
:
class
Logger
:
magic
=
'%
\
xf1
\
xbf
B'
magic
=
MAGIC
def
__init__
(
self
,
file
):
def
__init__
(
self
,
file
):
self
.
encode
=
encode
self
.
encode
=
encode
...
@@ -21,3 +24,36 @@ class Logger:
...
@@ -21,3 +24,36 @@ class Logger:
)
)
)
)
self
.
file
.
flush
()
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?"
)
coro/log/catlog
View file @
f4947f1b
...
@@ -6,37 +6,7 @@ import struct
...
@@ -6,37 +6,7 @@ import struct
import
sys
import
sys
import
datetime
import
datetime
from
coro.asn1.python
import
decode
from
coro.asn1.python
import
decode
from
coro.log.asn1
import
Sync
class
Sync
:
magic
=
'%
\
xf1
\
xbf
B'
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?"
)
def
is_binary
(
ob
):
def
is_binary
(
ob
):
if
type
(
ob
)
is
not
bytes
:
if
type
(
ob
)
is
not
bytes
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment