python类ljust()的实例源码

nmb.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def encode_name(name, type, scope):
    if name == '*':
        name += '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0'

# Internal method for use in encode_name()
utils.py 文件源码 项目:00scanner 作者: xiaoqin00 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def encode_name(name, type, scope = None):
    """
    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
    """
    if name == '*':
        name = name + '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    def _do_first_level_encoding(m):
        s = ord(m.group(0))
        return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0'
XpmImagePlugin.py 文件源码 项目:CNCGToolKit 作者: cineuse 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def load_read(self, bytes):

        #
        # load all image data in one chunk

        xsize, ysize = self.size

        s = [None] * ysize

        for i in range(ysize):
            s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize)

        self.fp = None

        return string.join(s, "")

#
# Registry
utils.py 文件源码 项目:xunfengES 作者: superhuahua 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def encode_name(name, type, scope = None):
    """
    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
    """
    if name == '*':
        name = name + '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    def _do_first_level_encoding(m):
        s = ord(m.group(0))
        return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0'
utils.py 文件源码 项目:xunfengES 作者: superhuahua 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def encode_name(name, type, scope = None):
    """
    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
    """
    if name == '*':
        name = name + '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    def _do_first_level_encoding(m):
        s = ord(m.group(0))
        return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0'
utils.py 文件源码 项目:addon 作者: alfa-addon 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def encode_name(name, type, scope = None):
    """
    Perform first and second level encoding of name as specified in RFC 1001 (Section 4)
    """
    if name == '*':
        name = name + '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    def _do_first_level_encoding(m):
        s = ord(m.group(0))
        return string.uppercase[s >> 4] + string.uppercase[s & 0x0f]

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name + '\0'
robust_multi_agent_optimal_run.py 文件源码 项目:lomap 作者: wasserfeder 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def pretty_print(agent_cnt, prefix, suffix):
    import string
    # Pretty print the prefix and suffix_cycle on team_ts
    hdr_line_1 = ''
    hdr_line_2 = ''
    for i in range(0,agent_cnt):
        hdr_line_1 += string.ljust('Robot-%d' % (i+1), 20)
        hdr_line_2 += string.ljust('-------', 20)
    logger.info(hdr_line_1)
    logger.info(hdr_line_2)

    logger.info('*** Prefix: ***')
    for s in prefix:
        line = ''
        for ss in s:
            line += string.ljust('%s' % (ss,), 20)
        logger.info(line)

    logger.info('*** Suffix: ***')
    for s in suffix:
        line = ''
        for ss in s:
            line += string.ljust('%s' % (ss,), 20)
        logger.info(line)
multi_agent_optimal_run.py 文件源码 项目:lomap 作者: wasserfeder 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def pretty_print(agent_cnt, prefix, suffix):
    import string
    # Pretty print the prefix and suffix_cycle on team_ts
    hdr_line_1 = ''
    hdr_line_2 = ''
    for i in range(0,agent_cnt):
        hdr_line_1 += string.ljust('Robot-%d' % (i+1), 20)
        hdr_line_2 += string.ljust('-------', 20)
    logger.info(hdr_line_1)
    logger.info(hdr_line_2)

    logger.info('*** Prefix: ***')
    for s in prefix:
        line = ''
        for ss in s:
            line += string.ljust('%s' % (ss,), 20)
        logger.info(line)

    logger.info('*** Suffix: ***')
    for s in suffix:
        line = ''
        for ss in s:
            line += string.ljust('%s' % (ss,), 20)
        logger.info(line)
nmb.py 文件源码 项目:HoneySMB 作者: r0hi7 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def encode_name(name, type, scope):
    if name == '*':
        name += '\0' * 15
    elif len(name) > 15:
        name = name[:15] + chr(type)
    else:
        name = string.ljust(name, 15) + chr(type)

    encoded_name = chr(len(name) * 2) + re.sub('.', _do_first_level_encoding, name)
    if scope:
        encoded_scope = ''
        for s in string.split(scope, '.'):
            encoded_scope = encoded_scope + chr(len(s)) + s
        return encoded_name + encoded_scope + '\0'
    else:
        return encoded_name.encode('ascii') + '\0'

# Internal method for use in encode_name()
XpmImagePlugin.py 文件源码 项目:InstagramPosting 作者: LeviParadis 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def load_read(self, bytes):

        #
        # load all image data in one chunk

        xsize, ysize = self.size

        s = [None] * ysize

        for i in range(ysize):
            s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize)

        self.fp = None

        return string.join(s, "")

