Skip to content
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

Fix for #406 (ascii issue) #536

Merged
merged 10 commits into from
Nov 25, 2016
14 changes: 8 additions & 6 deletions pynest/nest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,21 @@ def catching_sli_run(cmd):
"""

if sys.version_info >= (3,):
engine.run('{%s} runprotected' % cmd) # Python 3
def encode(s): return s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Precisely like this. The rest of the code is simplified and clear.


def decode(s): return s
else:
engine.run('{%s} runprotected' % cmd.decode('utf-8')) # Python 2
def encode(s): return s.encode('utf-8')

def decode(s): return s.decode('utf-8')
engine.run('{%s} runprotected' % decode(cmd))
if not sli_pop():
errorname = sli_pop()
message = sli_pop()
commandname = sli_pop()
engine.run('clear')
errorstring = '%s in %s%s' % (errorname, commandname, message)
if sys.version_info >= (3,):
raise _kernel.NESTError(errorstring) # Python 3
else:
raise _kernel.NESTError(errorstring.encode('utf-8')) # Python 2
raise _kernel.NESTError(encode(errorstring))

sli_run = hl_api.sr = catching_sli_run

Expand Down
6 changes: 2 additions & 4 deletions pynest/pynestkernel.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -212,13 +212,11 @@ cdef class NESTEngine(object):
return True

def run(self, cmd):

if self.pEngine is NULL:
raise NESTError("engine uninitialized")
cdef string cmd_bytes
try:
cmd_bytes = cmd.encode('utf-8')
except UnicodeEncodeError:
cmd_bytes = cmd.encode()
cmd_bytes = cmd.encode('utf-8')
self.pEngine.execute(cmd_bytes)

def push(self, obj):
Expand Down