Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.97 KB | None | 0 0
  1.  
  2. pypy\interpreter\astcompiler\astbuilder.py:901:
  3. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  4.  
  5. self = <pypy.interpreter.astcompiler.astbuilder.ASTBuilder object at 0x043b7610>
  6.  
  7. power_node = Nonterminal(type=311, children=[Nonterminal(type=267, children=[Non
  8. terminal(type=266, children=[Terminal(type=3, value="u'\\U00012345'")])])])
  9.  
  10. def handle_power(self, power_node):
  11. > atom_expr = self.handle_atom_expr(power_node.get_child(0))
  12.  
  13. pypy\interpreter\astcompiler\astbuilder.py:1018:
  14. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  15.  
  16. self = <pypy.interpreter.astcompiler.astbuilder.ASTBuilder object at 0x043b7610>
  17.  
  18. atom_node = Nonterminal(type=267, children=[Nonterminal(type=266, children=[Term
  19. inal(type=3, value="u'\\U00012345'")])])
  20.  
  21. def handle_atom_expr(self, atom_node):
  22. start = 0
  23. num_ch = atom_node.num_children()
  24. if atom_node.get_child(0).type == tokens.AWAIT:
  25. start = 1
  26. > atom_expr = self.handle_atom(atom_node.get_child(start))
  27.  
  28. pypy\interpreter\astcompiler\astbuilder.py:997:
  29. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  30.  
  31. self = <pypy.interpreter.astcompiler.astbuilder.ASTBuilder object at 0x043b7610>
  32.  
  33. atom_node = Nonterminal(type=266, children=[Terminal(type=3, value="u'\\U0001234
  34. 5'")])
  35.  
  36. def handle_atom(self, atom_node):
  37. first_child = atom_node.get_child(0)
  38. first_child_type = first_child.type
  39. if first_child_type == tokens.NAME:
  40. name = first_child.get_value()
  41. if name == "None":
  42. w_singleton = self.space.w_None
  43. elif name == "True":
  44. w_singleton = self.space.w_True
  45. elif name == "False":
  46. w_singleton = self.space.w_False
  47. else:
  48. name = self.new_identifier(name)
  49. return ast.Name(name, ast.Load, first_child.get_lineno(),
  50. first_child.get_column())
  51. return ast.NameConstant(w_singleton, first_child.get_lineno(),
  52. first_child.get_column())
  53. #
  54. elif first_child_type == tokens.STRING:
  55. > return fstring.string_parse_literal(self, atom_node)
  56.  
  57. pypy\interpreter\astcompiler\astbuilder.py:1254:
  58. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  59.  
  60. astbuilder = <pypy.interpreter.astcompiler.astbuilder.ASTBuilder object at 0x043
  61. b7610>
  62. atom_node = Nonterminal(type=266, children=[Terminal(type=3, value="u'\\U0001234
  63. 5'")])
  64.  
  65. def string_parse_literal(astbuilder, atom_node):
  66. space = astbuilder.space
  67. encoding = astbuilder.compile_info.encoding
  68. joined_pieces = []
  69. fmode = False
  70. for i in range(atom_node.num_children()):
  71. child = atom_node.get_child(i)
  72. try:
  73. w_next = parsestring.parsestr(
  74. > space, encoding, child.get_value())
  75.  
  76. pypy\interpreter\astcompiler\fstring.py:348:
  77. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  78.  
  79. space = StdObjSpace, encoding = 'utf-8', s = "u'\\U00012345'"
  80.  
  81. def parsestr(space, encoding, s):
  82. """Parses a string or unicode literal, and return usually
  83. a wrapped value. If we get an f-string, then instead return
  84. an unparsed but unquoted W_FString instance.
  85.  
  86. If encoding=None, the source string is ascii only.
  87. In other cases, the source string is in utf-8 encoding.
  88.  
  89. When a bytes string is returned, it will be encoded with the
  90. original encoding.
  91.  
  92. Yes, it's very inefficient.
  93. Yes, CPython has very similar code.
  94. """
  95. # we use ps as "pointer to s"
  96. # q is the virtual last char index of the string
  97. ps = 0
  98. quote = s[ps]
  99. rawmode = False
  100. unicode_literal = True
  101. saw_u = False
  102. saw_f = False
  103.  
  104. # string decoration handling
  105. if quote == 'b' or quote == 'B':
  106. ps += 1
  107. quote = s[ps]
  108. unicode_literal = False
  109. elif quote == 'u' or quote == 'U':
  110. ps += 1
  111. quote = s[ps]
  112. saw_u = True
  113. elif quote == 'r' or quote == 'R':
  114. ps += 1
  115. quote = s[ps]
  116. rawmode = True
  117. elif quote == 'f' or quote == 'F':
  118. ps += 1
  119. quote = s[ps]
  120. saw_f = True
  121.  
  122. if not saw_u:
  123. if quote == 'r' or quote == 'R':
  124. ps += 1
  125. quote = s[ps]
  126. rawmode = True
  127. elif quote == 'b' or quote == 'B':
  128. ps += 1
  129. quote = s[ps]
  130. unicode_literal = False
  131. elif quote == 'f' or quote == 'F':
  132. ps += 1
  133. quote = s[ps]
  134. saw_f = True
  135.  
  136. if quote != "'" and quote != '"':
  137. raise_app_valueerror(space,
  138. 'Internal error: parser passed unquoted literal
  139. ')
  140. ps += 1
  141. q = len(s) - 1
  142. if s[q] != quote:
  143. raise_app_valueerror(space, 'Internal error: parser passed unmatched
  144. '
  145. 'quotes in literal')
  146. if q-ps >= 4 and s[ps] == quote and s[ps+1] == quote:
  147. # triple quotes
  148. ps += 2
  149. if s[q-1] != quote or s[q-2] != quote:
  150. raise_app_valueerror(space, 'Internal error: parser passed '
  151. 'unmatched triple quotes in literal'
  152. )
  153. q -= 2
  154.  
  155. if unicode_literal and not rawmode: # XXX Py_UnicodeFlag is ignored for
  156. now
  157. assert 0 <= ps <= q
  158. if saw_f:
  159. return W_FString(s[ps:q], rawmode)
  160. if encoding is None:
  161. substr = s[ps:q]
  162. else:
  163. unicodehelper.check_utf8_or_raise(space, s, ps, q)
  164. substr = decode_unicode_utf8(space, s, ps, q)
  165. r = unicodehelper.decode_unicode_escape(space, substr)
  166. v, length, pos = r
  167. > return space.newutf8(v, length)
  168.  
  169. pypy\interpreter\pyparser\parsestring.py:99:
  170. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  171.  
  172. self = StdObjSpace, utf8s = '\xf0\x92\x8d\x85', length = 1
  173.  
  174. def newutf8(self, utf8s, length):
  175. assert isinstance(utf8s, str)
  176. > return W_UnicodeObject(utf8s, length)
  177.  
  178. pypy\objspace\std\objspace.py:405:
  179. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  180.  
  181. self = W_UnicodeObject('\xf0\x92\x8d\x85'), utf8str = '\xf0\x92\x8d\x85'
  182. length = 1
  183.  
  184. def __init__(self, utf8str, length):
  185. if not we_are_translated():
  186. typecheck(self, utf8str, length) # rpython.rlib.objectmodel
  187. > return __init___original(self, utf8str, length)
  188.  
  189. <677-codegen C:\pypy\rpython\tool\sourcetools.py:292>:5:
  190. _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
  191.  
  192. self = W_UnicodeObject('\xf0\x92\x8d\x85'), utf8str = '\xf0\x92\x8d\x85'
  193. length = 1
  194.  
  195. @enforceargs(utf8str=str)
  196. def __init__(self, utf8str, length):
  197. assert isinstance(utf8str, bytes)
  198. # TODO: how to handle surrogates
  199. assert length >= 0
  200. self._utf8 = utf8str
  201. self._length = length
  202. self._index_storage = rutf8.null_storage()
  203. if not we_are_translated():
  204. try:
  205. # best effort, too expensive to handle surrogates
  206. ulength = len(utf8str.decode('utf8'))
  207. except:
  208. ulength = length
  209. > assert ulength == length
  210. E assert 2 == 1
  211.  
  212. pypy\objspace\std\unicodeobject.py:47: AssertionError
  213. ========================== short test summary info ===========================
  214. FAIL pypy/module/_cffi_backend/test/test_ffi_obj.py::AppTestFFIObj::()::test_cha
  215. r32_t
  216. ==================== 1 failed, 45 passed in 77.59 seconds ====================
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement