Ejemplo n.º 1
0
 def test_from_timeslice_closed(self):
     ts = TimeSlice(
             start=Picoseconds(int(1e12)) * 2.5,
             duration=Milliseconds(2000))
     self.assertEqual(
             'seconds 2.5-4.5/100.0',
             str(ContentRange.from_timeslice(ts, Seconds(100))))
Ejemplo n.º 2
0
 def serialize(self, context):
     feature = context.feature
     document = context.document
     data = feature(_id=document._id, persistence=document)
     sliced_data = data[context.slce]
     td = data.dimensions[0]
     content_range = ContentRange.from_timeslice(
             context.slce, td.end)
     return generate_image(
             sliced_data,
             is_partial=True,
             content_range=content_range)
Ejemplo n.º 3
0
 def serialize(self, context):
     document = context.document
     feature = context.feature
     slce = context.slce
     flo = feature(_id=document._id, decoder=Decoder(), persistence=document)
     if slce.start:
         flo.seek(slce.start)
     if slce.stop:
         value = flo.read(slce.stop - slce.start)
     else:
         value = flo.read()
     key = document.key_builder.build(
             document._id, feature.key, feature.version)
     total = document.database.size(key)
     return TempResult(
             value,
             self.content_type,
             is_partial=slce.start is not None or slce.stop is not None,
             content_range=ContentRange.from_slice(slce, total))
Ejemplo n.º 4
0
 def serialize(self, context):
     feature = context.feature
     document = context.document
     slce = context.slce
     wrapper = feature(_id=document._id, persistence=document)
     samples = wrapper[slce]
     bio = BytesIO()
     with SoundFile(
             bio,
             mode='w',
             samplerate=wrapper.samplerate,
             channels=wrapper.channels,
             format='OGG',
             subtype='VORBIS') as sf:
         sf.write(samples)
     bio.seek(0)
     content_range = ContentRange.from_timeslice(
             slce, Picoseconds(int(1e12 * wrapper.duration_seconds)))
     return TempResult(
             bio.read(),
             'audio/ogg',
             is_partial=slce != TimeSlice(),
             content_range=content_range)
Ejemplo n.º 5
0
 def test_open_content_range(self):
     self.assertEqual(
             'bytes 10-100/100',
             str(ContentRange('bytes', 10, 100)))
Ejemplo n.º 6
0
 def test_from_timeslice_open_ended(self):
     ts = TimeSlice(start=Picoseconds(int(1e12)) * 2.5)
     self.assertEqual(
             'seconds 2.5-100.0/100.0',
             str(ContentRange.from_timeslice(ts, Seconds(100))))
Ejemplo n.º 7
0
 def test_from_timeslce_full_slice(self):
     ts = TimeSlice()
     self.assertEqual(
             'seconds 0.0-100.0/100.0',
             str(ContentRange.from_timeslice(ts, Seconds(100))))
Ejemplo n.º 8
0
 def test_closed_content_range(self):
     self.assertEqual(
             'seconds 10-90/100',
             str(ContentRange('seconds', 10, 100, stop=90)))