-
Notifications
You must be signed in to change notification settings - Fork 177
/
pyxl_strings.py
32 lines (25 loc) · 895 Bytes
/
pyxl_strings.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
# -*- coding: utf-8 -*-
import ast
from io import StringIO
import tokenize
try:
from pyxl.codec.tokenizer import pyxl_tokenize
from pyxl import html
except ImportError as e:
raise RuntimeError("External library missing, please install the 'pyxl3'"
" package.") from e
from macropy.core.macros import Macros
macros = Macros()
@macros.expr
def p(tree, **kw):
new_string = tokenize.untokenize(pyxl_tokenize(StringIO('(' + tree.s + ')')
.readline)).rstrip().rstrip("\\")
new_tree = ast.parse(new_string)
return new_tree.body[0].value
# expose to the calling module some symbols
macros.expose_unhygienic(html, 'html')
# these are needed due to bugs in the port to py3, I suppose
rawhtml = html.rawhtml
macros.expose_unhygienic(rawhtml)
unicode = str
macros.expose_unhygienic(unicode, 'unicode')