[libsoup] tld-parser: Rewrite in Python
- From: Colin Walters <walters src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup] tld-parser: Rewrite in Python
- Date: Tue, 26 Jun 2012 20:49:18 +0000 (UTC)
commit 29345a6d6b181956d3eaffe8d068aca63654e4cb
Author: Colin Walters <walters verbum org>
Date: Tue Jun 26 13:27:17 2012 -0400
tld-parser: Rewrite in Python
This avoids the issues in building native code to build an
intermediate file to build more native code. Automake has
BUILT_SOURCES but it's easier to just have build tools in scripting
languages.
https://bugzilla.gnome.org/show_bug.cgi?id=678909
libsoup/Makefile.am | 14 ++----
libsoup/tld-parser.c | 101 -------------------------------------------------
libsoup/tld-parser.py | 44 +++++++++++++++++++++
3 files changed, 49 insertions(+), 110 deletions(-)
---
diff --git a/libsoup/Makefile.am b/libsoup/Makefile.am
index 6997371..fdba1ef 100644
--- a/libsoup/Makefile.am
+++ b/libsoup/Makefile.am
@@ -1,5 +1,7 @@
## Process this file with automake to produce Makefile.in
+EXTRA_DIST =
+
include $(GLIB_MAKEFILE)
if OS_WIN32
@@ -81,7 +83,6 @@ libsoup_2_4_la_LIBADD = \
$(LIBWS2_32)
libsoup_2_4_la_SOURCES = \
- tld_data.inc \
soup-address.c \
soup-auth.c \
soup-auth-basic.h \
@@ -171,17 +172,12 @@ libsoup_2_4_la_SOURCES = \
soup-xmlrpc.c
# TLD rules
-noinst_PROGRAMS = \
- tld-parser
-
-tld_parser_SOURCES = tld-parser.c
-tld_parser_CFLAGS = $(GLIB_CFLAGS)
-tld_parser_LDADD = $(GLIB_LIBS)
+EXTRA_DIST += tld-parser.py
TLD_DATA_FILE=$(top_srcdir)/data/effective_tld_names.dat
-tld_data.inc: tld-parser $(TLD_DATA_FILE)
- $(builddir)/tld-parser $(TLD_DATA_FILE) tld_data.inc
+tld_data.inc: tld-parser.py $(TLD_DATA_FILE)
+ $(srcdir)/tld-parser.py $(TLD_DATA_FILE) tld_data.inc
if BUILD_LIBSOUP_GNOME
diff --git a/libsoup/tld-parser.py b/libsoup/tld-parser.py
new file mode 100755
index 0000000..469f721
--- /dev/null
+++ b/libsoup/tld-parser.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+# Generate tld rules
+# Copyright (C) 2012 Red Hat, Inc.
+# Based on tld-parser.c Copyright (C) 2012 Igalia S.L.
+
+import os,sys
+
+SOUP_TLD_RULE_NORMAL = 0
+SOUP_TLD_RULE_MATCH_ALL = 1 << 0
+SOUP_TLD_RULE_EXCEPTION = 1 << 1
+
+tlds_file = open(sys.argv[1])
+inc_file = open(sys.argv[2], 'w')
+
+first = True
+for rule in tlds_file:
+ rule = rule.strip()
+ if rule == '' or rule.startswith('//'):
+ continue
+ domain = rule
+ flags = 0
+ if rule[0] == '!':
+ domain = domain[1:]
+ flags |= SOUP_TLD_RULE_EXCEPTION
+
+ if domain.startswith('*.'):
+ domain = domain[2:]
+ flags |= SOUP_TLD_RULE_MATCH_ALL
+
+ if domain.startswith('.'):
+ domain = domain[1:]
+
+ if not first:
+ inc_file.write(',\n')
+ else:
+ first = False
+ inc_file.write('{ "%s", %d }' % (domain.strip(), flags))
+
+inc_file.write('\n')
+
+tlds_file.close()
+inc_file.close()
+
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]