Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
EdosL0Util
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
SIPS
EdosL0Util
Commits
fc5914f2
Commit
fc5914f2
authored
9 years ago
by
Bruce Flynn
Browse files
Options
Downloads
Patches
Plain Diff
Support pipes as streams
parent
82883d61
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
edosl0util/stream.py
+13
-1
13 additions, 1 deletion
edosl0util/stream.py
with
13 additions
and
1 deletion
edosl0util/stream.py
+
13
−
1
View file @
fc5914f2
import
os
import
os
import
errno
import
logging
import
logging
import
ctypes
as
c
import
ctypes
as
c
from
collections
import
deque
,
defaultdict
,
namedtuple
from
collections
import
deque
,
defaultdict
,
namedtuple
...
@@ -40,12 +41,22 @@ class NonConsecutiveSeqId(Error):
...
@@ -40,12 +41,22 @@ class NonConsecutiveSeqId(Error):
class
BasicStream
(
object
):
class
BasicStream
(
object
):
"""
Basic packet stream iterator that reads the primary and secondary headers and
maintains offsets and read sizes.
"""
Tracker
=
namedtuple
(
'
Tracker
'
,
[
'
h1
'
,
'
h2
'
,
'
size
'
,
'
offset
'
,
'
data
'
])
Tracker
=
namedtuple
(
'
Tracker
'
,
[
'
h1
'
,
'
h2
'
,
'
size
'
,
'
offset
'
,
'
data
'
])
def
__init__
(
self
,
fobj
,
header_lookup
=
None
,
with_data
=
True
):
def
__init__
(
self
,
fobj
,
header_lookup
=
None
,
with_data
=
True
):
self
.
file
=
fobj
self
.
file
=
fobj
self
.
header_lookup
=
header_lookup
self
.
header_lookup
=
header_lookup
self
.
with_data
=
with_data
self
.
with_data
=
with_data
try
:
self
.
_offset
=
self
.
file
.
tell
()
except
IOError
as
err
:
# handle illegal seek for pipes
if
err
.
errno
!=
errno
.
ESPIPE
:
raise
self
.
_offset
=
0
def
__iter__
(
self
):
def
__iter__
(
self
):
return
self
return
self
...
@@ -61,6 +72,7 @@ class BasicStream(object):
...
@@ -61,6 +72,7 @@ class BasicStream(object):
raise
PacketTooShort
(
raise
PacketTooShort
(
'
expected to read {:d} bytes, got {:d}
'
'
expected to read {:d} bytes, got {:d}
'
.
format
(
size
,
len
(
buf
)))
.
format
(
size
,
len
(
buf
)))
self
.
_offset
+=
size
return
buf
return
buf
def
read_primary_header
(
self
):
def
read_primary_header
(
self
):
...
@@ -77,7 +89,7 @@ class BasicStream(object):
...
@@ -77,7 +89,7 @@ class BasicStream(object):
return
H2Impl
.
from_buffer_copy
(
buf
),
h2size
return
H2Impl
.
from_buffer_copy
(
buf
),
h2size
def
next
(
self
):
def
next
(
self
):
offset
=
self
.
file
.
tell
()
offset
=
self
.
_offset
h1
,
h1size
=
self
.
read_primary_header
()
h1
,
h1size
=
self
.
read_primary_header
()
h2
,
h2size
=
self
.
read_secondary_header
(
h1
)
h2
,
h2size
=
self
.
read_secondary_header
(
h1
)
# data length includes h2size
# data length includes h2size
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment