Posts

Showing posts from December, 2014

The 5000mph car

Image
If your car dealer offers, for the additional sum of $500, to upgrade your car to a top speed of 5,000mph, would you take it? When it comes to broadband Internet access, people have been downing the Kool-Aid with exceptional enthusiasm. In some cities with weak or non-existent consumer laws, ISPs are offering 100Mbps, 200Mbps, 500Mbps and 1Gbps service. Each bigger number option (note I do not say faster option) costs a few dollars more than the smaller one. In some places, the ISPs have stopped offering 100Mbps altogether and start at 200Mbps. The reason couldn't be more obvious. The cost of providing 200Mbps is the same as 100Mbps. The small print in the T&Cs' essentially allows the ISPs to not do anything other than provide the specified speed between the customer and their first node. So, a higher priced product means more profits. Buying 200Mbps or 500Mbps is exactly the same as buying a 2,000mph or 5,000mph car respectively. People can easily relate to the

Serializing that convoluted cookielib.CookieJar

The Python cookielib.CookieJar object is a very convenient feature to manage cookies automatically as you traverse a series of Http web requests back and forth. However, the data structure of the class is a convoluted collection of Python dict . cookielib.CookieJar has a _cookies property which is a dictionary of a dictionary of a dictionary of cookielib.Cookie . To understand the data structure in the CookieJar object cj , try: for domain in cj._cookies.keys(): for path in cj._cookies[domain]: for name in cj._cookies[domain][path]: cookie = cj._cookies[domain][path][name] print domain, path, cookie.name, '=' , cookie.value However, the class-defined __iter__ method makes the above effort unnecessary if you just want to find the value of a cookie. The __iter__ method returns a cookielib.Cookie object for each iteration. You can simply go: for cookie in cj: print cookie.domain, cookie.path, cookie.name, cookie.value # etc I