104 lines
3.3 KiB
Diff
104 lines
3.3 KiB
Diff
From e44509b5e42525f30b62137599e574fdd41f68bc Mon Sep 17 00:00:00 2001
|
|
From: Benjamin Moran <benmoran@protonmail.com>
|
|
Date: Tue, 24 Nov 2020 11:42:02 +0900
|
|
Subject: [PATCH] Simplify UBO code, and revert some experimental code.
|
|
|
|
---
|
|
RELEASE_NOTES | 8 ++++++
|
|
pyglet/text/formats/attributed.py | 41 +++++++------------------------
|
|
2 files changed, 17 insertions(+), 32 deletions(-)
|
|
|
|
diff --git a/RELEASE_NOTES b/RELEASE_NOTES
|
|
index 5c4fe67a..f084a013 100644
|
|
--- a/RELEASE_NOTES
|
|
+++ b/RELEASE_NOTES
|
|
@@ -1,3 +1,11 @@
|
|
+pyglet 1.5.12
|
|
+Bugfix and feature release
|
|
+
|
|
+Bugfixes
|
|
+--------
|
|
+- Remove usage of deprecated `parser` module. (#312)
|
|
+
|
|
+
|
|
pyglet 1.5.11
|
|
Bugfix release
|
|
|
|
diff --git a/pyglet/text/formats/attributed.py b/pyglet/text/formats/attributed.py
|
|
index 350e0844..3eb815c6 100644
|
|
--- a/pyglet/text/formats/attributed.py
|
|
+++ b/pyglet/text/formats/attributed.py
|
|
@@ -38,11 +38,7 @@
|
|
"""
|
|
|
|
import re
|
|
-import token
|
|
-import parser
|
|
-import operator
|
|
-
|
|
-from functools import reduce
|
|
+import ast
|
|
|
|
import pyglet
|
|
|
|
@@ -63,11 +59,13 @@
|
|
|
|
|
|
class AttributedTextDecoder(pyglet.text.DocumentDecoder):
|
|
- def decode(self, text, location=None):
|
|
- self.doc = pyglet.text.document.FormattedDocument()
|
|
|
|
+ def __init__(self):
|
|
+ self.doc = pyglet.text.document.FormattedDocument()
|
|
self.length = 0
|
|
self.attributes = {}
|
|
+
|
|
+ def decode(self, text, location=None):
|
|
next_trailing_space = True
|
|
trailing_newline = True
|
|
|
|
@@ -90,22 +88,15 @@ def decode(self, text, location=None):
|
|
self.append(m.group('nl_para')[1:]) # ignore the first \n
|
|
trailing_newline = True
|
|
elif group == 'attr':
|
|
- try:
|
|
- ast = parser.expr(m.group('attr_val'))
|
|
- if self.safe(ast):
|
|
- val = eval(ast.compile())
|
|
- else:
|
|
- val = None
|
|
- except (parser.ParserError, SyntaxError):
|
|
- val = None
|
|
+ value = ast.literal_eval(m.group('attr_val'))
|
|
name = m.group('attr_name')
|
|
if name[0] == '.':
|
|
if trailing_newline:
|
|
- self.attributes[name[1:]] = val
|
|
+ self.attributes[name[1:]] = value
|
|
else:
|
|
- self.doc.set_paragraph_style(self.length, self.length, {name[1:]: val})
|
|
+ self.doc.set_paragraph_style(self.length, self.length, {name[1:]: value})
|
|
else:
|
|
- self.attributes[name] = val
|
|
+ self.attributes[name] = value
|
|
elif group == 'escape_dec':
|
|
self.append(chr(int(m.group('escape_dec_val'))))
|
|
elif group == 'escape_hex':
|
|
@@ -122,17 +113,3 @@ def append(self, text):
|
|
self.doc.insert_text(self.length, text, self.attributes)
|
|
self.length += len(text)
|
|
self.attributes.clear()
|
|
-
|
|
- _safe_names = ('True', 'False', 'None')
|
|
-
|
|
- def safe(self, ast):
|
|
- tree = ast.totuple()
|
|
- return self.safe_node(tree)
|
|
-
|
|
- def safe_node(self, node):
|
|
- if token.ISNONTERMINAL(node[0]):
|
|
- return reduce(operator.and_, map(self.safe_node, node[1:]))
|
|
- elif node[0] == token.NAME:
|
|
- return node[1] in self._safe_names
|
|
- else:
|
|
- return True
|