我们从Python开源项目中,提取了以下23个代码示例,用于说明如何使用__builtin__.print()。
def show_banner(self): banner = open(os.path.join(self.data_path, 'banner.txt')).read() banner_len = len(max(banner.split('\n'), key=len)) / 2 print(framework.Colors.N + banner + framework.Colors.N) # print('{0:^{1}}'.format('%s[%s v%s, %s]%s' % (framework.Colors.G, self._name, __version__, __author__, framework.Colors.N), banner_len+8)) # +8 compensates for the color bytes # print('%s[%s v%s, %s]%s' % (framework.Colors.B, self._name, __version__, __author__, framework.Colors.N), banner_len+8) # +8 compensates for the color bytes print('') counts = [(self.loaded_category[x], x) for x in self.loaded_category] count_len = len(max([str(x[0]) for x in counts], key=len)) for count in sorted(counts, reverse=True): cnt = '[%d]' % (count[0]) print('%s%s %s modules%s' % (framework.Colors.B, cnt.ljust(count_len+2), count[1].title(), framework.Colors.N)) # create dynamic easter egg command based on counts setattr(self, 'do_%d' % count[0], self._menu_egg) print('') #================================================== # COMMAND METHODS #==================================================
def do_workspaces(self, params): '''Manages workspaces''' if not params: self.help_workspaces() return params = params.split() arg = params.pop(0).lower() if arg == 'list': self.table([[x] for x in self._get_workspaces()], header=['Workspaces']) elif arg in ['add', 'select']: if len(params) == 1: if not self.init_workspace(params[0]): self.output('Unable to initialize \'%s\' workspace.' % (params[0])) else: print('Usage: workspace [add|select] <name>') elif arg == 'delete': if len(params) == 1: if not self.delete_workspace(params[0]): self.output('Unable to delete \'%s\' workspace.' % (params[0])) else: print('Usage: workspace delete <name>') else: self.help_workspaces()
def print(*args, **kwargs): sep = _get_print_kwarg(kwargs, 'sep') end = _get_print_kwarg(kwargs, 'end') stdout = sys.stdout file = kwargs.get('file') if file is None: file = stdout l = len(args) for i in xrange(l): arg = args[i] if isinstance(arg, str): pass elif isinstance(arg, unicode): if file is stdout: arg = arg.encode(file.encoding, 'ignore') else: arg = arg.encode(file.encoding) else: arg = str(arg) file.write(arg) if i + 1 < l: file.write(sep) file.write(end)
def _menu_egg(self, params): eggs = [ 'Really? A menu option? Try again.', 'You clearly need \'help\'.', 'That makes no sense to me.', '*grunt* *grunt* Nope. I got nothin\'.', 'Wait for it...', 'This is not the Social Engineering Toolkit.', 'Don\'t you think if that worked the numbers would at least be in order?', 'Reserving that option for the next-NEXT generation of the framework.', 'You\'ve clearly got the wrong framework. Attempting to start SET...', 'Your mother called. She wants her menu driven UI back.', 'What\'s the samurai password?' ] print(random.choice(eggs)) return #================================================== # WORKSPACE METHODS #==================================================
def oprint(level, string): """ Helper for printing to stdout Parameters --------- level: integer print level of the string (0: None, 1: results, 3: +progress, 4+: excess) string: string string to be printed """ if settings.print_level >= level: __builtin__.print(string)
def eprint(level, string): """ Helper for printing to stderr Parameters --------- level: integer print level of the string (0: None, 1: errors, 2: +warnings, 4+: excess) string: string string to be printed """ if settings.print_level >= level: __builtin__.print(string, file = sys.stderr)
def spool_print(*args, **kwargs): with _print_lock: if framework.Framework._spool: framework.Framework._spool.write('%s\n' % (args[0])) framework.Framework._spool.flush() if 'console' in kwargs and kwargs['console'] is False: return # new print function must still use the old print function via the backup __builtin__._print(*args, **kwargs) # make a builtin backup of the original print function
def do_snapshots(self, params): '''Manages workspace snapshots''' if not params: self.help_snapshots() return params = params.split() arg = params.pop(0).lower() if arg == 'list': snapshots = self._get_snapshots() if snapshots: self.table([[x] for x in snapshots], header=['Snapshots']) else: self.output('This workspace has no snapshots.') elif arg == 'take': from datetime import datetime snapshot = 'snapshot_%s.db' % (datetime.strftime(datetime.now(), '%Y%m%d%H%M%S')) src = os.path.join(self.workspace, 'data.db') dst = os.path.join(self.workspace, snapshot) shutil.copyfile(src, dst) self.output('Snapshot created: %s' % (snapshot)) elif arg == 'load': if len(params) == 1: # warn about overwriting current state if params[0] in self._get_snapshots(): src = os.path.join(self.workspace, params[0]) dst = os.path.join(self.workspace, 'data.db') shutil.copyfile(src, dst) self.output('Snapshot loaded: %s' % (params[0])) else: self.error('No snapshot named \'%s\'.' % (params[0])) else: print('Usage: snapshots [load] <name>') elif arg == 'delete': if len(params) == 1: if params[0] in self._get_snapshots(): os.remove(os.path.join(self.workspace, params[0])) self.output('Snapshot removed: %s' % (params[0])) else: self.error('No snapshot named \'%s\'.' % (params[0])) else: print('Usage: snapshots [delete] <name>') else: self.help_snapshots()
def help_workspaces(self): print(getattr(self, 'do_workspaces').__doc__) print('') print('Usage: workspaces [list|add|select|delete]') print('')
def help_snapshots(self): print(getattr(self, 'do_snapshots').__doc__) print('') print('Usage: snapshots [list|take|load|delete]') print('') #================================================== # COMPLETE METHODS #==================================================
def show_banner(self): banner = open(os.path.join(self.data_path, 'banner.txt')).read() banner_len = len(max(banner.split('\n'), key=len)) print(banner) print('{0:^{1}}'.format('%s[%s v%s, %s]%s' % (framework.Colors.O, self._name, __version__, __author__, framework.Colors.N), banner_len+8)) # +8 compensates for the color bytes print('') counts = [(self.loaded_category[x], x) for x in self.loaded_category] count_len = len(max([str(x[0]) for x in counts], key=len)) for count in sorted(counts, reverse=True): cnt = '[%d]' % (count[0]) print('%s%s %s modules%s' % (framework.Colors.B, cnt.ljust(count_len+2), count[1].title(), framework.Colors.N)) # create dynamic easter egg command based on counts setattr(self, 'do_%d' % count[0], self._menu_egg) print('')