#
# Registry
XpmImagePlugin.py 文件源码 项目:ngx_status 作者: YoYoAdorkable 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def load_read(self, bytes):

        #
        # load all image data in one chunk

        xsize, ysize = self.size

        s = [None] * ysize

        for i in range(ysize):
            s[i] = string.ljust(self.fp.readline()[1:xsize+1], xsize)

        self.fp = None

        return string.join(s, "")

#
# Registry
recipe-52194.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __str__(self):
    classStr = ''
    for name, value in self.__class__.__dict__.items( ) + self.__dict__.items( ): 
        classStr += string.ljust( name, 15 ) + '\t' + str( value ) + '\n'
    return classStr
core.py 文件源码 项目:logdissect 作者: dogoncouch 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def list_parsers(self, *args):
        """Return a list of available parsing modules"""
        print('==== Available parsing modules: ====\n')
        for parser in sorted(self.parse_modules):
            print(string.ljust(self.parse_modules[parser].name, 16) + \
                ': ' + self.parse_modules[parser].desc)
        sys.exit(0)
UEFfile.py 文件源码 项目:electron-cassette-io 作者: stardot 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def cat(self):
        """
        Prints a catalogue of the files stored in the UEF file.
        """

        # Catalogue command

        if self.contents == []:

            print 'No files'

        else:

            print 'Contents:'

            file_number = 0

            for file in self.contents:

                # Converts non printable characters in the filename
                # to ? symbols
                new_name = self.printable(file['name'])

                print string.expandtabs(string.ljust(str(file_number), 3)+': '+
                            string.ljust(new_name, 16)+
                            string.upper(
                                string.ljust(hex(file['load'])[2:], 10) +'\t'+
                                string.ljust(hex(file['exec'])[2:], 10) +'\t'+
                                string.ljust(hex(len(file['data']))[2:], 6)
                            ) +'\t'+
                            'chunks %i to %i' % (file['position'], file['last position']) )

                file_number = file_number + 1
vnh.py 文件源码 项目:swift 作者: nsg-ethz 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def insert_primary_rules(self, primary_ip):
        primary_tag = self.tag_dic[primary_ip]
        tmp_mac = bin(primary_tag)[2:]
        tmp_mac = tmp_mac.zfill(self.nexthops_nb_bits)

        tmp_mac = string.ljust(tmp_mac, 48, '0')

        bitmask = string.ljust('', self.nexthops_nb_bits, '1')
        bitmask = string.ljust(bitmask, 48, '0')

        try:
            real_mac = self.mapping_real[primary_ip][0]
            outport = self.mapping_real[primary_ip][1]
        except KeyError:
            real_mac = 'unknown'
            outport = 'unknown'

        # Binary to Hexadecimal conversion
        tmp_mac = hex(int(tmp_mac, 2))[2:].zfill(12)
        bitmask = hex(int(bitmask, 2))[2:].zfill(12)

        tmp_mac = ':'.join(s.encode('hex') for s in tmp_mac.decode('hex'))
        bitmask = ':'.join(s.encode('hex') for s in bitmask.decode('hex'))

        self.fd_rules.write('ovs-ofctl add-flow s1 priority=10,dl_dst='+tmp_mac+'/'+bitmask+',actions=mod_dl_dst:'+real_mac+',output:'+outport+'\n')
        os.system('ovs-ofctl add-flow s1 priority=10,dl_dst='+tmp_mac+'/'+bitmask+',actions=mod_dl_dst:'+real_mac+',output:'+outport)
nmb.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def __init__(self, nbname, nametype, flags): 
        self.__nbname = string.ljust(nbname,17)
        self.__nametype = nametype
        self.__flags = flags
        self.__isgroup = flags & 0x8000
        self.__nodetype = flags & 0x6000
        self.__deleting = flags & 0x1000
        self.__isconflict = flags & 0x0800
        self.__isactive = flags & 0x0400
        self.__ispermanent = flags & 0x0200
nmb.py 文件源码 项目:kekescan 作者: xiaoxiaoleo 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def set_nbname(self, name):
        self.__nbname = string.ljust(name,17)
segyfactory.py 文件源码 项目:PH5 作者: PIC-IRIS 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def set_ext_header_pas (self) :
        ext = {}
        self.extended_header = segy_h.Passcal ()

        cor_low, cor_high, sort_start_time = self._cor ()
        if cor_high < -MAX_16 or cor_high > MAX_16 :
            #print cor_high
            cor_high = int (MAX_16)

        ext['totalStaticHi'] = cor_high
        ext['num_samps'] = int (self.length_points)
        ext['max'] = numpy.max (self.data)
        ext['min'] = numpy.min (self.data)
        ext['samp_rate'] = int ((1.0 / self.sample_rate) * 1000000.0)
        ext['data_form'] = 1   #   32 bit
        #   *XXX*  Is this also set where the trace is written?
        ext['scale_fac'] = float (self.response_t['bit_weight/value_d'])
        #ext['scale_fac'] = 1. / 184128195.173

        corrected_start_time = self.cut_start_epoch + (cor_low / 1000.0)
        m_secs = int (math.modf (corrected_start_time)[0] * 1000.0)
        ext['m_secs'] = m_secs

        try :
            ttuple = time.gmtime ([self.event_t['time/epoch_l']])
            ext['trigyear'] = ttuple[0]
            ext['trigday'] = ttuple[7]
            ext['trighour'] = ttuple[3]
            ext['trigminute'] = ttuple[4]
            ext['trigsecond'] = ttuple[5]
            ext['trigmills'] = int (self.event_t['time/micro_seconds_i'] / 1000.0)
        except :
            pass

        try :
            try :
                ext['inst_no'] = int (self.array_t['das/serial_number_s']) & 0xFFFF
            except ValueError :
                ext['inst_no'] = int (self.array_t['das/serial_number_s'], 16)
        except :
            ext['inst_no'] = 0

        try :
            ext['station_name'] = string.ljust (string.strip (self.array_t['id_s']), 6)
        except :
            ext['station_name'] = string.ljust (string.strip (self.array_t['das/serial_number_s']), 6)

        return ext
polytope.py 文件源码 项目:base-robot-2016 作者: frc1678 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _SplitAndPad(s):
  """Splits a string on newlines, and pads the lines to be the same width."""
  split_string = s.split('\n')
  width = max(len(stringpiece) for stringpiece in split_string) + 1

  padded_strings = [string.ljust(stringpiece, width, ' ')
                        for stringpiece in split_string]
  return padded_strings
sfactory.py 文件源码 项目:PH5 作者: PIC-IRIS 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def set_ext_header_pas (self) :
        ext = {}
        self.extended_header = segy_h.Passcal ()

        cor_low, cor_high, sort_start_time = self._cor ()
        if cor_high < -MAX_16 or cor_high > MAX_16 :
            #print cor_high
            cor_high = int (MAX_16)

        ext['totalStaticHi'] = cor_high
        ext['num_samps'] = int (self.length_points)
        ext['max'] = numpy.max (self.data)
        ext['min'] = numpy.min (self.data)
        ext['samp_rate'] = int ((1.0 / self.sample_rate) * 1000000.0)
        ext['data_form'] = 1   #   32 bit
        ext['scale_fac'] = float (self.response_t['bit_weight/value_d'])

        corrected_start_time = self.cut_start_epoch + (cor_low / 1000.0)
        m_secs = int (math.modf (corrected_start_time)[0] * 1000.0)
        ext['m_secs'] = m_secs

        try :
            ttuple = time.gmtime ([self.event_t['time/epoch_l']])
            ext['trigyear'] = ttuple[0]
            ext['trigday'] = ttuple[7]
            ext['trighour'] = ttuple[3]
            ext['trigminute'] = ttuple[4]
            ext['trigsecond'] = ttuple[5]
            ext['trigmills'] = int (self.event_t['time/micro_seconds_i'] / 1000.0)
        except :
            pass

        try :
            try :
                ext['inst_no'] = int (self.array_t['das/serial_number_s'])
            except ValueError :
                ext['inst_no'] = int (self.array_t['das/serial_number_s'], 16)
        except :
            ext['inst_no'] = 0

        try :
            ext['station_name'] = string.ljust (string.strip (self.array_t['id_s']), 6)
        except :
            ext['station_name'] = string.ljust (string.strip (self.array_t['das/serial_number_s']), 6)

        return ext


问题


面经


文章

微信
公众号

扫码关注公众号