Explorar el Código

Start work on serializing; clean up languages.

tags/v1.0^2
Ben Kurtovic hace 10 años
padre
commit
326be3050f
Se han modificado 3 ficheros con 18 adiciones y 3 borrados
  1. +15
    -0
      bitshift/codelet.py
  2. +0
    -0
      bitshift/languages.json
  3. +3
    -3
      bitshift/languages.py

+ 15
- 0
bitshift/codelet.py Ver fichero

@@ -1,3 +1,7 @@
import json

from .languages import LANGS

__all__ = ["Codelet"]

class Codelet(object):
@@ -65,3 +69,14 @@ class Codelet(object):
self.rank = rank
self.symbols = symbols or {}
self.origin = origin or (None, None, None)

def serialize(self):
"""
Convert the codelet into a JSON string representation for the frontend.

:return: The JSON codelet representation.
:rtype: str
"""
lang = LANGS[self.language]
data = {"name": self.name, "code": self.code, "lang": lang}
return json.dumps(data)

bitshift/resources/languages.json → bitshift/languages.json Ver fichero


+ 3
- 3
bitshift/languages.py Ver fichero

@@ -1,5 +1,5 @@
import json
from os import path

with open("bitshift/resources/languages.json") as lang_json:
LANGS = [lang.encode("ascii","ignore") for lang in
json.load(lang_json)["languages"]]
with open(path.join(path.dirname(__file__), "languages.json")) as lang_json:
LANGS = [lang for lang in json.load(lang_json)["languages"]]

Cargando…
Cancelar
Guardar