Exemplo n.º 1
0
                d.close()
                success = True

if success:
    print "		<meta http-equiv='REFRESH' content='0;login.py?username=%s&password=%s'>" % (username, password)
    print """<!--Info -->
    <div class='container'>
        <div class='alert alert-success'>
            <h1>Account created successfully.</h1>
            <p>You will be automatically logged in, or <a href="/cgi/login.py">click here to log in manually</a>.</p>
        </div>
    </div>
"""
elif 'KOOKIE' in kookie:
	cookie = SimpleCookie(os.environ['HTTP_COOKIE'])['KOOKIE'].value
	username = cookie.split("_")[0]
	password = cookie.split("_")[1]

	print "    <META HTTP-EQUIV='refresh' CONTENT='5;URL=/'>"
	print """<!--Info -->
    <div class='container'>
        <div class='alert alert-error'>
            <h1>Already logged in.</h1>
            <p>You will be automatically redirected in 5 seconds, or <a href="/">click here</a>.</p>
        </div>
    </div>
"""
else:
    print """<!--Registration form -->
	<div class='container'>
		<form class='well' method='post'>
Exemplo n.º 2
0
Arquivo: Cookies.py Projeto: Afey/pyjs
def get_crumbs():
    docCookie = doc().cookie
    c = SimpleCookie(docCookie)
    c = c.output(header='')
    return map(strip, c.split('\n'))
Exemplo n.º 3
0
def get_crumbs():
    docCookie = doc().cookie
    c = SimpleCookie(docCookie)
    c = c.output(header='')
    return map(strip, c.split('\n'))
Exemplo n.º 4
0
class Response(object):
    """An HTTP Response, including status, headers, and body.
    
    Application developers should use Response.headers (a dict) to
    set or modify HTTP response headers. When the response is finalized,
    Response.headers is transformed into Response.header_list as
    (key, value) tuples.
    """

    __metaclass__ = cherrypy._AttributeDocstrings

    # Class attributes for dev-time introspection.
    status = ""
    status__doc = """The HTTP Status-Code and Reason-Phrase."""

    header_list = []
    header_list__doc = """
    A list of the HTTP response headers as (name, value) tuples.
    In general, you should use response.headers (a dict) instead."""

    headers = httputil.HeaderMap()
    headers__doc = """
    A dict-like object containing the response headers. Keys are header
    names (in Title-Case format); however, you may get and set them in
    a case-insensitive manner. That is, headers['Content-Type'] and
    headers['content-type'] refer to the same value. Values are header
    values (decoded according to RFC 2047 if necessary). See also:
    httputil.HeaderMap, httputil.HeaderElement."""

    cookie = SimpleCookie()
    cookie__doc = """See help(Cookie)."""

    body = ResponseBody()
    body__doc = """The body (entity) of the HTTP response."""

    time = None
    time__doc = """The value of time.time() when created. Use in HTTP dates."""

    timeout = 300
    timeout__doc = """Seconds after which the response will be aborted."""

    timed_out = False
    timed_out__doc = """
    Flag to indicate the response should be aborted, because it has
    exceeded its timeout."""

    stream = False
    stream__doc = """If False, buffer the response body."""

    def __init__(self):
        self.status = None
        self.header_list = None
        self._body = []
        self.time = time.time()

        self.headers = httputil.HeaderMap()
        # Since we know all our keys are titled strings, we can
        # bypass HeaderMap.update and get a big speed boost.
        dict.update(
            self.headers, {
                "Content-Type": 'text/html',
                "Server": "CherryPy/" + cherrypy.__version__,
                "Date": httputil.HTTPDate(self.time),
            })
        self.cookie = SimpleCookie()

    def collapse_body(self):
        """Collapse self.body to a single string; replace it and return it."""
        if isinstance(self.body, basestring):
            return self.body

        newbody = ''.join([chunk for chunk in self.body])
        self.body = newbody
        return newbody

    def finalize(self):
        """Transform headers (and cookies) into self.header_list. (Core)"""
        try:
            code, reason, _ = httputil.valid_status(self.status)
        except ValueError, x:
            raise cherrypy.HTTPError(500, x.args[0])

        headers = self.headers

        self.output_status = str(code) + " " + headers.encode(reason)

        if self.stream:
            # The upshot: wsgiserver will chunk the response if
            # you pop Content-Length (or set it explicitly to None).
            # Note that lib.static sets C-L to the file's st_size.
            if dict.get(headers, 'Content-Length') is None:
                dict.pop(headers, 'Content-Length', None)
        elif code < 200 or code in (204, 205, 304):
            # "All 1xx (informational), 204 (no content),
            # and 304 (not modified) responses MUST NOT
            # include a message-body."
            dict.pop(headers, 'Content-Length', None)
            self.body = ""
        else:
            # Responses which are not streamed should have a Content-Length,
            # but allow user code to set Content-Length if desired.
            if dict.get(headers, 'Content-Length') is None:
                content = self.collapse_body()
                dict.__setitem__(headers, 'Content-Length', len(content))

        # Transform our header dict into a list of tuples.
        self.header_list = h = headers.output()

        cookie = self.cookie.output()
        if cookie:
            for line in cookie.split("\n"):
                if line.endswith("\r"):
                    # Python 2.4 emits cookies joined by LF but 2.5+ by CRLF.
                    line = line[:-1]
                name, value = line.split(": ", 1)
                if isinstance(name, unicode):
                    name = name.encode("ISO-8859-1")
                if isinstance(value, unicode):
                    value = headers.encode(value)
                h.append((name, value))