forked from phalt/swapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrenderers.py
51 lines (47 loc) · 1.21 KB
/
renderers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from __future__ import unicode_literals
from rest_framework import renderers
class WookieeRenderer(renderers.JSONRenderer):
media_type = "application/json"
charset = 'utf-8'
format = "wookiee"
lookup = {
"a": "ra",
"b": "rh",
"c": "oa",
"d": "wa",
"e": "wo",
"f": "ww",
"g": "rr",
"h": "ac",
"i": "ah",
"j": "sh",
"k": "or",
"l": "an",
"m": "sc",
"n": "wh",
"o": "oo",
"p": "ak",
"q": "rq",
"r": "rc",
"s": "c",
"t": "ao",
"u": "hu",
"v": "ho",
"w": "oh",
"x": "k",
"y": "ro",
"z": "uf",
}
def render(self, data, media_type=None, renderer_context=None):
encoded_data = super(WookieeRenderer, self).render(
data, media_type, renderer_context
)
return bytes(self.translate_to_wookie(encoded_data))
def translate_to_wookie(self, data):
translated_data = ""
for char in data:
if char in self.lookup:
translated_data += self.lookup[char]
else:
translated_data += char
return translated_data