Internet radio browser GUI for music/video streams from various directory services.

⌈⌋ ⎇ branch:  streamtuner2


Check-in [eabee8e3c9]

Overview
Comment:remove pson fallback
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | py3
Files: files | file ages | folders
SHA1: eabee8e3c9e9c7fef4d11645b94be3aff5c4c826
User & Date: mario on 2014-04-11 01:24:35
Other Links: branch diff | manifest | tags
Context
2014-04-11
02:27
no more TV listings on Shoutcast check-in: c8dcfb540d user: mario tags: py3
01:24
remove pson fallback check-in: eabee8e3c9 user: mario tags: py3
2014-04-10
04:31
* Fixed gtk_list_store_get_value: assertion `column < list_store->n_columns' by removing {width:20} reference from treeview datamap. * row.setdefault() for absent search_col/set and deleted state * More __print__/dbg colorization * Disabled pson.filter_data in favour of str casting in mygtk.columns() * Removed streamactions.popup PY2/PY3 workaround with named args * More .iteritems() removal check-in: 1beab0563e user: mario tags: py3
Changes

Modified _package.epm from [789f724b9f] to [118b640e5b].

29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
f 755 root root /usr/bin/streamtuner2				./st2.py
f 644 root root /usr/share/applications/streamtuner2.desktop	./streamtuner2.desktop
d 755 root root /usr/share/streamtuner2				-
f 644 root root /usr/share/streamtuner2/streamtuner2.png	./streamtuner2.png
f 644 root root /usr/share/pixmaps/streamtuner2.png		./logo.png
f 644 root root /usr/share/streamtuner2/gtk2.xml		./gtk2.xml
f 644 root root /usr/share/streamtuner2/gtk3.xml		./gtk3.xml
f 644 root root /usr/share/streamtuner2/pson.py			./pson.py
#f 644 root root /usr/share/streamtuner2/processing.py		./processing.py
f 644 root root /usr/share/streamtuner2/action.py		./action.py
f 644 root root /usr/share/streamtuner2/config.py		./config.py
f 644 root root /usr/share/streamtuner2/ahttp.py		./ahttp.py
f 644 root root /usr/share/streamtuner2/cli.py			./cli.py
f 644 root root /usr/share/streamtuner2/mygtk.py		./mygtk.py
f 644 root root /usr/share/streamtuner2/favicon.py		./favicon.py







|







29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
f 755 root root /usr/bin/streamtuner2				./st2.py
f 644 root root /usr/share/applications/streamtuner2.desktop	./streamtuner2.desktop
d 755 root root /usr/share/streamtuner2				-
f 644 root root /usr/share/streamtuner2/streamtuner2.png	./streamtuner2.png
f 644 root root /usr/share/pixmaps/streamtuner2.png		./logo.png
f 644 root root /usr/share/streamtuner2/gtk2.xml		./gtk2.xml
f 644 root root /usr/share/streamtuner2/gtk3.xml		./gtk3.xml
#f 644 root root /usr/share/streamtuner2/pson.py			./pson.py
#f 644 root root /usr/share/streamtuner2/processing.py		./processing.py
f 644 root root /usr/share/streamtuner2/action.py		./action.py
f 644 root root /usr/share/streamtuner2/config.py		./config.py
f 644 root root /usr/share/streamtuner2/ahttp.py		./ahttp.py
f 644 root root /usr/share/streamtuner2/cli.py			./cli.py
f 644 root root /usr/share/streamtuner2/mygtk.py		./mygtk.py
f 644 root root /usr/share/streamtuner2/favicon.py		./favicon.py

Modified config.py from [8361dea5ee] to [4880b97351].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Here conf is already an instantiation of the underlying
# Config class.
#


import os
import sys
import pson
import gzip
import platform




#-- create a single instance of config object







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Here conf is already an instantiation of the underlying
# Config class.
#


import os
import sys
import json
import gzip
import platform




#-- create a single instance of config object
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
            if gz:
                f = gzip.open(file+".gz", "w")
                if os.path.exists(file):
                    os.unlink(file)
            else:
                f = open(file, "w")
            # encode
            pson.dump(data, f, indent=(4 if nice else None))
            f.close()


        # retrieve data from config file            
        def load(self, name):
            name = name + ".json"
            file = self.dir + "/" + name
            try:
                # .gz or normal file
                if os.path.exists(file + ".gz"):
                    f = gzip.open(file + ".gz", "r")
                elif os.path.exists(file):
                    f = open(file, "r")
                else:
                    return # file not found
                # decode
                r = pson.load(f)
                f.close()
                return r
            except Exception as e:
                print("PSON parsing error (in "+name+")", e)
            

        # recursive dict update







|
















|







141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
            if gz:
                f = gzip.open(file+".gz", "w")
                if os.path.exists(file):
                    os.unlink(file)
            else:
                f = open(file, "w")
            # encode
            json.dump(data, f, indent=(4 if nice else None))
            f.close()


        # retrieve data from config file            
        def load(self, name):
            name = name + ".json"
            file = self.dir + "/" + name
            try:
                # .gz or normal file
                if os.path.exists(file + ".gz"):
                    f = gzip.open(file + ".gz", "r")
                elif os.path.exists(file):
                    f = open(file, "r")
                else:
                    return # file not found
                # decode
                r = json.load(f)
                f.close()
                return r
            except Exception as e:
                print("PSON parsing error (in "+name+")", e)
            

        # recursive dict update

Deleted pson.py version [6186b9e864].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#
# encoding: UTF-8
# api: python
# type: functions
# title: json emulation
# description: simplify usage of some gtk widgets
# version: 1.7
# author: mario
# license: public domain
#
#
#  This module provides the JSON api. If the python 2.6 module
#  isn't available, it provides an emulation using str() and
#  eval() and Python notation. (The representations are close.)
#
#  Additionally it filters out any left-over objects. Sometimes
#  pygtk-objects crawled into the streams[] lists, because rows
#  might have been queried from the widgets.
#       (Need to find out if that still happens..)
#
#  filter_data should become redundant, as mygtk.columns now
#  converts unicode to str in Py2. And since we depend on Py2.7
#  anway the JSON-like Python serialization should be dropped.
#


#-- reading and writing json (for the config module)  ----------------------------------

import sys
from compat2and3 import unicode

# try to load the system module first
try:
        from json import dump as json_dump, load as json_load
except:
        print("no native Python JSON module")


#except:
    # pseudo-JSON implementation
    # - the basic python data types dict,list,str,int are mostly identical to json
    # - therefore a basic str() conversion is enough for writing
    # - for reading the more bothersome eval() is used
    # - it's however no severe security problem here, because we're just reading
    #   local config files (written by us) and accept no data from outside / web
    # NOTE: This code is only used, if the Python json module (since 2.6) isn't there.


# store object in string representation into filepointer
def dump(obj, fp, indent=0):

        obj = filter_data(obj)
        
        try:
                return json_dump(obj, fp, indent=indent, sort_keys=(indent and indent>0))
        except:
                return fp.write(str(obj))
                # .replace("'}, ", "'},\n ")    # add whitespace
              	# .replace("', ", "',\n "))
              	# .replace("': [{'", "':\n[\n{'")
        pass


# load from filepointer, decode string into dicts/list
def load(fp):
        try:
                #print("try json")
                r = json_load(fp)
#                r = filter_data(r)   # turn unicode() strings back into str() - pygtk does not accept u"strings"
        except:
                #print("fall back on pson")
                fp.seek(0)
                r = eval(fp.read(1<<27))   # max 128 MB
                # print("fake json module: in python variable dump notation")

        if r == None:
                r = {}
        return r


# removes any objects, turns unicode back into str
def filter_data(obj):
        if type(obj) in (int, float, bool, str):
                return obj
#        elif type(obj) == str:   #->str->utf8->str
#                return str(unicode(obj))
        elif type(obj) == unicode:
                return str(obj)
        elif type(obj) in (list, tuple, set):
                obj = list(obj)
                for i,v in enumerate(obj):
                        obj[i] = filter_data(v)
        elif type(obj) == dict:
                for i,v in list(obj.items()):
                        i = filter_data(i)
                        obj[i] = filter_data(v)
        else:
                print("invalid object in data, converting to string: ", type(obj), obj)
                obj = str(obj)
        return obj



<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<