Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
store.clear ()
busy(self.SMBBrowseDialog)
class X:
pass
dummy = X()
dummy.smbc_type = pysmb.smbc.PRINTER_SHARE
dummy.name = _('Scanning...')
dummy.comment = ''
store.append(None, [dummy])
while gtk.events_pending ():
gtk.main_iteration ()
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
entries = None
try:
while smbc_auth.perform_authentication () > 0:
try:
entries = ctx.opendir ("smb://").getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.ENOENT:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException ()
store.clear ()
try:
debug = 0
if get_debugging ():
debug = 10
if auth_set:
# No prompting.
def do_auth (svr, shr, wg, un, pw):
return (group, user, passwd)
ctx = pysmb.smbc.Context (debug=debug, auth_fn=do_auth)
f = ctx.open ("smb://%s/%s" % (host, share),
os.O_RDWR, 0777)
accessible = True
else:
# May need to prompt.
smbc_auth = pysmb.AuthContext (self.NewPrinterWindow,
workgroup=group,
user=user,
passwd=passwd)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
while smbc_auth.perform_authentication () > 0:
try:
f = ctx.open ("smb://%s/%s" % (host, share),
os.O_RDWR, 0777)
accessible = True
except Exception, e:
smbc_auth.failed (e)
if not accessible:
canceled = True
except RuntimeError, (e, s):
ready (self.SMBBrowseDialog)
elif entry.smbc_type == pysmb.smbc.SERVER:
# Server
try:
if self.expanding_row:
return
except:
self.expanding_row = 1
busy (self.SMBBrowseDialog)
uri = "smb://%s/" % entry.name
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
shares = []
try:
while smbc_auth.perform_authentication () > 0:
try:
shares = ctx.opendir (uri).getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.EACCES and e != errno.EPERM:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException()
while model.iter_has_child (iter):
# Workgroup
# Be careful though: if there is a server with the
# same name as the workgroup we will get a list of its
# shares, not the workgroup's servers.
try:
if self.expanding_row:
return
except:
self.expanding_row = 1
busy (self.SMBBrowseDialog)
uri = "smb://%s/" % entry.name
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
entries = []
try:
while smbc_auth.perform_authentication () > 0:
try:
entries = ctx.opendir (uri).getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.ENOENT:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException()
while model.iter_has_child (iter):
elif entry.smbc_type == pysmb.smbc.SERVER:
# Server
try:
if self.expanding_row:
return
except:
self.expanding_row = 1
busy (self.SMBBrowseDialog)
uri = "smb://%s/" % entry.name
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
shares = []
try:
while smbc_auth.perform_authentication () > 0:
try:
shares = ctx.opendir (uri).getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.EACCES and e != errno.EPERM:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException()
while model.iter_has_child (iter):
i = model.iter_nth_child (iter, 0)
busy(self.SMBBrowseDialog)
class X:
pass
dummy = X()
dummy.smbc_type = pysmb.smbc.PRINTER_SHARE
dummy.name = _('Scanning...')
dummy.comment = ''
store.append(None, [dummy])
while gtk.events_pending ():
gtk.main_iteration ()
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
entries = None
try:
while smbc_auth.perform_authentication () > 0:
try:
entries = ctx.opendir ("smb://").getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.ENOENT:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException ()
store.clear ()
if entries:
user = self.entSMBUsername.get_text ()
passwd = self.entSMBPassword.get_text ()
accessible = False
canceled = False
busy (self.NewPrinterWindow)
try:
debug = 0
if get_debugging ():
debug = 10
if auth_set:
# No prompting.
def do_auth (svr, shr, wg, un, pw):
return (group, user, passwd)
ctx = pysmb.smbc.Context (debug=debug, auth_fn=do_auth)
f = ctx.open ("smb://%s/%s" % (host, share),
os.O_RDWR, 0777)
accessible = True
else:
# May need to prompt.
smbc_auth = pysmb.AuthContext (self.NewPrinterWindow,
workgroup=group,
user=user,
passwd=passwd)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
while smbc_auth.perform_authentication () > 0:
try:
f = ctx.open ("smb://%s/%s" % (host, share),
os.O_RDWR, 0777)
accessible = True
# Be careful though: if there is a server with the
# same name as the workgroup we will get a list of its
# shares, not the workgroup's servers.
try:
if self.expanding_row:
return
except:
self.expanding_row = 1
busy (self.SMBBrowseDialog)
uri = "smb://%s/" % entry.name
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
ctx = pysmb.smbc.Context (debug=debug,
auth_fn=smbc_auth.callback)
entries = []
try:
while smbc_auth.perform_authentication () > 0:
try:
entries = ctx.opendir (uri).getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.ENOENT:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException()
while model.iter_has_child (iter):
i = model.iter_nth_child (iter, 0)
def on_tvSMBBrowser_row_expanded (self, view, iter, path):
"""Handler for expanding a row in the SMB tree view."""
model = view.get_model ()
entry = model.get_value (iter, 0)
if entry == None:
return
if entry.smbc_type == pysmb.smbc.WORKGROUP:
# Workgroup
# Be careful though: if there is a server with the
# same name as the workgroup we will get a list of its
# shares, not the workgroup's servers.
try:
if self.expanding_row:
return
except:
self.expanding_row = 1
busy (self.SMBBrowseDialog)
uri = "smb://%s/" % entry.name
debug = 0
if get_debugging ():
debug = 10
smbc_auth = pysmb.AuthContext (self.SMBBrowseDialog)
try:
entries = ctx.opendir (uri).getdents ()
except Exception, e:
smbc_auth.failed (e)
except RuntimeError, (e, s):
if e != errno.ENOENT:
debugprint ("Runtime error: %s" % repr ((e, s)))
except:
nonfatalException()
while model.iter_has_child (iter):
i = model.iter_nth_child (iter, 0)
model.remove (i)
for entry in entries:
if entry.smbc_type in [pysmb.smbc.SERVER,
pysmb.smbc.PRINTER_SHARE]:
i = model.append (iter, [entry])
if entry.smbc_type == pysmb.smbc.SERVER:
n = model.append (i)
view.expand_row (path, 0)
del self.expanding_row
ready (self.SMBBrowseDialog)
elif entry.smbc_type == pysmb.smbc.SERVER:
# Server
try:
if self.expanding_row:
return
except:
self.expanding_row = 1