grizzled-python icon indicating copy to clipboard operation
grizzled-python copied to clipboard

enum34 compatibility

Open mmilitzer opened this issue 9 years ago • 1 comments

I've installed grizzled-python 1.0.7 in python 2.7 to parse ftp directory listings (net/ftp/parse.py module). It pulls in also 'enum34' as a dependency but the 'Enum'-related code in parse.py looks like it's written against the older 'enum' and not the 'enum34' package. At least when I try to import 'parse_ftp_list_line', python also throws some exceptions.

I think the problem is that the enum34 "functional API" requires the first argument to be the name of the enumeration and the second argument the source of enumeration members as a sequence of names:

https://docs.python.org/3/library/enum.html#functional-api

Here's the patch that I applied, which seems to work for me:

--- ./grizzled/net/ftp/parse.py_orig    2016-11-01 12:10:47.795948217 +0000
+++ ./grizzled/net/ftp/parse.py 2016-11-01 12:19:08.766882529 +0000
@@ -48,6 +48,7 @@
 import time
 import calendar
 from ftplib import error_perm
+from enum import Enum

 # ---------------------------------------------------------------------------
 # Exports
@@ -67,7 +68,7 @@
 MONTHS = ('jan', 'feb', 'mar', 'apr', 'may', 'jun',
           'jul', 'aug', 'sep', 'oct', 'nov', 'dec')

-MTIME_TYPE = Enum('UNKNOWN', 'LOCAL', 'REMOTE_MINUTE', 'REMOTE_DAY')
+MTIME_TYPE = Enum('MTIME_TYPE', ['UNKNOWN', 'LOCAL', 'REMOTE_MINUTE', 'REMOTE_DAY'])
 """
 ``MTIME_TYPE`` identifies how a modification time ought to be interpreted
 (assuming the caller cares).
@@ -78,7 +79,7 @@
     - ``UNKNOWN``: Time's locale is unknown.
 """

-ID_TYPE = Enum('UNKNOWN', 'FULL')
+ID_TYPE = Enum('ID_TYPE', ['UNKNOWN', 'FULL'])
 """
 ``ID_TYPE`` identifies how a file's identifier should be interpreted.

mmilitzer avatar Nov 01 '16 22:11 mmilitzer

Honestly, enum is such a mess in Python that I should just rewrite the code to use constants. In any case, I'll patch a new version shortly. Thanks.

bmc avatar Nov 01 '16 22:11 bmc