diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2023-06-23 15:07:41 +0200 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-09-04 00:27:30 +0200 |
commit | 6b1044b37dce83d6930a17237a891ee00c6875d1 (patch) | |
tree | 822698782f14e21f34559facf8a36e7586411eea | |
parent | 1eeddb00405c4fa48ef9c3e81ad69885c934cdaa (diff) | |
download | wikipediafs-6b1044b37dce83d6930a17237a891ee00c6875d1.tar.gz |
Run 2to3 on the Python files
-rwxr-xr-x | src/mount.wikipediafs | 12 | ||||
-rw-r--r-- | src/wikipediafs/article.py | 91 | ||||
-rw-r--r-- | src/wikipediafs/config.py | 52 | ||||
-rw-r--r-- | src/wikipediafs/fs.py | 46 | ||||
-rw-r--r-- | src/wikipediafs/http.py | 23 | ||||
-rw-r--r-- | src/wikipediafs/logger.py | 4 | ||||
-rw-r--r-- | src/wikipediafs/metadir.py | 101 | ||||
-rw-r--r-- | src/wikipediafs/user.py | 10 |
8 files changed, 168 insertions, 171 deletions
diff --git a/src/mount.wikipediafs b/src/mount.wikipediafs index 19a3dc9..50d7541 100755 --- a/src/mount.wikipediafs +++ b/src/mount.wikipediafs @@ -25,13 +25,13 @@ from sys import exit try: from fuse import FuseError except: - print "The Python bindings for fuse do not seem to be installed." - print "Please install fuse-python 0.2 or later." + print("The Python bindings for fuse do not seem to be installed.") + print("Please install fuse-python 0.2 or later.") exit(1) # When WFS is mounted with fstab, HOME is not defined... # We have to deal with this since we need HOME for the config and the log. -if not os.environ.has_key("HOME"): +if "HOME" not in os.environ: last = len(sys.argv) - 1 mountoptions = sys.argv[last] arr = [] @@ -47,7 +47,7 @@ if not os.environ.has_key("HOME"): if home: os.environ["HOME"] = home - elif os.environ.has_key("USER"): + elif "USER" in os.environ: if os.environ["USER"] == "root": os.environ["HOME"] = "/root/" else: @@ -68,6 +68,6 @@ try: server.parse(errex=1) server.multithreaded = 0 server.main() -except FuseError, detail: - print detail +except FuseError as detail: + print(detail) diff --git a/src/wikipediafs/article.py b/src/wikipediafs/article.py index e9adc56..30df71b 100644 --- a/src/wikipediafs/article.py +++ b/src/wikipediafs/article.py @@ -17,15 +17,15 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import urllib, re, os, time +import urllib.request, urllib.parse, urllib.error, re, os, time from sgmllib import SGMLParser -from http import ExtendedHTTPConnection +from .http import ExtendedHTTPConnection class Article(SGMLParser): """ Gets and sets an article. """ - + def __init__(self, name, host, @@ -48,7 +48,7 @@ class Article(SGMLParser): SGMLParser.__init__(self) # Mediawiki replaces spaces with underscores - # because an URL cannot contain spaces + # because an URL cannot contain spaces self.name = name.replace(" ", "_") self.host = host self.basename = basename @@ -59,7 +59,7 @@ class Article(SGMLParser): self.httpauth_password = httpauth_password self.cache_time = cache_time self.logger = logger - + self.content = "" self.textarea = False self.wpEdittime = 0 @@ -68,14 +68,14 @@ class Article(SGMLParser): self.last_get = 0 # url patterns - title = urllib.urlencode({"title" : self.name}) - + title = urllib.parse.urlencode({"title" : self.name}) + self.edit_page = "%s?%s&action=edit" % \ (self.basename, title) # basename must include a leading / - + self.submit_page = "%s?%s&action=submit" % \ - (self.basename, title) + (self.basename, title) def start_textarea(self,attrs): """ @@ -83,48 +83,48 @@ class Article(SGMLParser): """ self.textarea = True self.content = "" - + def start_input(self,attrs): """ Called when an input is entered. """ # To set an article, we need to now its wpEdittime first. - + if len(attrs) == 3 and attrs[2][1] == "wpEdittime": self.wpEdittime = attrs[1][1] elif len(attrs) == 3 and attrs[2][1] == "wpEditToken": - self.wpEditToken = attrs[1][1] + self.wpEditToken = attrs[1][1] elif len(attrs) == 3 and attrs[2][1] == "wpStarttime": - self.wpStarttime = attrs[1][1] - + self.wpStarttime = attrs[1][1] + def end_textarea(self): """ Called when a textarea is left. """ self.textarea = False - + def handle_data(self,data): """ Called when data is parsed. - """ + """ # We add the parsed data to self.content when the data parsed # is in a textarea if self.textarea == True: self.content += data - def get(self): + def get(self): """ Gets the wiki content (not the whole html page). """ # Do not get article if cache is still ok - if int(time.time()) - self.last_get > self.cache_time: + if int(time.time()) - self.last_get > self.cache_time: self.logger.debug("pre-GET wpStarttime: '%s', wpEdittime: '%s', cookies: '%s', time diff: %d\n", self.wpEdittime, self.wpStarttime, self.cookie_str, int(time.time()) - self.last_get) headers = {"User-agent" : "WikipediaFS"} - + if self.cookie_str is not None: headers["Cookie"] = self.cookie_str - + conn = ExtendedHTTPConnection(self.host, self.port, self.https) if self.httpauth_username and self.httpauth_password: @@ -134,11 +134,11 @@ class Article(SGMLParser): conn.request(self.edit_page) #logger.info("HTTP GET %s" % self.edit_page) response = conn.getresponse() - + # Log http response if self.logger: - self.logger.info("HTTP GET %s" % self.edit_page) - + self.logger.info("HTTP GET %s" % self.edit_page) + # Feeds the SGMLparser self.feed(response.read()) conn.close() @@ -153,17 +153,17 @@ class Article(SGMLParser): if len(self.content.strip()) == 0: self.is_empty = True else: - self.is_empty = False + self.is_empty = False return self.content - - + + def set(self, text): - if text == self.content: + if text == self.content: return True # useless to continue further... self.logger.debug("POST wpStarttime: '%s', wpEdittime: '%s', cookies: '%s', time diff: %d\n", self.wpEdittime, self.wpStarttime, self.cookie_str, int(time.time()) - self.last_get) - + # Looking for a [[Summary:*]] regexp = '((\[\[)((s|S)ummary:)(.*)(\]\])(( )*\n)?)' summary = re.search(regexp, text) @@ -172,7 +172,7 @@ class Article(SGMLParser): text = text.replace(summary.group(1), '') else: wpSummary = " " - + # wpEdittime is empty if the article is a new article params = { "wpTextbox1" : text, @@ -181,19 +181,19 @@ class Article(SGMLParser): "wpStarttime": self.wpStarttime, "wpSave" : 1 } - + # Needed for logged in edition if self.wpEditToken is not None: params["wpEditToken"] = self.wpEditToken - - params = urllib.urlencode(params) - + + params = urllib.parse.urlencode(params) + headers = {"Content-type": "application/x-www-form-urlencoded", "User-agent" : "WikipediaFS"} - + if self.cookie_str is not None: headers["Cookie"] = self.cookie_str - + conn = ExtendedHTTPConnection(self.host, self.port, self.https) if self.httpauth_username and self.httpauth_password: @@ -202,9 +202,9 @@ class Article(SGMLParser): conn.add_headers(headers) conn.add_data(params) conn.request(self.submit_page) - + response = conn.getresponse() - + # Log http response if self.logger: self.logger.info("HTTP POST %s" % self.submit_page) @@ -221,7 +221,7 @@ class Article(SGMLParser): conn.close() self.content = text - + # forces the article to be get next time # (wpEdittime and wpStarttime need to be updated) self.last_get = 0 @@ -230,7 +230,7 @@ class Article(SGMLParser): if len(self.content.strip()) == 0: self.is_empty = True else: - self.is_empty = False + self.is_empty = False # Did the write actually succeed? if response.status == 302: @@ -243,7 +243,7 @@ class Article(SGMLParser): if __name__ == "__main__": import random import sys - from user import User + from .user import User import logging logger = logging.getLogger("mydebuglogger") logger.setLevel(logging.DEBUG) @@ -261,7 +261,7 @@ if __name__ == "__main__": } title = "Test" destructive = True - + if True: params["host"], params["basename"] = sys.argv[1], sys.argv[2] user = User(sys.argv[3], sys.argv[4], **params) @@ -276,13 +276,12 @@ if __name__ == "__main__": # Same as above + http auth params["httpauth_username"] = sys.argv[3] params["httpauth_password"] = sys.argv[4] - + user = User(sys.argv[1], sys.argv[2], **params) - params["cookie_str"] = user.getCookieString() - + params["cookie_str"] = user.getCookieString() + art = Article(title, **params) - print art.get() + print(art.get()) if destructive: art.set("Test ! (%s)" % str(random.random())) - diff --git a/src/wikipediafs/config.py b/src/wikipediafs/config.py index 2d42b29..31cb128 100644 --- a/src/wikipediafs/config.py +++ b/src/wikipediafs/config.py @@ -35,7 +35,7 @@ class Config: <login-cache-time>7200</login-cache-time> </general> <sites> - <!-- + <!-- Minimalist site entry sample: <site> <dirname>wikipedia-fr</dirname> @@ -55,11 +55,11 @@ class Config: <httpauth_password>Password</httpauth_password> <domain>DOMAIN (if using LDAP/AD Authentication extension)</domain> </site> - --> + --> <!-- Below a Mediawiki test site. Feel free to use it! - --> + --> <site> <dirname>mblondel.org</dirname> <host>www.mblondel.org</host> @@ -68,41 +68,41 @@ class Config: </sites> </wfs-config> """ - + def __init__(self, config_str=False): """ The XML config string can be passed as a parameter mainly for test purpose. """ - + self.home_dir = os.environ['HOME'] + "/.wikipediafs" self.conf_file = self.home_dir + "/config.xml" self.__initConfigDir() - - # Loads the config from a file or from a string - if(not config_str): + + # Loads the config from a file or from a string + if(not config_str): self.__config = minidom.parse(self.conf_file).documentElement else: self.__config = minidom.parseString(config_str).documentElement - + self.__setCacheTimes() self.__setDebug() - + self.__setSites() - + def __initConfigDir(self): # Creates .wikipediafs. in HOME if needed if not os.path.exists(self.home_dir): - os.mkdir(self.home_dir,0700) + os.mkdir(self.home_dir,0o700) # Creates default configuration file if needed if not os.path.exists(self.conf_file): - file = open(self.conf_file,"w",0700) + file = open(self.conf_file,"w",0o700) file.write(Config.DEFAULT) - file.close() + file.close() def __setSites(self): self.sites = {} @@ -120,7 +120,7 @@ class Config: dic[ele] = True # for elements like <https /> else: dic[ele] = None - + self.sites[dic["dirname"]] = dic @@ -141,12 +141,12 @@ class Config: if element.length == 0: self.debug_mode = False else: - self.debug_mode = True - - + self.debug_mode = True + + if __name__ != "__main__": CONFIG = Config() -else: +else: config_test = """\ <?xml version="1.0" encoding="UTF-8"?> <wfs-config> @@ -156,14 +156,14 @@ else: <login-cache-time>7200</login-cache-time> <debug /> </general> - <sites> + <sites> <site> <dirname>wikipedia-fr</dirname> <host>fr.wikipedia.org</host> <basename>/w/index.php</basename> <username>Username</username> <password>Password</password> - </site> + </site> <site> <dirname>mblondel.org</dirname> <host>www.mblondel.org</host> @@ -174,9 +174,9 @@ else: </sites> </wfs-config> """ - + config = Config(config_test) - print "cache time:", config.cache_time - print "debug:", config.debug_mode - for k, v in config.sites.items(): - print k, v + print("cache time:", config.cache_time) + print("debug:", config.debug_mode) + for k, v in list(config.sites.items()): + print(k, v) diff --git a/src/wikipediafs/fs.py b/src/wikipediafs/fs.py index 0c5b856..8e8ee6d 100644 --- a/src/wikipediafs/fs.py +++ b/src/wikipediafs/fs.py @@ -18,11 +18,11 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os.path, re, time -from metadir import MetaDir -from config import CONFIG -from article import Article -from user import User -from logger import LOGGER +from .metadir import MetaDir +from .config import CONFIG +from .article import Article +from .user import User +from .logger import LOGGER class ArticleDir: def __init__(self, fs, config): @@ -47,22 +47,22 @@ class ArticleDir: for forbidden_char in ('#', '<', '>', '[', ']', '|', '{', '}'): if file_name.count(forbidden_char) > 0: return False - + if file_name[-3:] == ".mw": return True else: return False def contents(self, path): - arr = self.dirs.keys() - for k in self.files.keys(): + arr = list(self.dirs.keys()) + for k in list(self.files.keys()): if not self.files[k].is_empty: arr.append(k) return arr - + def is_directory(self, path): name = self.get_article_file_name(path) - return self.dirs.has_key(name) + return name in self.dirs def is_file(self, path): if self.is_valid_file(path): @@ -75,7 +75,7 @@ class ArticleDir: return False def set_cookie_string(self, force): - if force or not self.config.has_key("cookie_str"): + if force or "cookie_str" not in self.config: if self.config["username"] is not None and \ self.config["password"] is not None: user = User(logger=LOGGER, **self.config) @@ -91,7 +91,7 @@ class ArticleDir: if int(time.time()) - self.login_time > CONFIG.login_cache_time: self.set_cookie_string(1) else: - if self.files.has_key(file_name): + if file_name in self.files: return self.files[file_name] else: self.set_cookie_string(0) @@ -134,26 +134,26 @@ class ArticleDir: t -= time.timezone return t - + def mode(self, path): LOGGER.debug("FSdir mode %s" % (path)) - return 0755 - + return 0o755 + def unlink(self, path): LOGGER.debug("FSdir unlink %s" % (path)) file_name = self.get_article_file_name(path) - if self.files.has_key(file_name): + if file_name in self.files: self.files.pop(file_name) return True # succeeded else: return False - + def mkdir(self, path): LOGGER.debug("FSdir mkdir %s" % (path)) name = self.get_article_file_name(path) - self.dirs[name] = True + self.dirs[name] = True self.fs.set_dir(path, ArticleDir(self.fs, self.config)) - return True + return True class Root: def __init__(self, fs): @@ -164,19 +164,19 @@ class Root: self.regexp += "\-([a-z]{2})" self.regexp = re.compile(self.regexp, re.IGNORECASE) - for dirname, config in CONFIG.sites.items(): + for dirname, config in list(CONFIG.sites.items()): self.dirs[dirname] = True self.fs.set_dir("/" + dirname, ArticleDir(self.fs, config)) def contents(self, path): if path == "/": - return self.dirs.keys() + return list(self.dirs.keys()) else: return [] def is_directory(self, path): basename = os.path.basename(path) - if path == "/" or self.dirs.has_key(basename): + if path == "/" or basename in self.dirs: return True else: return False @@ -185,7 +185,7 @@ class Root: return False # There is no file at the root def mode(self, path): - return 0755 + return 0o755 def mkdir(self, path): # add a site from the wikimedia foundation diff --git a/src/wikipediafs/http.py b/src/wikipediafs/http.py index 2db378b..bd9c42d 100644 --- a/src/wikipediafs/http.py +++ b/src/wikipediafs/http.py @@ -18,7 +18,7 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os, socket, string, base64 -import httplib +import http.client class ExtendedHTTPConnection: """ @@ -34,19 +34,19 @@ class ExtendedHTTPConnection: self.https = https self.port = port - self.host = host + self.host = host - if os.environ.has_key("http_proxy"): + if "http_proxy" in os.environ: self.proxy_enabled = True self.conn = self.get_proxy_connection() else: self.proxy_enabled = False - + if https: - self.conn = httplib.HTTPSConnection(host, port) + self.conn = http.client.HTTPSConnection(host, port) else: - self.conn = httplib.HTTPConnection(host, port) + self.conn = http.client.HTTPConnection(host, port) self.headers = {} self.data = None @@ -55,7 +55,7 @@ class ExtendedHTTPConnection: self.headers[header] = value def add_headers(self, headers): - for k, v in headers.items(): + for k, v in list(headers.items()): self.add_header(k, v) def request(self, path): @@ -75,7 +75,7 @@ class ExtendedHTTPConnection: else: url = path - + return self.conn.request(method, url, self.data, self.headers) def getresponse(self, *args): @@ -95,15 +95,14 @@ class ExtendedHTTPConnection: http_proxy = http_proxy.replace("http://", "").rstrip("/") (proxy_host, proxy_port) = http_proxy.split(":") proxy_port = int(proxy_port) - + if self.https: - return httplib.HTTPConnection(proxy_host, proxy_port) + return http.client.HTTPConnection(proxy_host, proxy_port) else: - return httplib.HTTPConnection(proxy_host, proxy_port) + return http.client.HTTPConnection(proxy_host, proxy_port) def http_auth(self, username, password): httpbasicauth = "%s:%s" % (username, password) self.add_header("Authorization", "Basic %s" % base64.encodestring(httpbasicauth).strip()) -
\ No newline at end of file diff --git a/src/wikipediafs/logger.py b/src/wikipediafs/logger.py index cbcc420..4c39b91 100644 --- a/src/wikipediafs/logger.py +++ b/src/wikipediafs/logger.py @@ -19,14 +19,14 @@ import logging import os, os.path -from config import CONFIG +from .config import CONFIG conf_dir = os.path.join(os.environ['HOME'], '.wikipediafs') file = os.path.join(conf_dir, 'wikipediafs.log') # Creates .wikipediafs. in HOME if needed if not os.path.exists(conf_dir): - os.mkdir(conf_dir,0700) + os.mkdir(conf_dir,0o700) LOGGER = logging.getLogger('wikipediafs') hdlr = logging.FileHandler(file) diff --git a/src/wikipediafs/metadir.py b/src/wikipediafs/metadir.py index 8a0481a..f2b3681 100644 --- a/src/wikipediafs/metadir.py +++ b/src/wikipediafs/metadir.py @@ -18,14 +18,14 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. import os, stat, errno, time -from cStringIO import StringIO +from io import StringIO import fuse from fuse import Fuse -from logger import LOGGER +from .logger import LOGGER # This setting is optional, but it ensures that this class will keep # working after a future API revision -fuse.fuse_python_api = (0, 2) +fuse.fuse_python_api = (0, 2) class MetaDir(Fuse): """ @@ -49,10 +49,10 @@ class MetaDir(Fuse): self.st_ctime = 0 READ = 0 - WRITE = 1 + WRITE = 1 def __init__(self, *arr, **dic): - Fuse.__init__(self, *arr, **dic) + Fuse.__init__(self, *arr, **dic) self.dirs = {} self.open_mode = None @@ -64,7 +64,7 @@ class MetaDir(Fuse): def set_dir(self, path, directory): self.dirs[path] = directory - + def set_root(self, directory): self.set_dir('/', directory) @@ -72,32 +72,32 @@ class MetaDir(Fuse): # Selects fs object on which we will call is_file, is_directory, # contents, etc dirname = os.path.dirname(path) - - if path == '/' and not self.dirs.has_key('/'): + + if path == '/' and '/' not in self.dirs: raise "At least the root class must be defined" - elif self.dirs.has_key(dirname): - return self.dirs[dirname] + elif dirname in self.dirs: + return self.dirs[dirname] else: return self.get_dir(dirname) def get_file_buf(self, path): - if not self.files.has_key(path): + if path not in self.files: self.files[path] = StringIO() return self.files[path] def remove_file_buf(self, path): - if self.files.has_key(path): + if path in self.files: self.files.pop(path) def has_file_buf(self, path): - if self.files.has_key(path): + if path in self.files: return True else: - return False + return False def is_valid_file(self, path): name = os.path.basename(path) - if len(name) > 0: + if len(name) > 0: if name[0] == ".":# hidden file return False elif name[-4:] == ".swp": # vi swap file @@ -108,27 +108,27 @@ class MetaDir(Fuse): name[0:2] == "p.": # emacs return False else: - return True + return True else: return True def getattr(self, path): LOGGER.debug("getattr %s" % path) - + d = self.get_dir(path) st = MetaDir.Stat() - if self.files.has_key(path): - st.st_mode = stat.S_IFREG | 0666 + if path in self.files: + st.st_mode = stat.S_IFREG | 0o666 st.st_nlink = 1 st.st_size = 0 elif not self.is_valid_file(path): return -errno.ENOENT # No such file or directory - elif d.is_directory(path): + elif d.is_directory(path): st.st_mode = stat.S_IFDIR | d.mode(path) st.st_nlink = 2 - elif d.is_file(path): + elif d.is_file(path): st.st_mode = stat.S_IFREG | d.mode(path) st.st_nlink = 1 st.st_size = d.size(path) @@ -136,14 +136,14 @@ class MetaDir(Fuse): else: return -errno.ENOENT # No such file or directory return st - + def readdir(self, path, offset): LOGGER.debug("readdir %s %d" % (path, offset)) if path == "/": d = self.get_dir(path) else: - d = self.get_dir(path + "/") + d = self.get_dir(path + "/") dirs = d.contents(path) @@ -153,7 +153,7 @@ class MetaDir(Fuse): for e in ('.', '..'): if dirs.count(e) == 0: dirs.append(e) - + for r in dirs: yield fuse.Direntry(r) @@ -172,9 +172,9 @@ class MetaDir(Fuse): return -errno.EACCES # Permission denied else: return -errno.EACCES # Permission denied - + self.get_file_buf(path) - + def truncate(self, path, size): # Truncate is called just before open when a file is to be written @@ -182,18 +182,18 @@ class MetaDir(Fuse): LOGGER.debug("truncate %s %d" % (path, size)) buf = self.get_file_buf(path) - + if self.is_valid_file(path): - d = self.get_dir(path) + d = self.get_dir(path) txt = d.read_file(path) buf.write(txt) - + buf.truncate(size) def open(self, path, flags): LOGGER.debug("open %s %d" % (path, flags)) - if not self.files.has_key(path): + if path not in self.files: if self.is_valid_file(path): buf = self.get_file_buf(path) d = self.get_dir(path) @@ -231,7 +231,7 @@ class MetaDir(Fuse): success = True # Called to close the file - LOGGER.debug("flush %s %x" % (path, flags)) + LOGGER.debug("flush %s %x" % (path, flags)) if self.open_mode == self.WRITE and self.is_valid_file(path): # for valid files @@ -247,7 +247,7 @@ class MetaDir(Fuse): def release(self, path, flags): # Called to close the file - LOGGER.debug("release %s %x" % (path, flags)) + LOGGER.debug("release %s %x" % (path, flags)) # Release can not return errors, but try anyhow because we have no other choices. # XXX: Is the flush called reliably enough to do this there? @@ -289,12 +289,12 @@ class MetaDir(Fuse): res = d.unlink(path) if res != True: return -errno.EACCES # Permission denied - + def rmdir(self, path): LOGGER.debug("rmdir %s" % path) d = self.get_dir(path) - + if dir(d).count("rmdir") == 0: return -errno.EACCES # Permission denied else: @@ -309,13 +309,13 @@ class MetaDir(Fuse): if self.is_valid_file(path) and d.is_file(path): if not self.is_valid_file(path1): - # from a valid file to an editor file + # from a valid file to an editor file buf = self.get_file_buf(path1) buf.write(d.read_file(path)) # TODO : remove path ? else: # from a valid file to a valid file - # if rename is defined + # if rename is defined # TODO : with unlink method defined in fs pass elif not self.is_valid_file(path): @@ -331,17 +331,17 @@ class MetaDir(Fuse): # from an editor file to an editor file # TODO pass - + def utime(self, path, times): LOGGER.debug("utime %s %s" % (path, times)) d = self.get_dir(path) - + if dir(d).count("utime") == 0: return -errno.ENOSYS # Not implemented else: return d.utime(path, times) - + def chmod(self, path, mode): LOGGER.debug("chmod %s %s" % (path,mode)) return None @@ -349,7 +349,7 @@ class MetaDir(Fuse): def chown(self, path, user, group): LOGGER.debug("chown %s %s %s" % (path,user,group)) return None - + if __name__ == "__main__": class Hello: def __init__(self): @@ -380,7 +380,7 @@ if __name__ == "__main__": return 0 def mode(self, path): - return 0755 + return 0o755 def read_file(self, path): if path == '/hello_file': @@ -391,28 +391,27 @@ if __name__ == "__main__": def write_to(self, path, txt): if path == '/hello_file': self.hello_file_content = txt - + class TestFS(MetaDir): def __init__(self, *arr, **dic): MetaDir.__init__(self, *arr, **dic) self.set_root(Hello()) fs = TestFS() - print fs.getattr('/') - print fs.readdir('/', 0) - print fs.getattr('/hello_file') + print(fs.getattr('/')) + print(fs.readdir('/', 0)) + print(fs.getattr('/hello_file')) - fs.open('/hello_file', 32768) - print fs.read('/hello_file', 100, 0) + fs.open('/hello_file', 32768) + print(fs.read('/hello_file', 100, 0)) fs.release('/hello_file', 32768) - fs.open('/hello_file', 32768) + fs.open('/hello_file', 32768) fs.write('/hello_file', 'New string', 0) fs.release('/hello_file', 32768) fs.open('/hello_file', 32768) - print fs.read('/hello_file', 100, 0) + print(fs.read('/hello_file', 100, 0)) fs.release('/hello_file', 32768) - print fs.mkdir('/new_dir', 32768) - + print(fs.mkdir('/new_dir', 32768)) diff --git a/src/wikipediafs/user.py b/src/wikipediafs/user.py index 5955476..d615a13 100644 --- a/src/wikipediafs/user.py +++ b/src/wikipediafs/user.py @@ -17,9 +17,9 @@ # with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -import urllib, re -from http import ExtendedHTTPConnection -from logger import printlog +import urllib.request, urllib.parse, urllib.error, re +from .http import ExtendedHTTPConnection +from .logger import printlog class User: """ @@ -118,7 +118,7 @@ class User: if self.domain: params["wpDomain"] = self.domain - params = urllib.urlencode(params) + params = urllib.parse.urlencode(params) conn.add_data(params) conn.add_headers(headers) @@ -159,7 +159,7 @@ if __name__ == "__main__": import logging if len(sys.argv) < 4: - print "python user.py host urlbase username " + print("python user.py host urlbase username ") else: if len(sys.argv) == 4: https = False |