Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../lib64/python2..../idlelib
File: PathBrowser.py
import os
[0] Fix | Delete
import sys
[1] Fix | Delete
import imp
[2] Fix | Delete
[3] Fix | Delete
from idlelib.TreeWidget import TreeItem
[4] Fix | Delete
from idlelib.ClassBrowser import ClassBrowser, ModuleBrowserTreeItem
[5] Fix | Delete
from idlelib.PyShell import PyShellFileList
[6] Fix | Delete
[7] Fix | Delete
[8] Fix | Delete
class PathBrowser(ClassBrowser):
[9] Fix | Delete
[10] Fix | Delete
def __init__(self, flist, _htest=False):
[11] Fix | Delete
"""
[12] Fix | Delete
_htest - bool, change box location when running htest
[13] Fix | Delete
"""
[14] Fix | Delete
self._htest = _htest
[15] Fix | Delete
self.init(flist)
[16] Fix | Delete
[17] Fix | Delete
def settitle(self):
[18] Fix | Delete
"Set window titles."
[19] Fix | Delete
self.top.wm_title("Path Browser")
[20] Fix | Delete
self.top.wm_iconname("Path Browser")
[21] Fix | Delete
[22] Fix | Delete
def rootnode(self):
[23] Fix | Delete
return PathBrowserTreeItem()
[24] Fix | Delete
[25] Fix | Delete
class PathBrowserTreeItem(TreeItem):
[26] Fix | Delete
[27] Fix | Delete
def GetText(self):
[28] Fix | Delete
return "sys.path"
[29] Fix | Delete
[30] Fix | Delete
def GetSubList(self):
[31] Fix | Delete
sublist = []
[32] Fix | Delete
for dir in sys.path:
[33] Fix | Delete
item = DirBrowserTreeItem(dir)
[34] Fix | Delete
sublist.append(item)
[35] Fix | Delete
return sublist
[36] Fix | Delete
[37] Fix | Delete
class DirBrowserTreeItem(TreeItem):
[38] Fix | Delete
[39] Fix | Delete
def __init__(self, dir, packages=[]):
[40] Fix | Delete
self.dir = dir
[41] Fix | Delete
self.packages = packages
[42] Fix | Delete
[43] Fix | Delete
def GetText(self):
[44] Fix | Delete
if not self.packages:
[45] Fix | Delete
return self.dir
[46] Fix | Delete
else:
[47] Fix | Delete
return self.packages[-1] + ": package"
[48] Fix | Delete
[49] Fix | Delete
def GetSubList(self):
[50] Fix | Delete
try:
[51] Fix | Delete
names = os.listdir(self.dir or os.curdir)
[52] Fix | Delete
except os.error:
[53] Fix | Delete
return []
[54] Fix | Delete
packages = []
[55] Fix | Delete
for name in names:
[56] Fix | Delete
file = os.path.join(self.dir, name)
[57] Fix | Delete
if self.ispackagedir(file):
[58] Fix | Delete
nn = os.path.normcase(name)
[59] Fix | Delete
packages.append((nn, name, file))
[60] Fix | Delete
packages.sort()
[61] Fix | Delete
sublist = []
[62] Fix | Delete
for nn, name, file in packages:
[63] Fix | Delete
item = DirBrowserTreeItem(file, self.packages + [name])
[64] Fix | Delete
sublist.append(item)
[65] Fix | Delete
for nn, name in self.listmodules(names):
[66] Fix | Delete
item = ModuleBrowserTreeItem(os.path.join(self.dir, name))
[67] Fix | Delete
sublist.append(item)
[68] Fix | Delete
return sublist
[69] Fix | Delete
[70] Fix | Delete
def ispackagedir(self, file):
[71] Fix | Delete
if not os.path.isdir(file):
[72] Fix | Delete
return False
[73] Fix | Delete
init = os.path.join(file, "__init__.py")
[74] Fix | Delete
return os.path.exists(init)
[75] Fix | Delete
[76] Fix | Delete
def listmodules(self, allnames):
[77] Fix | Delete
modules = {}
[78] Fix | Delete
suffixes = imp.get_suffixes()
[79] Fix | Delete
sorted = []
[80] Fix | Delete
for suff, mode, flag in suffixes:
[81] Fix | Delete
i = -len(suff)
[82] Fix | Delete
for name in allnames[:]:
[83] Fix | Delete
normed_name = os.path.normcase(name)
[84] Fix | Delete
if normed_name[i:] == suff:
[85] Fix | Delete
mod_name = name[:i]
[86] Fix | Delete
if mod_name not in modules:
[87] Fix | Delete
modules[mod_name] = None
[88] Fix | Delete
sorted.append((normed_name, name))
[89] Fix | Delete
allnames.remove(name)
[90] Fix | Delete
sorted.sort()
[91] Fix | Delete
return sorted
[92] Fix | Delete
[93] Fix | Delete
def _path_browser(parent): # htest #
[94] Fix | Delete
flist = PyShellFileList(parent)
[95] Fix | Delete
PathBrowser(flist, _htest=True)
[96] Fix | Delete
parent.mainloop()
[97] Fix | Delete
[98] Fix | Delete
if __name__ == "__main__":
[99] Fix | Delete
from unittest import main
[100] Fix | Delete
main('idlelib.idle_test.test_pathbrowser', verbosity=2, exit=False)
[101] Fix | Delete
[102] Fix | Delete
from idlelib.idle_test.htest import run
[103] Fix | Delete
run(_path_browser)
[104] Fix | Delete
[105] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function