Nothing Special   »   [go: up one dir, main page]

Monday, November 22, 2010

Snaked 0.4

Next big Snaked's release. It features:

Also some minor improvements:

  • Hide tab bar on <Alt>F11.
  • Switch tabs on additional "standard" <Ctrl>PageUp/PageDown keys.
  • Automatic character encoding detection.
  • Highlight selection on <Ctrl>H.
  • All search dialogs allow activate the one item by Enter key in search entry.
  • Hints config format changed. Now it is ordinary python module.
  • Show cursor column on <Ctrl><Alt>O
  • Editor's line spacing option.
  • Hints for re.RegexObject and re.MatchObject.
  • Auto remove trailing space on file save.
  • Disable left mouse button click in text view window.
  • Rewrap text on right margin with <Alt>F.

What will be in next version?

  • Multiple snippet contexts.
  • Variable autocomplete in Django/Jinja templates.
  • Editing capabilities improving.

You can install:

sudo pip install snaked

Upgrade:

sudo pip install -U snaked

Or download package directly from PyPI. Also check install instructions.

Thursday, November 4, 2010

Bad servers, chunked encoding and IncompleteRead

Have you ever got IncompleteRead exception on trying to fetch chunked data with urllib2? I did. Look at the snippet:

import urllib2, httplib

try:
    data = urllib2.urlopen('http://some.url/address').read()
except httplib.IncompleteRead:
    # Ahtung! At this point you lose any fetched data except last chunk.

IRL most bad servers transmit all data, but due implementation errors they wrongly close session and urllib raise error and bury your precious bytes.

What you have to do to handle such situation?

I don't like any solutions which involve manual data reading loop, so I prefer to patch read function.

import httplib

def patch_http_response_read(func):
    def inner(*args):
        try:
            return func(*args)
        except httplib.IncompleteRead, e:
            return e.partial

    return inner
httplib.HTTPResponse.read = patch_http_response_read(httplib.HTTPResponse.read)

It allows you to deal with defective http servers.