diff --git a/case-study-porting-chardet-to-python-3.html b/case-study-porting-chardet-to-python-3.html index cb442b1..5a7bfc3 100755 --- a/case-study-porting-chardet-to-python-3.html +++ b/case-study-porting-chardet-to-python-3.html @@ -74,7 +74,7 @@ del{background:#f87}

Running 2to3

-

We’re going to migrate the chardet module from Python 2 to Python 3. Python 3 comes with a utility script called 2to3, which takes your actual Python 2 source code as input and auto-converts as much as it can to Python 3. In some cases this is easy — a function was renamed or moved to a different modules — but in other cases it can get pretty complex. To get a sense of all that it can do, refer to the appendix, Porting code to Python 3 with 2to3. In this chapter, we’ll start by running 2to3 on the chardet package, but as you’ll see, there will still be a lot of work to do after the automated tools have performed their magic. +

We’re going to migrate the chardet module from Python 2 to Python 3. Python 3 comes with a utility script called 2to3, which takes your actual Python 2 source code as input and auto-converts as much as it can to Python 3. In some cases this is easy — a function was renamed or moved to a different module — but in other cases it can get pretty complex. To get a sense of all that it can do, refer to the appendix, Porting code to Python 3 with 2to3. In this chapter, we’ll start by running 2to3 on the chardet package, but as you’ll see, there will still be a lot of work to do after the automated tools have performed their magic.

The main chardet package is split across several different files, all in the same directory. The 2to3 script makes it easy to convert multiple files at once: just pass a directory as a command line argument, and 2to3 will convert each of the files in turn.

C:\home\chardet> python c:\Python30\Tools\Scripts\2to3.py -w chardet\
 RefactoringTool: Skipping implicit fixer: buffer
@@ -617,7 +617,7 @@ TypeError: unorderable types: int() >= str()
# find out current char's byte length - if ((aStr[0] >= '\x81') and (aStr[0] <= '\x9F')) or \ - ((aBuf[0] >= '\xE0') and (aBuf[0] <= '\xFC')): -+ if ((aStr[0] >= 0x81) and (aStr[0] <= 0x9F)) or \ ++ if ((aBuf[0] >= 0x81) and (aBuf[0] <= 0x9F)) or \ + ((aBuf[0] >= 0xE0) and (aBuf[0] <= 0xFC)): charLen = 2 else: @@ -646,7 +646,7 @@ TypeError: unorderable types: int() >= str() - if (aStr[0] == '\x8E') or \ - ((aStr[0] >= '\xA1') and (aStr[0] <= '\xFE')): + if (aBuf[0] == 0x8E) or \ -+ ((aBuf[0] >= 0xA1) and (aStr[0] <= 0xFE)): ++ ((aBuf[0] >= 0xA1) and (aBuf[0] <= 0xFE)): charLen = 2 - elif aStr[0] == '\x8F': + elif aBuf[0] == 0x8F: diff --git a/http-web-services.html b/http-web-services.html index 0cac97d..bf5d9e7 100755 --- a/http-web-services.html +++ b/http-web-services.html @@ -773,7 +773,7 @@ Updates the authenticating user’s status. Requires the statusAuthenticated? Sure. To update your status on Identi.ca, you need to prove who you are. Identi.ca is not a wiki; only you can update your own status. Identi.ca uses HTTP Basic Authentication (a.k.a. RFC 2617) over SSL to provide secure but easy-to-use authentication. httplib2 supports both SSL and HTTP Basic Authentication, so this part is easy. -

A POST request is different from a GET request, because it includes a payload. The payload is the data you want to send to the server. The once piece of data that this API method requires is status, and it should be URL-encoded. This is a very simple serialization format that takes a set of key-value pairs (i.e. a dictionary) and transforms it into a string. +

A POST request is different from a GET request, because it includes a payload. The payload is the data you want to send to the server. The one piece of data that this API method requires is status, and it should be URL-encoded. This is a very simple serialization format that takes a set of key-value pairs (i.e. a dictionary) and transforms it into a string.

 >>> from urllib.parse import urlencode