Thread: SF.net SVN: fclient: [302] trunk/sandbox/fcp2/uri.py
Status: Pre-Alpha
Brought to you by:
jurner
From: <ju...@us...> - 2008-02-29 13:05:01
|
Revision: 302 http://fclient.svn.sourceforge.net/fclient/?rev=302&view=rev Author: jurner Date: 2008-02-29 05:03:27 -0800 (Fri, 29 Feb 2008) Log Message: ----------- fixed re pattern for freenet keys Modified Paths: -------------- trunk/sandbox/fcp2/uri.py Modified: trunk/sandbox/fcp2/uri.py =================================================================== --- trunk/sandbox/fcp2/uri.py 2008-02-29 13:02:56 UTC (rev 301) +++ trunk/sandbox/fcp2/uri.py 2008-02-29 13:03:27 UTC (rev 302) @@ -57,7 +57,7 @@ #*************************************************************************************** KeyPat = re.compile( r''' -^(CHK | SSK | SVK | USK @) +^(CHK@ | SSK@ | SVK@ | USK@) ( [a-z0-9\-~]{43}, [a-z0-9\-~]{43}, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-04 17:36:48
|
Revision: 305 http://fclient.svn.sourceforge.net/fclient/?rev=305&view=rev Author: jurner Date: 2008-03-04 09:36:51 -0800 (Tue, 04 Mar 2008) Log Message: ----------- ... Modified Paths: -------------- trunk/sandbox/fcp2/uri.py Modified: trunk/sandbox/fcp2/uri.py =================================================================== --- trunk/sandbox/fcp2/uri.py 2008-02-29 16:26:02 UTC (rev 304) +++ trunk/sandbox/fcp2/uri.py 2008-03-04 17:36:51 UTC (rev 305) @@ -129,6 +129,3 @@ return tail return '' - - - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ju...@us...> - 2008-03-04 17:37:20
|
Revision: 306 http://fclient.svn.sourceforge.net/fclient/?rev=306&view=rev Author: jurner Date: 2008-03-04 09:37:20 -0800 (Tue, 04 Mar 2008) Log Message: ----------- no longer needed, use key.py instead Removed Paths: ------------- trunk/sandbox/fcp2/uri.py Deleted: trunk/sandbox/fcp2/uri.py =================================================================== --- trunk/sandbox/fcp2/uri.py 2008-03-04 17:36:51 UTC (rev 305) +++ trunk/sandbox/fcp2/uri.py 2008-03-04 17:37:20 UTC (rev 306) @@ -1,131 +0,0 @@ -"""Freennet Client Protocol uri and related methods""" - -import os, sys -import base64 -import re -import urlparse - -#--> rel import hack -class _RelImportHack(object): - def __init__(self, n): - fpath = os.path.abspath(__file__) - for i in xrange(n): fpath = os.path.dirname(fpath) - sys.path.insert(0, fpath) - def __del__(self): sys.path.pop(0) -hack = _RelImportHack(2) - -from fcp2 import consts - - -del hack -#<-- rel import hack - -#************************************************************************************** -# freenet base64 for keys -#************************************************************************************** -def base64UrlsaveDecode(string): - """Decodes a base64 urlsave encoded string as encoded by freenet - @param string: string to decode - @return: decoded string - - @raise TypeError: if the string can not be decoded - @note: this function handles non-standard encoding as used by freenet (see: freenet/src/support/base64.java) - """ - # freenet uses - for + and ~ for / - altchars = '-~' - - # padding may be ommitted or not - padding = 4 - len(string) % 4 - if padding: - string += '=' * padding - return base64.b64decode(string, altchars) - -#**************************************************************************************** -# freenet keys -# -# KeyType@32 bytes hash, 32 bytes encryption key, 5 bytes extra -# -# all byte components are base64 encoded. Freenet uses base64 without padding -# along with the following altchars for urlsave encode: - for + and ~ for / -# see: freenet/support/base64.java -# -# so a key as the user gets it to see is: -# KeyType@43 bytes, 43 bytes, 7 bytes ..of [A-Za-z0-9\-~] -# -# see: [freenet/src/support/base64.java] -# -#*************************************************************************************** -KeyPat = re.compile( -r''' -^(CHK@ | SSK@ | SVK@ | USK@) -( - [a-z0-9\-~]{43}, - [a-z0-9\-~]{43}, - [a-z0-9\-~]{7} -) -''', re.I | re.X) #TODO: ignorecase? - - -def keyType(uri): - """Returns the ky type of a freenet key or None if the type could not be determined""" - if uri.startswith(consts.KeyType.KSK): - return consts.KeyType.KSK - result = KeyPat.match(uri) - if result is None: - return None - return result.group(1) - -#********************************************************************* -# -#********************************************************************* -def stripUri(uri): - """Strips scheme and location parts from an uri""" - result = urlparse.urlsplit(uri)[2] - result = result.lstrip('/') - return result - - -class Uri(object): - """Class wrappinf a freenet Uri - - @ivar keyType: L{consts.KeyType} of the uri - @ivar uri: (str) uri contained in the instance - """ - - KeyType = consts.KeyType - - - def __init__(self, uri): - """ - @param uri: (str) freenet uri (may be an uri like http://..CHK@ or - freenet:CHK@ or whatever or a a freenet key) - """ - self.uri = stripUri(uri) - result = keyType(self.uri) - self.keyType = self.KeyType.Invalid if result is None else result - - - def __nonzero__(self): - """Checks if the uri contained in the instance is a vaild freenet uri""" - return self.keyType != self.KeyType.Invalid - - - def split(self): - """Splits the uri - @return: tuple(freenet-key, file-name) - """ - if self.keyType != self.KeyType.Invalid: - head, sep, tail = self.uri.partition('/') - return head, tail - return self.uri, '' - - - def fileName(self): - """Returns the filename part of the uri - @return: str - """ - head, tail = self.split() - if tail: - return tail - return '' - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |