Changeset 517

Show
Ignore:
Timestamp:
03/14/08 18:35:27 (8 months ago)
Author:
migurski
Message:

Nice little list comprehension goes away in favor of a more HTTP-aware tile loader

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/py/ModestMaps/__init__.py

    r480 r517  
    88""" 
    99 
    10 import PIL.Image, urllib, StringIO, math, thread, time 
     10import sys, PIL.Image, urllib, httplib, urlparse, StringIO, math, thread, time 
    1111 
    1212import Tiles 
     
    107107        # this is the time-consuming part 
    108108        try: 
    109             imgs = [PIL.Image.open(StringIO.StringIO(urllib.urlopen(url).read())).convert('RGBA') 
    110                     for url in urls]                 
     109            imgs = [] 
     110         
     111            for (scheme, netloc, path, params, query, fragment) in map(urlparse.urlparse, urls): 
     112                conn = httplib.HTTPConnection(netloc) 
     113                conn.request('GET', path + '?' + query) 
     114                response = conn.getresponse() 
     115                 
     116                if str(response.status).startswith('2'): 
     117                    imgs.append(PIL.Image.open(StringIO.StringIO(response.read())).convert('RGBA')) 
     118 
    111119        except: 
    112120