Skip to content

Problem passing string value as docid #26

@oktaal

Description

@oktaal

When creating a Frog instance such as:

from frog import Frog, FrogOptions
frog_instance = Frog(FrogOptions(
    xmlout=True,
    docid='DOCID',
    mwu=False,
    parser=False
))

I get the following error:

  File "frog_wrapper.pyx", line 80, in frog.FrogOptions.__init__
  File "frog_wrapper.pyx", line 125, in frog.FrogOptions.__setitem__
  File "<stringsource>", line 15, in string.from_py.__pyx_convert_string_from_py_std__in_string
TypeError: expected bytes, str found

When I add an encode() to docid='DOCID' it works:

from frog import Frog, FrogOptions
frog_instance = Frog(FrogOptions(
    xmlout=True,
    docid='DOCID'.encode(),
    mwu=False,
    parser=False
))

Reading:

elif key.lower() in ('docid','id'):
self.capi.insert(<string>b"id", <string>value)
elif key.lower() in ('numthreads','threads'):
self.capi.insert(<string>b"threads",<string>value)
else:
if key == 'x':
self.shadow['xmlin'] = True
elif key == 'X':
self.shadow['xmlout'] = True
self.capi.insert(<string>key, <string>value)
def finish(self):
v = "".join(self.skip)
self.capi.insert(<string>b"skip", <string>v.encode('utf-8'))

I think it might need this for id and threads as well, such as it already does for skip, and/or it might need to check if the value has already been encoded to bytes.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions