Exemplo n.º 1
0
 def add_cached_builtin_decl(self, entry):
     if Options.cache_builtins:
         if self.should_declare(entry.cname, entry):
             self.put_pyobject_decl(entry)
             w = self.parts['cached_builtins']
             if entry.name == 'xrange':
                 # replaced by range() in Py3
                 w.putln('#if PY_MAJOR_VERSION >= 3')
                 self.put_cached_builtin_init(
                     entry.pos, StringEncoding.EncodedString('range'),
                     entry.cname)
                 w.putln('#else')
             self.put_cached_builtin_init(
                 entry.pos, StringEncoding.EncodedString(entry.name),
                 entry.cname)
             if entry.name == 'xrange':
                 w.putln('#endif')
Exemplo n.º 2
0
 def slot_code(self, scope):
     if scope.doc is not None:
         if scope.doc.is_unicode:
             doc = scope.doc.utf8encode()
         else:
             doc = scope.doc.byteencode()
         return '__Pyx_DOCSTR("%s")' % StringEncoding.escape_byte_string(doc)
     else:
         return "0"
Exemplo n.º 3
0
 def slot_code(self, scope):
     if scope.doc is not None:
         if scope.doc.is_unicode:
             doc = scope.doc.utf8encode()
         else:
             doc = scope.doc.byteencode()
         return '"%s"' % StringEncoding.escape_byte_string(doc)
     else:
         return "0"
Exemplo n.º 4
0
Arquivo: Code.py Projeto: dagss/cython
    def generate_string_constants(self):
        c_consts = [(len(c.cname), c.cname, c) for c in self.string_const_index.values()]
        c_consts.sort()
        py_strings = []

        decls_writer = self.parts["decls"]
        for _, cname, c in c_consts:
            decls_writer.putln(
                'static char %s[] = "%s";' % (cname, StringEncoding.split_string_literal(c.escaped_value))
            )
            if c.py_strings is not None:
                for py_string in c.py_strings.values():
                    py_strings.append((c.cname, len(py_string.cname), py_string))

        if py_strings:
            import Nodes

            self.use_utility_code(Nodes.init_string_tab_utility_code)

            py_strings.sort()
            w = self.parts["pystring_table"]
            w.putln("")
            w.putln("static __Pyx_StringTabEntry %s[] = {" % Naming.stringtab_cname)
            for c_cname, _, py_string in py_strings:
                if (
                    not py_string.is_str
                    or not py_string.encoding
                    or py_string.encoding in ("ASCII", "USASCII", "US-ASCII", "UTF8", "UTF-8")
                ):
                    encoding = "0"
                else:
                    encoding = '"%s"' % py_string.encoding.lower()

                decls_writer.putln("static PyObject *%s;" % py_string.cname)
                w.putln(
                    "{&%s, %s, sizeof(%s), %s, %d, %d, %d},"
                    % (
                        py_string.cname,
                        c_cname,
                        c_cname,
                        encoding,
                        py_string.is_unicode,
                        py_string.is_str,
                        py_string.intern,
                    )
                )
            w.putln("{0, 0, 0, 0, 0, 0, 0}")
            w.putln("};")

            init_globals = self.parts["init_globals"]
            init_globals.putln(
                "if (__Pyx_InitStrings(%s) < 0) %s;"
                % (Naming.stringtab_cname, init_globals.error_goto(self.module_pos))
            )
Exemplo n.º 5
0
Arquivo: Code.py Projeto: dagss/cython
 def __init__(self, cname, text, byte_string):
     self.cname = cname
     self.text = text
     self.escaped_value = StringEncoding.escape_byte_string(byte_string)
     self.py_strings = None
Exemplo n.º 6
0
 def __init__(self, cname, text, byte_string):
     self.cname = cname
     self.text = text
     self.escaped_value = StringEncoding.escape_byte_string(byte_string)
     self.py_strings = None
Exemplo n.º 7
0
import sys
import struct
import re
import os

from StringEncoding import *


myEncoding = StringEncoding()

bytes = sys.stdin.read()
x = bytes[:-1].decode("hex")
d = bytearray(x)
l = myEncoding.decode(d)
if(l):
	k = os.getenv("USE_TRIVIAL_IMPLEMENTATION", 0)
	if(int(k) ==  1):
		r = myEncoding.encode(l,True)
	else:
		r = myEncoding.encode(l,False)

	

sys.stdout.write("stdout: " +l+"\n")

if(r):
	sys.stderr.write("stderr: "+str(r)+"\n")
else:
	sys.stderr.write("stderr: Error\n");

Exemplo n.º 8
0
 def literal_code(self, value):
     assert isinstance(value, str)
     return '"%s"' % StringEncoding.escape_byte_string(value)
Exemplo n.º 9
0
 def literal_code(self, value):
     assert isinstance(value, str)
     return '"%s"' % StringEncoding.escape_byte_string(value)