Skip to content

Migration from 0.8.1 to 0.9

Evan Darwin edited this page Jun 15, 2016 · 1 revision

0.8.1 => 0.9+ Migration

To migrate your application from the 0.8.1 version to the new APIs provided in 0.9.0+, you should look throughout your codebase for these specific categories, and update your code where necessary.

If you have a use case or some backwards compatibility is broken for you, feel free to open an issue and we can see what we can do.

Migrating

register_openers()

The register_openers() function (found in the poster.encode module) has scheduled for deprecation and will be removed in 1.0. To ensure that your code runs error free, look for any calls to this method.

It is completely safe to just remove all references to this function, its function can be done automatically when poster3 is loaded.

Before

from poster.encode import register_openers

register_openers()

After

# No code necessary

multipart_encode()

The multipart_encode() function encodes multiple parameters, taken from a dict or list of Parameter objects.

Before

from poster.encode import multipart_encode

# Create and encode the form, also return the headers
content, headers = multipart_encode({
    'profile': open('profile.jpg', 'rb'),
    'foo': 'bar',
    'test: 'ooo',
})

# Complete the request

After

from poster.multipart import Multipart, Parameter

# Create the form
form = Multipart()

# The image
form.add_file('profile', open('profile.jpg', 'rb'))

# Custom string
form.add_data('foo', 'bar')

# If you need more control, you can do this
parameter = Parameter('test', 'ooo')
form.add_parameter(parameter)

# Create and encode the form, also return the headers
content, headers = form.encode()

# Complete your request

MultipartParam class

The MultipartParam class has changed dramatically and is now the poster.multipart.Parameter class.

Before

from poster.encode import MultipartParam, multipart_encode

# Set the parameters
profile = MultipartParam.from_file('profile', open('profile.jpg', 'rb'))
custom = MultipartParam.from_params('custom', 'value')

# Generate the response and headers
content, headers = multipart_encode([profile, custom])

After

from poster.multipart import Multipart

# Create the form
form = Multipart()

# Set the parameters
form.add_file('profile', open('profile.jpg', 'rb'))
form.add_data('custom', 'value')

# Generate the response and headers
content, headers = form.encode()