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))
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))
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
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)
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']) if getattr(lexer_runner, "rulehash", 0) != hash(str(rules)): raise ImportError # hack 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() with open(runner_file, "w") as f: f.write(code) f.write("\n\nrulehash = %s" % hash(str(rules))) exec py.code.Source(code).compile() self.runners_context[context] = (recognize, automaton)
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
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
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
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