source: OpenRLabs-Git/deploy/rlabs-docker/web2py-rlabs/gluon/contrib/fpdf/php.py

main
Last change on this file was 42bd667, checked in by David Fuertes <dfuertes@…>, 4 years ago

Historial Limpio

  • Property mode set to 100755
File size: 1.5 KB
Line 
1#!/usr/bin/env python
2# -*- coding: latin-1 -*-
3
4from .py3k import PY3K, basestring, unicode
5
6# fpdf php helpers:
7
8def substr(s, start, length=-1):
9       if length < 0:
10               length=len(s)-start
11       return s[start:start+length]
12
13def sprintf(fmt, *args): return fmt % args
14
15def print_r(array):
16    if not isinstance(array, dict):
17        array = dict([(k, k) for k in array])
18    for k, v in array.items():
19        print("[%s] => %s " % (k, v))
20       
21def UTF8ToUTF16BE(instr, setbom=True):
22    "Converts UTF-8 strings to UTF16-BE."
23    outstr = "".encode()
24    if (setbom):
25        outstr += "\xFE\xFF".encode("latin1")
26    if not isinstance(instr, unicode):
27        instr = instr.decode('UTF-8')
28    outstr += instr.encode('UTF-16BE')
29    # convert bytes back to fake unicode string until PEP461-like is implemented
30    if PY3K:
31        outstr = outstr.decode("latin1")
32    return outstr
33
34def UTF8StringToArray(instr):
35    "Converts UTF-8 strings to codepoints array"
36    return [ord(c) for c in instr]
37
38# ttfints php helpers:   
39
40def die(msg):
41    raise RuntimeError(msg)
42   
43def str_repeat(s, count):
44    return s * count
45   
46def str_pad(s, pad_length=0, pad_char= " ", pad_type= +1 ):
47    if pad_type<0: # pad left
48        return s.rjust(pad_length, pad_char)
49    elif pad_type>0: # pad right
50        return s.ljust(pad_length, pad_char)
51    else: # pad both
52        return s.center(pad_length, pad_char)
53
54strlen = count = lambda s: len(s)
Note: See TracBrowser for help on using the repository browser.