Ejemplo n.º 1
0
 def _find_file(self, interp, fname):
     if not exists(fname):
         for path in interp.include_path:
             if exists(join(path, [fname])):
                 return join(path, [fname])
     # this is stupid, but...
     actual_code_dir = dirname(interp.global_frame.bytecode.filename)
     if exists(join(actual_code_dir, [fname])):
         return join(actual_code_dir, [fname])
     return abspath(fname)
Ejemplo n.º 2
0
 def read_session_file(self, interp):
     space = interp.space
     cookie_path = interp.space.str_w(
         interp.config.get_ini_w('session.cookie_path'))
     w_cookie = self.get_cookie_var(interp).deref()
     w_cookie_id = space.getitem(w_cookie, space.wrap(self.name))
     if space.is_null(w_cookie_id):
         interp.header(
             'Set-Cookie: %s=%s; path=%s' %
             (self.name, self.session_id, cookie_path), True, False)
     else:
         cookie_id = space.str_w(w_cookie_id)
         self.session_id = cookie_id
     path = interp.space.str_w(interp.config.get_ini_w('session.save_path'))
     fname = self.name + "-" + self.session_id
     dest = rpath.join(path, [fname])
     try:
         f = open(dest)
         data = f.read(-1)
         f.close()
     except OSError:
         dct = None
     except IOError:
         dct = None
     else:
         dct = self.unserialize(interp, data)
     w_ses = self.get_session_var(interp)
     if dct is None:
         w_ses.store(space.new_array_from_rdict(OrderedDict()))
     else:
         d = OrderedDict()
         for k, w_v in dct.iteritems():
             d[k] = w_v
         w_ses.store(space.new_array_from_rdict(d))
Ejemplo n.º 3
0
 def read_session_file(self, interp):
     space = interp.space
     cookie_path = interp.space.str_w(interp.config.get_ini_w("session.cookie_path"))
     w_cookie = self.get_cookie_var(interp).deref()
     w_cookie_id = space.getitem(w_cookie, space.wrap(self.name))
     if space.is_null(w_cookie_id):
         interp.header("Set-Cookie: %s=%s; path=%s" % (self.name, self.session_id, cookie_path), True, False)
     else:
         cookie_id = space.str_w(w_cookie_id)
         self.session_id = cookie_id
     path = interp.space.str_w(interp.config.get_ini_w("session.save_path"))
     fname = self.name + "-" + self.session_id
     dest = rpath.join(path, [fname])
     try:
         f = open(dest)
         data = f.read(-1)
         f.close()
     except OSError:
         dct = None
     except IOError:
         dct = None
     else:
         dct = self.unserialize(interp, data)
     w_ses = self.get_session_var(interp)
     if dct is None:
         w_ses.store(space.new_array_from_rdict(OrderedDict()))
     else:
         d = OrderedDict()
         for k, w_v in dct.iteritems():
             d[k] = w_v
         w_ses.store(space.new_array_from_rdict(d))
Ejemplo n.º 4
0
def stream_resolve_include_path(interp, filename):
    """ Resolve filename against the include path"""

    for path in interp.include_path:
        fullpath = rpath.join(path, [filename])
        if rpath.exists(fullpath):
            return interp.space.wrap(rpath.realpath(fullpath))

    return interp.space.w_False
Ejemplo n.º 5
0
def _spl_autoload(interp, class_name, file_extensions_list):
    class_id = class_name.lower()

    for extension in file_extensions_list:
        for path in interp.include_path:
            fname = rpath.join(path, ["%s%s" % (class_id, extension)])
            if rpath.exists(fname):
                bc = interp.compile_file(fname)
                interp.run_include(bc, interp.global_frame)
Ejemplo n.º 6
0
def stream_resolve_include_path(interp, filename):
    """ Resolve filename against the include path"""

    for path in interp.include_path:
        fullpath = rpath.join(path, [filename])
        if rpath.exists(fullpath):
            return interp.space.wrap(rpath.realpath(fullpath))

    return interp.space.w_False
