summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2015-09-29 19:07:24 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2015-09-29 19:07:24 (GMT)
commitb071adbbfbfbd3b63e75818c0850d0fa1f8c8faa (patch) (side-by-side diff)
treedbef1e8bbe658c0d7005e8133f3388a95c95adf5
parent8388e2dced146e17e63b0166f2df684b4a2c70a3 (diff)
parent3fcf9ee5980319e25fa8d225ea3d46f67f503d5f (diff)
downloaddico-b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa.tar.gz
dico-b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa.tar.bz2
Merge branch 'master' into modinc
Diffstat (more/less context) (ignore whitespace changes)
-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,4 +1,4 @@
-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
See the end of file for copying conditions.
@@ -13,6 +13,8 @@ Version 2.2.90 (Git)
* Implement info and description for gcide dictionary.
+* Added manpages
+
Version 2.2, 2012-03-04
diff --git a/dico/connect.c b/dico/connect.c
index 6362dd8..b77cdc6 100644
--- a/dico/connect.c
+++ b/dico/connect.c
@@ -276,9 +276,9 @@ dict_connect(struct dict_connection **pconn, dico_url_t url)
struct addrinfo hints, *res, *rp;
dico_stream_t str;
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);
if (source_addr) {
memset(&hints, 0, sizeof(hints));
@@ -310,7 +310,7 @@ dict_connect(struct dict_connection **pconn, dico_url_t url)
memset(&hints, 0, sizeof(hints));
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) {
if (fd != -1 && family != rp->ai_family) {
close(fd);
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,5 +1,5 @@
# This file is part of GNU Dico.
-# Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+# Copyright (C) 2008-2010, 2012, 2013, 2015 Wojciech Polak
#
# GNU Dico is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -19,10 +19,16 @@ import socket
import base64
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'
class DicoClient:
+
"""GNU Dico client module written in Python
(a part of GNU Dico software)"""
@@ -77,8 +83,8 @@ class DicoClient:
"""Send the OPTION command."""
if self.__connected:
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()
code, msg = res[0].split(' ', 1)
if int(code) == 250:
@@ -113,7 +119,10 @@ class DicoClient:
del mimeinfo['content-transfer-encoding']
elif mimeinfo['content-transfer-encoding'].lower() == 'quoted-printable':
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] == '':
del lines[-1]
del mimeinfo['content-transfer-encoding']
@@ -166,7 +175,11 @@ class DicoClient:
def __send(self, command):
if not self.__connected:
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:
self.__debug('C:%s' % command)
@@ -191,7 +204,7 @@ class DicoClient:
def __send_define(self, database, word):
if self.verbose:
self.__debug('Sending query for word "%s" in database "%s"' %
- (word, database))
+ (word, database))
self.__send('DEFINE "%s" "%s"' % (database, word))
return self.__read()
@@ -273,8 +286,8 @@ class DicoClient:
lang_dst[dst.strip()] = True
return {
'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()),
}
else:
return {'error': code, 'msg': msg}
@@ -387,13 +400,14 @@ class DicoClient:
def __decode(self, encoded):
for octc in (c for c in re.findall(r'\\(\d{3})', encoded)):
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)
class DicoNotConnectedError (Exception):
+
def __init__(self, value):
self.parameter = 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,5 +1,5 @@
# This file is part of GNU Dico.
-# Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+# Copyright (C) 2008-2010, 2012, 2013, 2015 Wojciech Polak
#
# GNU Dico is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -24,6 +24,11 @@ import curses.ascii
import socket
import dicoclient
+try:
+ from django.utils.six.moves import range, input
+except ImportError:
+ from six.moves import range, input
+
class Shell:
"""Simple GNU Dico-Python Shell."""
@@ -54,17 +59,16 @@ class Shell:
pass
atexit.register(readline.write_history_file, histfile)
- 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()
try:
- self.parse(input)
+ self.parse(inputcmd)
except socket.timeout:
self.__error('socket timed out')
except dicoclient.DicoNotConnectedError:
@@ -74,45 +78,48 @@ class Shell:
self.last_databases = dict['databases']
dict = self.dc.show_strategies()
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])
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'])
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:
self.last_matches = []
lmi = 0
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])
lmi = lmi + 1
elif 'error' in dict:
- print dict['msg']
+ print(dict['msg'])
else:
if len(self.last_matches) > 0:
m = {}
@@ -122,33 +129,34 @@ class Shell:
m[db[0]] = []
m[db[0]].append(self.last_matches[i][1])
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
else:
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]
if cmd == 'open':
try:
@@ -164,7 +172,8 @@ class Shell:
self.last_databases = dict['databases']
dict = self.dc.show_strategies()
self.last_strategies = dict['strategies']
- except socket.error, (errno, strerror):
+ except socket.error as serror:
+ (errno, strerror) = serror.args
self.__error(strerror)
elif cmd == 'close':
self.dc.close()
@@ -172,52 +181,52 @@ class Shell:
if args != None:
self.database = args
else:
- print self.database
+ print(self.database)
elif cmd == 'strategy':
if args != None:
self.strategy = args
else:
- print self.strategy
+ print(self.strategy)
elif cmd == 'distance':
if args != None:
self.dc.levenshtein_distance = int(args)
else:
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':
dict = self.dc.show_strategies()
self.last_strategies = dict['strategies']
if len(self.last_strategies):
for i in self.last_strategies:
- print '%s "%s"' % (i[0], i[1])
+ print('%s "%s"' % (i[0], i[1]))
elif cmd == 'ld':
dict = self.dc.show_databases()
self.last_databases = dict['databases']
if len(self.last_databases):
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':
dict = self.dc.show_server()
if 'desc' in dict:
- print dict['desc']
+ print(dict['desc'])
elif 'error' in dict:
self.__error(dict['error'] + ' ' + dict['msg'])
elif cmd == 'info':
if args != None:
dict = self.dc.show_info(args)
if 'desc' in dict:
- print dict['desc']
+ print(dict['desc'])
elif 'error' in dict:
self.__error(dict['error'] + ' ' + dict['msg'])
elif cmd == 'history':
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':
self.print_help()
elif cmd == 'transcript':
@@ -230,14 +239,14 @@ class Shell:
self.__error('Expected boolean value')
else:
if self.dc.transcript:
- print 'transcript is on'
+ print('transcript is on')
else:
- print 'transcript is off'
+ print('transcript is off')
elif cmd == 'verbose':
if args != None:
self.dc.verbose = args
else:
- print self.dc.verbose
+ print(self.dc.verbose)
elif cmd == 'prompt':
if args != None:
self.prompt = args
@@ -264,14 +273,14 @@ class Shell:
return ''
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__)
def print_warranty(self):
self.print_version()
- print """Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+ print("""Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
GNU Dico is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -284,38 +293,38 @@ class Shell:
GNU General Public License for more details.
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.')
if __name__ == '__main__':
try:
opts, args = getopt.getopt(sys.argv[1:], 'h:', ['host='])
except getopt.GetoptError:
- print '\nusage: %s [-h, --host=hostname]' % (sys.argv[0])
+ print('\nusage: %s [-h, --host=hostname]' % (sys.argv[0]))
sys.exit(0)
shell = Shell(opts, args)
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
@@ -1,6 +1,7 @@
{% extends 'base.html' %}
{% load i18n %}
{% load dictlookup %}
+{% load firstof from future %}
{% block search %}
diff --git a/dicoweb/views.py b/dicoweb/views.py
index 6cf5349..14cf124 100644
--- a/dicoweb/views.py
+++ b/dicoweb/views.py
@@ -1,5 +1,5 @@
# This file is part of GNU Dico.
-# Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak
+# Copyright (C) 2008-2010, 2012-2015 Wojciech Polak
#
# GNU Dico is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -21,10 +21,15 @@ from django.conf import settings
from django.core import urlresolvers
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.')
def index(request):
@@ -56,8 +61,8 @@ def index(request):
if len(settings.DICT_SERVERS) > 1:
selects['sv'] = HtmlOptions(settings.DICT_SERVERS, server)
- 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()
type = 'search'
@@ -110,9 +115,10 @@ def index(request):
if database == '*':
langkey = ','.join(accept_lang)
- 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()
result = cache.get('dicoweb/' + key)
@@ -171,7 +177,8 @@ def index(request):
rx1 = re.compile('{+(.*?)}+', re.DOTALL)
for df in result['definitions']:
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'] \
if 'x-wiki-language' in df else 'en'
wikiparser = wiki2html.HtmlWiktionaryMarkup(text=df['desc'],
@@ -196,7 +203,7 @@ def opensearch(request):
url_media = request.build_absolute_uri(settings.MEDIA_URL)
return render_to_response('opensearch.xml', {'url_query': url_query,
'url_media': url_media},
- mimetype='application/xml')
+ content_type='application/xml')
def __subs1(match):
@@ -216,6 +223,10 @@ class HtmlOptions:
if len(opt) == 2:
if not opt[1]:
opt[1] = opt[0]
+ try:
+ opt[1] = opt[1].decode('utf-8')
+ except:
+ pass
if opt[0] == self.value:
buf.append('<option value="%s" selected="selected">%s</option>' % (
opt[0], opt[1]))

Return to:

Send suggestions and report system problems to the System administrator.