/+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: Gerald Kaszuba
  • Date: 2010-12-24 05:18:55 UTC
  • Revision ID: git-v1:1a633e0584a557e812fae20deceaef514a515f62
gitignore compiled py files and setup.py build dir

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
 
24
24
import os
25
25
import urllib
26
 
import urllib.request, urllib.error
 
26
import urllib2
27
27
import math
28
28
import random
29
29
import re
284
284
    of the chart. legend requires a list that corresponds to datasets.
285
285
    """
286
286
 
287
 
    BASE_URL = 'http://chart.apis.google.com/chart'
 
287
    BASE_URL = 'http://chart.apis.google.com/chart?'
288
288
    BACKGROUND = 'bg'
289
289
    CHART = 'c'
290
290
    ALPHA = 'a'
337
337
 
338
338
    # URL generation
339
339
    # -------------------------------------------------------------------------
340
 
        
 
340
 
341
341
    def get_url(self, data_class=None):
342
 
        return self.BASE_URL + '?' + self.get_url_extension(data_class)
343
 
    
344
 
    def get_url_extension(self, data_class=None):
345
342
        url_bits = self.get_url_bits(data_class=data_class)
346
 
        return '&'.join(url_bits)
 
343
        return self.BASE_URL + '&'.join(url_bits)
347
344
 
348
345
    def get_url_bits(self, data_class=None):
349
346
        url_bits = []
375
372
            url_bits.append(self.markers_to_url())        
376
373
        if self.line_styles:
377
374
            style = []
378
 
            for index in range(max(self.line_styles) + 1):
 
375
            for index in xrange(max(self.line_styles) + 1):
379
376
                if index in self.line_styles:
380
377
                    values = self.line_styles[index]
381
378
                else:
389
386
    # Downloading
390
387
    # -------------------------------------------------------------------------
391
388
 
392
 
    def download(self, file_name, use_post=True):
393
 
        if use_post:
394
 
            opener = urllib.request.urlopen(self.BASE_URL, self.get_url_extension())
395
 
        else:
396
 
            opener = urllib.request.urlopen(self.get_url())
 
389
    def download(self, file_name):
 
390
        opener = urllib2.urlopen(self.get_url())
397
391
 
398
392
        if opener.headers['content-type'] != 'image/png':
399
393
            raise BadContentTypeException('Server responded with a ' \
406
400
 
407
401
    def set_title(self, title):
408
402
        if title:
409
 
            self.title = urllib.parse.quote(title)
 
403
            self.title = urllib.quote(title)
410
404
        else:
411
405
            self.title = None
412
406
 
423
417
        assert(isinstance(legend, list) or isinstance(legend, tuple) or
424
418
            legend is None)
425
419
        if legend:
426
 
            self.legend = [urllib.parse.quote(a) for a in legend]
 
420
            self.legend = [urllib.quote(a) for a in legend]
427
421
        else:
428
422
            self.legend = None
429
423
 
430
424
    def set_legend_position(self, legend_position):
431
425
        if legend_position:
432
 
            self.legend_position = urllib.parse.quote(legend_position)
 
426
            self.legend_position = urllib.quote(legend_position)
433
427
        else:    
434
428
            self.legend_position = None
435
429
 
470
464
        assert(angle >= 0 and angle <= 90)
471
465
        assert(len(args) % 2 == 0)
472
466
        args = list(args)  # args is probably a tuple and we need to mutate
473
 
        for a in range(int(len(args) / 2)):
 
467
        for a in xrange(int(len(args) / 2)):
474
468
            col = args[a * 2]
475
469
            offset = args[a * 2 + 1]
476
470
            _check_colour(col)
626
620
 
627
621
    def set_axis_labels(self, axis_type, values):
628
622
        assert(axis_type in Axis.TYPES)
629
 
        values = [urllib.parse.quote(str(a)) for a in values]
 
623
        values = [urllib.quote(str(a)) for a in values]
630
624
        axis_index = len(self.axis)
631
625
        axis = LabelAxis(axis_index, axis_type, values)
632
626
        self.axis.append(axis)
812
806
            url_bits.append('chbh=%i' % self.bar_width)
813
807
        zero_line = []
814
808
        if self.zero_lines:
815
 
            for index in range(max(self.zero_lines) + 1):
 
809
            for index in xrange(max(self.zero_lines) + 1):
816
810
                if index in self.zero_lines:
817
811
                    zero_line.append(str(self.zero_lines[index]))
818
812
                else:
906
900
                (self.__class__.__name__))
907
901
 
908
902
    def set_pie_labels(self, labels):
909
 
        self.pie_labels = [urllib.parse.quote(a) for a in labels]
 
903
        self.pie_labels = [urllib.quote(a) for a in labels]
910
904
 
911
905
    def get_url_bits(self, data_class=None):
912
906
        url_bits = Chart.get_url_bits(self, data_class=data_class)
1077
1071
    def data_to_url(self, data_class=None):
1078
1072
        if not self.data:
1079
1073
            raise NoDataGivenException()
1080
 
        return 'chl=%s' % urllib.parse.quote(self.data[0])
 
1074
        return 'chl=%s' % urllib.quote(self.data[0])
1081
1075
 
1082
1076
    def get_url_bits(self, data_class=None):
1083
1077
        url_bits = Chart.get_url_bits(self, data_class=data_class)