Ejemplo n.º 7
0
 def destroy(self, interp):
     if self.status == PHP_SESSION_ACTIVE:
         path = interp.space.str_w(interp.config.get_ini_w("session.save_path"))
         fname = self.name + "-" + self.session_id
         dest = rpath.join(path, [fname])
         try:
             assert dest is not None
             dest = assert_str0(dest)
             os.remove(dest)
         except:
             pass
         self.session_id = ""
         self.status = PHP_SESSION_NONE
Ejemplo n.º 8
0
 def destroy(self, interp):
     if self.status == PHP_SESSION_ACTIVE:
         path = interp.space.str_w(
             interp.config.get_ini_w('session.save_path'))
         fname = self.name + "-" + self.session_id
         dest = rpath.join(path, [fname])
         try:
             assert dest is not None
             dest = assert_str0(dest)
             os.remove(dest)
         except:
             pass
         self.session_id = ""
         self.status = PHP_SESSION_NONE
Ejemplo n.º 9
0
    def __init__(self):
        self.token_class = Token

        RULES_FOR_CONTEXT_BRACKETS = [
            (parse_regex("[a-zA-Z_][a-zA-Z_0-9]*"), 'T_VARIABLE')
        ]

        self.rules = {
            CONTEXT_NORMAL: KEYWORDS + RULES,
            CONTEXT_OBJECT_ACCESS: RULES,
            CONTEXT_DOUBLEQUOTE: RULES_FOR_DOUBLE_QUOTE,
            CONTEXT_CURLY_BRACES: KEYWORDS + RULES_FOR_CONTEXT_BRACKETS + RULES,
            CONTEXT_BRACKETS: RULES_FOR_BRACKETS,
            CONTEXT_HEREDOC: RULES_FOR_HEREDOC,
            CONTEXT_BACKTICK: RULES_FOR_BACKTICK
         }

        self.runners_context = {}
        for context, rules in self.rules.items():

            base_dir = rpath.dirname(__file__)
            runner_name = 'runner_%s' % context

            try:
                lexer_runner = __import__(
                    'hippy.%s.%s' % ("lexer_cache", runner_name) , None, None,
                    ['recognize', 'automaton']
                )

                self.runners_context[context] = (
                    lexer_runner.recognize, lexer_runner.automaton)
            except ImportError:
                runner_file = rpath.join(base_dir,
                    ["lexer_cache", "%s.py" % runner_name])

                names, regexs = [], []
                for rule, name in rules:
                    names.append(name)
                    regexs.append(rule)

                rex = regex.LexingOrExpression(regexs, names)
                automaton = rex.make_automaton()
                automaton = automaton.make_deterministic(names)
                automaton.optimize()
                code = automaton.generate_lexing_code()
                open(runner_file, "w").write(code)

                exec py.code.Source(code).compile()
                self.runners_context[context] = (recognize, automaton)
Ejemplo n.º 10
0
 def create_session_file(self, interp, val):
     if self.status != PHP_SESSION_ACTIVE:
         return
     space = interp.space
     path = space.str_w(interp.config.get_ini_w("session.save_path"))
     fname = self.name + "-" + self.session_id
     dest = rpath.join(path, [fname])
     try:
         f = open(dest, "w")
         f.write(val)
         f.close()
     except OSError:
         interp.warn("session_start(): open(%s, O_RDWR) failed")
         return
     except IOError, e:
         if not we_are_translated():
             interp.warn("session_start(): open(%s, O_RDWR) " "failed: %s (%d)" % (dest, e.strerror, e.errno))
         return
Ejemplo n.º 11
0
 def create_session_file(self, interp, val):
     if self.status != PHP_SESSION_ACTIVE:
         return
     space = interp.space
     path = space.str_w(interp.config.get_ini_w('session.save_path'))
     fname = self.name + "-" + self.session_id
     dest = rpath.join(path, [fname])
     try:
         f = open(dest, "w")
         f.write(val)
         f.close()
     except OSError:
         interp.warn("session_start(): open(%s, O_RDWR) failed")
         return
     except IOError, e:
         if not we_are_translated():
             interp.warn("session_start(): open(%s, O_RDWR) "
                         "failed: %s (%d)" % (dest, e.strerror, e.errno))
         return