76 | | line = line.rstrip("\n\r") |
77 | | if line.startswith("#") or not (line.strip()): |
78 | | continue |
79 | | parts = line.rsplit("=", 1) |
80 | | #ie: "title:helloworld=text #some comments here" -> "title:helloworld", "text #some comments here" |
81 | | if len(parts)!=2: |
82 | | log.warn("Warning: invalid content-type definition") |
83 | | log.warn(" found in '%s' at line %i", line, l) |
84 | | log.warn(" '%s' is missing a '='", line) |
85 | | continue |
86 | | match, content_type = parts |
87 | | parts = match.split(":", 1) |
88 | | #ie: "title:helloworld" -> "title", "helloworld" |
89 | | if len(parts)!=2: |
90 | | log.warn("Warning: invalid content-type definition") |
91 | | log.warn(" match string '%s' is missing a ':'", match) |
92 | | continue |
93 | | #ignore comments: |
94 | | #"text #some comments here" > "text" |
95 | | content_type = content_type.split(":")[0].strip() |
96 | | prop_name, regex = parts |
97 | | try: |
98 | | c = re.compile(regex) |
99 | | content_type_defs.setdefault(prop_name, OrderedDict())[c]=(regex, content_type) |
100 | | log("%16s matching '%s' is %s", prop_name, regex, content_type) |
101 | | except Exception as e: |
102 | | log.warn("Warning: invalid regular expression") |
103 | | log.warn(" match string '%s':", regex) |
104 | | log.warn(" %s", e) |
105 | | continue |
| 82 | def process_content_type_entry(entry): |
| 83 | global content_type_defs |
| 84 | entry = entry.rstrip("\n\r") |
| 85 | if entry.startswith("#") or not (entry.strip()): |
| 86 | return True |
| 87 | parts = entry.rsplit("=", 1) |
| 88 | #ie: "title:helloworld=text #some comments here" -> "title:helloworld", "text #some comments here" |
| 89 | if len(parts)!=2: |
| 90 | log.warn("Warning: invalid content-type definition") |
| 91 | log.warn(" found in '%s'", entry) |
| 92 | log.warn(" '%s' is missing a '='", entry) |
| 93 | return False |
| 94 | match, content_type = parts |
| 95 | parts = match.split(":", 1) |
| 96 | #ie: "title:helloworld" -> "title", "helloworld" |
| 97 | if len(parts)!=2: |
| 98 | log.warn("Warning: invalid content-type definition") |
| 99 | log.warn(" match string '%s' is missing a ':'", match) |
| 100 | return False |
| 101 | #ignore comments: |
| 102 | #"text #some comments here" > "text" |
| 103 | content_type = content_type.split(":")[0].strip() |
| 104 | prop_name, regex = parts |
| 105 | try: |
| 106 | c = re.compile(regex) |
| 107 | content_type_defs.setdefault(prop_name, OrderedDict())[c]=(regex, content_type) |
| 108 | log("%16s matching '%s' is %s", prop_name, regex, content_type) |
| 109 | except Exception as e: |
| 110 | log.warn("Warning: invalid regular expression") |
| 111 | log.warn(" match string '%s':", regex) |
| 112 | log.warn(" %s", e) |
| 113 | return False |
| 114 | return True |