diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2015-09-29 22:07:24 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2015-09-29 22:07:24 +0300 |
commit | b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa (patch) | |
tree | dbef1e8bbe658c0d7005e8133f3388a95c95adf5 | |
parent | 8388e2dced146e17e63b0166f2df684b4a2c70a3 (diff) | |
parent | 3fcf9ee5980319e25fa8d225ea3d46f67f503d5f (diff) | |
download | dico-b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa.tar.gz dico-b071adbbfbfbd3b63e75818c0850d0fa1f8c8faa.tar.bz2 |
Merge branch 'master' into modinc
-rw-r--r-- | NEWS | 4 | ||||
-rw-r--r-- | dico/connect.c | 6 | ||||
-rw-r--r-- | dicoweb/dicoclient/dicoclient.py | 36 | ||||
-rw-r--r-- | dicoweb/dicoclient/dicoshell.py | 179 | ||||
-rw-r--r-- | dicoweb/requirements.txt | 2 | ||||
-rw-r--r-- | dicoweb/templates/index.html | 1 | ||||
-rw-r--r-- | dicoweb/views.py | 31 |
7 files changed, 148 insertions, 111 deletions
@@ -1,4 +1,4 @@ | |||
1 | GNU Dico NEWS -- history of user-visible changes. 2014-09-26 | 1 | GNU Dico NEWS -- history of user-visible changes. 2014-09-28 |
2 | Copyright (C) 2008-2010, 2012-2014 Sergey Poznyakoff | 2 | Copyright (C) 2008-2010, 2012-2014 Sergey Poznyakoff |
3 | See the end of file for copying conditions. | 3 | See the end of file for copying conditions. |
4 | 4 | ||
@@ -13,6 +13,8 @@ Version 2.2.90 (Git) | |||
13 | 13 | ||
14 | * Implement info and description for gcide dictionary. | 14 | * Implement info and description for gcide dictionary. |
15 | 15 | ||
16 | * Added manpages | ||
17 | |||
16 | 18 | ||
17 | Version 2.2, 2012-03-04 | 19 | Version 2.2, 2012-03-04 |
18 | 20 | ||
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) | |||
276 | struct addrinfo hints, *res, *rp; | 276 | struct addrinfo hints, *res, *rp; |
277 | dico_stream_t str; | 277 | dico_stream_t str; |
278 | struct dict_connection *conn; | 278 | struct dict_connection *conn; |
279 | char const *port = url->port ? url->port : DICO_DICT_PORT_STR; | ||
279 | 280 | ||
280 | XDICO_DEBUG_F2(1, _("Connecting to %s:%s\n"), url->host, | 281 | XDICO_DEBUG_F2(1, _("Connecting to %s:%s\n"), url->host, port); |
281 | url->port ? url->port : DICO_DICT_PORT_STR); | ||
282 | 282 | ||
283 | if (source_addr) { | 283 | if (source_addr) { |
284 | memset(&hints, 0, sizeof(hints)); | 284 | memset(&hints, 0, sizeof(hints)); |
@@ -310,7 +310,7 @@ dict_connect(struct dict_connection **pconn, dico_url_t url) | |||
310 | 310 | ||
311 | memset(&hints, 0, sizeof(hints)); | 311 | memset(&hints, 0, sizeof(hints)); |
312 | hints.ai_socktype = SOCK_STREAM; | 312 | hints.ai_socktype = SOCK_STREAM; |
313 | rc = getaddrinfo(url->host, url->port, &hints, &res); | 313 | rc = getaddrinfo(url->host, port, &hints, &res); |
314 | for (rp = res; rp; rp = rp->ai_next) { | 314 | for (rp = res; rp; rp = rp->ai_next) { |
315 | if (fd != -1 && family != rp->ai_family) { | 315 | if (fd != -1 && family != rp->ai_family) { |
316 | close(fd); | 316 | 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 @@ | |||
1 | # This file is part of GNU Dico. | 1 | # This file is part of GNU Dico. |
2 | # Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak | 2 | # Copyright (C) 2008-2010, 2012, 2013, 2015 Wojciech Polak |
3 | # | 3 | # |
4 | # GNU Dico is free software; you can redistribute it and/or modify | 4 | # GNU Dico is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by | 5 | # it under the terms of the GNU General Public License as published by |
@@ -19,10 +19,16 @@ import socket | |||
19 | import base64 | 19 | import base64 |
20 | import quopri | 20 | import quopri |
21 | 21 | ||
22 | __version__ = '1.0' | 22 | try: |
23 | from django.utils.six.moves import range, reduce | ||
24 | except ImportError: | ||
25 | from six.moves import range, reduce | ||
26 | |||
27 | __version__ = '1.1' | ||
23 | 28 | ||
24 | 29 | ||
25 | class DicoClient: | 30 | class DicoClient: |
31 | |||
26 | """GNU Dico client module written in Python | 32 | """GNU Dico client module written in Python |
27 | (a part of GNU Dico software)""" | 33 | (a part of GNU Dico software)""" |
28 | 34 | ||
@@ -77,8 +83,8 @@ class DicoClient: | |||
77 | """Send the OPTION command.""" | 83 | """Send the OPTION command.""" |
78 | if self.__connected: | 84 | if self.__connected: |
79 | self.__send('OPTION %s%s' % | 85 | self.__send('OPTION %s%s' % |
80 | (name, reduce(lambda x, y: str(x) + ' ' + str(y), | 86 | (name, reduce(lambda x, y: str(x) + ' ' + str(y), |
81 | args, ''))) | 87 | args, ''))) |
82 | res = self.__read() | 88 | res = self.__read() |
83 | code, msg = res[0].split(' ', 1) | 89 | code, msg = res[0].split(' ', 1) |
84 | if int(code) == 250: | 90 | if int(code) == 250: |
@@ -113,7 +119,10 @@ class DicoClient: | |||
113 | del mimeinfo['content-transfer-encoding'] | 119 | del mimeinfo['content-transfer-encoding'] |
114 | elif mimeinfo['content-transfer-encoding'].lower() == 'quoted-printable': | 120 | elif mimeinfo['content-transfer-encoding'].lower() == 'quoted-printable': |
115 | buf = quopri.decodestring('\n'.join(lines)) | 121 | buf = quopri.decodestring('\n'.join(lines)) |
116 | lines[:] = buf.split('\r\n') | 122 | try: |
123 | lines[:] = buf.split('\r\n') | ||
124 | except TypeError: | ||
125 | lines[:] = buf.decode('utf-8').split('\r\n') | ||
117 | if lines[-1] == '': | 126 | if lines[-1] == '': |
118 | del lines[-1] | 127 | del lines[-1] |
119 | del mimeinfo['content-transfer-encoding'] | 128 | del mimeinfo['content-transfer-encoding'] |
@@ -166,7 +175,11 @@ class DicoClient: | |||
166 | def __send(self, command): | 175 | def __send(self, command): |
167 | if not self.__connected: | 176 | if not self.__connected: |
168 | raise DicoNotConnectedError('Not connected') | 177 | raise DicoNotConnectedError('Not connected') |
169 | self.socket.send(command.encode('utf_8') + "\r\n") | 178 | cmd = command + "\r\n" |
179 | try: | ||
180 | self.socket.send(cmd) | ||
181 | except (UnicodeEncodeError, TypeError): | ||
182 | self.socket.send(cmd.encode('utf-8')) | ||
170 | if self.transcript: | 183 | if self.transcript: |
171 | self.__debug('C:%s' % command) | 184 | self.__debug('C:%s' % command) |
172 | 185 | ||
@@ -191,7 +204,7 @@ class DicoClient: | |||
191 | def __send_define(self, database, word): | 204 | def __send_define(self, database, word): |
192 | if self.verbose: | 205 | if self.verbose: |
193 | self.__debug('Sending query for word "%s" in database "%s"' % | 206 | self.__debug('Sending query for word "%s" in database "%s"' % |
194 | (word, database)) | 207 | (word, database)) |
195 | self.__send('DEFINE "%s" "%s"' % (database, word)) | 208 | self.__send('DEFINE "%s" "%s"' % (database, word)) |
196 | return self.__read() | 209 | return self.__read() |
197 | 210 | ||
@@ -273,8 +286,8 @@ class DicoClient: | |||
273 | lang_dst[dst.strip()] = True | 286 | lang_dst[dst.strip()] = True |
274 | return { | 287 | return { |
275 | 'desc': '\n'.join(dsc), | 288 | 'desc': '\n'.join(dsc), |
276 | 'lang_src': lang_src.keys(), | 289 | 'lang_src': list(lang_src.keys()), |
277 | 'lang_dst': lang_dst.keys(), | 290 | 'lang_dst': list(lang_dst.keys()), |
278 | } | 291 | } |
279 | else: | 292 | else: |
280 | return {'error': code, 'msg': msg} | 293 | return {'error': code, 'msg': msg} |
@@ -387,13 +400,14 @@ class DicoClient: | |||
387 | def __decode(self, encoded): | 400 | def __decode(self, encoded): |
388 | for octc in (c for c in re.findall(r'\\(\d{3})', encoded)): | 401 | for octc in (c for c in re.findall(r'\\(\d{3})', encoded)): |
389 | encoded = encoded.replace(r'\%s' % octc, chr(int(octc, 8))) | 402 | encoded = encoded.replace(r'\%s' % octc, chr(int(octc, 8))) |
390 | return unicode(encoded, 'utf_8') | 403 | return encoded |
391 | 404 | ||
392 | def __debug(self, msg): | 405 | def __debug(self, msg): |
393 | print 'dico: Debug: %s' % msg | 406 | print('dico: Debug: %s' % msg) |
394 | 407 | ||
395 | 408 | ||
396 | class DicoNotConnectedError (Exception): | 409 | class DicoNotConnectedError (Exception): |
410 | |||
397 | def __init__(self, value): | 411 | def __init__(self, value): |
398 | self.parameter = value | 412 | self.parameter = value |
399 | 413 | ||
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 @@ | |||
1 | # This file is part of GNU Dico. | 1 | # This file is part of GNU Dico. |
2 | # Copyright (C) 2008-2010, 2012, 2013 Wojciech Polak | 2 | # Copyright (C) 2008-2010, 2012, 2013, 2015 Wojciech Polak |
3 | # | 3 | # |
4 | # GNU Dico is free software; you can redistribute it and/or modify | 4 | # GNU Dico is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by | 5 | # it under the terms of the GNU General Public License as published by |
@@ -24,6 +24,11 @@ import curses.ascii | |||
24 | import socket | 24 | import socket |
25 | import dicoclient | 25 | import dicoclient |
26 | 26 | ||
27 | try: | ||
28 | from django.utils.six.moves import range, input | ||
29 | except ImportError: | ||
30 | from six.moves import range, input | ||
31 | |||
27 | 32 | ||
28 | class Shell: | 33 | class Shell: |
29 | """Simple GNU Dico-Python Shell.""" | 34 | """Simple GNU Dico-Python Shell.""" |
@@ -54,17 +59,16 @@ class Shell: | |||
54 | pass | 59 | pass |
55 | atexit.register(readline.write_history_file, histfile) | 60 | atexit.register(readline.write_history_file, histfile) |
56 | 61 | ||
57 | print '\nType ? for help summary\n' | 62 | print('\nType ? for help summary\n') |
58 | while True: | 63 | while True: |
59 | try: | 64 | try: |
60 | input = raw_input(self.prompt).strip() | 65 | inputcmd = input(self.prompt).strip() |
61 | input = unicode(input, 'utf_8') | ||
62 | except (EOFError, KeyboardInterrupt): | 66 | except (EOFError, KeyboardInterrupt): |
63 | 67 | print() | |
64 | sys.exit() | 68 | sys.exit() |
65 | 69 | ||
66 | try: | 70 | try: |
67 | self.parse(input) | 71 | self.parse(inputcmd) |
68 | except socket.timeout: | 72 | except socket.timeout: |
69 | self.__error('socket timed out') | 73 | self.__error('socket timed out') |
70 |