Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

Supporting Python 2.6
Moderators: adafruit_support_bill, adafruit

Forum rules
If you're posting code, please make sure your code does not include your Adafruit IO Active Key or WiFi network credentials.
Please be positive and constructive with your questions and comments.

Supporting Python 2.6

by krambriw on Sun Feb 21, 2016 3:48 am

Hi, since the library currently is written to support Python 2.7+ and 3.0+, I still needed this to work also with Python 2.6 ( In my particular case, Python 2.6.5 Stackless 3.1b3 060516 (release26-maint, Mar 20 2010, 15:26:51) [MSC v.1500 32 bit (Intel)] on win32 running in Win10 64 bit). I actually made this work by making a small code change in model.py:

Code: Select all | TOGGLE FULL SIZE
# Define methods to convert from dicts to the data types.
def _from_dict(cls, data):
    # Convert dict to call to class initializer (to work with the data types
    # base on namedtuple).  However be very careful to preserve forwards
    # compatibility by ignoring any attributes in the dict which are unknown
    # by the data type.
    #params = {x: data.get(x, None) for x in cls._fields}
    #
    #Modified to support Python 2.6 by krambriw 2015-02-19
    params = {}
    for x in cls._fields:
        params[x] = data.get(x, None)
    return cls(**params)


def _feed_from_dict(cls, data):
    #params = {x: data.get(x, None) for x in cls._fields}
    #
    #Modified to support Python 2.6 by krambriw 2015-02-19
    params = {}
    for x in cls._fields:
        params[x] = data.get(x, None)
     # Parse the stream if provided and generate a stream instance.
    params['stream'] = Stream.from_dict(data.get('stream', {}))
    return cls(**params)


def _group_from_dict(cls, data):
    #params = {x: data.get(x, None) for x in cls._fields}
    #
    #Modified to support Python 2.6 by krambriw 2015-02-19
    params = {}
    for x in cls._fields:
        params[x] = data.get(x, None)
    # Parse the feeds if they're provided and generate feed instances.
    params['feeds'] = tuple(map(Feed.from_dict, data.get('feeds', [])))
    return cls(**params)


Maybe the author could introduce a kind of switch that detects what version of Python is running and depending on this, select the appropriate way.

Kind regards

krambriw
 
Posts: 22
Joined: Fri Feb 19, 2016 6:07 pm

Please be positive and constructive with your questions and comments.