Setting up http redirect

I was trying to setup a http redirect on ubuntu. Spent quite some time.
1) Ubuntu has a
/etc/apache2/sites-available/default
file where you will have to change the AllowOverride option from None to All.
Only this step will enable you to use .htaccess file.
2) In the .htaccess file, I was doing

Redirect 302 ./index.html http://localhost/new.html


Spent more than a hour to figure out, why the redirect is not happening. The problem was, I was doing
./index.html
instead of just
/index.html

Bytes and String in Py3k

Martin's Explaination:

It's really very similar to 2.x: the "bytes" type is to used in all
interfaces that operate on byte sequences that may or may not represent characters; in particular, for interface where the operating system deliberately uses bytes - ie. low-level file IO and socket IO; also for cases where the encoding is embedded in the stream that still needs to be processed (e.g. XML parsing).

(Unicode) strings should be used where the data is truly text by
nature, i.e. where no encoding information is necessary to find out
what characters are intended. It's used on interfaces where the
encoding is known (e.g. text IO, where the encoding is specified
on opening, XML parser results, with the declared encoding, and
GUI libraries, which naturally expect text).

- base64.encodestring expects bytes (naturally, since it is supposed to
encode arbitrary binary data), and produces bytes (debatably)
- binascii.b2a_hex likewise (expect and produce bytes)
- pickle.dumps produces bytes (uniformly, both for binary and text
pickles)
- marshal.dumps likewise
- email.message.Message().as_string produces a (unicode) string
(see Barry's recent thread on whether that's a good thing; the
email package hasn't been fully ported to 3k, either)
- the XML libraries (continue to) parse bytes, and produce
Unicode strings
- for the IO libraries, see above

Does parse_header really belong to cgi?

http://bugs.python.org/issue3609

Barry's thought is it can be moved to email module.

Bugs Fixed

Fixed Bugs:
http://bugs.python.org/issue4675
http://bugs.python.org/issue4962

Simple CGIHTTPServer and Client in Python 3k

Python 3k - CGIHTTPRequestHandler example.


import http.server
import http.server

class Handler(http.server.CGIHTTPRequestHandler):
cgi_directories = ["/cgi"]

server = http.server.HTTPServer(("",8000),Handler)
server.serve_forever()


Run this server.

Create a Directory 'cgi' in the directory you have the above server script and place the following python cgi code.

filename: test.py

#!/usr/local/bin/python3.1

import cgitb;cgitb.enable()

print("Content-type: text/html")
print()
print("<title>CGI 101</title>")
print("<h1>First CGI Example</h1>")
print("<p>Hello, CGI World!</p>")



Open the Browser and point to http://localhost:8000/cgi/test.py

file opening modes.

Possible values for the mode open are

"r" or "rt"
Open for reading in text mode.
"w" or "wt"
Open for writing in text mode.
"a" or "at"
Open for appending in text mode.
"rb"
Open for reading in binary mode.
"wb"
Open for writing in binary mode.
"ab"
Open for appending in binary mode.
"r+", "r+b"
Open for reading and writing.
"w+", "w+b"
Open for reading and writing, truncating file initially.
"a+", "a+b"
Open for reading and appending.

Yahoo Hack Day India 2009

I developed an application using Y! BOSS Search APIs, Linguistics, Machine Learning and Google App engine.

Here is the Application Live. Use it anytime:



Here is the Source code for the Project:

unix_time_1234567890


unix_time_1234567890

This was fun. I could manage to capture it again. This time it was with Vijay.

Previously, while at Dell, along with another friend, Raj, had captured 1111111111.

Capturing History