8000 Decode works · graphql-python/gql-next@c29268c · GitHub
[go: up one dir, main page]

Skip to content

Commit c29268c

Browse files
committed
Decode works
1 parent c342f04 commit c29268c

File tree

2 files changed

+8
-12
lines changed

2 files changed

+8
-12
lines changed

examples/simple/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
# coding: gql
22

3+
# pylint:disable=no-member,unused-import
34
QUERY = gql"""
45
query HelloQuery {
56
hello(argument: "World")
67
}
78
"""
9+
# pylint:enable=no-member,unused-import
810

911
def main():
1012
result = QUERY.execute()

gql/codec/register.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
import os
23
import sys
34
import codecs
45
import encodings
@@ -7,19 +8,9 @@
78

89
from gql.codec.transform import gql_transform
910

10-
DEFAULT_RESULT = None
11-
1211

1312
def gql_decode(value, **_):
14-
if isinstance(value, memoryview):
15-
value = value.tobytes().decode("utf-8")
16-
17-
# strip the gql coding line from code so that the python tokenizer can read the code
18-
value = '# coding: utf-8\n' + value
19-
20-
bio = BytesIO(value.encode('utf-8'))
21-
result = gql_transform(bio)
22-
return result, len(result)
13+
return utf_8.decode(value)
2314

2415

2516
class GQLIncrementalDecoder(utf_8.IncrementalDecoder):
@@ -28,9 +19,12 @@ def decode(self, input: bytes, final: bool = False): # pylint:disable=redefined
2819
if final:
2920
buff = self.buffer
3021
self.buffer = ''
22+
buff = buff.decode('utf-8')
23+
buff = buff.replace('# coding: gql', '')
24+
buff = buff.encode('utf-8')
3125
return gql_transform(BytesIO(buff))
3226

33-
return DEFAULT_RESULT
27+
return None
3428

3529

3630
class GQLStreamReader(utf_8.StreamReader):

0 commit comments

Comments
 (0)
0