/+junk/pygooglechart-py3k

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/%2Bjunk/pygooglechart-py3k

« back to all changes in this revision

Viewing changes to pygooglechart.py

  • Committer: Gustav Hartvigsson
  • Date: 2011-01-03 20:24:45 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20110103202445-qh7ogio9ined8ufv
Made it compatible with Python 3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import os
25
25
import urllib
26
 
import urllib2
 
26
import urllib.request, urllib.error
27
27
import math
28
28
import random
29
29
import re
375
375
            url_bits.append(self.markers_to_url())        
376
376
        if self.line_styles:
377
377
            style = []
378
 
            for index in xrange(max(self.line_styles) + 1):
 
378
            for index in range(max(self.line_styles) + 1):
379
379
                if index in self.line_styles:
380
380
                    values = self.line_styles[index]
381
381
                else:
391
391
 
392
392
    def download(self, file_name, use_post=True):
393
393
        if use_post:
394
 
            opener = urllib2.urlopen(self.BASE_URL, self.get_url_extension())
 
394
            opener = urllib.request.urlopen(self.BASE_URL, self.get_url_extension())
395
395
        else:
396
 
            opener = urllib2.urlopen(self.get_url())
 
396
            opener = urllib.request.urlopen(self.get_url())
397
397
 
398
398
        if opener.headers['content-type'] != 'image/png':
399
399
            raise BadContentTypeException('Server responded with a ' \
406
406
 
407
407
    def set_title(self, title):
408
408
        if title:
409
 
            self.title = urllib.quote(title)
 
409
            self.title = urllib.parse.quote(title)
410
410
        else:
411
411
            self.title = None
412
412
 
423
423
        assert(isinstance(legend, list) or isinstance(legend, tuple) or
424
424
            legend is None)
425
425
        if legend:
426
 
            self.legend = [urllib.quote(a) for a in legend]
 
426
            self.legend = [urllib.parse.quote(a) for a in legend]
427
427
        else:
428
428
            self.legend = None
429
429
 
430
430
    def set_legend_position(self, legend_position):
431
431
        if legend_position:
432
 
            self.legend_position = urllib.quote(legend_position)
 
432
            self.legend_position = urllib.parse.quote(legend_position)
433
433
        else:    
434
434
            self.legend_position = None
435
435
 
470
470
        assert(angle >= 0 and angle <= 90)
471
471
        assert(len(args) % 2 == 0)
472
472
        args = list(args)  # args is probably a tuple and we need to mutate
473
 
        for a in xrange(int(len(args) / 2)):
 
473
        for a in range(int(len(args) / 2)):
474
474
            col = args[a * 2]
475
475
            offset = args[a * 2 + 1]
476
476
            _check_colour(col)
626
626
 
627
627
    def set_axis_labels(self, axis_type, values):
628
628
        assert(axis_type in Axis.TYPES)
629
 
        values = [urllib.quote(str(a)) for a in values]
 
629
        values = [urllib.parse.quote(str(a)) for a in values]
630
630
        axis_index = len(self.axis)
631
631
        axis = LabelAxis(axis_index, axis_type, values)
632
632
        self.axis.append(axis)
812
812
            url_bits.append('chbh=%i' % self.bar_width)
813
813
        zero_line = []
814
814
        if self.zero_lines:
815
 
            for index in xrange(max(self.zero_lines) + 1):
 
815
            for index in range(max(self.zero_lines) + 1):
816
816
                if index in self.zero_lines:
817
817
                    zero_line.append(str(self.zero_lines[index]))
818
818
                else:
906
906
                (self.__class__.__name__))
907
907
 
908
908
    def set_pie_labels(self, labels):
909
 
        self.pie_labels = [urllib.quote(a) for a in labels]
 
909
        self.pie_labels = [urllib.parse.quote(a) for a in labels]
910
910
 
911
911
    def get_url_bits(self, data_class=None):
912
912
        url_bits = Chart.get_url_bits(self, data_class=data_class)
1077
1077
    def data_to_url(self, data_class=None):
1078
1078
        if not self.data:
1079
1079
            raise NoDataGivenException()
1080
 
        return 'chl=%s' % urllib.quote(self.data[0])
 
1080
        return 'chl=%s' % urllib.parse.quote(self.data[0])
1081
1081
 
1082
1082
    def get_url_bits(self, data_class=None):
1083
1083
        url_bits = Chart.get_url_bits(self, data_class=data_class)