Skip to content

Commit

Permalink
zippath: Fix up docstrings.
Browse files Browse the repository at this point in the history
  • Loading branch information
MostAwesomeDude committed Jan 2, 2014
1 parent 4331e30 commit 869f408
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 22 deletions.
51 changes: 29 additions & 22 deletions bp/zippath.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
@implementer(IFilePath)
class ZipPath(object):
"""
I represent a file or directory contained within a zip file.
I am a file or directory contained within a zip file.
"""

sep = ZIP_PATH_SEP
Expand All @@ -40,9 +40,9 @@ def __init__(self, archive, pathInArchive):
"""
Don't construct me directly. Use ZipArchive.child().
@param archive: a ZipArchive instance.
:param ZipArchive archive: a ZipArchive instance.
@param pathInArchive: a ZIP_PATH_SEP-separated string.
:param str pathInArchive: a ZIP_PATH_SEP-separated string.
"""
self.archive = archive
self.pathInArchive = pathInArchive
Expand Down Expand Up @@ -88,12 +88,13 @@ def child(self, path):
Return a new ZipPath representing a path in C{self.archive} which is
a child of this path.
@note: Requesting the C{".."} (or other special name) child will not
cause L{InsecurePath} to be raised since these names do not have
any special meaning inside a zip archive. Be particularly
careful with the C{path} attribute (if you absolutely must use
it) as this means it may include special names with special
meaning outside of the context of a zip archive.
.. note:: Requesting the C{".."} (or other special name) child will
**not** cause L{InsecurePath} to be raised since these names
do not have any special meaning inside a zip archive. Be
particularly careful with the C{path} attribute (if you
absolutely must use it) as this means it may include special
names with special meaning outside of the context of a zip
archive.
"""
return ZipPath(self.archive,
ZIP_PATH_SEP.join([self.pathInArchive, path]))
Expand Down Expand Up @@ -141,7 +142,8 @@ def listdir(self):

def splitext(self):
"""
Return a value similar to that returned by os.path.splitext.
Return a value similar to that returned by
:py:func:`os.path.splitext`.
"""
# This happens to work out because of the fact that we use OS-specific
# path separators in the constructor to construct our fake 'path'
Expand Down Expand Up @@ -173,19 +175,23 @@ def getsize(self):

def getAccessTime(self):
"""
Retrieve this file's last access-time. This is the same as the last
access time for the archive.
Retrieve this file's last access-time.
@return: a number of seconds since the epoch
This is the same as the last access time for the archive.
:return: a number of seconds since the epoch
:rtype: int
"""
return self.archive.getAccessTime()

def getModificationTime(self):
"""
Retrieve this file's last modification time. This is the time of
modification recorded in the zipfile.
Retrieve this file's last modification time.
This is the time of modification recorded in the zipfile.
@return: a number of seconds since the epoch.
:return: a number of seconds since the epoch.
:rtype: int
"""
return time.mktime(
self.archive.zipfile.NameToInfo[self.pathInArchive].date_time
Expand All @@ -209,9 +215,10 @@ def __init__(self, archivePathname, mode="r"):
Create a ZipArchive, treating the archive at archivePathname as a zip
file.
@param archivePathname: a str, naming a path in the filesystem.
@param mode: A file mode which can be "r" for reading, "w" for
truncating and writing, or "a" for appending and writing.
:param str archivePathname: A path in the filesystem.
:param str mode: A file mode which can be "r" for reading, "w" for
truncating and writing, or "a" for appending and
writing.
"""
self.zipfile = ZipFile(archivePathname, mode)
self.path = archivePathname
Expand All @@ -234,14 +241,14 @@ def child(self, path):
"""
Create a ZipPath pointing at a path within the archive.
@param path: a str with no path separators in it, either '/' or the
system path separator, if it's different.
:param str path: A string with no path separators in it, either '/' or
the system path separator, if it's different.
"""
return ZipPath(self, path)

def exists(self):
"""
Returns true if the underlying archive exists.
Returns whether the underlying archive exists.
"""
return FilePath(self.zipfile.filename).exists()

Expand Down
1 change: 1 addition & 0 deletions docs/zippath.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ ZipPath

.. autoclass:: bp.zippath.ZipPath
:members:
:special-members:

0 comments on commit 869f408

Please sign in to comment.