From trac at ftputil.sschwarzer.net Mon Jun 13 17:50:46 2011 From: trac at ftputil.sschwarzer.net (ftputil) Date: Mon, 13 Jun 2011 15:50:46 -0000 Subject: [ftputil] #58: Ability to access source text line for file stats. Message-ID: <052.27a32e4feed7b55c6b26e0333ca25faf@ftputil.sschwarzer.net> #58: Ability to access source text line for file stats. -------------------------+-------------------------------------------------- Reporter: ftputiluser | Owner: schwa Type: enhancement | Status: new Priority: trivial | Milestone: Component: Library | Version: 2.6 Keywords: | -------------------------+-------------------------------------------------- Hi I'm using your awesome lib. Please consider adding the following functionality: to be able access source text for file attributes entry while doing lstat on file. Use case: While debugging issue when source FTP server returning dates in GMT timezone I realize that users of my program will have to be able to detect this issue also. So I added functionality to StatResult class to store and retrieve source text line for a file. {{{ class StatResult(tuple): ... def __init__(self, sequence): # Don't call `__init__` via `super`. Construction from a # sequence is implicitly handled by `tuple.__new__`, not # `tuple.__init__`. As a by-product, this avoids a # `DeprecationWarning` in Python 2.6+ . # pylint: disable=W0231, W0613 # # These may be overwritten in a `Parser.parse_line` method. self._st_name = "" self._st_target = None self._st_mtime_precision = None self._line = "" def set_line(self,line): self._line = line def get_line(self): return self._line ... }}} adding source line {{{ stat_result = StatResult( (st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime) ) stat_result.set_line(line) }}} Vlad (smartkiwi at gmail.com) -- Ticket URL: ftputil Python FTP client library From trac at ftputil.sschwarzer.net Mon Jun 13 23:13:33 2011 From: trac at ftputil.sschwarzer.net (ftputil) Date: Mon, 13 Jun 2011 21:13:33 -0000 Subject: [ftputil] #58: Ability to access source text line for file stats. In-Reply-To: <052.27a32e4feed7b55c6b26e0333ca25faf@ftputil.sschwarzer.net> References: <052.27a32e4feed7b55c6b26e0333ca25faf@ftputil.sschwarzer.net> Message-ID: <061.4695c247118810538eb3e5c473c10ebd@ftputil.sschwarzer.net> #58: Ability to access source text line for file stats. --------------------------+------------------------------------------------- Reporter: ftputiluser | Owner: schwa Type: enhancement | Status: assigned Priority: trivial | Milestone: Component: Library | Version: 2.6 Resolution: | Keywords: --------------------------+------------------------------------------------- Changes (by schwa): * status: new => assigned Old description: > Hi > I'm using your awesome lib. > Please consider adding the following functionality: to be able access > source text for file attributes entry while doing lstat on file. > Use case: > While debugging issue when source FTP server returning dates in GMT > timezone I realize that users of my program will have to be able to > detect this issue also. > So I added functionality to StatResult class to store and retrieve source > text line for a file. > > {{{ > class StatResult(tuple): > ... > def __init__(self, sequence): > # Don't call `__init__` via `super`. Construction from a > # sequence is implicitly handled by `tuple.__new__`, not > # `tuple.__init__`. As a by-product, this avoids a > # `DeprecationWarning` in Python 2.6+ . > # pylint: disable=W0231, W0613 > # > # These may be overwritten in a `Parser.parse_line` method. > self._st_name = "" > self._st_target = None > self._st_mtime_precision = None > self._line = "" > > def set_line(self,line): > self._line = line > > def get_line(self): > return self._line > > ... > > }}} > > adding source line > {{{ > stat_result = StatResult( > (st_mode, st_ino, st_dev, st_nlink, st_uid, > st_gid, st_size, st_atime, st_mtime, st_ctime) ) > stat_result.set_line(line) > }}} > > Vlad (smartkiwi at gmail.com) New description: Hi, I'm using your awesome lib. Please consider adding the following functionality: to be able access source text for file attributes entry while doing lstat on file. Use case: While debugging issue when source FTP server returning dates in GMT timezone I realize that users of my program will have to be able to detect this issue also. So I added functionality to !StatResult class to store and retrieve source text line for a file. {{{ class StatResult(tuple): ... def __init__(self, sequence): # Don't call `__init__` via `super`. Construction from a # sequence is implicitly handled by `tuple.__new__`, not # `tuple.__init__`. As a by-product, this avoids a # `DeprecationWarning` in Python 2.6+ . # pylint: disable=W0231, W0613 # # These may be overwritten in a `Parser.parse_line` method. self._st_name = "" self._st_target = None self._st_mtime_precision = None self._line = "" def set_line(self,line): self._line = line def get_line(self): return self._line ... }}} adding source line {{{ stat_result = StatResult( (st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid, st_size, st_atime, st_mtime, st_ctime) ) stat_result.set_line(line) }}} Vlad (smartkiwi at gmail.com) -- Comment: Hello Vlad, Thanks for the compliment and your suggestion. :-) I'll ''probably'' add this to the parsers in `ftp_stat.py`, but nonetheless you can already save the line without modifying the `ftputil` source code, by using the [wiki:Documentation#writing-directory-parsers interface for custom parsers]. '''Step 1.''' Define a custom parser class: {{{ from ftputil import ftp_stat class DebuggingParser(ftp_stat.UnixParser): def parse_line(line, time_shift=0.0): """Parse a line like `UnixParser` does, but in addition save the original line in an attribute `_line` for debugging. """ stat_result = super(ftp_stat.UnixParser, self).\ parse_line(line, time_shift) stat_result._line = line return stat_result }}} '''Step 2.''' Set an ''instance'' of this class as the parser to use: {{{ import ftputil import debugging_parser ftp_host = ftputil.FTPHost(host, userid, password) ftp_host.set_parser(debugging_parser.DebuggingParser()) # Use `ftp_host`. ... }}} You can of course modify the `MSParser` class in the same way if you need this. -- Ticket URL: ftputil Python FTP client library