MCPcopy Create free account
hub / github.com/ActiveState/code / __getsid

Method __getsid

recipes/Python/577524_Python_Sessions/recipe-577524.py:74–94  ·  view source on GitHub ↗

Get the current session ID or return a new one

(self)

Source from the content-addressed store, hash-verified

72 return h.hexdigest()
73
74 def __getsid(self):
75 """Get the current session ID or return a new one"""
76 # first, try to load the sid from the GET or POST forms
77 form = cgi.FieldStorage()
78 if form.has_key(S_ID):
79 sid = form[S_ID].value
80 return sid
81
82 # then try to load the sid from the HTTP cookie
83 self.cookie = SimpleCookie()
84 if os.environ.has_key('HTTP_COOKIE'):
85 self.cookie.load(os.environ['HTTP_COOKIE'])
86
87 if S_ID in self.cookie:
88 sid = self.cookie[S_ID].value
89 return sid
90 else:
91 raise NoCookiesError("Could not find any cookies")
92
93 # if all else fails, return a new sid
94 return self.__newsid()
95
96 def getsid(self):
97 """

Callers 1

__init__Method · 0.95

Calls 4

__newsidMethod · 0.95
NoCookiesErrorClass · 0.85
has_keyMethod · 0.45
loadMethod · 0.45

Tested by

no test coverage detected