コード例 #1
0
ファイル: transport.py プロジェクト: pecila/python-msrplib
 def make_send_request(self,
                       message_id=None,
                       data='',
                       start=1,
                       end=None,
                       length=None):
     chunk = self.make_request('SEND')
     if end is None:
         end = start - 1 + len(data)
     if length is None:
         length = start - 1 + len(data)
     if end == length != '*':
         contflag = '$'
     else:
         contflag = '+'
     chunk.add_header(
         protocol.ByteRangeHeader(
             protocol.ByteRange(start, end if length <= 2048 else None,
                                length)))
     if message_id is None:
         message_id = '%x' % random.getrandbits(64)
     chunk.add_header(protocol.MessageIDHeader(message_id))
     chunk.data = data
     chunk.contflag = contflag
     return chunk
コード例 #2
0
def make_report(chunk, code, comment):
    if chunk.success_report == 'yes' or (chunk.failure_report in ('yes', 'partial') and code != 200):
        report = protocol.MSRPData(transaction_id='%x' % random.getrandbits(64), method='REPORT')
        report.add_header(protocol.ToPathHeader(chunk.from_path))
        report.add_header(protocol.FromPathHeader([chunk.to_path[0]]))
        report.add_header(protocol.StatusHeader(protocol.Status(code, comment)))
        report.add_header(protocol.MessageIDHeader(chunk.message_id))
        if chunk.byte_range is None:
            start = 1
            total = chunk.size
        else:
            start, end, total = chunk.byte_range
        report.add_header(protocol.ByteRangeHeader(protocol.ByteRange(start, start+chunk.size-1, total)))
        return report
    else:
        return None
コード例 #3
0
def make_report(chunk, code, comment):
    if chunk.success_report == 'yes' or (
            chunk.failure_report in ('yes', 'partial') and code != 200):
        report = protocol.MSRPData(transaction_id='%x' %
                                   random.getrandbits(64),
                                   method='REPORT')
        report.add_header(
            protocol.ToPathHeader(chunk.headers['From-Path'].decoded))
        report.add_header(
            protocol.FromPathHeader([chunk.headers['To-Path'].decoded[0]]))
        report.add_header(protocol.StatusHeader('000 %d %s' % (code, comment)))
        report.add_header(protocol.MessageIDHeader(chunk.message_id))
        byterange = chunk.headers.get('Byte-Range')
        if byterange is None:
            start = 1
            total = chunk.size
        else:
            start, end, total = byterange.decoded
        report.add_header(
            protocol.ByteRangeHeader((start, start + chunk.size - 1, total)))
        return report
    else:
        return None