diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-09-29 21:11:11 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-09-29 21:11:11 +0100 |
| commit | 0db42091514c60d9d6a09d77fb085c09376e1327 (patch) | |
| tree | 56c1394dd6a9e02e95800a80b389d1c85db6e1fb /jq.pyx | |
| parent | 51189b3e5a4559419fbd33b48932e98be246a9ef (diff) | |
Add unicode support
Diffstat (limited to 'jq.pyx')
| -rw-r--r-- | jq.pyx | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -29,13 +29,15 @@ cdef extern from "jq.h": jv jq_next(jq_state *) -def jq(char* program): +def jq(object program): + cdef object program_bytes_obj = program.encode("utf8") + cdef char* program_bytes = program_bytes_obj cdef jq_state *jq = jq_init() if not jq: raise Exception("jq_init failed") # TODO: jq_compile prints error to stderr - cdef int compiled = jq_compile(jq, program) + cdef int compiled = jq_compile(jq, program_bytes) if not compiled: raise ValueError("program was not valid") @@ -53,7 +55,9 @@ cdef class _Program(object): def transform(self, input, raw_input=False, raw_output=False, multiple_output=False): string_input = input if raw_input else json.dumps(input) - result_strings = self._string_to_strings(string_input) + bytes_input = string_input.encode("utf8") + result_bytes = self._string_to_strings(bytes_input) + result_strings = result_bytes if raw_output: return "\n".join(result_strings) elif multiple_output: |
