123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- import unicodedata
- import string
- import re
- import struct
- def unicode_test(value):
- name = unicodedata.name(value)
- value2 = unicodedata.lookup(name)
- print('value = "%s", name = "%s", value2 = "%s"' % (value, name, value2))
- def unicode_test2():
- u_umlaut = '\N{LATIN SMALL LETTER U WITH DIAERESIS}'
- drink = 'Gew' + u_umlaut + 'rztraminer'
- print(drink)
- def encode_test():
- snowman = '\u2603'
- ds = snowman.encode('utf-8')
- print(ds)
- def decode_test():
- place = 'caf\u00e9'
- place_bytes = place.encode('utf-8')
- print(place_bytes)
- print(place_bytes.decode('utf-8'))
-
- def re_test():
- printable =string.printable
- print(printable)
- l1 = re.findall('\w', printable)
- print(l1)
- l2 = re.findall('\s', printable)
- print(l2)
-
- def re_template_1():
- source = '''I wish I may, I wish I might
- ... Have a dish of fish tonight.'''
-
- print(re.findall('wish', source))
-
- print(re.findall('wish|fish', source))
-
- print(re.findall('^wish', source))
-
- print(re.findall('^I wish', source))
-
-
-
- print(re.findall('fish tonight.$', source))
-
- print(re.findall('[wsh]+', source))
- def test_struct_1():
- valid_png_header = b'\x89PNG\r\n\x1a\n'
- data = b'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR' + \
- b'\x00\x00\x00\x9a\x00\x00\x00\x8d\x08\x02\x00\x00\x00\xc0'
- if data[:8] == valid_png_header:
- width, height = struct.unpack('>LL', data[16:24])
- print('Valid PNG, width', width, 'height', height)
- else:
- print('Not a valid PNG')
- def test_struct_2():
- print(struct.pack('>L', 154))
- test_struct_2()
|