def say_hello_as_binary_file(ctx, name, times): # WARNING!: the native value for data is an iterable of bytes, not just # bytes! If you forget this you may return data using 1-byte http chunks # which is incredibly inefficient. # WARNING!: don't forget to encode your data! This is the binary # output mode! You can't just write unicode data to socket! mime_type = HttpTransportContext.gen_header("text/plain", charset="utf8") return File.Value(type=mime_type, data=['\n'.join(s.encode('utf8') for s in _say_hello(ctx, name, times, 'txt'))] )
def say_hello_as_binary_file(ctx, name, times): # WARNING!: the native value for data is an iterable of bytes, not just # bytes! If you forget this you may return data using 1-byte http chunks # which is incredibly inefficient. # WARNING!: don't forget to encode your data! This is the binary # output mode! You can't just write unicode data to socket! mime_type = HttpTransportContext.gen_header("text/plain", charset="utf8") return File.Value(type=mime_type, data=[ '\n'.join( s.encode('utf8') for s in _say_hello(ctx, name, times, 'txt')) ])
def test_gen_header(self): val = HttpTransportContext.gen_header("text/plain", charset="utf8") assert val == 'text/plain; charset="utf8"'