Python string.zfill() Examples

The following are 16 code examples of string.zfill(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module string , or try the search function .
Example #1
Source File: cache.py    From tileserver with MIT License 6 votes vote down vote up
def _generate_key(self, key_type, cache_key):
        x_fill = zfill(cache_key.coord.column, 9)
        y_fill = zfill(cache_key.coord.row, 9)

        return os.path.join(
            self.prefix,
            str(cache_key.tile_size),
            cache_key.layers,
            zfill(cache_key.coord.zoom, 2),
            x_fill[0:3],
            x_fill[3:6],
            x_fill[6:9],
            y_fill[0:3],
            y_fill[3:6],
            '{}.{}.{}'.format(y_fill[6:9], cache_key.fmt.extension, key_type),
        ) 
Example #2
Source File: ttx.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def ttList(input, output, options):
	import string
	ttf = TTFont(input, fontNumber=options.fontNumber)
	reader = ttf.reader
	tags = reader.keys()
	tags.sort()
	print 'Listing table info for "%s":' % input
	format = "    %4s  %10s  %7s  %7s"
	print format % ("tag ", "  checksum", " length", " offset")
	print format % ("----", "----------", "-------", "-------")
	for tag in tags:
		entry = reader.tables[tag]
		checkSum = long(entry.checkSum)
		if checkSum < 0:
			checkSum = checkSum + 0x100000000L
		checksum = "0x" + string.zfill(hex(checkSum)[2:-1], 8)
		print format % (tag, checksum, entry.length, entry.offset)
	print
	ttf.close() 
Example #3
Source File: cffLib.py    From stdm with GNU General Public License v2.0 6 votes vote down vote up
def parseCharset(numGlyphs, file, strings, isCID, format):
	charset = ['.notdef']
	count = 1
	if format == 1:
		nLeftFunc = readCard8
	else:
		nLeftFunc = readCard16
	while count < numGlyphs:
		first = readCard16(file)
		nLeft = nLeftFunc(file)
		if isCID:
			for CID in range(first, first+nLeft+1):
				charset.append("cid" + string.zfill(str(CID), 5) )
		else:
			for SID in range(first, first+nLeft+1):
				charset.append(strings[SID])
		count = count + nLeft + 1
	return charset 
Example #4
Source File: imap4.py    From python-for-android with Apache License 2.0 6 votes vote down vote up
def spew_internaldate(self, id, msg, _w=None, _f=None):
        if _w is None:
            _w = self.transport.write
        idate = msg.getInternalDate()
        ttup = rfc822.parsedate_tz(idate)
        if ttup is None:
            log.msg("%d:%r: unpareseable internaldate: %r" % (id, msg, idate))
            raise IMAP4Exception("Internal failure generating INTERNALDATE")

        odate = time.strftime("%d-%b-%Y %H:%M:%S ", ttup[:9])
        if ttup[9] is None:
            odate = odate + "+0000"
        else:
            if ttup[9] >= 0:
                sign = "+"
            else:
                sign = "-"
            odate = odate + sign + string.zfill(str(((abs(ttup[9]) / 3600) * 100 + (abs(ttup[9]) % 3600) / 60)), 4)
        _w('INTERNALDATE ' + _quote(odate)) 
Example #5
Source File: imap4.py    From BitTorrent with GNU General Public License v3.0 6 votes vote down vote up
def spew_internaldate(self, id, msg, _w=None, _f=None):
        if _w is None:
            _w = self.transport.write
        idate = msg.getInternalDate()
        ttup = rfc822.parsedate_tz(idate)
        if ttup is None:
            log.msg("%d:%r: unpareseable internaldate: %r" % (id, msg, idate))
            raise IMAP4Exception("Internal failure generating INTERNALDATE")

        odate = time.strftime("%d-%b-%Y %H:%M:%S ", ttup[:9])
        if ttup[9] is None:
            odate = odate + "+0000"
        else:
            if ttup[9] >= 0:
                sign = "+"
            else:
                sign = "-"
            odate = odate + sign + string.zfill(str(((abs(ttup[9]) / 3600) * 100 + (abs(ttup[9]) % 3600) / 60)), 4)
        _w('INTERNALDATE ' + _quote(odate)) 
Example #6
Source File: fig24_04.py    From PythonClassBook with GNU General Public License v3.0 5 votes vote down vote up
def updateTime( self ):
      """Update time display if disc is loaded"""

      if self.CD.get_init():
         seconds = int( self.CD.get_current()[ 1 ] )
         endSeconds = int( self.CD.get_track_length(
            self.currentTrack - 1 ) )

         # if reached end of current track, play next track
         if seconds >= ( endSeconds - 1 ):
            self.nextTrack()
         else:      
            minutes = seconds / 60
            endMinutes = endSeconds / 60
            seconds = seconds - ( minutes * 60 )
            endSeconds = endSeconds - ( endMinutes * 60 )

            # display time in format mm:ss/mm:ss   
            trackTime = string.zfill( str( minutes ), 2 ) + \
               ":" + string.zfill( str( seconds ), 2 )
            endTime = string.zfill( str( endMinutes ), 2 ) +  \
               ":" + string.zfill( str( endSeconds ), 2 )

            if self.CD.get_paused():
      
               # alternate pause symbol and time in display
               if not self.timeLabel.get() == "     ||    ":
                  self.timeLabel.set( "     ||    " )
               else:
                  self.timeLabel.set( trackTime + "/" + endTime )

            else:
               self.timeLabel.set( trackTime + "/" + endTime )

      # call updateTime method again after 1000ms ( 1 second )
      self.after( 1000, self.updateTime ) 
Example #7
Source File: tntwrapper.py    From 20up with GNU General Public License v3.0 5 votes vote down vote up
def getFullName(picture, counter):
    return normalize(string.zfill(counter, CONSTANT_FILL) + '_' + picture[2] + '_' + picture[1]) 
Example #8
Source File: VideoCapture.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def now():
    """Returns a string containing the current date and time.

    This function is used internally by VideoCapture to generate the timestamp
    with which a snapshot can optionally be marked.

    """
    weekday = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
    #weekday = ('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So')
    #weekday = ('-', '-', '-', '-', '-', '-', '-')
    y, m, d, hr, min, sec, wd, jd, dst = time.localtime(time.time())
    return '%s:%s:%s %s %s.%s.%s' % (string.zfill(hr, 2), string.zfill(min, 2), string.zfill(sec, 2), weekday[wd], d, m, y) 
Example #9
Source File: VideoCapture.py    From NoobSec-Toolkit with GNU General Public License v2.0 5 votes vote down vote up
def now():
    """Returns a string containing the current date and time.

    This function is used internally by VideoCapture to generate the timestamp
    with which a snapshot can optionally be marked.

    """
    weekday = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
    #weekday = ('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So')
    #weekday = ('-', '-', '-', '-', '-', '-', '-')
    y, m, d, hr, min, sec, wd, jd, dst = time.localtime(time.time())
    return '%s:%s:%s %s %s.%s.%s' % (string.zfill(hr, 2), string.zfill(min, 2), string.zfill(sec, 2), weekday[wd], d, m, y) 
Example #10
Source File: recipe-442460.py    From code with MIT License 5 votes vote down vote up
def increment(s):
    """ look for the last sequence of number(s) in a string and increment """
    if numbers.findall(s):
        lastoccr_sre = list(numbers.finditer(s))[-1]
        lastoccr = lastoccr_sre.group()
        lastoccr_incr = str(int(lastoccr) + 1)
        if len(lastoccr) > len(lastoccr_incr):
            lastoccr_incr = zfill(lastoccr_incr, len(lastoccr))
        return s[:lastoccr_sre.start()]+lastoccr_incr+s[lastoccr_sre.end():]

    return s 
Example #11
Source File: cffLib.py    From stdm with GNU General Public License v2.0 5 votes vote down vote up
def parseCharset0(numGlyphs, file, strings, isCID):
	charset = [".notdef"]
	if isCID:
		for i in range(numGlyphs - 1):
			CID = readCard16(file)
			charset.append("cid" + string.zfill(str(CID), 5) )
	else:
		for i in range(numGlyphs - 1):
			SID = readCard16(file)
			charset.append(strings[SID])
	return charset 
Example #12
Source File: HMAC.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def hexdigest(self):
        """Like digest(), but returns a string of hexadecimal digits instead.
        """
        return "".join([string.zfill(hex(ord(x))[2:], 2)
                        for x in tuple(self.digest())]) 
Example #13
Source File: HMAC.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def hexdigest(self):
        """Like digest(), but returns a string of hexadecimal digits instead.
        """
        return "".join([string.zfill(hex(ord(x))[2:], 2)
                        for x in tuple(self.digest())]) 
Example #14
Source File: HMAC.py    From python-for-android with Apache License 2.0 5 votes vote down vote up
def hexdigest(self):
        """Like digest(), but returns a string of hexadecimal digits instead.
        """
        return "".join([string.zfill(hex(ord(x))[2:], 2)
                        for x in tuple(self.digest())]) 
Example #15
Source File: VideoCapture.py    From backdoorme with MIT License 5 votes vote down vote up
def now():
    """Returns a string containing the current date and time.

    This function is used internally by VideoCapture to generate the timestamp
    with which a snapshot can optionally be marked.

    """
    weekday = ('Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun')
    #weekday = ('Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So')
    #weekday = ('-', '-', '-', '-', '-', '-', '-')
    y, m, d, hr, min, sec, wd, jd, dst = time.localtime(time.time())
    return '%s:%s:%s %s %s.%s.%s' % (string.zfill(hr, 2), string.zfill(min, 2), string.zfill(sec, 2), weekday[wd], d, m, y) 
Example #16
Source File: text2pdf.py    From yap with Apache License 2.0 4 votes vote down vote up
def WriteRest(self):
        """Finish the file"""

        ws = self.writestr
        self._locations[3] = self._fpos

        ws("3 0 obj\n")
        ws("<<\n")
        ws("/Type /Pages\n")
        buf = "".join(("/Count ", str(self._pageNo), "\n"))
        ws(buf)
        buf = "".join(
            ("/MediaBox [ 0 0 ", str(self._pageWd), " ", str(self._pageHt), " ]\n"))
        ws(buf)
        ws("/Kids [ ")

        for i in range(1, self._pageNo + 1):
            buf = "".join((str(self._pageObs[i]), " 0 R "))
            ws(buf)

        ws("]\n")
        ws(">>\n")
        ws("endobj\n")

        xref = self._fpos
        ws("xref\n")
        buf = "".join(("0 ", str((self._curobj) + 1), "\n"))
        ws(buf)
        buf = "".join(("0000000000 65535 f ", str(LINE_END)))
        ws(buf)

        for i in range(1, self._curobj + 1):
            val = self._locations[i]
            buf = "".join(
                (string.zfill(str(val), 10), " 00000 n ", str(LINE_END)))
            ws(buf)

        ws("trailer\n")
        ws("<<\n")
        buf = "".join(("/Size ", str(self._curobj + 1), "\n"))
        ws(buf)
        ws("/Root 2 0 R\n")
        ws("/Info 1 0 R\n")
        ws(">>\n")

        ws("startxref\n")
        buf = "".join((str(xref), "\n"))
        ws(buf)
        ws("%%EOF\n")