unt-libraries / pycallnumber

Parse, model, and manipulate any type of call number string.
BSD 3-Clause "New" or "Revised" License
63 stars 9 forks source link

Error with struct on package import (python 2.7.5) #14

Closed cherveny closed 6 years ago

cherveny commented 6 years ago

File "/usr/lib/python2.7/site-packages/pycallnumber/utils.py", line 141, in get_terminal_size winsize_struct = struct.pack('HHHH', 0, 0, 0, 0) TypeError: Struct() argument 1 must be string, not unicode

I believe can be fixed with str('HHHH'). WIll be testing on my end.

Getting the error on initial import using python 2.7.5

cherveny commented 6 years ago

FYI, same on line 147.

cherveny commented 6 years ago

FYI, my temporary kludge, comment out the structs, have the function just return the default values for now. Some google searches on others having similar issues with struct seem to suggest this may be an issue with 2.7.5 and unicode, but not 100% sure.

jthomale commented 6 years ago

Thanks for the problem report! I confirmed the error on 2.7.5, and I think you're right about the problem, i.e.:

Some google searches on others having similar issues with struct seem to suggest this may be an issue with 2.7.5 and unicode ...

You were definitely on the right track with your initial fix, casting HHHH to str, but the reason that didn't work is because I'm using future for Python 2/3 compatibility, which overrides the str type with its own, and struct in 2.7.5 doesn't like that, either. Apparently, a workaround for that is to use types.StringType instead of str — which works in Python 2 but then breaks in Python 3.

So ultimately I ended up putting it in a try/except block. If Unicode works, then great, otherwise it uses the types.StringType workaround.

When you get a chance would you mind pulling down the fix-issue-14 branch and making sure that fixes the issue for you?

Note that I haven't incorporated this into master yet because there seems to be another problem with Python 2.7.5 regular expressions, which came to light once I fixed the struct/unicode issue and could actually run the test suite against 2.7.5. I almost have that one solved as well but will have to put it off a couple of days...

cherveny commented 6 years ago

Ok, will try to get to this today, but might not be till Tuesday. Will respond here as soon as I can with results.

jthomale commented 6 years ago

Not a problem. Thanks!

jthomale commented 6 years ago

Tests for this issue on Python 2.7.5 are passing, so I went ahead and merged fix-issue-14 into master, closing this issue. But feel free to open a new issue if this ended up not fixing the problem for you. Thanks again for reporting the problem.