5 # This software may be used and distributed according to the terms of the |
5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. |
6 # GNU General Public License version 2 or any later version. |
7 |
7 |
8 from i18n import _ |
8 from i18n import _ |
9 import error, util |
9 import error, util |
10 import re, os, errno |
10 import os, errno |
11 |
11 |
12 class sortdict(dict): |
12 class sortdict(dict): |
13 'a simple sorted dictionary' |
13 'a simple sorted dictionary' |
14 def __init__(self, data=None): |
14 def __init__(self, data=None): |
15 self._list = [] |
15 self._list = [] |
103 if section in self._data: |
103 if section in self._data: |
104 del self._data[section][item] |
104 del self._data[section][item] |
105 self._source.pop((section, item), None) |
105 self._source.pop((section, item), None) |
106 |
106 |
107 def parse(self, src, data, sections=None, remap=None, include=None): |
107 def parse(self, src, data, sections=None, remap=None, include=None): |
108 sectionre = re.compile(r'\[([^\[]+)\]') |
108 sectionre = util.compilere(r'\[([^\[]+)\]') |
109 itemre = re.compile(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
109 itemre = util.compilere(r'([^=\s][^=]*?)\s*=\s*(.*\S|)') |
110 contre = re.compile(r'\s+(\S|\S.*\S)\s*$') |
110 contre = util.compilere(r'\s+(\S|\S.*\S)\s*$') |
111 emptyre = re.compile(r'(;|#|\s*$)') |
111 emptyre = util.compilere(r'(;|#|\s*$)') |
112 commentre = re.compile(r'(;|#)') |
112 commentre = util.compilere(r'(;|#)') |
113 unsetre = re.compile(r'%unset\s+(\S+)') |
113 unsetre = util.compilere(r'%unset\s+(\S+)') |
114 includere = re.compile(r'%include\s+(\S|\S.*\S)\s*$') |
114 includere = util.compilere(r'%include\s+(\S|\S.*\S)\s*$') |
115 section = "" |
115 section = "" |
116 item = None |
116 item = None |
117 line = 0 |
117 line = 0 |
118 cont = False |
118 cont = False |
119 |
119 |