New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value.__str__() issues with Unicode #229

Closed
kathychurch opened this Issue May 15, 2017 · 3 comments

Comments

Projects
None yet
2 participants
@kathychurch
Contributor

kathychurch commented May 15, 2017

Expected Behaviour

I expect the Value._str_() function to always work, but it doesn't if the value is Unicode and you are running in 2.7. (Works fine in Python 3)
https://github.com/circuits/circuits/blob/master/circuits/core/values.py#L76

Steps to reproduce

To get this error:

UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-1: ordinal not in range(128)

Run this:

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import logging
from circuits import Event, Component
LOG = logging.getLogger(__name__)

class something(Event):
    def __init__(self, value):
        self.success = True
        super(something, self).__init__(value=value)
        self.saved_value = value
class TestComponent(Component):
    """ test component """
        
    def something(self, event, value):
        LOG.info("Handling value %s for event %s", value, event)
        yield value

    def something_success(self, event, *args):
        LOG.info("Event %s with value %s was successfully handled", event.parent, repr(event.parent.value))
        LOG.info(event.parent.value)
        yield "done"
        
    def started(self, event, *args):
        """ helper that does the first 3 items of work """
        LOG.info("Firing event with Unicode")
        value = u"те яуо еиус дицам е"
        self.fire(something(value))

def main():
    logging.basicConfig()
    LOG.setLevel(logging.DEBUG)
    TestComponent().run()
    
if __name__ == "__main__":
    main()

Environment and Platform

  • OS: Mac OS
  • Python: 2.7
  • circuits: 3.2

@prologic prologic added this to the 3.2.1 milestone May 21, 2017

@prologic

This comment has been minimized.

Show comment
Hide comment
@prologic

prologic May 21, 2017

Member

Thanks @kathychurch for the report! Can you offer up a PR to fix this?

Member

prologic commented May 21, 2017

Thanks @kathychurch for the report! Can you offer up a PR to fix this?

@kathychurch

This comment has been minimized.

Show comment
Hide comment
@kathychurch

kathychurch May 31, 2017

Contributor

Looks like a small fix, I'm sure I can find time for that

Contributor

kathychurch commented May 31, 2017

Looks like a small fix, I'm sure I can find time for that

@prologic

This comment has been minimized.

Show comment
Hide comment
@prologic

prologic May 31, 2017

Member
Member

prologic commented May 31, 2017

bloodywing added a commit to bloodywing/circuits that referenced this issue Jul 17, 2017

make __str__ compatible with py2 (six-decorator)
This the one with decorator.
Also see: #232 and #229

@spaceone spaceone closed this in #233 Jul 17, 2017

spaceone added a commit that referenced this issue Jul 17, 2017

make __str__ compatible with py2 (six-decorator) (#233)
* make __str__ compatible with py2 (six-decorator)
See also: #232 and #229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment