aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2015-09-29 22:07:24 +0300
committerSergey Poznyakoff <gray@gnu.org>2015-09-29 22:07:24 +0300
commitb071adbbfbfbd3b63e75818c0850d0fa1f8c8faa (patch)
treedbef1e8bbe658c0d7005e8133f3388a95c95adf5
parent8388e2dced146e17e63b0166f2df684b4a2c70a3 (diff)
parent3fcf9ee5980319e25fa8d225ea3d46f67f503d5f (diff)
downloaddico-b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa.tar.gz
dico-b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa.tar.bz2
Merge branch 'master' into modinc
-rw-r--r--NEWS4
-rw-r--r--dico/connect.c6
-rw-r--r--dicoweb/dicoclient/dicoclient.py36
-rw-r--r--dicoweb/dicoclient/dicoshell.py179
-rw-r--r--dicoweb/requirements.txt2
-rw-r--r--dicoweb/templates/index.html1
-rw-r--r--dicoweb/views.py31
7 files changed, 148 insertions, 111 deletions
diff --git a/NEWS b/NEWS
index 1f7636d..8a8c486 100644
--- a/NEWS
+++ b/NEWS
@@ -1,2 +1,2 @@
-GNU Dico NEWS -- history of user-visible changes. 2014-09-26
+GNU Dico NEWS -- history of user-visible changes. 2014-09-28
Copyright (C) 2008-2010, 2012-2014 Sergey Poznyakoff
@@ -15,2 +15,4 @@ Version 2.2.90 (Git)
+* Added manpages
+
diff --git a/dico/connect.c b/dico/connect.c
index 6362dd8..b77cdc6 100644
--- a/dico/connect.c
+++ b/dico/connect.c
@@ -278,5 +278,5 @@ dict_connect(struct dict_connection **pconn, dico_url_t url)
struct dict_connection *conn;
+ char const *port = url->port ? url->port : DICO_DICT_PORT_STR;
- XDICO_DEBUG_F2(1, _("Connecting to %s:%s\n"), url->host,
- url->port ? url->port : DICO_DICT_PORT_STR);
+ XDICO_DEBUG_F2(1, _("Connecting to %s:%s\n"), url->host, port);
@@ -312,3 +312,3 @@ dict_connect(struct dict_connection **pconn, dico_url_t url)
hints.ai_socktype = SOCK_STREAM;
- rc = getaddrinfo(url->host, url->port, &hints, &res);
+ rc = getaddrinfo(url->host, port, &hints, &res);
for (rp = res; rp; rp = rp->ai_next) {
diff --git a/dicoweb/dicoclient/dicoclient.py b/dicoweb/dicoclient/dicoclient.py
index 2c93706..a929c30 100644
--- a/dicoweb/dicoclient/dicoclient.py
+++ b/dicoweb/dicoclient/dicoclient.py
@@ -1,3 +1,3 @@
# This file is part of GNU Dico.
-# Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+# Copyright (C) 2008-2010, 2012, 2013, 2015 Wojciech Polak
#
@@ -21,3 +21,8 @@ import quopri
-__version__ = '1.0'
+try:
+ from django.utils.six.moves import range, reduce
+except ImportError:
+ from six.moves import range, reduce
+
+__version__ = '1.1'
@@ -25,2 +30,3 @@ __version__ = '1.0'
class DicoClient:
+
"""GNU Dico client module written in Python
@@ -79,4 +85,4 @@ class DicoClient:
self.__send('OPTION %s%s' %
- (name, reduce(lambda x, y: str(x) + ' ' + str(y),
- args, '')))
+ (name, reduce(lambda x, y: str(x) + ' ' + str(y),
+ args, '')))
res = self.__read()
@@ -115,3 +121,6 @@ class DicoClient:
buf = quopri.decodestring('\n'.join(lines))
- lines[:] = buf.split('\r\n')
+ try:
+ lines[:] = buf.split('\r\n')
+ except TypeError:
+ lines[:] = buf.decode('utf-8').split('\r\n')
if lines[-1] == '':
@@ -168,3 +177,7 @@ class DicoClient:
raise DicoNotConnectedError('Not connected')
- self.socket.send(command.encode('utf_8') + "\r\n")
+ cmd = command + "\r\n"
+ try:
+ self.socket.send(cmd)
+ except (UnicodeEncodeError, TypeError):
+ self.socket.send(cmd.encode('utf-8'))
if self.transcript:
@@ -193,3 +206,3 @@ class DicoClient:
self.__debug('Sending query for word "%s" in database "%s"' %
- (word, database))
+ (word, database))
self.__send('DEFINE "%s" "%s"' % (database, word))
@@ -275,4 +288,4 @@ class DicoClient:
'desc': '\n'.join(dsc),
- 'lang_src': lang_src.keys(),
- 'lang_dst': lang_dst.keys(),
+ 'lang_src': list(lang_src.keys()),
+ 'lang_dst': list(lang_dst.keys()),
}
@@ -389,6 +402,6 @@ class DicoClient:
encoded = encoded.replace(r'\%s' % octc, chr(int(octc, 8)))
- return unicode(encoded, 'utf_8')
+ return encoded
def __debug(self, msg):
- print 'dico: Debug: %s' % msg
+ print('dico: Debug: %s' % msg)
@@ -396,2 +409,3 @@ class DicoClient:
class DicoNotConnectedError (Exception):
+
def __init__(self, value):
diff --git a/dicoweb/dicoclient/dicoshell.py b/dicoweb/dicoclient/dicoshell.py
index b6493fa..8cbac3d 100644
--- a/dicoweb/dicoclient/dicoshell.py
+++ b/dicoweb/dicoclient/dicoshell.py
@@ -1,3 +1,3 @@
# This file is part of GNU Dico.
-# Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+# Copyright (C) 2008-2010, 2012, 2013, 2015 Wojciech Polak
#
@@ -26,2 +26,7 @@ import dicoclient
+try:
+ from django.utils.six.moves import range, input
+except ImportError:
+ from six.moves import range, input
+
@@ -56,9 +61,8 @@ class Shell:
- print '\nType ? for help summary\n'
+ print('\nType ? for help summary\n')
while True:
try:
- input = raw_input(self.prompt).strip()
- input = unicode(input, 'utf_8')
+ inputcmd = input(self.prompt).strip()
except (EOFError, KeyboardInterrupt):
- print
+ print()
sys.exit()
@@ -66,3 +70,3 @@ class Shell:
try:
- self.parse(input)
+ self.parse(inputcmd)
except socket.timeout:
@@ -76,16 +80,20 @@ class Shell:
self.last_strategies = dict['strategies']
- self.parse(input)
- except socket.error, (errno, strerror):
+ self.parse(inputcmd)
+ except socket.error as serror:
+ (errno, strerror) = serror.args
self.__error(strerror)
- def parse(self, input):
- if len(input) < 1:
+ def parse(self, inputcmd):
+ if len(inputcmd) < 1:
return
- if input[0] == self.prefix:
- self.parse_command(input[1:])
- elif input == '?':
+
+ if inputcmd[0] == self.prefix:
+ self.parse_command(inputcmd[1:])
+
+ elif inputcmd == '?':
self.print_help()
- elif re.match(r'^[0-9]+$', input):
+
+ elif re.match(r'^[0-9]+$', inputcmd):
try:
- match = self.last_matches[int(input)]
+ match = self.last_matches[int(inputcmd)]
dict = self.dc.define(match[0], match[1])
@@ -93,12 +101,12 @@ class Shell:
for d in dict['definitions']:
- print 'From %s, %s:' % (d['db'], d['db_fullname'].
- encode('utf_8'))
- print d['desc']
+ print('From %s, %s:' % (d['db'], d['db_fullname']))
+ print(d['desc'])
elif 'error' in dict:
- print dict['msg']
+ print(dict['msg'])
except IndexError:
self.__error('No previous match')
- elif input[0] == '/':
- if len(input) > 1:
- dict = self.dc.match(self.database, self.strategy, input[1:])
+
+ elif inputcmd[0] == '/':
+ if len(inputcmd) > 1:
+ dict = self.dc.match(self.database, self.strategy, inputcmd[1:])
if 'matches' in dict:
@@ -107,6 +115,5 @@ class Shell:
for db in dict['matches']:
- print 'From %s, %s:' % (db, self.__lookup_db(db).
- encode('utf_8'))
+ print('From %s, %s:' % (db, self.__lookup_db(db)))
for term in dict['matches'][db]:
- print '%4d) "%s"' % (lmi, term.encode('utf_8'))
+ print('%4d) "%s"' % (lmi, term))
self.last_matches.append([db, term])
@@ -114,3 +121,3 @@ class Shell:
elif 'error' in dict:
- print dict['msg']
+ print(dict['msg'])
else:
@@ -124,5 +131,5 @@ class Shell:
for db in m:
- print 'From %s, %s:' % (db, self.__lookup_db(db))
+ print('From %s, %s:' % (db, self.__lookup_db(db)))
for term in m[db]:
- print '%4d) "%s"' % (lmi, term)
+ print('%4d) "%s"' % (lmi, term))
lmi = lmi + 1
@@ -130,23 +137,24 @@ class Shell:
self.__error('No previous match')
- elif input[0] == '!':
- if re.match(r'^![0-9]+$', input):
- number = int(input[1:])
+
+ elif inputcmd[0] == '!':
+ if re.match(r'^![0-9]+$', inputcmd):
+ number = int(inputcmd[1:])
readline.insert_text(readline.get_history_item(number))
readline.redisplay()
+
else:
- dict = self.dc.define(self.database, input)
+ dict = self.dc.define(self.database, inputcmd)
if 'count' in dict:
for d in dict['definitions']:
- print 'From %s, %s:' % (d['db'], d['db_fullname'].
- encode('utf_8'))
- print d['desc']
+ print('From %s, %s:' % (d['db'], d['db_fullname']))
+ print(d['desc'])
elif 'error' in dict:
- print dict['msg']
+ print(dict['msg'])
- def parse_command(self, input):
- input = input.split(' ', 1)
- cmd = input[0]
+ def parse_command(self, inputcmd):
+ inputcmd = inputcmd.split(' ', 1)
+ cmd = inputcmd[0]
args = None
- if len(input) == 2:
- args = input[1]
+ if len(inputcmd) == 2:
+ args = inputcmd[1]
@@ -166,3 +174,4 @@ class Shell:
self.last_strategies = dict['strategies']
- except socket.error, (errno, strerror):
+ except socket.error as serror:
+ (errno, strerror) = serror.args
self.__error(strerror)
@@ -174,3 +183,3 @@ class Shell:
else:
- print self.database
+ print(self.database)
elif cmd == 'strategy':
@@ -179,3 +188,3 @@ class Shell:
else:
- print self.strategy
+ print(self.strategy)
elif cmd == 'distance':
@@ -185,6 +194,6 @@ class Shell:
if self.dc.levenshtein_distance:
- print 'Configured Levenshtein distance: %u' % \
- self.dc.levenshtein_distance
+ print('Configured Levenshtein distance: %u' % \
+ self.dc.levenshtein_distance)
else:
- print 'No distance configured'
+ print('No distance configured')
elif cmd == 'ls':
@@ -194,3 +203,3 @@ class Shell:
for i in self.last_strategies:
- print '%s "%s"' % (i[0], i[1])
+ print('%s "%s"' % (i[0], i[1]))
elif cmd == 'ld':
@@ -200,5 +209,5 @@ class Shell:
for i in self.last_databases:
- print '%s "%s"' % (i[0], i[1])
+ print('%s "%s"' % (i[0], i[1]))
elif cmd == 'mime':
- print self.dc.option('MIME')
+ print(self.dc.option('MIME'))
elif cmd == 'server':
@@ -206,3 +215,3 @@ class Shell:
if 'desc' in dict:
- print dict['desc']
+ print(dict['desc'])
elif 'error' in dict:
@@ -213,3 +222,3 @@ class Shell:
if 'desc' in dict:
- print dict['desc']
+ print(dict['desc'])
elif 'error' in dict:
@@ -218,4 +227,4 @@ class Shell:
hl = int(readline.get_current_history_length())
- for i in xrange(0, hl):
- print '%4d) %s' % (i, readline.get_history_item(i))
+ for i in range(0, hl):
+ print('%4d) %s' % (i, readline.get_history_item(i)))
elif cmd == 'help':
@@ -232,5 +241,5 @@ class Shell:
if self.dc.transcript:
- print 'transcript is on'
+ print('transcript is on')
else:
- print 'transcript is off'
+ print('transcript is off')
elif cmd == 'verbose':
@@ -239,3 +248,3 @@ class Shell:
else:
- print self.dc.verbose
+ print(self.dc.verbose)
elif cmd == 'prompt':
@@ -266,6 +275,6 @@ class Shell:
def __error(self, msg):
- print 'dico: Error: %s' % msg
+ print('dico: Error: %s' % msg)
def print_version(self):
- print 'GNU Dico (Python Edition) ' + dicoclient.__version__
+ print('GNU Dico (Python Edition) ' + dicoclient.__version__)
@@ -273,3 +282,3 @@ class Shell:
self.print_version()
- print """Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+ print("""Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
@@ -286,28 +295,28 @@ class Shell:
You should have received a copy of the GNU General Public License
- along with GNU Dico. If not, see <http://www.gnu.org/licenses/>."""
+ along with GNU Dico. If not, see <http://www.gnu.org/licenses/>.""")
def print_help(self):
- print 'WORD Define WORD.'
- print '/WORD Match WORD.'
- print '/ Redisplay previous matches.'
- print 'NUMBER Define NUMBERth match.'
- print '!NUMBER Edit NUMBERth previous command.'
- print
- print self.prefix + 'open [HOST [PORT]] Connect to a DICT server.'
- print self.prefix + 'close Close the connection.'
- print self.prefix + 'database [NAME] Set or display current database name.'
- print self.prefix + 'strategy [NAME] Set or display current strategy.'
- print self.prefix + 'distance [NUM] Set or query Levenshtein distance (server-dependent).'
- print self.prefix + 'ls List available matching strategies'
- print self.prefix + 'ld List all accessible databases'
- print self.prefix + 'info [DB] Display the information about the database.'
- print self.prefix + 'prefix [CHAR] Set or display command prefix.'
- print self.prefix + 'transcript [BOOL] Set or display session transcript mode.'
- print self.prefix + 'verbose [NUMBER] Set or display verbosity level.'
- print self.prefix + 'prompt STRING Change command line prompt.'
- print self.prefix + 'history Display command history.'
- print self.prefix + 'help Display this help text.'
- print self.prefix + 'version Print program version.'
- print self.prefix + 'warranty Print copyright statement.'
- print self.prefix + 'quit Quit the shell.'
+ print('WORD Define WORD.')
+ print('/WORD Match WORD.')
+ print('/ Redisplay previous matches.')
+ print('NUMBER Define NUMBERth match.')
+ print('!NUMBER Edit NUMBERth previous command.')
+ print()
+ print(self.prefix + 'open [HOST [PORT]] Connect to a DICT server.')
+ print(self.prefix + 'close Close the connection.')
+ print(self.prefix + 'database [NAME] Set or display current database name.')
+ print(self.prefix + 'strategy [NAME] Set or display current strategy.')
+ print(self.prefix + 'distance [NUM] Set or query Levenshtein distance (server-dependent).')
+ print(self.prefix + 'ls List available matching strategies')
+ print(self.prefix + 'ld List all accessible databases')
+ print(self.prefix + 'info [DB] Display the information about the database.')
+ print(self.prefix + 'prefix [CHAR] Set or display command prefix.')
+ print(self.prefix + 'transcript [BOOL] Set or display session transcript mode.')
+ print(self.prefix + 'verbose [NUMBER] Set or display verbosity level.')
+ print(self.prefix + 'prompt STRING Change command line prompt.')
+ print(self.prefix + 'history Display command history.')
+ print(self.prefix + 'help Display this help text.')
+ print(self.prefix + 'version Print program version.')
+ print(self.prefix + 'warranty Print copyright statement.')
+ print(self.prefix + 'quit Quit the shell.')
@@ -317,3 +326,3 @@ if __name__ == '__main__':
except getopt.GetoptError:
- print '\nusage: %s [-h, --host=hostname]' % (sys.argv[0])
+ print('\nusage: %s [-h, --host=hostname]' % (sys.argv[0]))
sys.exit(0)
diff --git a/dicoweb/requirements.txt b/dicoweb/requirements.txt
index 47b7897..022e93f 100644
--- a/dicoweb/requirements.txt
+++ b/dicoweb/requirements.txt
@@ -1,2 +1,2 @@
-Django >=1.4.5
+Django >=1.7
git+git://git.gnu.org.ua/wit.git#egg=wit
diff --git a/dicoweb/templates/index.html b/dicoweb/templates/index.html
index 5ebb46a..7f35e3f 100644
--- a/dicoweb/templates/index.html
+++ b/dicoweb/templates/index.html
@@ -3,2 +3,3 @@
{% load dictlookup %}
+{% load firstof from future %}
diff --git a/dicoweb/views.py b/dicoweb/views.py
index 6cf5349..14cf124 100644
--- a/dicoweb/views.py
+++ b/dicoweb/views.py
@@ -1,3 +1,3 @@
# This file is part of GNU Dico.
-# Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+# Copyright (C) 2008-2010, 2012-2015 Wojciech Polak
#
@@ -23,6 +23,11 @@ from django.core.cache import cache
from django.shortcuts import render_to_response
+from django.utils.encoding import force_bytes
from django.utils.translation import ugettext as _
-import dicoclient
-from wit import wiki2html
+from dicoclient import dicoclient
+try:
+ from wit import wiki2html
+except ImportError:
+ wiki2html = None
+ print('WARNING: The wit module is not installed.')
@@ -58,4 +63,4 @@ def index(request):
- key = hashlib.md5('%s/%s' % (sid, server.encode('ascii',
- 'backslashreplace')))
+ key = hashlib.md5(force_bytes(
+ '%s/%s' % (sid, server.encode('ascii', 'backslashreplace'))))
sid = key.hexdigest()
@@ -112,5 +117,6 @@ def index(request):
- key = hashlib.md5('%s:%d/%s/%s/%s/%s/%s' %
- (server, port, langkey, type, database, strategy,
- q.encode('ascii', 'backslashreplace')))
+ key = hashlib.md5(force_bytes(
+ '%s:%d/%s/%s/%s/%s/%s' % (server, port, langkey, type,
+ database, strategy,
+ q.encode('ascii', 'backslashreplace'))))
key = key.hexdigest()
@@ -173,3 +179,4 @@ def index(request):
if 'content-type' in df \
- and df['content-type'].startswith('text/x-wiki'):
+ and df['content-type'].startswith('text/x-wiki') \
+ and wiki2html:
lang = df['x-wiki-language'] \
@@ -198,3 +205,3 @@ def opensearch(request):
'url_media': url_media},
- mimetype='application/xml')
+ content_type='application/xml')
@@ -218,2 +225,6 @@ class HtmlOptions:
opt[1] = opt[0]
+ try:
+ opt[1] = opt[1].decode('utf-8')
+ except:
+ pass
if opt[0] == self.value:

Return to:

Send suggestions and report system problems to the System administrator.