content
stringlengths
7
1.05M
fixed_cases
stringlengths
1
1.28M
class TreeNode: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def construct(inorder, level_order): def helper(inorder): if inorder is None: return None root = TreeNode(level_order.pop(0)) mid = inorder.index(root.val) root.left = helper(inorder[:mid]) root.right = helper(inorder[mid+1:]) return root helper(inorder) def main(): root = TreeNode(20) root.left = TreeNode(8) root.right = TreeNode(22) root.left.left = TreeNode(4) root.left.right = TreeNode(12) root.left.right.left = TreeNode(10) root.left.right.right = TreeNode(4) if __name__ == '__main__': main()
class Treenode: def __init__(self, val, left=None, right=None): self.val = val self.left = left self.right = right def construct(inorder, level_order): def helper(inorder): if inorder is None: return None root = tree_node(level_order.pop(0)) mid = inorder.index(root.val) root.left = helper(inorder[:mid]) root.right = helper(inorder[mid + 1:]) return root helper(inorder) def main(): root = tree_node(20) root.left = tree_node(8) root.right = tree_node(22) root.left.left = tree_node(4) root.left.right = tree_node(12) root.left.right.left = tree_node(10) root.left.right.right = tree_node(4) if __name__ == '__main__': main()
android_desired_caps = { "build": "Python Android", 'device': 'Google Pixel', 'os_version': '7.1', 'appPackage': 'com.auth0.samples', 'appActivity': 'com.auth0.samples.MainActivity', 'app': 'Auth0', 'chromeOptions': { 'androidPackage': 'com.android.chrome' } } android_desired_caps_emulator = { 'platformName': 'android', 'deviceName': 'Nexus_6p', 'appPackage': 'com.auth0.samples', 'appActivity': 'com.auth0.samples.MainActivity', 'chromeOptions': { 'androidPackage': 'com.android.chrome' } } ios_desired_caps = { "platformName": "iOS", "platformVersion": "11.0", "deviceName": "iPhone 7", "automationName": "XCUITest", "app": "/path/to/my.app" } login_user = "asdasd" login_password = "asdasd"
android_desired_caps = {'build': 'Python Android', 'device': 'Google Pixel', 'os_version': '7.1', 'appPackage': 'com.auth0.samples', 'appActivity': 'com.auth0.samples.MainActivity', 'app': 'Auth0', 'chromeOptions': {'androidPackage': 'com.android.chrome'}} android_desired_caps_emulator = {'platformName': 'android', 'deviceName': 'Nexus_6p', 'appPackage': 'com.auth0.samples', 'appActivity': 'com.auth0.samples.MainActivity', 'chromeOptions': {'androidPackage': 'com.android.chrome'}} ios_desired_caps = {'platformName': 'iOS', 'platformVersion': '11.0', 'deviceName': 'iPhone 7', 'automationName': 'XCUITest', 'app': '/path/to/my.app'} login_user = 'asdasd' login_password = 'asdasd'
def to_arabic(roman): table = {"I":1, "V":5, "X":10, "L":50, "C":100, "D":500, "M":1000} n = len(roman) number = 0 for i in range(n): if i < n - 1 and table[roman[i]] < table[roman[i + 1]]: number -= table[roman[i]] else: number += table[roman[i]] return number def to_roman(N): table={1000:'M', 900:'CM', 500:'D', 400:'CD', 100:'C', 90:'XC', 50:'L', 40:'XL', 10:'X', 9:'IX', 5:'V', 4:'IV', 1:'I'} roman = "" for key in table.keys(): while N >= key: roman += table[key] N -= key return roman romans = ["CCCLXIX", "LXXX", "XXIX", "CLV", "XIV", "CDXCII", "CCCXLVIII", "CCCI", "CDLXIX", "CDXCIX"] nums = [369, 80, 29, 155, 14, 492, 348, 301, 469, 499] n = to_arabic(input()) m = to_arabic(input()) print(to_roman(n + m))
def to_arabic(roman): table = {'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000} n = len(roman) number = 0 for i in range(n): if i < n - 1 and table[roman[i]] < table[roman[i + 1]]: number -= table[roman[i]] else: number += table[roman[i]] return number def to_roman(N): table = {1000: 'M', 900: 'CM', 500: 'D', 400: 'CD', 100: 'C', 90: 'XC', 50: 'L', 40: 'XL', 10: 'X', 9: 'IX', 5: 'V', 4: 'IV', 1: 'I'} roman = '' for key in table.keys(): while N >= key: roman += table[key] n -= key return roman romans = ['CCCLXIX', 'LXXX', 'XXIX', 'CLV', 'XIV', 'CDXCII', 'CCCXLVIII', 'CCCI', 'CDLXIX', 'CDXCIX'] nums = [369, 80, 29, 155, 14, 492, 348, 301, 469, 499] n = to_arabic(input()) m = to_arabic(input()) print(to_roman(n + m))
n = int(input()) students_bellow_3 = 0 students_3_4 = 0 students_4_5 = 0 students_above_5 = 0 all_student_scores = 0 for i in range(1, n + 1): student_score = float(input()) all_student_scores += student_score if 2.00 <= student_score <= 2.99: students_bellow_3 += 1 elif 3.00 <= student_score <= 3.99: students_3_4 += 1 elif 4.00 <= student_score <= 4.99: students_4_5 += 1 elif student_score >= 5.00: students_above_5 += 1 students_above_5_perc = students_above_5 / n * 100 students_4_5_perc = students_4_5 / n * 100 students_3_4_perc = students_3_4 / n * 100 students_bellow_3_perc = students_bellow_3 / n * 100 average_score = all_student_scores / n print(f"Top students: {students_above_5_perc:.2f}%") print(f"Between 4.00 and 4.99: {students_4_5_perc:.2f}%") print(f"Between 3.00 and 3.99: {students_3_4_perc:.2f}%") print(f"Fail: {students_bellow_3_perc:.2f}%") print(f"Average: {average_score:.2f}")
n = int(input()) students_bellow_3 = 0 students_3_4 = 0 students_4_5 = 0 students_above_5 = 0 all_student_scores = 0 for i in range(1, n + 1): student_score = float(input()) all_student_scores += student_score if 2.0 <= student_score <= 2.99: students_bellow_3 += 1 elif 3.0 <= student_score <= 3.99: students_3_4 += 1 elif 4.0 <= student_score <= 4.99: students_4_5 += 1 elif student_score >= 5.0: students_above_5 += 1 students_above_5_perc = students_above_5 / n * 100 students_4_5_perc = students_4_5 / n * 100 students_3_4_perc = students_3_4 / n * 100 students_bellow_3_perc = students_bellow_3 / n * 100 average_score = all_student_scores / n print(f'Top students: {students_above_5_perc:.2f}%') print(f'Between 4.00 and 4.99: {students_4_5_perc:.2f}%') print(f'Between 3.00 and 3.99: {students_3_4_perc:.2f}%') print(f'Fail: {students_bellow_3_perc:.2f}%') print(f'Average: {average_score:.2f}')
#Ingresar un numero de 4 digitos; Crea un algoritmo para sumar us digitos. Numero=int(input("Ingresa el Valor: ")) D1=Numero//1000 r1=Numero%1000 D2=r1//100 r2=r1%100 D3=r2//10 D4=r2%10 Suma=D1+D2+D3+D4 print("El resultado es:",Suma) print("orden: ",D1,D2,D3,D4) print("reves",D4,D3,D2,D1)
numero = int(input('Ingresa el Valor: ')) d1 = Numero // 1000 r1 = Numero % 1000 d2 = r1 // 100 r2 = r1 % 100 d3 = r2 // 10 d4 = r2 % 10 suma = D1 + D2 + D3 + D4 print('El resultado es:', Suma) print('orden: ', D1, D2, D3, D4) print('reves', D4, D3, D2, D1)
fname = 'se.zone.txt' names = set() with open(fname, 'r') as f: for line in f: line = line.partition(';')[0].strip() if len(line) == 0: continue domain, *_ = line.split() domain = domain[:-1] # remove trailing dot domain = domain.split('.') if len(domain) == 1: # top level, ignore continue name = domain[-2] names.add(name) with open('se.names.txt', 'w') as f: for name in sorted(names): f.write(name + '\n')
fname = 'se.zone.txt' names = set() with open(fname, 'r') as f: for line in f: line = line.partition(';')[0].strip() if len(line) == 0: continue (domain, *_) = line.split() domain = domain[:-1] domain = domain.split('.') if len(domain) == 1: continue name = domain[-2] names.add(name) with open('se.names.txt', 'w') as f: for name in sorted(names): f.write(name + '\n')
#!/usr/bin/env python # -*- coding: utf-8 -*- class Hint(): def __init__(self, label, value): self.label = label self.value = value def __repr__(self): return '<Hint %r>' % self.label def serialize(self): return { 'label': self.label, 'value': self.value }
class Hint: def __init__(self, label, value): self.label = label self.value = value def __repr__(self): return '<Hint %r>' % self.label def serialize(self): return {'label': self.label, 'value': self.value}
def pre_order(visitor, node): visitor(node) if node.l: pre_order(visitor, node.l) if node.r: pre_order(visitor, node.r) def in_order(visitor, node): if node.l: in_order(visitor, node.l) visitor(node) if node.r: in_order(visitor, node.r) def post_order(visitor, node): if node.l: post_order(visitor, node.l) if node.r: post_order(visitor, node.r) visitor(node) def visit(visitor, iter, order=pre_order): for deriv in iter: order(visitor, deriv.root) yield deriv def match(pattern, iter): for deriv in iter: res = pattern(deriv) if res: yield deriv, res
def pre_order(visitor, node): visitor(node) if node.l: pre_order(visitor, node.l) if node.r: pre_order(visitor, node.r) def in_order(visitor, node): if node.l: in_order(visitor, node.l) visitor(node) if node.r: in_order(visitor, node.r) def post_order(visitor, node): if node.l: post_order(visitor, node.l) if node.r: post_order(visitor, node.r) visitor(node) def visit(visitor, iter, order=pre_order): for deriv in iter: order(visitor, deriv.root) yield deriv def match(pattern, iter): for deriv in iter: res = pattern(deriv) if res: yield (deriv, res)
#Collect name from the user name = input("What is your name? ") #Display the name print(name) #Update the value name = "Mary" print(name) #Create a friendly name firstName = input("What is your first name? " ) lastName = input("What is your first name? " ) print("Hello " + firstName + " " + lastName)
name = input('What is your name? ') print(name) name = 'Mary' print(name) first_name = input('What is your first name? ') last_name = input('What is your first name? ') print('Hello ' + firstName + ' ' + lastName)
def LeiaInt(msg): valor = False resultado = 0 while True: n = (input(msg)) if n.isnumeric(): resultado = int(n) valor = True else: print('ERROR: Digite novamente.') if valor: break return resultado # PROGRAMA n = LeiaInt('Digite um numero: ') print(f'O numero escolhido foi {n}')
def leia_int(msg): valor = False resultado = 0 while True: n = input(msg) if n.isnumeric(): resultado = int(n) valor = True else: print('ERROR: Digite novamente.') if valor: break return resultado n = leia_int('Digite um numero: ') print(f'O numero escolhido foi {n}')
# This script converts a multiple sequence alignment into a matrix # of pairwise sequence identities. # # Aleix Lafita - June 2018 # Input alignment and output identity matrix files alignment_file = "PF06758_A0A87WZJ2.sto" matrix_file = "PF06758_A0A87WZJ2_matrix.tsv" with open(alignment_file, 'r') as input, open(matrix_file, 'w') as output: # Load the alignment into a dictionary alignment = {} domains = [] # Read every line in the alignment file for line in input: # Check for comment lines or separators (Stockholm format) if not line.startswith("#") and not line.startswith("//"): row = line.split() domain_id = row[0] domains.append(domain_id) if domain_id not in alignment.keys(): alignment[domain_id] = {} alignment[domain_id] = row[1].strip("\n") # Compute the sequence identity between all domain pairs output.write("domain1\tdomain2\tpid\n") # Double for loop for each domain pair for i in range(0, len(domains)): domain1 = domains[i] for j in range(i + 1, len(domains)): domain2 = domains[j] length = 0 identicals = 0 # Just a check that the alignment is correct and residues are in position assert len(alignment[domain1]) == len(alignment[domain2]) # Compare each position in the alignment for x in range(0, len(alignment[domain1])): # Check for gaps and aligned residues only if (alignment[domain1][x] != '.' and alignment[domain2][x] != '.' and alignment[domain1][x] != '-' and alignment[domain2][x] != '-' and alignment[domain1][x].isupper() and alignment[domain2][x].isupper()): length += 1 if (alignment[domain1][x] == alignment[domain2][x]): identicals += 1 # Compute the percentage of identity pid = 1.0 * identicals / length # Write the results into a tab separated format output.write("{}\t{}\t{}\n".format(domain1, domain2, pid))
alignment_file = 'PF06758_A0A87WZJ2.sto' matrix_file = 'PF06758_A0A87WZJ2_matrix.tsv' with open(alignment_file, 'r') as input, open(matrix_file, 'w') as output: alignment = {} domains = [] for line in input: if not line.startswith('#') and (not line.startswith('//')): row = line.split() domain_id = row[0] domains.append(domain_id) if domain_id not in alignment.keys(): alignment[domain_id] = {} alignment[domain_id] = row[1].strip('\n') output.write('domain1\tdomain2\tpid\n') for i in range(0, len(domains)): domain1 = domains[i] for j in range(i + 1, len(domains)): domain2 = domains[j] length = 0 identicals = 0 assert len(alignment[domain1]) == len(alignment[domain2]) for x in range(0, len(alignment[domain1])): if alignment[domain1][x] != '.' and alignment[domain2][x] != '.' and (alignment[domain1][x] != '-') and (alignment[domain2][x] != '-') and alignment[domain1][x].isupper() and alignment[domain2][x].isupper(): length += 1 if alignment[domain1][x] == alignment[domain2][x]: identicals += 1 pid = 1.0 * identicals / length output.write('{}\t{}\t{}\n'.format(domain1, domain2, pid))
#email slicer program email=[] username=[] mail_server=[] top_level_domain=[] n=int(input("ENTER THE NUMBER OF EMAILS : ")) print("\n") for i in range(1,n+1): name=input("PLEASE ENTER THE EMAIL ID : ").strip() email.append(name) for j in email: a=j[:j.index('@')] b=j[j.index('@')+1:j.index('.')] c=j[j.index('.'):] username.append(a) mail_server.append(b) top_level_domain.append(c) for k in range(0,n): print("\n{} .USERNAME : {}\n\nMAIL SERVER NAME : {}\n\nTOP LEVEL DOMAIN : {}".format(k+1,username[k],mail_server[k],top_level_domain[k])) print("\n") print("***************************************************************************")
email = [] username = [] mail_server = [] top_level_domain = [] n = int(input('ENTER THE NUMBER OF EMAILS : ')) print('\n') for i in range(1, n + 1): name = input('PLEASE ENTER THE EMAIL ID : ').strip() email.append(name) for j in email: a = j[:j.index('@')] b = j[j.index('@') + 1:j.index('.')] c = j[j.index('.'):] username.append(a) mail_server.append(b) top_level_domain.append(c) for k in range(0, n): print('\n{} .USERNAME : {}\n\nMAIL SERVER NAME : {}\n\nTOP LEVEL DOMAIN : {}'.format(k + 1, username[k], mail_server[k], top_level_domain[k])) print('\n') print('***************************************************************************')
list_of_inputs = open("./input.txt").readlines() cleaned_list = [] for item in list_of_inputs: cleaned_list.append(item.strip()) correct_passwords_count = 0 for item in cleaned_list: chCorrect = 0 pCurrent = item.split(" ") pInfo = pCurrent[0] pTimesMin, pTimesMax = pInfo.split ("-") pLetter = pCurrent[1].strip(":") pCheckString = pCurrent[2].strip() pCurrentLetterCount = pCheckString.count(pLetter) if int(pTimesMin) <= int(pTimesMax) <= len(pCheckString): if pCheckString[int(pTimesMin)-1] == pLetter: chCorrect += 1 if pCheckString[int(pTimesMax)-1] == pLetter: chCorrect += 1 if chCorrect == 1: correct_passwords_count += 1 print(correct_passwords_count)
list_of_inputs = open('./input.txt').readlines() cleaned_list = [] for item in list_of_inputs: cleaned_list.append(item.strip()) correct_passwords_count = 0 for item in cleaned_list: ch_correct = 0 p_current = item.split(' ') p_info = pCurrent[0] (p_times_min, p_times_max) = pInfo.split('-') p_letter = pCurrent[1].strip(':') p_check_string = pCurrent[2].strip() p_current_letter_count = pCheckString.count(pLetter) if int(pTimesMin) <= int(pTimesMax) <= len(pCheckString): if pCheckString[int(pTimesMin) - 1] == pLetter: ch_correct += 1 if pCheckString[int(pTimesMax) - 1] == pLetter: ch_correct += 1 if chCorrect == 1: correct_passwords_count += 1 print(correct_passwords_count)
# Advent Of Code 2017, day 12, part 1 # http://adventofcode.com/2017/day/12 # solution by ByteCommander, 2017-12-12 with open("inputs/aoc2017_12.txt") as file: links = {} for line in file: src, dests = line.split(" <-> ") links[int(src)] = [int(dest) for dest in dests.split(", ")] visited = set() todo = {0} while todo: node = todo.pop() visited.add(node) for link in links[node]: if link not in visited: todo.add(link) print("Answer: {} nodes are connected to node 0." .format(len(visited)))
with open('inputs/aoc2017_12.txt') as file: links = {} for line in file: (src, dests) = line.split(' <-> ') links[int(src)] = [int(dest) for dest in dests.split(', ')] visited = set() todo = {0} while todo: node = todo.pop() visited.add(node) for link in links[node]: if link not in visited: todo.add(link) print('Answer: {} nodes are connected to node 0.'.format(len(visited)))
stocks = { 'GOOG' : 434, 'AAPL' : 325, 'FB' : 54, 'AMZN' : 623, 'F' : 32, 'MSFT' : 549 } print(min(zip(stocks.values(), stocks.keys())))
stocks = {'GOOG': 434, 'AAPL': 325, 'FB': 54, 'AMZN': 623, 'F': 32, 'MSFT': 549} print(min(zip(stocks.values(), stocks.keys())))
def format_positive_integer(number): l = list(str(number)) c = len(l) while c > 3: c -= 3 l.insert(c, '.') return ''.join(l) def format_number(number, precision=0, group_sep='.', decimal_sep=','): number = ('%.*f' % (max(0, precision), number)).split('.') integer_part = number[0] if integer_part[0] == '-': sign = integer_part[0] integer_part = integer_part[1:] else: sign = '' if len(number) == 2: decimal_part = decimal_sep + number[1] else: decimal_part = '' integer_part = list(integer_part) c = len(integer_part) while c > 3: c -= 3 integer_part.insert(c, group_sep) return sign + ''.join(integer_part) + decimal_part
def format_positive_integer(number): l = list(str(number)) c = len(l) while c > 3: c -= 3 l.insert(c, '.') return ''.join(l) def format_number(number, precision=0, group_sep='.', decimal_sep=','): number = ('%.*f' % (max(0, precision), number)).split('.') integer_part = number[0] if integer_part[0] == '-': sign = integer_part[0] integer_part = integer_part[1:] else: sign = '' if len(number) == 2: decimal_part = decimal_sep + number[1] else: decimal_part = '' integer_part = list(integer_part) c = len(integer_part) while c > 3: c -= 3 integer_part.insert(c, group_sep) return sign + ''.join(integer_part) + decimal_part
# MIT License # # # Copyright (c) 2022 by exersalza # # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # for more information look at: https://aniapi.com/docs/pagination PAGINATION = ['page', 'locale', 'per_page', 'ids', 'sort_fields', 'sort_directions'] ANIME_REQ = ['title', 'anilist_id', 'mal_id', 'tmdb_id', 'formats', 'status', 'year', 'season', 'genres', 'nsfw', 'with_episodes'] + PAGINATION EPISODE_REQ = ['anime_id', 'number', 'is_dub', 'locale'] + PAGINATION SONG_REQ = ['anime_id', 'title', 'artist', 'year', 'season', 'type'] + PAGINATION USER_REQ = ['username', 'email'] + PAGINATION UPDATE_USER_REQ = ['password', 'localization', 'anilist_id', 'anilist_token'] USER_STORY_REQ = ['anime_id', 'user_id', 'status', 'synced']
pagination = ['page', 'locale', 'per_page', 'ids', 'sort_fields', 'sort_directions'] anime_req = ['title', 'anilist_id', 'mal_id', 'tmdb_id', 'formats', 'status', 'year', 'season', 'genres', 'nsfw', 'with_episodes'] + PAGINATION episode_req = ['anime_id', 'number', 'is_dub', 'locale'] + PAGINATION song_req = ['anime_id', 'title', 'artist', 'year', 'season', 'type'] + PAGINATION user_req = ['username', 'email'] + PAGINATION update_user_req = ['password', 'localization', 'anilist_id', 'anilist_token'] user_story_req = ['anime_id', 'user_id', 'status', 'synced']
#!/usr/bin/env python3 NUM_SOCKET = 2 NUM_PHYSICAL_CPU_PER_SOCKET = 12 SMT_LEVEL = 2 OS_CPU_ID = {} # socket_id, physical_cpu_id, smt_id OS_CPU_ID[0,0,0] = 0 OS_CPU_ID[0,0,1] = 24 OS_CPU_ID[0,1,0] = 1 OS_CPU_ID[0,1,1] = 25 OS_CPU_ID[0,2,0] = 2 OS_CPU_ID[0,2,1] = 26 OS_CPU_ID[0,3,0] = 3 OS_CPU_ID[0,3,1] = 27 OS_CPU_ID[0,4,0] = 4 OS_CPU_ID[0,4,1] = 28 OS_CPU_ID[0,5,0] = 5 OS_CPU_ID[0,5,1] = 29 OS_CPU_ID[0,8,0] = 6 OS_CPU_ID[0,8,1] = 30 OS_CPU_ID[0,9,0] = 7 OS_CPU_ID[0,9,1] = 31 OS_CPU_ID[0,10,0] = 8 OS_CPU_ID[0,10,1] = 32 OS_CPU_ID[0,11,0] = 9 OS_CPU_ID[0,11,1] = 33 OS_CPU_ID[0,12,0] = 10 OS_CPU_ID[0,12,1] = 34 OS_CPU_ID[0,13,0] = 11 OS_CPU_ID[0,13,1] = 35 OS_CPU_ID[1,0,0] = 12 OS_CPU_ID[1,0,1] = 36 OS_CPU_ID[1,1,0] = 13 OS_CPU_ID[1,1,1] = 37 OS_CPU_ID[1,2,0] = 14 OS_CPU_ID[1,2,1] = 38 OS_CPU_ID[1,3,0] = 15 OS_CPU_ID[1,3,1] = 39 OS_CPU_ID[1,4,0] = 16 OS_CPU_ID[1,4,1] = 40 OS_CPU_ID[1,5,0] = 17 OS_CPU_ID[1,5,1] = 41 OS_CPU_ID[1,8,0] = 18 OS_CPU_ID[1,8,1] = 42 OS_CPU_ID[1,9,0] = 19 OS_CPU_ID[1,9,1] = 43 OS_CPU_ID[1,10,0] = 20 OS_CPU_ID[1,10,1] = 44 OS_CPU_ID[1,11,0] = 21 OS_CPU_ID[1,11,1] = 45 OS_CPU_ID[1,12,0] = 22 OS_CPU_ID[1,12,1] = 46 OS_CPU_ID[1,13,0] = 23 OS_CPU_ID[1,13,1] = 47
num_socket = 2 num_physical_cpu_per_socket = 12 smt_level = 2 os_cpu_id = {} OS_CPU_ID[0, 0, 0] = 0 OS_CPU_ID[0, 0, 1] = 24 OS_CPU_ID[0, 1, 0] = 1 OS_CPU_ID[0, 1, 1] = 25 OS_CPU_ID[0, 2, 0] = 2 OS_CPU_ID[0, 2, 1] = 26 OS_CPU_ID[0, 3, 0] = 3 OS_CPU_ID[0, 3, 1] = 27 OS_CPU_ID[0, 4, 0] = 4 OS_CPU_ID[0, 4, 1] = 28 OS_CPU_ID[0, 5, 0] = 5 OS_CPU_ID[0, 5, 1] = 29 OS_CPU_ID[0, 8, 0] = 6 OS_CPU_ID[0, 8, 1] = 30 OS_CPU_ID[0, 9, 0] = 7 OS_CPU_ID[0, 9, 1] = 31 OS_CPU_ID[0, 10, 0] = 8 OS_CPU_ID[0, 10, 1] = 32 OS_CPU_ID[0, 11, 0] = 9 OS_CPU_ID[0, 11, 1] = 33 OS_CPU_ID[0, 12, 0] = 10 OS_CPU_ID[0, 12, 1] = 34 OS_CPU_ID[0, 13, 0] = 11 OS_CPU_ID[0, 13, 1] = 35 OS_CPU_ID[1, 0, 0] = 12 OS_CPU_ID[1, 0, 1] = 36 OS_CPU_ID[1, 1, 0] = 13 OS_CPU_ID[1, 1, 1] = 37 OS_CPU_ID[1, 2, 0] = 14 OS_CPU_ID[1, 2, 1] = 38 OS_CPU_ID[1, 3, 0] = 15 OS_CPU_ID[1, 3, 1] = 39 OS_CPU_ID[1, 4, 0] = 16 OS_CPU_ID[1, 4, 1] = 40 OS_CPU_ID[1, 5, 0] = 17 OS_CPU_ID[1, 5, 1] = 41 OS_CPU_ID[1, 8, 0] = 18 OS_CPU_ID[1, 8, 1] = 42 OS_CPU_ID[1, 9, 0] = 19 OS_CPU_ID[1, 9, 1] = 43 OS_CPU_ID[1, 10, 0] = 20 OS_CPU_ID[1, 10, 1] = 44 OS_CPU_ID[1, 11, 0] = 21 OS_CPU_ID[1, 11, 1] = 45 OS_CPU_ID[1, 12, 0] = 22 OS_CPU_ID[1, 12, 1] = 46 OS_CPU_ID[1, 13, 0] = 23 OS_CPU_ID[1, 13, 1] = 47
''' Created on Aug 13, 2018 @author: david avalos ''' class Person: def __init__(self, name): self.name = name def talk(self, words): print(words) def hobby(self): print("My hobby is to watch movies") class Teacher(Person): def __init__(self, name, signature): self.__name = name self.__signature = signature def hobby(self): print("My hobby is to read") def teach(self): print(self.__name,"is giving",self.__signature,"class") def getName(self): return self.__name def setName(self, name): self.__name = name class Engineer(Person): def hobby(self): print("My hobby is to play video games") myPerson = Person("David") myPerson.talk("Hello! :)") myPerson.hobby() print(myPerson.name) print() myTeacher = Teacher("Jorge","Math") myTeacher.talk("Ready for my class?") myTeacher.hobby() myTeacher.teach() #print(myTeacher.__name) myTeacher.setName("Martin") print(myTeacher.getName()) print() myEngineer = Engineer("Genaro") myEngineer.talk("Don't know what to say D:") myEngineer.hobby() print(myEngineer.name)
""" Created on Aug 13, 2018 @author: david avalos """ class Person: def __init__(self, name): self.name = name def talk(self, words): print(words) def hobby(self): print('My hobby is to watch movies') class Teacher(Person): def __init__(self, name, signature): self.__name = name self.__signature = signature def hobby(self): print('My hobby is to read') def teach(self): print(self.__name, 'is giving', self.__signature, 'class') def get_name(self): return self.__name def set_name(self, name): self.__name = name class Engineer(Person): def hobby(self): print('My hobby is to play video games') my_person = person('David') myPerson.talk('Hello! :)') myPerson.hobby() print(myPerson.name) print() my_teacher = teacher('Jorge', 'Math') myTeacher.talk('Ready for my class?') myTeacher.hobby() myTeacher.teach() myTeacher.setName('Martin') print(myTeacher.getName()) print() my_engineer = engineer('Genaro') myEngineer.talk("Don't know what to say D:") myEngineer.hobby() print(myEngineer.name)
# description: Generate PaseCliAsync_gen.c # command: python gen.py PaseSqlCli_file = "./gen_cli_template.c" # =============================================== # utilities # =============================================== def parse_sizeme( st ): sz = '4' if 'SMALL' in st: sz = '2' elif '*' in st: sz = '4' return sz def parse_star( line ): v1 = "" v2 = "" v3 = "" # SQLRETURN * SQLFlinstone # 0 1 split1 = line.split('*') if len(split1) > 1: v1 = split1[0] v2 = "*" v3 = split1[1] else: # SQLRETURN SQLRubble # 0 1 split1 = line.split() v1 = split1[0] v2 = "" v3 = split1[1] return [v1.strip(),v2,v3.strip()] def parse_method( line ): # SQLRETURN SQLPrimaryKeys(...) # ===func=================1 split1 = line.split("(") func = split1[0] # (SQLHSTMT hstmt, SQLCHAR * szTableQualifier, ...) # 1================================argv========================2 split2 = split1[1].split(")") argv = split2[0] # SQLRETURN SQLRubble # 0 1 # SQLRETURN * SQLFlinstone # 0 1 2 funcs = parse_star(func) # SQLHSTMT hstmt, SQLCHAR * szTableQualifier, ... # 3 3 split3 = argv.split(",") args = [] for arg in split3: # SQLHSTMT hstmt # 0 1 # SQLCHAR * szTableQualifier # 0 1 2 args.append(parse_star(arg)) return [funcs,args] # =============================================== # special processing CLI interfaces (unique gen) # =============================================== # SQLRETURN SQLAllocEnv ( SQLHENV * phenv ); def PaseCliAsync_c_main_SQLAllocEnv(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n" c_main += " init_table_ctor(*phenv, *phenv);" + "\n" c_main += " custom_SQLSetEnvCCSID(*phenv, myccsid);" + "\n" c_main += " }" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLAllocConnect ( SQLHENV henv, SQLHDBC * phdbc ); def PaseCliAsync_c_main_SQLAllocConnect(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n" c_main += " init_table_ctor(*phdbc, *phdbc);" + "\n" c_main += " }" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLAllocStmt ( SQLHDBC hdbc, SQLHSTMT * phstmt ); def PaseCliAsync_c_main_SQLAllocStmt(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n" c_main += " init_table_ctor(*phstmt, hdbc);" + "\n" c_main += " }" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLAllocHandle ( SQLSMALLINT htype, SQLINTEGER ihnd, SQLINTEGER * ohnd ); def PaseCliAsync_c_main_SQLAllocHandle(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " switch (htype) {" + "\n" c_main += " case SQL_HANDLE_ENV:" + "\n" c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n" c_main += " init_table_ctor(*ohnd, *ohnd);" + "\n" c_main += " custom_SQLSetEnvCCSID(*ohnd, myccsid);" + "\n" c_main += " }" + "\n" c_main += " break;" + "\n" c_main += " case SQL_HANDLE_DBC:" + "\n" c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n" c_main += " init_table_ctor(*ohnd, *ohnd);" + "\n" c_main += " }" + "\n" c_main += " break;" + "\n" c_main += " case SQL_HANDLE_STMT:" + "\n" c_main += " case SQL_HANDLE_DESC:" + "\n" c_main += " if (sqlrc == SQL_SUCCESS) {" + "\n" c_main += " init_table_ctor(*ohnd, ihnd);" + "\n" c_main += " }" + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLFreeEnv ( SQLHENV henv ); def PaseCliAsync_c_main_SQLFreeEnv(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLFreeConnect ( SQLHDBC hdbc ); def PaseCliAsync_c_main_SQLFreeConnect(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " int active = init_table_hash_active(hdbc, 0);" + "\n" c_main += " /* persistent connect only close with SQL400pClose */" + "\n" c_main += " if (active) {" + "\n" c_main += " return SQL_ERROR;" + "\n" c_main += " }" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " init_table_dtor(hdbc);" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLFreeStmt ( SQLHSTMT hstmt, SQLSMALLINT fOption ); def PaseCliAsync_c_main_SQLFreeStmt(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " init_table_dtor(hstmt);" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLFreeHandle ( SQLSMALLINT htype, SQLINTEGER hndl ); def PaseCliAsync_c_main_SQLFreeHandle(ile_or_custom_call, call_name, normal_db400_args): c_main = "" c_main += " int myccsid = init_CCSID400(0);" + "\n" c_main += " int persistent = init_table_hash_active(hndl, 0);" + "\n" c_main += " /* persistent connect only close with SQL400pClose */" + "\n" c_main += " switch (htype) {" + "\n" c_main += " case SQL_HANDLE_DBC:" + "\n" c_main += " if (persistent) {" + "\n" c_main += " return SQL_ERROR;" + "\n" c_main += " }" + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " init_lock();" + "\n" c_main += " switch(myccsid) {" + "\n" c_main += ' case 1208: /* UTF-8 */' + "\n" c_main += ' case 1200: /* UTF-16 */' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += ' default:' + "\n" c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " switch (htype) {" + "\n" c_main += " case SQL_HANDLE_ENV:" + "\n" c_main += " break;" + "\n" c_main += " default:" + "\n" c_main += " init_table_dtor(hndl);" + "\n" c_main += " break;" + "\n" c_main += " }" + "\n" c_main += " init_unlock();" + "\n" # dump trace c_main += " if (init_cli_trace()) {" + "\n" c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" c_main += " }" + "\n" return c_main # SQLRETURN SQLDisconnect( SQLHDBC hdbc ) def SQLDisconnect_check_persistent(hdbc_code, return_code, set_code): c_main = "" c_main += " int persistent = init_table_hash_active(" + hdbc_code + ", 0);" + "\n" c_main += " /* persistent connect only close with SQL400pClose */" + "\n" c_main += " if (persistent) {" + "\n" c_main += " " + set_code + "\n" c_main += " " + return_code + "\n" c_main += " }" + "\n" return c_main # =============================================== # non-utf (old libdb400.a) # =============================================== # SQL400IgnoreNullAnyToAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid) # SQL400IgnoreNullAnyFromAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid) def non_utf_copy_in(): c_main = "" c_main += 'int non_utf_copy_in_hdbc(SQLHDBC hdbc, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + "\n" c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + "\n" c_main += ' int inccsid = init_CCSID400(0);' + "\n" c_main += ' int outccsid = init_job_CCSID400();' + "\n" c_main += ' SQLCHAR * inparm = *src;' + "\n" c_main += ' SQLINTEGER inlen = srclen;' + "\n" c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + "\n" c_main += ' SQLINTEGER outlen = 0;' + "\n" c_main += ' if (inparm) {' + "\n" c_main += ' if (srclen == SQL_NTS) {' + "\n" c_main += ' inlen = strlen(inparm);' + "\n" c_main += ' }' + "\n" c_main += ' outlen = maxlen;' + "\n" c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + "\n" c_main += ' memset(outparm,0,outlen);' + "\n" c_main += ' sqlrc1 = SQL400IgnoreNullAnyToAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + "\n" c_main += ' outlen = strlen(outparm);' + "\n" c_main += ' }' + "\n" c_main += ' *tmp = *src;' + "\n" c_main += ' if (*src) {' + "\n" c_main += ' *src = outparm;' + "\n" c_main += ' }' + "\n" c_main += ' return outlen;' + "\n" c_main += '}' + "\n" c_main += 'int non_utf_copy_in_hstmt(SQLHSTMT hstmt, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + "\n" c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + "\n" c_main += ' return non_utf_copy_in_hdbc(hdbc, tmp, src, srclen, maxlen);' + "\n" c_main += '}' + "\n" return c_main def non_utf_copy_in_free(): c_main = "" c_main += 'void non_utf_copy_in_free(SQLCHAR **tmp, SQLCHAR **src) {' + "\n" c_main += ' char * trash = *src;' + "\n" c_main += ' *src = *tmp;' + "\n" c_main += ' if (trash) {' + "\n" c_main += ' free(trash);' + "\n" c_main += ' *tmp = NULL;' + "\n" c_main += ' }' + "\n" c_main += '}' + "\n" return c_main def non_utf_copy_out(): c_main = "" c_main += 'int non_utf_copy_out_hdbc(SQLHDBC hdbc, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + "\n" c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + "\n" c_main += ' int inccsid = init_CCSID400(0);' + "\n" c_main += ' int outccsid = init_job_CCSID400();' + "\n" c_main += ' SQLCHAR * inparm = src;' + "\n" c_main += ' SQLINTEGER inlen = srclen;' + "\n" c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + "\n" c_main += ' SQLINTEGER outlen = 0;' + "\n" c_main += ' if (inparm && (inlen != SQL_NULL_DATA) && (sqlrc == SQL_SUCCESS || sqlrc == SQL_SUCCESS_WITH_INFO)) {' + "\n" c_main += ' outlen = inlen + 1;' + "\n" c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + "\n" c_main += ' memset(outparm,0,outlen);' + "\n" c_main += ' sqlrc1 = SQL400IgnoreNullAnyFromAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + "\n" c_main += ' outlen = strlen(outparm);' + "\n" c_main += ' memcpy(inparm,outparm,inlen);' + "\n" c_main += ' free(outparm);' + "\n" c_main += ' }' + "\n" c_main += ' return outlen;' + "\n" c_main += '}' + "\n" c_main += 'int non_utf_copy_out_hstmt(SQLHSTMT hstmt, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + "\n" c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + "\n" c_main += ' return non_utf_copy_out_hdbc(hdbc, sqlrc, src, srclen);' + "\n" c_main += '}' + "\n" return c_main def non_utf_isconvert_ordinal(): c_main = "" c_main += 'int non_utf_isconvert_ordinal(SQLINTEGER ord) {' + "\n" c_main += ' int convert = 0;' + "\n" c_main += ' switch(ord) {' + "\n" c_main += ' case SQL_ATTR_DBC_DEFAULT_LIB:' + " \n" c_main += ' case SQL_ATTR_SAVEPOINT_NAME:' + " \n" c_main += ' case SQL_ATTR_INFO_ACCTSTR:' + " \n" c_main += ' case SQL_ATTR_INFO_APPLNAME:' + " \n" c_main += ' case SQL_ATTR_INFO_PROGRAMID:' + " \n" c_main += ' case SQL_ATTR_INFO_USERID:' + " \n" c_main += ' case SQL_ATTR_INFO_WRKSTNNAME:' + " \n" c_main += ' case SQL_ATTR_SERVERMODE_SUBSYSTEM:' + " \n" c_main += ' case SQL_DBMS_NAME:' + " \n" c_main += ' case SQL_DBMS_VER:' + " \n" c_main += ' case SQL_PROCEDURES:' + " \n" c_main += ' case SQL_DATA_SOURCE_NAME:' + " \n" c_main += ' case SQL_COLUMN_ALIAS:' + " \n" c_main += ' case SQL_DATA_SOURCE_READ_ONLY:' + " \n" c_main += ' case SQL_MULTIPLE_ACTIVE_TXN:' + " \n" c_main += ' case SQL_DRIVER_NAME:' + " \n" c_main += ' case SQL_IDENTIFIER_QUOTE_CHAR:' + " \n" c_main += ' case SQL_PROCEDURE_TERM:' + " \n" c_main += ' case SQL_QUALIFIER_TERM:' + " \n" c_main += ' case SQL_QUALIFIER_NAME_SEPARATOR:' + " \n" c_main += ' case SQL_OWNER_TERM:' + " \n" c_main += ' case SQL_DRIVER_ODBC_VER:' + " \n" c_main += ' case SQL_ORDER_BY_COLUMNS_IN_SELECT:' + " \n" c_main += ' case SQL_SEARCH_PATTERN_ESCAPE:' + " \n" c_main += ' case SQL_OUTER_JOINS:' + " \n" c_main += ' case SQL_LIKE_ESCAPE_CLAUSE:' + " \n" c_main += ' case SQL_CATALOG_NAME:' + " \n" c_main += ' case SQL_DESCRIBE_PARAMETER:' + " \n" c_main += ' convert = 1;' + "\n" c_main += ' break;' + "\n" c_main += ' }' + "\n" c_main += ' return convert;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLColAttributes(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (fDescType == SQL_DESC_NAME) {' + "\n" c_main += ' outsz = non_utf_copy_out_hstmt(hstmt, sqlrc, (SQLCHAR *)rgbDesc, (SQLINTEGER)cbDescMax);' + "\n" c_main += ' if (pcbDesc) *pcbDesc = outsz;' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLColumnPrivileges(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' SQLCHAR * tmp4 = NULL;' + "\n" c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLColumns(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' SQLCHAR * tmp4 = NULL;' + "\n" c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLConnect(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' cbDSN = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN, (SQLINTEGER)cbDSN, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbUID = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp2, (SQLCHAR **)&szUID, (SQLINTEGER)cbUID, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbAuthStr = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr, (SQLINTEGER)cbAuthStr, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szUID);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLDataSources(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER tmpsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDSN, (SQLINTEGER)cbDSNMax);' + "\n" c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDescription, (SQLINTEGER)cbDescriptionMax);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLDescribeCol(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szColName, (SQLINTEGER)cbColNameMax);' + "\n" c_main += ' if (pcbColName) *pcbColName = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLDriverConnect(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' cbConnStrin = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn, (SQLINTEGER)cbConnStrin, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn);' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szConnStrOut, (SQLINTEGER)cbConnStrOutMax);' + "\n" c_main += ' if (pcbConnStrOut) *pcbConnStrOut = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLError(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + "\n" c_main += ' SQLINTEGER tmpsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szSqlState, (SQLINTEGER)maxsz);' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szErrorMsg, (SQLINTEGER)cbErrorMsgMax);' + "\n" c_main += ' if (pcbErrorMsg) *pcbErrorMsg = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLExecDirect(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLForeignKeys(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' SQLCHAR * tmp4 = NULL;' + "\n" c_main += ' SQLCHAR * tmp5 = NULL;' + "\n" c_main += ' SQLCHAR * tmp6 = NULL;' + "\n" c_main += ' cbPkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier, (SQLINTEGER)cbPkTableQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbPkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner, (SQLINTEGER)cbPkTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbPkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName, (SQLINTEGER)cbPkTableName, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbFkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier, (SQLINTEGER)cbFkTableQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbFkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner, (SQLINTEGER)cbFkTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbFkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName, (SQLINTEGER)cbFkTableName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetConnectAttr(call_name, normal_db400_args): c_main = "" c_main += ' int isconvert = non_utf_isconvert_ordinal(attr);' + "\n" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)ilen);' + "\n" c_main += ' if (olen) *olen = outsz;' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetConnectOption(call_name, normal_db400_args): c_main = "" c_main += ' int isconvert = non_utf_isconvert_ordinal(iopt);' + "\n" c_main += ' SQLINTEGER maxsz = DFTCOLSIZE;' + "\n" c_main += ' SQLINTEGER tmpsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' tmpsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)maxsz);' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetCursorName(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szCursor, (SQLINTEGER)cbCursorMax);' + "\n" c_main += ' if (pcbCursor) *pcbCursor = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetDescField(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (fieldID == SQL_DESC_NAME) {' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fValue, (SQLINTEGER)fLength);' + "\n" c_main += ' if (stLength) *stLength = outsz;' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetDescRec(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fname, (SQLINTEGER)bufLen);' + "\n" c_main += ' if (sLength) *sLength = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetDiagField(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (diagID == SQL_DIAG_SQLSTATE || diagID == SQL_DIAG_MESSAGE_TEXT || diagID == SQL_DIAG_SERVER_NAME) {' + "\n" c_main += ' if (hType == SQL_HANDLE_DBC) {' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + "\n" c_main += ' } else {' + "\n" c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + "\n" c_main += ' }' + "\n" c_main += ' if (sLength) *sLength = outsz;' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetDiagRec(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + "\n" c_main += ' SQLINTEGER tmpsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (hType == SQL_HANDLE_DBC) {' + "\n" c_main += ' tmpsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + "\n" c_main += ' } else {' + "\n" c_main += ' tmpsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + "\n" c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + "\n" c_main += ' }' + "\n" c_main += ' if (SLength) *SLength = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetEnvAttr(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (fAttribute == SQL_ATTR_DEFAULT_LIB || fAttribute == SQL_ATTR_ESCAPE_CHAR) {' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)pParam, (SQLINTEGER)cbParamMax);' + "\n" c_main += ' }' + "\n" c_main += ' if (pcbParam) *pcbParam = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetInfo(call_name, normal_db400_args): c_main = "" c_main += ' int isconvert = non_utf_isconvert_ordinal(fInfoType);' + "\n" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)rgbInfoValue, (SQLINTEGER)cbInfoValueMax);' + "\n" c_main += ' if (pcbInfoValue) *pcbInfoValue = outsz;' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLGetPosition(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' srchLiteralLen = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral, (SQLINTEGER)srchLiteralLen, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLNativeSql(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER outsz = 0;' + "\n" c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' cbSqlStrIn = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn, (SQLINTEGER)cbSqlStrIn, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn);' + "\n" c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)szSqlStr, (SQLINTEGER)cbSqlStrMax);' + "\n" c_main += ' if (pcbSqlStr) *pcbSqlStr = outsz;' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLParamData(call_name, normal_db400_args): c_main = "" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLPrepare(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLPrimaryKeys(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLProcedureColumns(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' SQLCHAR * tmp4 = NULL;' + "\n" c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLProcedures(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLSetConnectAttr(call_name, normal_db400_args): c_main = "" c_main += ' int isconvert = non_utf_isconvert_ordinal(attrib);' + "\n" c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' inlen = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)inlen, (SQLINTEGER)maxsz);' + "\n" c_main += ' }' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLSetConnectOption(call_name, normal_db400_args): c_main = "" c_main += ' int isconvert = non_utf_isconvert_ordinal(fOption);' + "\n" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLINTEGER tmpsz = 0;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' tmpsz = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)SQL_NTS, (SQLINTEGER)maxsz);' + "\n" c_main += ' }' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (isconvert) {' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLSetCursorName(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' cbCursor = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor, (SQLINTEGER)cbCursor, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLSetEnvAttr(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + "\n" c_main += ' cbParam = non_utf_copy_in_hdbc(0, (SQLCHAR **)&tmp1, (SQLCHAR **)&pParam, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += ' }' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&pParam);' + "\n" c_main += ' }' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLSpecialColumns(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' cbTableQual = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual, (SQLINTEGER)cbTableQual, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLStatistics(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLTablePrivileges(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main def non_utf_SQLTables(call_name, normal_db400_args): c_main = "" c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + "\n" c_main += ' SQLCHAR * tmp1 = NULL;' + "\n" c_main += ' SQLCHAR * tmp2 = NULL;' + "\n" c_main += ' SQLCHAR * tmp3 = NULL;' + "\n" c_main += ' SQLCHAR * tmp4 = NULL;' + "\n" c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += ' cbTableType = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + "\n" c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + "\n" c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType);' + "\n" c_main += ' return sqlrc;' + "\n" c_main += '}' + "\n" return c_main # =============================================== # special ILE CLI APIs # =============================================== # SQLRETURN ILE_SQLParamData( SQLHSTMT hstmt, SQLPOINTER * Value ) def ILE_SQLParamData_copy_var(): c_main = "" c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr) */ ' + "\n" c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + "\n" c_main += ' ILEpointer *returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + "\n" return c_main def ILE_SQLParamData_copy_in(): c_main = "" c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + "\n" c_main += ' if (Value) {' + "\n" c_main += ' arglist->Value.s.addr = (ulong) returnPtr;' + "\n" c_main += ' }' + "\n" return c_main def ILE_SQLParamData_copy_out(): c_main = "" c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + "\n" c_main += ' if (Value) {' + "\n" c_main += ' if (arglist->base.result.s_int32.r_int32 == SQL_NEED_DATA) {' + "\n" c_main += ' *Value = _CVTSPP(returnPtr);' + "\n" c_main += ' }' + "\n" c_main += ' }' + "\n" return c_main # SQLRETURN ILE_SQLGetDescField( SQLHDESC hdesc, SQLSMALLINT rcdNum, SQLSMALLINT fieldID, # SQLPOINTER fValue, SQLINTEGER fLength, SQLINTEGER * stLength ) def ILE_SQLGetDescField_copy_var(): c_main = "" c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr)' + "\n" c_main += ' * Return ILE SP likely outside PASE mapable addr space.' + "\n" c_main += ' * However, _CVTSPP is safe. The result is zero (null)' + "\n" c_main += ' * if the input is a 16-byte null pointer or a tagged space pointer ' + "\n" c_main += ' * that does not contain the teraspace address' + "\n" c_main += ' * equivalent of some valid IBM PASE for i memory address.' + "\n" c_main += ' * (I suspect options never used in years of PASE.' + "\n" c_main += ' * Rochester CLI team was notified).' + "\n" c_main += ' */' + "\n" c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + "\n" c_main += ' ILEpointer *returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + "\n" return c_main def ILE_SQLGetDescField_copy_in(): c_main = "" c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + "\n" c_main += ' if (fValue) {' + "\n" c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + "\n" c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + "\n" c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + "\n" c_main += ' {' + "\n" c_main += ' arglist->fValue.s.addr = (ulong) returnPtr;' + "\n" c_main += ' }' + "\n" c_main += ' }' + "\n" return c_main def ILE_SQLGetDescField_copy_out(): c_main = "" c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + "\n" c_main += ' if (fValue) {' + "\n" c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + "\n" c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + "\n" c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + "\n" c_main += ' {' + "\n" c_main += ' *((void **)fValue) = _CVTSPP(returnPtr);' + "\n" c_main += ' }' + "\n" c_main += ' }' + "\n" return c_main # =============================================== # pre-process CLI gen_cli_template.c # (future ... if wide interface or not) # =============================================== pre = open(PaseSqlCli_file,"r") ile_wide_api = {'nothing': 'nothing'} for line in pre: # start of SQL function .. # SQLRETURN SQLxxx( if "SQLRETURN SQL" in line: # parse function lesss = line.split("(") parts = lesss[0].split(" ") funcs = parts[1] # forget if "400" in funcs: continue # wide api if "W" in funcs: line_no_W = funcs.split("W") assoc_name = line_no_W[0] ile_wide_api[assoc_name] = funcs # if call_name in ile_wide_api.values(): # print("ile_wide_api['" + assoc_name + "'] = '" + funcs + "'") # =============================================== # process CLI gen_cli_template.c # =============================================== f = open(PaseSqlCli_file,"r") g = False c400 = True c400_CCSID = False c400_not_wide = True ile_or_custom_call = "" ile_or_libdb400_call = "" line_func = "" libdb400_exp="" PaseCliLibDB400_h_proto = "" PaseCliLibDB400_c_symbol = "" PaseCliLibDB400_c_main = "" PaseCliAsync_h_struct = "" PaseCliAsync_h_proto_async = "" PaseCliAsync_h_proto_join = "" PaseCliAsync_c_main = "" PaseCliAny_h_proto = "" PaseCliOnly400_h_proto = "" PaseCliILE_h_proto = "" PaseCliILE_c_symbol = "" PaseCliCustom_h_proto = "" PaseCliILE_h_struct = "" PaseCliILE_c_main = "" PaseCliDump_h_proto = "" PaseCliDump_c_main = "" for line in f: # start of SQL function .. # SQLRETURN SQLxxx( if "SQLRETURN SQL" in line: g = True line_func = "" if g: # throw out change flags and comments # SQLRETURN SQLPrimaryKeys ... /* @08A*/ # 0 line_no_comment = line.split("/") split0 = line_no_comment[0] line_func += split0 # end of function ..args..) if not ")" in split0: continue else: g = False else: continue # --------------- # parse function # --------------- parts = parse_method(line_func) funcs = parts[0] args = parts[1] # SQLRETURN SQLPrimaryKeys # 0 (1 or 2) call_retv = funcs[0] + funcs[1] call_name = funcs[2] struct_name = call_name + "Struct" struct_ile_name = call_name + "IleCallStruct" struct_ile_sig = call_name + "IleSigStruct" struct_ile_flag = call_name + "Loaded" struct_ile_buf = call_name + "Buf" struct_ile_ptr = call_name + "Ptr" # --------------- # custom function (super api) # --------------- c400_not_wide = True c400_CCSID = False c400 = True ile_or_custom_call = "custom_" ile_or_libdb400_call = "libdb400_" if "SQLOverrideCCSID400" in call_name: c400_CCSID = True if "SQL400" in call_name: c400 = False if c400: ile_or_custom_call = "ILE_" if "W" in call_name: ile_or_libdb400_call = "ILE_" c400_not_wide = False # --------------- # arguments (params) # --------------- idx = 0 comma = "," semi = ";" argtype1st = "" argname1st = "" normal_call_types = "" normal_call_args = "" normal_db400_args = "" async_struct_types = " SQLRETURN sqlrc;" async_call_args = "" async_db400_args = "" async_copyin_args = "" ILE_struct_sigs = "" ILE_struct_types = "ILEarglist_base base;" ILE_copyin_args = "" dump_args = "" dump_sigs = "" for arg in args: idx += 1 if idx == len(args): comma = "" # SQLHSTMT hstmt # 0 1 # SQLCHAR * szTableQualifier # 0 1 2 argfull = ' '.join(arg) argsig = arg[0] + arg[1] argname = arg[2] if idx == 1: argtype1st = arg[0]; argname1st = arg[2]; sigile = '' ilefull = argfull if arg[1] == '*': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'PTR': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'SQLHWND': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'SQLPOINTER': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'SQLCHAR': sigile = 'ARG_UINT8' elif arg[0] == 'SQLWCHAR': sigile = 'ARG_UINT8' elif arg[0] == 'SQLSMALLINT': sigile = 'ARG_INT16' elif arg[0] == 'SQLUSMALLINT': sigile = 'ARG_UINT16' elif arg[0] == 'SQLSMALLINT': sigile = 'ARG_INT16' elif arg[0] == 'SQLINTEGER': sigile = 'ARG_INT32' elif arg[0] == 'SQLUINTEGER': sigile = 'ARG_UINT32' elif arg[0] == 'SQLDOUBLE': sigile = 'ARG_FLOAT64' elif arg[0] == 'SQLREAL': sigile = 'ARG_FLOAT32' elif arg[0] == 'HENV': sigile = 'ARG_INT32' elif arg[0] == 'HDBC': sigile = 'ARG_INT32' elif arg[0] == 'HSTMT': sigile = 'ARG_INT32' elif arg[0] == 'HDESC': sigile = 'ARG_INT32' elif arg[0] == 'SQLHANDLE': sigile = 'ARG_INT32' elif arg[0] == 'SQLHENV': sigile = 'ARG_INT32' elif arg[0] == 'SQLHDBC': sigile = 'ARG_INT32' elif arg[0] == 'SQLHSTMT': sigile = 'ARG_INT32' elif arg[0] == 'SQLHDESC': sigile = 'ARG_INT32' elif arg[0] == 'RETCODE': sigile = 'ARG_INT32' elif arg[0] == 'SQLRETURN': sigile = 'ARG_INT32' elif arg[0] == 'SFLOAT': sigile = 'ARG_FLOAT32' # each SQL function override # SQLRETURN SQLPrimaryKeys( SQLHSTMT hstmt, SQLCHAR * szTableQualifier, SQLSMALLINT cbTableQualifier, ... # ------------------------------------------------------------------------- normal_call_args += ' ' + argfull + comma # each SQL function call libdb400 # sqlrc = libdb400_SQLPrimaryKeys( hstmt, szTableQualifier, cbTableQualifier, ... # ------------------------------------------ normal_db400_args += ' ' + argname + comma # SQLRETURN (*libdb400_SQLPrimaryKeys)(SQLHSTMT,SQLCHAR*,SQLSMALLINT, ... # ------------------------------ normal_call_types += ' ' + argsig + comma # Dump args and sigs # dump_args += ' ' + argname dump_sigs += ' ' + argsig # ILE call structure ILE_struct_types += ' ' + ilefull + semi # ILE call signature ILE_struct_sigs += ' ' + sigile + comma # ILE copyin params if sigile == 'ARG_MEMPTR': ILE_copyin_args += ' arglist->' + argname + '.s.addr = (ulong) ' + argname + ";" + "\n" else: ILE_copyin_args += ' arglist->' + argname + ' = (' + argsig + ') ' + argname + ";" + "\n" # each SQL async struct # typedef struct SQLPrimaryKeysStruct { SQLRETURN sqlrc; SQLHSTMT hstmt; ... # -------------------------------- async_struct_types += ' ' + argfull + semi # each SQL asyn call libdb400 # myptr->sqlrc = libdb400_SQLPrimaryKeys( myptr->hstmt, myptr->szTableQualifier, myptr->cbTableQualifier, ... # ------------------------------------------ async_db400_args += ' myptr->' + argname + comma # each SQL asyn copyin parms # myptr->hstmt = hstmt; # myptr->szTableQualifier = szTableQualifier; # myptr->cbTableQualifier = cbTableQualifier; # ... # ------------------------------------------ async_copyin_args += ' myptr->' + argname + " = " + argname + ";" + "\n" # =============================================== # standard dumping function # =============================================== PaseCliDump_h_proto += "void dump_" + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' );' + "\n" PaseCliDump_c_main += "void dump_" + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' ) {' + "\n" PaseCliDump_c_main += ' if (dev_go(sqlrc,"'+call_name.lower()+'")) {' + "\n" PaseCliDump_c_main += ' char mykey[256];' + "\n" PaseCliDump_c_main += ' printf_key(mykey,"' + call_name + '");' + "\n" PaseCliDump_c_main += ' printf_clear();' + "\n" PaseCliDump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 1);' + "\n" PaseCliDump_c_main += ' printf_stack(mykey);' + "\n" PaseCliDump_c_main += ' printf_sqlrc_status((char *)&mykey, sqlrc);' + "\n" args = dump_args.split() sigs = dump_sigs.split() dump_handle = '' dump_type = '' i = 0 for arg in args: sig = sigs[i] PaseCliDump_c_main += ' printf_format("%s.parm %s %s 0x%p (%d)\\n",mykey,"'+sig+'","'+arg+'",'+arg+','+arg+');' + "\n" if '*' in sig or 'SQLPOINTER' in sig: PaseCliDump_c_main += ' printf_hexdump(mykey,'+arg+',80);' + "\n" elif 'SQLHDBC' in sig: dump_handle = arg dump_type = 'SQL_HANDLE_DBC' elif 'SQLHSTMT' in sig: dump_handle = arg dump_type = 'SQL_HANDLE_STMT' elif 'SQLHDESC' in sig: dump_handle = arg dump_type = 'SQL_HANDLE_DESC' i += 1 PaseCliDump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 0);' + "\n" PaseCliDump_c_main += ' dev_dump();' + "\n" PaseCliDump_c_main += ' if (sqlrc < SQL_SUCCESS) {' + "\n" if 'SQL' in dump_type: PaseCliDump_c_main += ' printf_sql_diag('+dump_type +','+dump_handle+');' + "\n" PaseCliDump_c_main += ' printf_force_SIGQUIT((char *)&mykey);' + "\n" PaseCliDump_c_main += ' }' + "\n" PaseCliDump_c_main += ' }' + "\n" PaseCliDump_c_main += '}' + "\n" # =============================================== # non-async SQL interfaces with lock added # =============================================== if c400: # each SQL400 function special (header) # SQLRETURN SQL400Environment( SQLINTEGER * ohnd, SQLPOINTER options ) # PaseCliAny_h_proto += " * " + call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + "\n" # =============================================== # libdb400 call (here adc tony) # =============================================== # SQLRETURN custom_SQLOverrideCCSID400( SQLINTEGER newCCSID ) if c400_CCSID: PaseCliCustom_h_proto += call_retv + ' ' + "custom_" + call_name + '(' + normal_call_args + ' );' + "\n" else: # old libdb400.a (non-utf) PaseCliLibDB400_h_proto += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' );' + "\n" # main PaseCliLibDB400_c_main += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' ) {' + "\n" PaseCliLibDB400_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + "\n" if 'W' in call_name: PaseCliLibDB400_c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliLibDB400_c_main += " return sqlrc;" + "\n" PaseCliLibDB400_c_main += '}' + "\n" else: if 'SQLColAttributes' in call_name: PaseCliLibDB400_c_main += non_utf_SQLColAttributes(call_name, normal_db400_args) elif 'SQLColumnPrivileges' in call_name: PaseCliLibDB400_c_main += non_utf_SQLColumnPrivileges(call_name, normal_db400_args) elif 'SQLColumns' in call_name: PaseCliLibDB400_c_main += non_utf_SQLColumns(call_name, normal_db400_args) elif 'SQLConnect' in call_name: PaseCliLibDB400_c_main += non_utf_SQLConnect(call_name, normal_db400_args) elif 'SQLDataSources' in call_name: PaseCliLibDB400_c_main += non_utf_SQLDataSources(call_name, normal_db400_args) elif 'SQLDescribeCol' in call_name: PaseCliLibDB400_c_main += non_utf_SQLDescribeCol(call_name, normal_db400_args) elif 'SQLDriverConnect' in call_name: PaseCliLibDB400_c_main += non_utf_SQLDriverConnect(call_name, normal_db400_args) elif 'SQLError' in call_name: PaseCliLibDB400_c_main += non_utf_SQLError(call_name, normal_db400_args) elif 'SQLExecDirect' in call_name: PaseCliLibDB400_c_main += non_utf_SQLExecDirect(call_name, normal_db400_args) elif 'SQLForeignKeys' in call_name: PaseCliLibDB400_c_main += non_utf_SQLForeignKeys(call_name, normal_db400_args) elif 'SQLGetConnectAttr' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetConnectAttr(call_name, normal_db400_args) elif 'SQLGetConnectOption' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetConnectOption(call_name, normal_db400_args) elif 'SQLGetCursorName' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetCursorName(call_name, normal_db400_args) elif 'SQLGetDescField' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetDescField(call_name, normal_db400_args) elif 'SQLGetDescRec' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetDescRec(call_name, normal_db400_args) elif 'SQLGetDiagField' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetDiagField(call_name, normal_db400_args) elif 'SQLGetDiagRec' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetDiagRec(call_name, normal_db400_args) elif 'SQLGetEnvAttr' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetEnvAttr(call_name, normal_db400_args) elif 'SQLGetInfo' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetInfo(call_name, normal_db400_args) elif 'SQLGetPosition' in call_name: PaseCliLibDB400_c_main += non_utf_SQLGetPosition(call_name, normal_db400_args) elif 'SQLNativeSql' in call_name: PaseCliLibDB400_c_main += non_utf_SQLNativeSql(call_name, normal_db400_args) elif 'SQLParamData' in call_name: PaseCliLibDB400_c_main += non_utf_SQLParamData(call_name, normal_db400_args) elif 'SQLPrepare' in call_name: PaseCliLibDB400_c_main += non_utf_SQLPrepare(call_name, normal_db400_args) elif 'SQLPrimaryKeys' in call_name: PaseCliLibDB400_c_main += non_utf_SQLPrimaryKeys(call_name, normal_db400_args) elif 'SQLProcedureColumns' in call_name: PaseCliLibDB400_c_main += non_utf_SQLProcedureColumns(call_name, normal_db400_args) elif 'SQLProcedures' in call_name: PaseCliLibDB400_c_main += non_utf_SQLProcedures(call_name, normal_db400_args) elif 'SQLSetConnectAttr' in call_name: PaseCliLibDB400_c_main += non_utf_SQLSetConnectAttr(call_name, normal_db400_args) elif 'SQLSetConnectOption' in call_name: PaseCliLibDB400_c_main += non_utf_SQLSetConnectOption(call_name, normal_db400_args) elif 'SQLSetCursorName' in call_name: PaseCliLibDB400_c_main += non_utf_SQLSetCursorName(call_name, normal_db400_args) elif 'SQLSetEnvAttr' in call_name: PaseCliLibDB400_c_main += non_utf_SQLSetEnvAttr(call_name, normal_db400_args) elif 'SQLSpecialColumns' in call_name: PaseCliLibDB400_c_main += non_utf_SQLSpecialColumns(call_name, normal_db400_args) elif 'SQLStatistics' in call_name: PaseCliLibDB400_c_main += non_utf_SQLStatistics(call_name, normal_db400_args) elif 'SQLTablePrivileges' in call_name: PaseCliLibDB400_c_main += non_utf_SQLTablePrivileges(call_name, normal_db400_args) elif 'SQLTables' in call_name: PaseCliLibDB400_c_main += non_utf_SQLTables(call_name, normal_db400_args) else: PaseCliLibDB400_c_main += " sqlrc = ILE_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliLibDB400_c_main += " return sqlrc;" + "\n" PaseCliLibDB400_c_main += '}' + "\n" libdb400_exp += "libdb400_" + call_name + "\n" else: # each SQL400 function special (header) # SQLRETURN SQL400Environment( SQLINTEGER * ohnd, SQLPOINTER options ) # PaseCliOnly400_h_proto += call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + "\n" PaseCliCustom_h_proto += call_retv + ' ' + "custom_" + call_name + '(' + normal_call_args + ' );' + "\n" # export special libdb400.a libdb400_exp += call_name + "\n" # each SQL function override # SQLRETURN SQLAllocEnv( SQLHENV * phenv ) # { # } if c400_CCSID: PaseCliAsync_c_main += 'int SQLOverrideCCSID400(int newCCSID)' + "\n" else: PaseCliAsync_c_main += call_retv + ' ' + call_name + '(' + normal_call_args + ' )' + "\n" PaseCliAsync_c_main += "{" + "\n" PaseCliAsync_c_main += " SQLRETURN sqlrc = SQL_SUCCESS;" + "\n" # special handling routines if call_name == "SQLAllocEnv": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocEnv(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLAllocConnect": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocConnect(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLAllocStmt": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocStmt(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLAllocHandle": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLAllocHandle(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLFreeEnv": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeEnv(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLFreeConnect": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeConnect(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLFreeStmt": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeStmt(ile_or_custom_call, call_name, normal_db400_args) elif call_name == "SQLFreeHandle": PaseCliAsync_c_main += PaseCliAsync_c_main_SQLFreeHandle(ile_or_custom_call, call_name, normal_db400_args) # SQLRETURN SQLOverrideCCSID400( SQLINTEGER newCCSID ) elif c400_CCSID: PaseCliAsync_c_main += " sqlrc = custom_" + call_name + '(' + normal_db400_args + ' );' + "\n" # all other CLI APIs else: # normal cli function PaseCliAsync_c_main += " int myccsid = init_CCSID400(0);" + "\n" if call_name == "SQLDisconnect": PaseCliAsync_c_main += SQLDisconnect_check_persistent("hdbc","return SQL_ERROR;", "/* return now */") if argtype1st == "SQLHENV": if ile_or_custom_call == "custom_": PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" else: PaseCliAsync_c_main += " switch(myccsid) {" + "\n" PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n" PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n" PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += ' default:' + "\n" PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += " }" + "\n" # dump trace PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n" PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " }" + "\n" elif argtype1st == "SQLHDBC": PaseCliAsync_c_main += " init_table_lock(" + argname1st + ", 0);" + "\n" if ile_or_custom_call == "custom_": PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" else: PaseCliAsync_c_main += " switch(myccsid) {" + "\n" PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n" PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n" PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += ' default:' + "\n" PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += " }" + "\n" # dump trace PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n" PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " }" + "\n" PaseCliAsync_c_main += " init_table_unlock(" + argname1st + ", 0);" + "\n" elif argtype1st == "SQLHSTMT": PaseCliAsync_c_main += " init_table_lock(" + argname1st + ", 1);" + "\n" if ile_or_custom_call == "custom_": PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" else: PaseCliAsync_c_main += " switch(myccsid) {" + "\n" PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n" PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n" PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += ' default:' + "\n" PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += " }" + "\n" # dump trace PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n" PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " }" + "\n" PaseCliAsync_c_main += " init_table_unlock(" + argname1st + ", 1);" + "\n" elif argtype1st == "SQLHDESC": PaseCliAsync_c_main += " init_table_lock(" + argname1st + ", 1);" + "\n" if ile_or_custom_call == "custom_": PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" else: PaseCliAsync_c_main += " switch(myccsid) {" + "\n" PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n" PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n" PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += ' default:' + "\n" PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += " }" + "\n" # dump trace PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n" PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " }" + "\n" PaseCliAsync_c_main += " init_table_unlock(" + argname1st + ", 1);" + "\n" else: if ile_or_custom_call == "custom_": PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" else: PaseCliAsync_c_main += " switch(myccsid) {" + "\n" PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n" PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n" PaseCliAsync_c_main += " sqlrc = " + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += ' default:' + "\n" PaseCliAsync_c_main += " sqlrc = libdb400_" + call_name + '(' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += " }" + "\n" # dump trace PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n" PaseCliAsync_c_main += " dump_" + call_name + '(sqlrc, ' + normal_db400_args + ' );' + "\n" PaseCliAsync_c_main += " }" + "\n" # common code PaseCliAsync_c_main += " return sqlrc;" + "\n" PaseCliAsync_c_main += "}" + "\n" # =============================================== # ILE call # =============================================== if c400 and c400_CCSID == False: PaseCliILE_h_proto += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' );' + "\n" PaseCliILE_h_struct += 'typedef struct ' + struct_ile_name + ' {' + ILE_struct_types + ' } ' + struct_ile_name + ';' + "\n"; PaseCliILE_c_symbol += 'SQLINTEGER ' + struct_ile_flag + ';' + "\n" PaseCliILE_c_symbol += 'SQLCHAR ' + struct_ile_buf + '[132];' + "\n" PaseCliILE_c_main += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' )' + "\n" PaseCliILE_c_main += '{' + "\n" PaseCliILE_c_main += ' int rc = 0;' + "\n" PaseCliILE_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + "\n" if 'SQLParamData' in call_name: PaseCliILE_c_main += ILE_SQLParamData_copy_var() if 'SQLGetDescField' in call_name: PaseCliILE_c_main += ILE_SQLGetDescField_copy_var() PaseCliILE_c_main += ' int actMark = 0;' + "\n" PaseCliILE_c_main += ' char * ileSymPtr = (char *) NULL;' + "\n" PaseCliILE_c_main += ' ' + struct_ile_name + ' * arglist = (' + struct_ile_name + ' *) NULL;' + "\n" PaseCliILE_c_main += ' char buffer[ sizeof(' + struct_ile_name + ') + 16 ];' + "\n" PaseCliILE_c_main += ' static arg_type_t ' + struct_ile_sig + '[] = {' + ILE_struct_sigs + ', ARG_END };' + "\n"; PaseCliILE_c_main += ' arglist = (' + struct_ile_name + ' *)ROUND_QUAD(buffer);' + "\n" PaseCliILE_c_main += ' ileSymPtr = (char *)ROUND_QUAD(&' + struct_ile_buf + ');' + "\n" PaseCliILE_c_main += ' memset(buffer,0,sizeof(buffer));' + "\n" PaseCliILE_c_main += ' actMark = init_cli_srvpgm();' + "\n" PaseCliILE_c_main += ' if (!'+ struct_ile_flag +') {' + "\n" PaseCliILE_c_main += ' rc = _ILESYM((ILEpointer *)ileSymPtr, actMark, "' + call_name + '");' + "\n" PaseCliILE_c_main += ' if (rc < 0) {' + "\n" PaseCliILE_c_main += ' return SQL_ERROR;' + "\n" PaseCliILE_c_main += ' }' + "\n" PaseCliILE_c_main += ' ' + struct_ile_flag + ' = 1;' + "\n" PaseCliILE_c_main += ' }' + "\n" PaseCliILE_c_main += ILE_copyin_args if 'SQLParamData' in call_name: PaseCliILE_c_main += ILE_SQLParamData_copy_in() if 'SQLGetDescField' in call_name: PaseCliILE_c_main += ILE_SQLGetDescField_copy_in() PaseCliILE_c_main += ' rc = _ILECALL((ILEpointer *)ileSymPtr, &arglist->base, ' + struct_ile_sig + ', RESULT_INT32);' + "\n" PaseCliILE_c_main += ' if (rc != ILECALL_NOERROR) {' + "\n" PaseCliILE_c_main += ' return SQL_ERROR;' + "\n" PaseCliILE_c_main += ' }' + "\n" if 'SQLParamData' in call_name: PaseCliILE_c_main += ILE_SQLParamData_copy_out() if 'SQLGetDescField' in call_name: PaseCliILE_c_main += ILE_SQLGetDescField_copy_out() PaseCliILE_c_main += ' return arglist->base.result.s_int32.r_int32;' + "\n" PaseCliILE_c_main += '}' + "\n" # =============================================== # NO async SQL interfaces with thread # =============================================== if call_name == "SQLAllocEnv": continue elif call_name == "SQLAllocConnect": continue elif call_name == "SQLAllocStmt": continue elif call_name == "SQLAllocHandle": continue elif call_name == "SQLFreeEnv": continue elif call_name == "SQLFreeConnect": continue elif call_name == "SQLFreeStmt": continue elif call_name == "SQLFreeHandle": continue elif c400_CCSID: continue # =============================================== # async SQL interfaces with thread # =============================================== async_call_args = normal_call_args + ', void * callback' async_struct_types += ' void * callback;' async_copyin_args += ' myptr->callback = callback;' + "\n" # each SQL function async (header) # SQLRETURN SQLSpecialColumnsAsync ( SQLHSTMT hstmt, SQLSMALLINT fColType, ... , void * callback ) # void (*callback)(SQLSpecialColumnsStruct* ) # SQLSpecialColumnsStruct * SQLSpecialColumnsJoin (pthread_t tid, SQLINTEGER flag) # tmp_PaseCliAsync_comment = '/* void ' + call_name + 'Callback(' + struct_name + '* ); */' PaseCliAsync_h_proto_async += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' );' + "\n" PaseCliAsync_h_proto_join += tmp_PaseCliAsync_comment + "\n" PaseCliAsync_h_proto_join += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag);' + "\n" # export special libdb400.a libdb400_exp += call_name + 'Async' + "\n" libdb400_exp += call_name + 'Join' + "\n" if c400: libdb400_exp += 'ILE_' + call_name + "\n" # each SQL function async # typedef struct SQLAllocEnvStruct { # SQLRETURN sqlrc; # SQLHENV * phenv; # } SQLAllocEnvStruct; # # PaseCliAsync_h_struct += 'typedef struct ' + struct_name + ' {' + async_struct_types + ' } ' + struct_name + ';' + "\n"; # each SQL function async # void * SQLAllocEnvThread(void *ptr) # { # void (*callback)(SQLSpecialColumnsStruct* ) # } PaseCliAsync_c_main += 'void * ' + call_name + 'Thread (void *ptr)' + "\n" PaseCliAsync_c_main += "{" + "\n" PaseCliAsync_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + "\n" PaseCliAsync_c_main += " int myccsid = init_CCSID400(0);" + "\n" PaseCliAsync_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) ptr;' + "\n" if call_name == "SQLDisconnect": PaseCliAsync_c_main += SQLDisconnect_check_persistent("myptr->hdbc","pthread_exit((void *)myptr);","myptr->sqlrc = SQL_ERROR;") if argtype1st == "SQLHENV": PaseCliAsync_c_main += " /* not lock */" + "\n" elif argtype1st == "SQLHDBC": PaseCliAsync_c_main += " init_table_lock(myptr->" + argname1st + ", 0);" + "\n" elif argtype1st == "SQLHSTMT": PaseCliAsync_c_main += " init_table_lock(myptr->" + argname1st + ", 1);" + "\n" elif argtype1st == "SQLHDESC": PaseCliAsync_c_main += " init_table_lock(myptr->" + argname1st + ", 1);" + "\n" if ile_or_custom_call == "custom_": PaseCliAsync_c_main += " myptr->sqlrc = " + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + "\n" else: # CLI call PaseCliAsync_c_main += " switch(myccsid) {" + "\n" PaseCliAsync_c_main += ' case 1208: /* UTF-8 */' + "\n" PaseCliAsync_c_main += ' case 1200: /* UTF-16 */' + "\n" PaseCliAsync_c_main += " myptr->sqlrc = " + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += ' default:' + "\n" PaseCliAsync_c_main += " myptr->sqlrc = libdb400_" + call_name + '(' + async_db400_args + ' );' + "\n" PaseCliAsync_c_main += " break;" + "\n" PaseCliAsync_c_main += " }" + "\n" # dump trace PaseCliAsync_c_main += " if (init_cli_trace()) {" + "\n" PaseCliAsync_c_main += " dump_" + call_name + '(myptr->sqlrc, ' + async_db400_args + ' );' + "\n" PaseCliAsync_c_main += " }" + "\n" if argtype1st == "SQLHENV": PaseCliAsync_c_main += " /* not lock */" + "\n" elif argtype1st == "SQLHDBC": PaseCliAsync_c_main += " init_table_unlock(myptr->" + argname1st + ", 0);" + "\n" elif argtype1st == "SQLHSTMT": PaseCliAsync_c_main += " init_table_unlock(myptr->" + argname1st + ", 1);" + "\n" elif argtype1st == "SQLHDESC": PaseCliAsync_c_main += " init_table_unlock(myptr->" + argname1st + ", 1);" + "\n" PaseCliAsync_c_main += ' ' + tmp_PaseCliAsync_comment + "\n" PaseCliAsync_c_main += ' if (myptr->callback) {' + "\n" PaseCliAsync_c_main += ' void (*ptrFunc)(' + struct_name + '* ) = myptr->callback;' + "\n" PaseCliAsync_c_main += ' ptrFunc( myptr );' + "\n" PaseCliAsync_c_main += " }" + "\n" PaseCliAsync_c_main += " pthread_exit((void *)myptr);" + "\n" PaseCliAsync_c_main += "}" + "\n" # each SQL function async # pthread_t SQLSpecialColumnsAsync ( SQLHSTMT hstmt, SQLSMALLINT fColType, ... , void * callback ) # { # } PaseCliAsync_c_main += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' )' + "\n" PaseCliAsync_c_main += '{' + "\n" PaseCliAsync_c_main += ' int rc = 0;' + "\n" PaseCliAsync_c_main += ' pthread_t tid = 0;' + "\n" PaseCliAsync_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) malloc(sizeof(' + struct_name + '));' + "\n" PaseCliAsync_c_main += ' myptr->sqlrc = SQL_SUCCESS;' + "\n" PaseCliAsync_c_main += async_copyin_args PaseCliAsync_c_main += ' rc = pthread_create(&tid, NULL, '+ call_name + 'Thread, (void *)myptr);' + "\n" PaseCliAsync_c_main += ' return tid;' + "\n" PaseCliAsync_c_main += '}' + "\n" # each SQL function async # SQLSpecialColumnsStruct * SQLSpecialColumnsJoin (pthread_t tid, SQLINTEGER flag) # { # } PaseCliAsync_c_main += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag)' + "\n" PaseCliAsync_c_main += "{" + "\n" PaseCliAsync_c_main += " " + struct_name + " * myptr = (" + struct_name + " *) NULL;" + "\n" PaseCliAsync_c_main += " int active = 0;" + "\n" if argtype1st == "SQLHENV": PaseCliAsync_c_main += " /* not lock */" + "\n" elif argtype1st == "SQLHDBC": PaseCliAsync_c_main += " active = init_table_in_progress(tid, 0);" + "\n" elif argtype1st == "SQLHSTMT": PaseCliAsync_c_main += " active = init_table_in_progress(tid, 1);" + "\n" elif argtype1st == "SQLHDESC": PaseCliAsync_c_main += " active = init_table_in_progress(tid, 1);" + "\n" PaseCliAsync_c_main += " if (flag == SQL400_FLAG_JOIN_WAIT || !active) {" + "\n" PaseCliAsync_c_main += " pthread_join(tid,(void**)&myptr);" + "\n" PaseCliAsync_c_main += " } else {" + "\n" PaseCliAsync_c_main += " return (" + struct_name + " *) NULL;" + "\n" PaseCliAsync_c_main += " }" + "\n" PaseCliAsync_c_main += " return myptr;" + "\n" PaseCliAsync_c_main += "}" + "\n" # =============================================== # write files # =============================================== # pase includes file_pase_incl = "" file_pase_incl += "#include <stdio.h>" + "\n" file_pase_incl += "#include <stdlib.h>" + "\n" file_pase_incl += "#include <unistd.h>" + "\n" file_pase_incl += "#include <dlfcn.h>" + "\n" file_pase_incl += "#include <sqlcli1.h>" + "\n" file_pase_incl += "#include <as400_types.h>" + "\n" file_pase_incl += "#include <as400_protos.h>" + "\n" # new libdb400 includes file_local_incl = "" file_local_incl += '#include "PaseCliInit.h"' + "\n" file_local_incl += '#include "PaseCliAsync.h"' + "\n" # write PaseCliILE_gen.c file_PaseCliILE_c = "" file_PaseCliILE_c += file_pase_incl file_PaseCliILE_c += file_local_incl file_PaseCliILE_c += "" + "\n" file_PaseCliILE_c += ' /* gcc compiler' + "\n" file_PaseCliILE_c += ' * as400_types.h (edit change required)' + "\n" file_PaseCliILE_c += ' * #if defined( __GNUC__ )' + "\n" file_PaseCliILE_c += ' * long double align __attribute__((aligned(16)));' + "\n" file_PaseCliILE_c += ' * #else ' + "\n" file_PaseCliILE_c += ' * long double;' + "\n" file_PaseCliILE_c += ' * #endif ' + "\n" file_PaseCliILE_c += ' * ' + "\n" file_PaseCliILE_c += ' * Use we also need cast ulong to match size of pointer 32/64 ' + "\n" file_PaseCliILE_c += ' * arglist->ohnd.s.addr = (ulong) ohnd;' + "\n" file_PaseCliILE_c += ' */' + "\n" file_PaseCliILE_c += "" + "\n" file_PaseCliILE_c += '#define ROUND_QUAD(x) (((size_t)(x) + 0xf) & ~0xf)' + "\n" file_PaseCliILE_c += "" + "\n" file_PaseCliILE_c += PaseCliILE_c_symbol file_PaseCliILE_c += "" + "\n" file_PaseCliILE_c += "/* ILE call structures */" + "\n" file_PaseCliILE_c += "" + "\n" file_PaseCliILE_c += PaseCliILE_h_struct + "\n" file_PaseCliILE_c += "" + "\n" file_PaseCliILE_c += PaseCliILE_c_main file_PaseCliILE_c += "" + "\n" with open("PaseCliILE_gen.c", "w") as text_file: text_file.write(file_PaseCliILE_c) # write PaseCliLibDB400_gen.c file_PaseCliLibDB400_c = "" file_PaseCliLibDB400_c += file_pase_incl file_PaseCliLibDB400_c += file_local_incl file_PaseCliLibDB400_c += "" + "\n" file_PaseCliLibDB400_c += "#define DFTCOLSIZE 18" + "\n" file_PaseCliLibDB400_c += "#define SQL_MAXINTVAL_REASONABLE 131072" + "\n" file_PaseCliLibDB400_c += "" + "\n" file_PaseCliLibDB400_c += PaseCliLibDB400_c_symbol file_PaseCliLibDB400_c += "" + "\n" file_PaseCliLibDB400_c += non_utf_copy_in() file_PaseCliLibDB400_c += non_utf_copy_in_free() file_PaseCliLibDB400_c += non_utf_copy_out() file_PaseCliLibDB400_c += non_utf_isconvert_ordinal(); file_PaseCliLibDB400_c += "" + "\n" file_PaseCliLibDB400_c += PaseCliLibDB400_c_main file_PaseCliLibDB400_c += "" + "\n" with open("PaseCliLibDB400_gen.c", "w") as text_file: text_file.write(file_PaseCliLibDB400_c) # write PaseCliAsync_gen.c file_PaseCliAsync_c = "" file_PaseCliAsync_c += file_pase_incl file_PaseCliAsync_c += file_local_incl file_PaseCliAsync_c += "" + "\n" file_PaseCliAsync_c += "" + "\n" file_PaseCliAsync_c += PaseCliAsync_c_main with open("PaseCliAsync_gen.c", "w") as text_file: text_file.write(file_PaseCliAsync_c) # write PaseCliDump_gen.c file_PaseCliDump_c = "" file_PaseCliDump_c += file_pase_incl file_PaseCliDump_c += file_local_incl file_PaseCliDump_c += '#include "PaseCliDev.h"' + "\n" file_PaseCliDump_c += '#include "PaseCliPrintf.h"' + "\n" file_PaseCliDump_c += "" + "\n" file_PaseCliDump_c += "" + "\n" file_PaseCliDump_c += PaseCliDump_c_main with open("PaseCliDump_gen.c", "w") as text_file: text_file.write(file_PaseCliDump_c) # write PaseCliAsync.h file_PaseCliAsync_h = "" file_PaseCliAsync_h += '#ifndef _PASECLIASYNC_H' + "\n" file_PaseCliAsync_h += '#define _PASECLIASYNC_H' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += file_pase_incl file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '#ifdef __cplusplus' + "\n" file_PaseCliAsync_h += 'extern "C" {' + "\n" file_PaseCliAsync_h += '#endif' + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * Using the driver' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "/* " + "\n" file_PaseCliAsync_h += ' * SQL400Environment -- set the mode of driver' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * === UTF-8 mode, most popular AIX/PASE/Linux ===' + "\n" file_PaseCliAsync_h += ' * SQLOverrideCCSID400(1208) -- UTF-8 mode, CLI normal/async direct ILE call' + "\n" file_PaseCliAsync_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirect-->DB2' + "\n" file_PaseCliAsync_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * === UTF-8 mode, most popular Windows/Java ===' + "\n" file_PaseCliAsync_h += ' * SQLOverrideCCSID400(1200) -- UTF-16 mode, CLI normal/async direct ILE call' + "\n" file_PaseCliAsync_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirectW-->DB2' + "\n" file_PaseCliAsync_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * === PASE default (original libdb400.a) ===' + "\n" file_PaseCliAsync_h += ' * SQLOverrideCCSID400(other) -- PASE ccsid, CLI API calls PASE libdb400.a' + "\n" file_PaseCliAsync_h += ' * -->SQLExecDirect(Async)-->PASE libdb400.a(SQLExecDirect)-->DB2' + "\n" file_PaseCliAsync_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2 (*)' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * PASE ccsid setting occurs before any other CLI operations' + "\n" file_PaseCliAsync_h += ' * at the environment level. Therefore the driver mode is' + "\n" file_PaseCliAsync_h += ' * established (restricted, if you choose). ' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * 1) non-Unicode interfaces (call old libdb400.a, messy stuff):' + "\n" file_PaseCliAsync_h += ' * int ccsid = 819;' + "\n" file_PaseCliAsync_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * 2) UTF8 interfaces (call direct to ILE DB2):' + "\n" file_PaseCliAsync_h += ' * int ccsid = 1208;' + "\n" file_PaseCliAsync_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + "\n" file_PaseCliAsync_h += ' * if ccsid == 1208:' + "\n" file_PaseCliAsync_h += ' * env attr SQL_ATTR_UTF8 &true -- no conversion required by PASE' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * 3) UTF16 wide interfaces (call direct to ILE DB2):' + "\n" file_PaseCliAsync_h += ' * **** NEVER set PASE_CCSID or ATTR_UTF8 in UTF-16 mode. ****' + "\n" file_PaseCliAsync_h += ' * So, database exotic ebcdic column and PASE binds c type as WVARCHAR/WCHAR output is UTF16?' + "\n" file_PaseCliAsync_h += ' * Yes, the database will do the conversion from EBCDIC to UTF16 for data bound as WVARCHAR/WCHAR.' + "\n" file_PaseCliAsync_h += ' * not sure about DBCLOB -- I want to guess that is bound as UTF-16, not 100% sure.' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * IF your data not UTF-8 or UTF-16, interfaces to convert (experimental).' + "\n" file_PaseCliAsync_h += ' * SQL400ToUtf8 -- use before passing to CLI normal interfaces' + "\n" file_PaseCliAsync_h += ' * SQL400FromUtf8 -- use return output normal CLI (if needed)' + "\n" file_PaseCliAsync_h += ' * SQL400ToUtf16 -- use before passing to CLI wide interfaces' + "\n" file_PaseCliAsync_h += ' * SQL400FromUtf16 -- use return output wide CLI (if needed)' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += " * A choice of exported APIs (SQLExecDirect one of many):" + "\n" file_PaseCliAsync_h += " * " + "\n" file_PaseCliAsync_h += ' * === CLI APIs UTF-8 or APIWs UTF-16 ===' + "\n" file_PaseCliAsync_h += ' * === choose async and/or normal wait ===' + "\n" file_PaseCliAsync_h += ' * SQLRETURN SQLExecDirect(..);' + "\n" file_PaseCliAsync_h += ' * SQLRETURN SQLExecDirectW(..);' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * == callback or reap/join with async ===' + "\n" file_PaseCliAsync_h += ' * pthread_t SQLExecDirectAsync(..);' + "\n" file_PaseCliAsync_h += ' * pthread_t SQLExecDirectWAsync(..);' + "\n" file_PaseCliAsync_h += ' * void SQLExecDirectCallback(SQLExecDirectStruct* );' + "\n" file_PaseCliAsync_h += ' * SQLExecDirectStruct * SQLExecDirectJoin (pthread_t tid, SQLINTEGER flag);' + "\n" file_PaseCliAsync_h += ' * void SQLExecDirectWCallback(SQLExecDirectWStruct* );' + "\n" file_PaseCliAsync_h += ' * SQLExecDirectWStruct * SQLExecDirectWJoin (pthread_t tid, SQLINTEGER flag);' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * === bypass all, call PASE libdb400.a directly (not recommended) ===' + "\n" file_PaseCliAsync_h += ' * SQLRETURN libdb400_SQLExecDirect(..);' + "\n" file_PaseCliAsync_h += ' * SQLRETURN libdb400_SQLExecDirectW(..); (*)' + "\n" file_PaseCliAsync_h += ' * ' + "\n" file_PaseCliAsync_h += ' * === bypass all, call ILE directly (not recommended) ===' + "\n" file_PaseCliAsync_h += ' * SQLRETURN ILE_SQLExecDirect(..);' + "\n" file_PaseCliAsync_h += ' * SQLRETURN ILE_SQLExecDirectW(..);' + "\n" file_PaseCliAsync_h += " * " + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * CUSTOM interfaces' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* Use:' + "\n" file_PaseCliAsync_h += ' * SQL400Environment ( ..., SQLPOINTER options )' + "\n" file_PaseCliAsync_h += ' * SQL400Connect ( ..., SQLPOINTER options )' + "\n" file_PaseCliAsync_h += ' * SQL400SetAttr ( ..., SQLPOINTER options )' + "\n" file_PaseCliAsync_h += ' * CTOR:' + "\n" file_PaseCliAsync_h += ' * SQL400AddAttr' + "\n" file_PaseCliAsync_h += ' * Struct:' + "\n" file_PaseCliAsync_h += ' * SQL400AttrStruct' + "\n" file_PaseCliAsync_h += ' * e - EnvAttr' + "\n" file_PaseCliAsync_h += ' * c - ConnectAttr' + "\n" file_PaseCliAsync_h += ' * s - StmtAttr' + "\n" file_PaseCliAsync_h += ' * o - StmtOption' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += '/* CLI hidden attributes */' + "\n" file_PaseCliAsync_h += '#define SQL400_ATTR_PASE_CCSID 10011' + "\n" file_PaseCliAsync_h += '#define SQL400_ATTR_CONN_JDBC 10201' + "\n" file_PaseCliAsync_h += '/* stop or not on attribute failure */' + "\n" file_PaseCliAsync_h += '#define SQL400_ONERR_CONT 1' + "\n" file_PaseCliAsync_h += '#define SQL400_ONERR_STOP 2' + "\n" file_PaseCliAsync_h += '/* normal attributes */' + "\n" file_PaseCliAsync_h += '#define SQL400_FLAG_IMMED 0' + "\n" file_PaseCliAsync_h += '/* post connect attributes */' + "\n" file_PaseCliAsync_h += '#define SQL400_FLAG_POST_CONNECT 1' + "\n" file_PaseCliAsync_h += '#define SQL400_ATTR_CONN_CHGCURLIB 424201' + "\n" file_PaseCliAsync_h += '#define SQL400_ATTR_CONN_CHGLIBL 424202' + "\n" file_PaseCliAsync_h += 'typedef struct SQL400AttrStruct {' + "\n" file_PaseCliAsync_h += ' SQLINTEGER scope; /* - scope - SQL_HANDLE_ENV|DBC|SRTMT|DESC */' + "\n" file_PaseCliAsync_h += ' SQLHANDLE hndl; /* ecso - hndl - CLI handle */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER attrib; /* ecso - attrib - CLI attribute */' + "\n" file_PaseCliAsync_h += ' SQLPOINTER vParam; /* ecso - vParam - ptr to CLI value */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER inlen; /* ecs - inlen - len CLI value (string) */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER sqlrc; /* - sqlrc - sql return code */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER onerr; /* - onerr - SQL400_ONERR_xxx */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER flag; /* - flag - SQL400_FLAG_xxx */' + "\n" file_PaseCliAsync_h += '} SQL400AttrStruct;' + "\n" file_PaseCliAsync_h += '/* Use:' + "\n" file_PaseCliAsync_h += ' * SQL400Execute( ..., SQLPOINTER parms, SQLPOINTER desc_parms)' + "\n" file_PaseCliAsync_h += ' * SQL400Fetch (..., SQLPOINTER desc_cols)' + "\n" file_PaseCliAsync_h += ' * CTOR:' + "\n" file_PaseCliAsync_h += ' * SQL400Describe' + "\n" file_PaseCliAsync_h += ' * SQL400AddCVar' + "\n" file_PaseCliAsync_h += ' * Struct:' + "\n" file_PaseCliAsync_h += ' * SQL400ParamStruct' + "\n" file_PaseCliAsync_h += ' * SQL400DescribeStruct' + "\n" file_PaseCliAsync_h += ' * p - SQLDescribeParam' + "\n" file_PaseCliAsync_h += ' * c - SQLDescribeCol' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += '#define SQL400_DESC_PARM 0' + "\n" file_PaseCliAsync_h += '#define SQL400_DESC_COL 1' + "\n" file_PaseCliAsync_h += '#define SQL400_PARM_IO_FILE 42' + "\n" file_PaseCliAsync_h += 'typedef struct SQL400ParamStruct {' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT icol; /* icol - param number (in) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT inOutType; /* inOutType - sql C in/out flag (in) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT pfSqlCType; /* pfSqlCType - sql C data type (in) */' + "\n" file_PaseCliAsync_h += ' SQLPOINTER pfSqlCValue; /* pfSqlCValue - sql C ptr to data (out) */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER * indPtr; /* indPtr - sql strlen/ind (out) */' + "\n" file_PaseCliAsync_h += '} SQL400ParamStruct;' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += 'typedef struct SQL400DescStruct {' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT itype; /* - itype - descr col/parm (out) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT icol; /* pc - icol - column number (in) */' + "\n" file_PaseCliAsync_h += ' SQLCHAR * szColName; /* c - szColName - column name ptr (out) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT cbColNameMax; /* c - cbColNameMax - name max len (in) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT pcbColName; /* c - pcbColName - name size len (out) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT pfSqlType; /* pc - pfSqlType - sql data type (out) */' + "\n" file_PaseCliAsync_h += ' SQLINTEGER pcbColDef; /* pc - pcbColDef - sql size column (out) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT pibScale; /* pc - pibScale - decimal digits (out) */' + "\n" file_PaseCliAsync_h += ' SQLSMALLINT pfNullable; /* pc - pfNullable - null allowed (out) */' + "\n" file_PaseCliAsync_h += ' SQLCHAR bfColName[1024]; /* c - bfColName - column name buf (out) */' + "\n" file_PaseCliAsync_h += '} SQL400DescStruct;' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "/* special SQL400 aggregate functions */" + "\n" file_PaseCliAsync_h += "/* do common work for language driver */" + "\n" file_PaseCliAsync_h += "/* composite calls to CLI also async */" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliOnly400_h_proto file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * NORMAL CLI interfaces' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "/* === sqlcli.h -- normal CLI interfaces (copy) === " + "\n" file_PaseCliAsync_h += PaseCliAny_h_proto file_PaseCliAsync_h += " * === sqlcli.h === */" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * ASYNC CLI interfaces' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "/* choose either callback or join */" + "\n" file_PaseCliAsync_h += "/* following structures returned */" + "\n" file_PaseCliAsync_h += "/* caller must free return structure */" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliAsync_h_struct + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "/* join async thread */" + "\n" file_PaseCliAsync_h += "/* flag: */" + "\n" file_PaseCliAsync_h += "/* SQL400_FLAG_JOIN_WAIT */" + "\n" file_PaseCliAsync_h += "/* - block until complete */" + "\n" file_PaseCliAsync_h += "/* SQL400_FLAG_JOIN_NO_WAIT */" + "\n" file_PaseCliAsync_h += "/* - no block, NULL still executing */" + "\n" file_PaseCliAsync_h += '#define SQL400_FLAG_JOIN_WAIT 0' + "\n" file_PaseCliAsync_h += '#define SQL400_FLAG_JOIN_NO_WAIT 1' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliAsync_h_proto_join file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "/* start an async call to DB2 CLI */" + "\n" file_PaseCliAsync_h += "/* choose either callback or join */" + "\n" file_PaseCliAsync_h += "/* for results returned. */" + "\n" file_PaseCliAsync_h += "/* sqlrc returned in structure. */" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliAsync_h_proto_async file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * ILE CLI interfaces' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliILE_h_proto file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * LIBDB400.A CLI interfaces (PASE old CLI driver)' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliLibDB400_h_proto file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * trace dump' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliDump_h_proto file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '/* ===================================================' + "\n" file_PaseCliAsync_h += ' * INTERNAL USE' + "\n" file_PaseCliAsync_h += ' * ===================================================' + "\n" file_PaseCliAsync_h += ' */' + "\n" file_PaseCliAsync_h += "#ifndef SQL_ATTR_SERVERMODE_SUBSYSTEM" + "\n" file_PaseCliAsync_h += "#define SQL_ATTR_SERVERMODE_SUBSYSTEM 10204" + "\n" file_PaseCliAsync_h += "#endif" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += PaseCliCustom_h_proto file_PaseCliAsync_h += "SQLRETURN custom_SQLSetEnvCCSID( SQLHANDLE env, int myccsid);" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += "" + "\n" file_PaseCliAsync_h += '#ifdef __cplusplus ' + "\n" file_PaseCliAsync_h += '}' + "\n" file_PaseCliAsync_h += '#endif /* __cplusplus */' + "\n" file_PaseCliAsync_h += '#endif /* _PASECLIASYNC_H */' + "\n" with open("PaseCliAsync.h", "w") as text_file: text_file.write(file_PaseCliAsync_h) # write libdb400.exp file_libdb400_exp = "" file_libdb400_exp += "#!libdb400.a(shr.o)" + "\n" file_libdb400_exp += "" + "\n" file_libdb400_exp += "" + "\n" file_libdb400_exp += libdb400_exp file_libdb400_exp += "" + "\n" file_libdb400_exp += "" + "\n" file_libdb400_exp += "dev_dump" + "\n" file_libdb400_exp += "dev_go" + "\n" file_libdb400_exp += "printf_key" + "\n" file_libdb400_exp += "printf_buffer" + "\n" file_libdb400_exp += "printf_clear" + "\n" file_libdb400_exp += "printf_format" + "\n" file_libdb400_exp += "printf_hexdump" + "\n" file_libdb400_exp += "printf_stack" + "\n" file_libdb400_exp += "printf_script" + "\n" file_libdb400_exp += "printf_script_include" + "\n" file_libdb400_exp += "printf_script_exclude" + "\n" file_libdb400_exp += "printf_script_clear" + "\n" file_libdb400_exp += "printf_force_SIGQUIT" + "\n" file_libdb400_exp += "printf_sqlrc_status" + "\n" file_libdb400_exp += "printf_sqlrc_head_foot" + "\n" file_libdb400_exp += "sprintf_format" + "\n" file_libdb400_exp += "" + "\n" file_libdb400_exp += "" + "\n" with open("libdb400.exp", "w") as text_file: text_file.write(file_libdb400_exp)
pase_sql_cli_file = './gen_cli_template.c' def parse_sizeme(st): sz = '4' if 'SMALL' in st: sz = '2' elif '*' in st: sz = '4' return sz def parse_star(line): v1 = '' v2 = '' v3 = '' split1 = line.split('*') if len(split1) > 1: v1 = split1[0] v2 = '*' v3 = split1[1] else: split1 = line.split() v1 = split1[0] v2 = '' v3 = split1[1] return [v1.strip(), v2, v3.strip()] def parse_method(line): split1 = line.split('(') func = split1[0] split2 = split1[1].split(')') argv = split2[0] funcs = parse_star(func) split3 = argv.split(',') args = [] for arg in split3: args.append(parse_star(arg)) return [funcs, args] def pase_cli_async_c_main_sql_alloc_env(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n' c_main += ' init_table_ctor(*phenv, *phenv);' + '\n' c_main += ' custom_SQLSetEnvCCSID(*phenv, myccsid);' + '\n' c_main += ' }' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_alloc_connect(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n' c_main += ' init_table_ctor(*phdbc, *phdbc);' + '\n' c_main += ' }' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_alloc_stmt(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n' c_main += ' init_table_ctor(*phstmt, hdbc);' + '\n' c_main += ' }' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_alloc_handle(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' switch (htype) {' + '\n' c_main += ' case SQL_HANDLE_ENV:' + '\n' c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n' c_main += ' init_table_ctor(*ohnd, *ohnd);' + '\n' c_main += ' custom_SQLSetEnvCCSID(*ohnd, myccsid);' + '\n' c_main += ' }' + '\n' c_main += ' break;' + '\n' c_main += ' case SQL_HANDLE_DBC:' + '\n' c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n' c_main += ' init_table_ctor(*ohnd, *ohnd);' + '\n' c_main += ' }' + '\n' c_main += ' break;' + '\n' c_main += ' case SQL_HANDLE_STMT:' + '\n' c_main += ' case SQL_HANDLE_DESC:' + '\n' c_main += ' if (sqlrc == SQL_SUCCESS) {' + '\n' c_main += ' init_table_ctor(*ohnd, ihnd);' + '\n' c_main += ' }' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_free_env(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_free_connect(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' int active = init_table_hash_active(hdbc, 0);' + '\n' c_main += ' /* persistent connect only close with SQL400pClose */' + '\n' c_main += ' if (active) {' + '\n' c_main += ' return SQL_ERROR;' + '\n' c_main += ' }' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' init_table_dtor(hdbc);' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_free_stmt(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' init_table_dtor(hstmt);' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def pase_cli_async_c_main_sql_free_handle(ile_or_custom_call, call_name, normal_db400_args): c_main = '' c_main += ' int myccsid = init_CCSID400(0);' + '\n' c_main += ' int persistent = init_table_hash_active(hndl, 0);' + '\n' c_main += ' /* persistent connect only close with SQL400pClose */' + '\n' c_main += ' switch (htype) {' + '\n' c_main += ' case SQL_HANDLE_DBC:' + '\n' c_main += ' if (persistent) {' + '\n' c_main += ' return SQL_ERROR;' + '\n' c_main += ' }' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' init_lock();' + '\n' c_main += ' switch(myccsid) {' + '\n' c_main += ' case 1208: /* UTF-8 */' + '\n' c_main += ' case 1200: /* UTF-16 */' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' switch (htype) {' + '\n' c_main += ' case SQL_HANDLE_ENV:' + '\n' c_main += ' break;' + '\n' c_main += ' default:' + '\n' c_main += ' init_table_dtor(hndl);' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' init_unlock();' + '\n' c_main += ' if (init_cli_trace()) {' + '\n' c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' c_main += ' }' + '\n' return c_main def sql_disconnect_check_persistent(hdbc_code, return_code, set_code): c_main = '' c_main += ' int persistent = init_table_hash_active(' + hdbc_code + ', 0);' + '\n' c_main += ' /* persistent connect only close with SQL400pClose */' + '\n' c_main += ' if (persistent) {' + '\n' c_main += ' ' + set_code + '\n' c_main += ' ' + return_code + '\n' c_main += ' }' + '\n' return c_main def non_utf_copy_in(): c_main = '' c_main += 'int non_utf_copy_in_hdbc(SQLHDBC\thdbc, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + '\n' c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + '\n' c_main += ' int inccsid = init_CCSID400(0);' + '\n' c_main += ' int outccsid = init_job_CCSID400();' + '\n' c_main += ' SQLCHAR * inparm = *src;' + '\n' c_main += ' SQLINTEGER inlen = srclen;' + '\n' c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + '\n' c_main += ' SQLINTEGER outlen = 0;' + '\n' c_main += ' if (inparm) {' + '\n' c_main += ' if (srclen == SQL_NTS) {' + '\n' c_main += ' inlen = strlen(inparm);' + '\n' c_main += ' }' + '\n' c_main += ' outlen = maxlen;' + '\n' c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + '\n' c_main += ' memset(outparm,0,outlen);' + '\n' c_main += ' sqlrc1 = SQL400IgnoreNullAnyToAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + '\n' c_main += ' outlen = strlen(outparm);' + '\n' c_main += ' }' + '\n' c_main += ' *tmp = *src;' + '\n' c_main += ' if (*src) {' + '\n' c_main += ' *src = outparm;' + '\n' c_main += ' }' + '\n' c_main += ' return outlen;' + '\n' c_main += '}' + '\n' c_main += 'int non_utf_copy_in_hstmt(SQLHSTMT hstmt, SQLCHAR **tmp, SQLCHAR **src, SQLINTEGER srclen, SQLINTEGER maxlen) {' + '\n' c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + '\n' c_main += ' return non_utf_copy_in_hdbc(hdbc, tmp, src, srclen, maxlen);' + '\n' c_main += '}' + '\n' return c_main def non_utf_copy_in_free(): c_main = '' c_main += 'void non_utf_copy_in_free(SQLCHAR **tmp, SQLCHAR **src) {' + '\n' c_main += ' char * trash = *src;' + '\n' c_main += ' *src = *tmp;' + '\n' c_main += ' if (trash) {' + '\n' c_main += ' free(trash);' + '\n' c_main += ' *tmp = NULL;' + '\n' c_main += ' }' + '\n' c_main += '}' + '\n' return c_main def non_utf_copy_out(): c_main = '' c_main += 'int non_utf_copy_out_hdbc(SQLHDBC\thdbc, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + '\n' c_main += ' SQLRETURN sqlrc1 = SQL_SUCCESS;' + '\n' c_main += ' int inccsid = init_CCSID400(0);' + '\n' c_main += ' int outccsid = init_job_CCSID400();' + '\n' c_main += ' SQLCHAR * inparm = src;' + '\n' c_main += ' SQLINTEGER inlen = srclen;' + '\n' c_main += ' SQLCHAR * outparm = (SQLCHAR *) NULL;' + '\n' c_main += ' SQLINTEGER outlen = 0;' + '\n' c_main += ' if (inparm && (inlen != SQL_NULL_DATA) && (sqlrc == SQL_SUCCESS || sqlrc == SQL_SUCCESS_WITH_INFO)) {' + '\n' c_main += ' outlen = inlen + 1;' + '\n' c_main += ' outparm = (SQLCHAR *) malloc(outlen);' + '\n' c_main += ' memset(outparm,0,outlen);' + '\n' c_main += ' sqlrc1 = SQL400IgnoreNullAnyFromAny(hdbc, inparm, inlen, outparm, outlen, inccsid, outccsid);' + '\n' c_main += ' outlen = strlen(outparm);' + '\n' c_main += ' memcpy(inparm,outparm,inlen);' + '\n' c_main += ' free(outparm);' + '\n' c_main += ' }' + '\n' c_main += ' return outlen;' + '\n' c_main += '}' + '\n' c_main += 'int non_utf_copy_out_hstmt(SQLHSTMT hstmt, SQLRETURN sqlrc, SQLCHAR *src, SQLINTEGER srclen) {' + '\n' c_main += ' SQLHDBC hdbc = init_table_stmt_2_conn(hstmt);' + '\n' c_main += ' return non_utf_copy_out_hdbc(hdbc, sqlrc, src, srclen);' + '\n' c_main += '}' + '\n' return c_main def non_utf_isconvert_ordinal(): c_main = '' c_main += 'int non_utf_isconvert_ordinal(SQLINTEGER ord) {' + '\n' c_main += ' int convert = 0;' + '\n' c_main += ' switch(ord) {' + '\n' c_main += ' case SQL_ATTR_DBC_DEFAULT_LIB:' + ' \n' c_main += ' case SQL_ATTR_SAVEPOINT_NAME:' + ' \n' c_main += ' case SQL_ATTR_INFO_ACCTSTR:' + ' \n' c_main += ' case SQL_ATTR_INFO_APPLNAME:' + ' \n' c_main += ' case SQL_ATTR_INFO_PROGRAMID:' + ' \n' c_main += ' case SQL_ATTR_INFO_USERID:' + ' \n' c_main += ' case SQL_ATTR_INFO_WRKSTNNAME:' + ' \n' c_main += ' case SQL_ATTR_SERVERMODE_SUBSYSTEM:' + ' \n' c_main += ' case SQL_DBMS_NAME:' + ' \n' c_main += ' case SQL_DBMS_VER:' + ' \n' c_main += ' case SQL_PROCEDURES:' + ' \n' c_main += ' case SQL_DATA_SOURCE_NAME:' + ' \n' c_main += ' case SQL_COLUMN_ALIAS:' + ' \n' c_main += ' case SQL_DATA_SOURCE_READ_ONLY:' + ' \n' c_main += ' case SQL_MULTIPLE_ACTIVE_TXN:' + ' \n' c_main += ' case SQL_DRIVER_NAME:' + ' \n' c_main += ' case SQL_IDENTIFIER_QUOTE_CHAR:' + ' \n' c_main += ' case SQL_PROCEDURE_TERM:' + ' \n' c_main += ' case SQL_QUALIFIER_TERM:' + ' \n' c_main += ' case SQL_QUALIFIER_NAME_SEPARATOR:' + ' \n' c_main += ' case SQL_OWNER_TERM:' + ' \n' c_main += ' case SQL_DRIVER_ODBC_VER:' + ' \n' c_main += ' case SQL_ORDER_BY_COLUMNS_IN_SELECT:' + ' \n' c_main += ' case SQL_SEARCH_PATTERN_ESCAPE:' + ' \n' c_main += ' case SQL_OUTER_JOINS:' + ' \n' c_main += ' case SQL_LIKE_ESCAPE_CLAUSE:' + ' \n' c_main += ' case SQL_CATALOG_NAME:' + ' \n' c_main += ' case SQL_DESCRIBE_PARAMETER:' + ' \n' c_main += ' convert = 1;' + '\n' c_main += ' break;' + '\n' c_main += ' }' + '\n' c_main += ' return convert;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_col_attributes(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (fDescType == SQL_DESC_NAME) {' + '\n' c_main += ' outsz = non_utf_copy_out_hstmt(hstmt, sqlrc, (SQLCHAR *)rgbDesc, (SQLINTEGER)cbDescMax);' + '\n' c_main += ' if (pcbDesc) *pcbDesc = outsz;' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_column_privileges(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' SQLCHAR * tmp4 = NULL;' + '\n' c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_columns(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' SQLCHAR * tmp4 = NULL;' + '\n' c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_connect(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' cbDSN = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN, (SQLINTEGER)cbDSN, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbUID = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp2, (SQLCHAR **)&szUID, (SQLINTEGER)cbUID, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbAuthStr = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr, (SQLINTEGER)cbAuthStr, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szDSN);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szUID);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szAuthStr);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_data_sources(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER tmpsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDSN, (SQLINTEGER)cbDSNMax);' + '\n' c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szDescription, (SQLINTEGER)cbDescriptionMax);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_describe_col(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szColName, (SQLINTEGER)cbColNameMax);' + '\n' c_main += ' if (pcbColName) *pcbColName = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_driver_connect(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' cbConnStrin = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn, (SQLINTEGER)cbConnStrin, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szConnStrIn);' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szConnStrOut, (SQLINTEGER)cbConnStrOutMax);' + '\n' c_main += ' if (pcbConnStrOut) *pcbConnStrOut = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_error(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + '\n' c_main += ' SQLINTEGER tmpsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' tmpsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szSqlState, (SQLINTEGER)maxsz);' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szErrorMsg, (SQLINTEGER)cbErrorMsgMax);' + '\n' c_main += ' if (pcbErrorMsg) *pcbErrorMsg = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_exec_direct(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_foreign_keys(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' SQLCHAR * tmp4 = NULL;' + '\n' c_main += ' SQLCHAR * tmp5 = NULL;' + '\n' c_main += ' SQLCHAR * tmp6 = NULL;' + '\n' c_main += ' cbPkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier, (SQLINTEGER)cbPkTableQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbPkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner, (SQLINTEGER)cbPkTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbPkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName, (SQLINTEGER)cbPkTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbFkTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier, (SQLINTEGER)cbFkTableQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbFkTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner, (SQLINTEGER)cbFkTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbFkTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName, (SQLINTEGER)cbFkTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szPkTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szPkTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szPkTableName);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szFkTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp5, (SQLCHAR **)&szFkTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp6, (SQLCHAR **)&szFkTableName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_connect_attr(call_name, normal_db400_args): c_main = '' c_main += ' int isconvert = non_utf_isconvert_ordinal(attr);' + '\n' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)ilen);' + '\n' c_main += ' if (olen) *olen = outsz;' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_connect_option(call_name, normal_db400_args): c_main = '' c_main += ' int isconvert = non_utf_isconvert_ordinal(iopt);' + '\n' c_main += ' SQLINTEGER maxsz = DFTCOLSIZE;' + '\n' c_main += ' SQLINTEGER tmpsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' tmpsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)oval, (SQLINTEGER)maxsz);' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_cursor_name(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)szCursor, (SQLINTEGER)cbCursorMax);' + '\n' c_main += ' if (pcbCursor) *pcbCursor = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_desc_field(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (fieldID == SQL_DESC_NAME) {' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fValue, (SQLINTEGER)fLength);' + '\n' c_main += ' if (stLength) *stLength = outsz;' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_desc_rec(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)fname, (SQLINTEGER)bufLen);' + '\n' c_main += ' if (sLength) *sLength = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_diag_field(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (diagID == SQL_DIAG_SQLSTATE || diagID == SQL_DIAG_MESSAGE_TEXT || diagID == SQL_DIAG_SERVER_NAME) {' + '\n' c_main += ' if (hType == SQL_HANDLE_DBC) {' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + '\n' c_main += ' } else {' + '\n' c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)dValue, (SQLINTEGER)bLength);' + '\n' c_main += ' }' + '\n' c_main += ' if (sLength) *sLength = outsz;' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_diag_rec(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' SQLINTEGER maxsz = SQL_SQLSTATE_SIZE + 1;' + '\n' c_main += ' SQLINTEGER tmpsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (hType == SQL_HANDLE_DBC) {' + '\n' c_main += ' tmpsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + '\n' c_main += ' } else {' + '\n' c_main += ' tmpsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)SQLstate, (SQLINTEGER)maxsz);' + '\n' c_main += ' outsz = non_utf_copy_out_hstmt(hndl, sqlrc, (SQLCHAR *)msgText, (SQLINTEGER)bLength);' + '\n' c_main += ' }' + '\n' c_main += ' if (SLength) *SLength = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_env_attr(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (fAttribute == SQL_ATTR_DEFAULT_LIB || fAttribute == SQL_ATTR_ESCAPE_CHAR) {' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(0, sqlrc, (SQLCHAR *)pParam, (SQLINTEGER)cbParamMax);' + '\n' c_main += ' }' + '\n' c_main += ' if (pcbParam) *pcbParam = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_info(call_name, normal_db400_args): c_main = '' c_main += ' int isconvert = non_utf_isconvert_ordinal(fInfoType);' + '\n' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)rgbInfoValue, (SQLINTEGER)cbInfoValueMax);' + '\n' c_main += ' if (pcbInfoValue) *pcbInfoValue = outsz;' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_get_position(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' srchLiteralLen = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral, (SQLINTEGER)srchLiteralLen, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&srchLiteral);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_native_sql(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER outsz = 0;' + '\n' c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' cbSqlStrIn = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn, (SQLINTEGER)cbSqlStrIn, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStrIn);' + '\n' c_main += ' outsz = non_utf_copy_out_hdbc(hdbc, sqlrc, (SQLCHAR *)szSqlStr, (SQLINTEGER)cbSqlStrMax);' + '\n' c_main += ' if (pcbSqlStr) *pcbSqlStr = outsz;' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_param_data(call_name, normal_db400_args): c_main = '' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_prepare(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' cbSqlStr = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr, (SQLINTEGER)cbSqlStr, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szSqlStr);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_primary_keys(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_procedure_columns(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' SQLCHAR * tmp4 = NULL;' + '\n' c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbColumnName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName, (SQLINTEGER)cbColumnName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szColumnName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_procedures(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' cbProcQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier, (SQLINTEGER)cbProcQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbProcOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner, (SQLINTEGER)cbProcOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbProcName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName, (SQLINTEGER)cbProcName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szProcQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szProcOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szProcName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_set_connect_attr(call_name, normal_db400_args): c_main = '' c_main += ' int isconvert = non_utf_isconvert_ordinal(attrib);' + '\n' c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' inlen = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)inlen, (SQLINTEGER)maxsz);' + '\n' c_main += ' }' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_set_connect_option(call_name, normal_db400_args): c_main = '' c_main += ' int isconvert = non_utf_isconvert_ordinal(fOption);' + '\n' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLINTEGER tmpsz = 0;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' tmpsz = non_utf_copy_in_hdbc(hdbc, (SQLCHAR **)&tmp1, (SQLCHAR **)&vParam, (SQLINTEGER)SQL_NTS, (SQLINTEGER)maxsz);' + '\n' c_main += ' }' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (isconvert) {' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&vParam);' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_set_cursor_name(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' cbCursor = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor, (SQLINTEGER)cbCursor, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szCursor);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_set_env_attr(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXINTVAL_REASONABLE;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + '\n' c_main += ' cbParam = non_utf_copy_in_hdbc(0, (SQLCHAR **)&tmp1, (SQLCHAR **)&pParam, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' }' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' if (fAttribute == SQL_ATTR_DBC_DEFAULT_LIB || fAttribute == SQL_ATTR_SAVEPOINT_NAME) {' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&pParam);' + '\n' c_main += ' }' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_special_columns(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' cbTableQual = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual, (SQLINTEGER)cbTableQual, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQual);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_statistics(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)cbTableQualifier, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)cbTableOwner, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)cbTableName, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_table_privileges(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def non_utf_sql_tables(call_name, normal_db400_args): c_main = '' c_main += ' SQLINTEGER maxsz = SQL_MAXSMALLVAL;' + '\n' c_main += ' SQLCHAR * tmp1 = NULL;' + '\n' c_main += ' SQLCHAR * tmp2 = NULL;' + '\n' c_main += ' SQLCHAR * tmp3 = NULL;' + '\n' c_main += ' SQLCHAR * tmp4 = NULL;' + '\n' c_main += ' cbTableQualifier = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableOwner = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableName = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' cbTableType = non_utf_copy_in_hstmt(hstmt, (SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType, (SQLINTEGER)maxsz, (SQLINTEGER)maxsz);' + '\n' c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp1, (SQLCHAR **)&szTableQualifier);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp2, (SQLCHAR **)&szTableOwner);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp3, (SQLCHAR **)&szTableName);' + '\n' c_main += ' non_utf_copy_in_free((SQLCHAR **)&tmp4, (SQLCHAR **)&szTableType);' + '\n' c_main += ' return sqlrc;' + '\n' c_main += '}' + '\n' return c_main def ile_sql_param_data_copy_var(): c_main = '' c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr) */ ' + '\n' c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + '\n' c_main += ' ILEpointer\t*returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + '\n' return c_main def ile_sql_param_data_copy_in(): c_main = '' c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + '\n' c_main += ' if (Value) {' + '\n' c_main += ' arglist->Value.s.addr = (ulong) returnPtr;' + '\n' c_main += ' }' + '\n' return c_main def ile_sql_param_data_copy_out(): c_main = '' c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + '\n' c_main += ' if (Value) {' + '\n' c_main += ' if (arglist->base.result.s_int32.r_int32 == SQL_NEED_DATA) {' + '\n' c_main += ' *Value = _CVTSPP(returnPtr);' + '\n' c_main += ' }' + '\n' c_main += ' }' + '\n' return c_main def ile_sql_get_desc_field_copy_var(): c_main = '' c_main += ' /* returnPtr - API returns ILE SP pointer buffer (alias of PASE ptr)' + '\n' c_main += ' * Return ILE SP likely outside PASE mapable addr space.' + '\n' c_main += ' * However, _CVTSPP is safe. The result is zero (null)' + '\n' c_main += ' * if the input is a 16-byte null pointer or a tagged space pointer ' + '\n' c_main += ' * that does not contain the teraspace address' + '\n' c_main += ' * equivalent of some valid IBM PASE for i memory address.' + '\n' c_main += ' * (I suspect options never used in years of PASE.' + '\n' c_main += ' * Rochester CLI team was notified).' + '\n' c_main += ' */' + '\n' c_main += ' char returnBuffer[ sizeof(ILEpointer ) + 16 ];' + '\n' c_main += ' ILEpointer\t*returnPtr = (ILEpointer *)ROUND_QUAD(returnBuffer);' + '\n' return c_main def ile_sql_get_desc_field_copy_in(): c_main = '' c_main += ' /* returnPtr - ILE SP pointer buffer return area */ ' + '\n' c_main += ' if (fValue) {' + '\n' c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + '\n' c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + '\n' c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + '\n' c_main += ' {' + '\n' c_main += ' arglist->fValue.s.addr = (ulong) returnPtr;' + '\n' c_main += ' }' + '\n' c_main += ' }' + '\n' return c_main def ile_sql_get_desc_field_copy_out(): c_main = '' c_main += ' /* returnPtr - ILE SP to PASE pointer */ ' + '\n' c_main += ' if (fValue) {' + '\n' c_main += ' if (fieldID == SQL_DESC_DATA_PTR' + '\n' c_main += ' || fieldID == SQL_DESC_LENGTH_PTR' + '\n' c_main += ' || fieldID == SQL_DESC_INDICATOR_PTR)' + '\n' c_main += ' {' + '\n' c_main += ' *((void **)fValue) = _CVTSPP(returnPtr);' + '\n' c_main += ' }' + '\n' c_main += ' }' + '\n' return c_main pre = open(PaseSqlCli_file, 'r') ile_wide_api = {'nothing': 'nothing'} for line in pre: if 'SQLRETURN SQL' in line: lesss = line.split('(') parts = lesss[0].split(' ') funcs = parts[1] if '400' in funcs: continue if 'W' in funcs: line_no_w = funcs.split('W') assoc_name = line_no_W[0] ile_wide_api[assoc_name] = funcs f = open(PaseSqlCli_file, 'r') g = False c400 = True c400_ccsid = False c400_not_wide = True ile_or_custom_call = '' ile_or_libdb400_call = '' line_func = '' libdb400_exp = '' pase_cli_lib_db400_h_proto = '' pase_cli_lib_db400_c_symbol = '' pase_cli_lib_db400_c_main = '' pase_cli_async_h_struct = '' pase_cli_async_h_proto_async = '' pase_cli_async_h_proto_join = '' pase_cli_async_c_main = '' pase_cli_any_h_proto = '' pase_cli_only400_h_proto = '' pase_cli_ile_h_proto = '' pase_cli_ile_c_symbol = '' pase_cli_custom_h_proto = '' pase_cli_ile_h_struct = '' pase_cli_ile_c_main = '' pase_cli_dump_h_proto = '' pase_cli_dump_c_main = '' for line in f: if 'SQLRETURN SQL' in line: g = True line_func = '' if g: line_no_comment = line.split('/') split0 = line_no_comment[0] line_func += split0 if not ')' in split0: continue else: g = False else: continue parts = parse_method(line_func) funcs = parts[0] args = parts[1] call_retv = funcs[0] + funcs[1] call_name = funcs[2] struct_name = call_name + 'Struct' struct_ile_name = call_name + 'IleCallStruct' struct_ile_sig = call_name + 'IleSigStruct' struct_ile_flag = call_name + 'Loaded' struct_ile_buf = call_name + 'Buf' struct_ile_ptr = call_name + 'Ptr' c400_not_wide = True c400_ccsid = False c400 = True ile_or_custom_call = 'custom_' ile_or_libdb400_call = 'libdb400_' if 'SQLOverrideCCSID400' in call_name: c400_ccsid = True if 'SQL400' in call_name: c400 = False if c400: ile_or_custom_call = 'ILE_' if 'W' in call_name: ile_or_libdb400_call = 'ILE_' c400_not_wide = False idx = 0 comma = ',' semi = ';' argtype1st = '' argname1st = '' normal_call_types = '' normal_call_args = '' normal_db400_args = '' async_struct_types = ' SQLRETURN sqlrc;' async_call_args = '' async_db400_args = '' async_copyin_args = '' ile_struct_sigs = '' ile_struct_types = 'ILEarglist_base base;' ile_copyin_args = '' dump_args = '' dump_sigs = '' for arg in args: idx += 1 if idx == len(args): comma = '' argfull = ' '.join(arg) argsig = arg[0] + arg[1] argname = arg[2] if idx == 1: argtype1st = arg[0] argname1st = arg[2] sigile = '' ilefull = argfull if arg[1] == '*': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'PTR': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'SQLHWND': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'SQLPOINTER': sigile = 'ARG_MEMPTR' ilefull = 'ILEpointer' + ' ' + arg[2] elif arg[0] == 'SQLCHAR': sigile = 'ARG_UINT8' elif arg[0] == 'SQLWCHAR': sigile = 'ARG_UINT8' elif arg[0] == 'SQLSMALLINT': sigile = 'ARG_INT16' elif arg[0] == 'SQLUSMALLINT': sigile = 'ARG_UINT16' elif arg[0] == 'SQLSMALLINT': sigile = 'ARG_INT16' elif arg[0] == 'SQLINTEGER': sigile = 'ARG_INT32' elif arg[0] == 'SQLUINTEGER': sigile = 'ARG_UINT32' elif arg[0] == 'SQLDOUBLE': sigile = 'ARG_FLOAT64' elif arg[0] == 'SQLREAL': sigile = 'ARG_FLOAT32' elif arg[0] == 'HENV': sigile = 'ARG_INT32' elif arg[0] == 'HDBC': sigile = 'ARG_INT32' elif arg[0] == 'HSTMT': sigile = 'ARG_INT32' elif arg[0] == 'HDESC': sigile = 'ARG_INT32' elif arg[0] == 'SQLHANDLE': sigile = 'ARG_INT32' elif arg[0] == 'SQLHENV': sigile = 'ARG_INT32' elif arg[0] == 'SQLHDBC': sigile = 'ARG_INT32' elif arg[0] == 'SQLHSTMT': sigile = 'ARG_INT32' elif arg[0] == 'SQLHDESC': sigile = 'ARG_INT32' elif arg[0] == 'RETCODE': sigile = 'ARG_INT32' elif arg[0] == 'SQLRETURN': sigile = 'ARG_INT32' elif arg[0] == 'SFLOAT': sigile = 'ARG_FLOAT32' normal_call_args += ' ' + argfull + comma normal_db400_args += ' ' + argname + comma normal_call_types += ' ' + argsig + comma dump_args += ' ' + argname dump_sigs += ' ' + argsig ile_struct_types += ' ' + ilefull + semi ile_struct_sigs += ' ' + sigile + comma if sigile == 'ARG_MEMPTR': ile_copyin_args += ' arglist->' + argname + '.s.addr = (ulong) ' + argname + ';' + '\n' else: ile_copyin_args += ' arglist->' + argname + ' = (' + argsig + ') ' + argname + ';' + '\n' async_struct_types += ' ' + argfull + semi async_db400_args += ' myptr->' + argname + comma async_copyin_args += ' myptr->' + argname + ' = ' + argname + ';' + '\n' pase_cli_dump_h_proto += 'void dump_' + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' );' + '\n' pase_cli_dump_c_main += 'void dump_' + call_name + '(SQLRETURN sqlrc, ' + normal_call_args + ' ) {' + '\n' pase_cli_dump_c_main += ' if (dev_go(sqlrc,"' + call_name.lower() + '")) {' + '\n' pase_cli_dump_c_main += ' char mykey[256];' + '\n' pase_cli_dump_c_main += ' printf_key(mykey,"' + call_name + '");' + '\n' pase_cli_dump_c_main += ' printf_clear();' + '\n' pase_cli_dump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 1);' + '\n' pase_cli_dump_c_main += ' printf_stack(mykey);' + '\n' pase_cli_dump_c_main += ' printf_sqlrc_status((char *)&mykey, sqlrc);' + '\n' args = dump_args.split() sigs = dump_sigs.split() dump_handle = '' dump_type = '' i = 0 for arg in args: sig = sigs[i] pase_cli_dump_c_main += ' printf_format("%s.parm %s %s 0x%p (%d)\\n",mykey,"' + sig + '","' + arg + '",' + arg + ',' + arg + ');' + '\n' if '*' in sig or 'SQLPOINTER' in sig: pase_cli_dump_c_main += ' printf_hexdump(mykey,' + arg + ',80);' + '\n' elif 'SQLHDBC' in sig: dump_handle = arg dump_type = 'SQL_HANDLE_DBC' elif 'SQLHSTMT' in sig: dump_handle = arg dump_type = 'SQL_HANDLE_STMT' elif 'SQLHDESC' in sig: dump_handle = arg dump_type = 'SQL_HANDLE_DESC' i += 1 pase_cli_dump_c_main += ' printf_sqlrc_head_foot((char *)&mykey, sqlrc, 0);' + '\n' pase_cli_dump_c_main += ' dev_dump();' + '\n' pase_cli_dump_c_main += ' if (sqlrc < SQL_SUCCESS) {' + '\n' if 'SQL' in dump_type: pase_cli_dump_c_main += ' printf_sql_diag(' + dump_type + ',' + dump_handle + ');' + '\n' pase_cli_dump_c_main += ' printf_force_SIGQUIT((char *)&mykey);' + '\n' pase_cli_dump_c_main += ' }' + '\n' pase_cli_dump_c_main += ' }' + '\n' pase_cli_dump_c_main += '}' + '\n' if c400: pase_cli_any_h_proto += ' * ' + call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + '\n' if c400_CCSID: pase_cli_custom_h_proto += call_retv + ' ' + 'custom_' + call_name + '(' + normal_call_args + ' );' + '\n' else: pase_cli_lib_db400_h_proto += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' );' + '\n' pase_cli_lib_db400_c_main += call_retv + ' libdb400_' + call_name + '(' + normal_call_args + ' ) {' + '\n' pase_cli_lib_db400_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n' if 'W' in call_name: pase_cli_lib_db400_c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_lib_db400_c_main += ' return sqlrc;' + '\n' pase_cli_lib_db400_c_main += '}' + '\n' elif 'SQLColAttributes' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_col_attributes(call_name, normal_db400_args) elif 'SQLColumnPrivileges' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_column_privileges(call_name, normal_db400_args) elif 'SQLColumns' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_columns(call_name, normal_db400_args) elif 'SQLConnect' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_connect(call_name, normal_db400_args) elif 'SQLDataSources' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_data_sources(call_name, normal_db400_args) elif 'SQLDescribeCol' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_describe_col(call_name, normal_db400_args) elif 'SQLDriverConnect' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_driver_connect(call_name, normal_db400_args) elif 'SQLError' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_error(call_name, normal_db400_args) elif 'SQLExecDirect' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_exec_direct(call_name, normal_db400_args) elif 'SQLForeignKeys' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_foreign_keys(call_name, normal_db400_args) elif 'SQLGetConnectAttr' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_connect_attr(call_name, normal_db400_args) elif 'SQLGetConnectOption' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_connect_option(call_name, normal_db400_args) elif 'SQLGetCursorName' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_cursor_name(call_name, normal_db400_args) elif 'SQLGetDescField' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_desc_field(call_name, normal_db400_args) elif 'SQLGetDescRec' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_desc_rec(call_name, normal_db400_args) elif 'SQLGetDiagField' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_diag_field(call_name, normal_db400_args) elif 'SQLGetDiagRec' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_diag_rec(call_name, normal_db400_args) elif 'SQLGetEnvAttr' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_env_attr(call_name, normal_db400_args) elif 'SQLGetInfo' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_info(call_name, normal_db400_args) elif 'SQLGetPosition' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_get_position(call_name, normal_db400_args) elif 'SQLNativeSql' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_native_sql(call_name, normal_db400_args) elif 'SQLParamData' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_param_data(call_name, normal_db400_args) elif 'SQLPrepare' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_prepare(call_name, normal_db400_args) elif 'SQLPrimaryKeys' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_primary_keys(call_name, normal_db400_args) elif 'SQLProcedureColumns' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_procedure_columns(call_name, normal_db400_args) elif 'SQLProcedures' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_procedures(call_name, normal_db400_args) elif 'SQLSetConnectAttr' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_set_connect_attr(call_name, normal_db400_args) elif 'SQLSetConnectOption' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_set_connect_option(call_name, normal_db400_args) elif 'SQLSetCursorName' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_set_cursor_name(call_name, normal_db400_args) elif 'SQLSetEnvAttr' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_set_env_attr(call_name, normal_db400_args) elif 'SQLSpecialColumns' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_special_columns(call_name, normal_db400_args) elif 'SQLStatistics' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_statistics(call_name, normal_db400_args) elif 'SQLTablePrivileges' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_table_privileges(call_name, normal_db400_args) elif 'SQLTables' in call_name: pase_cli_lib_db400_c_main += non_utf_sql_tables(call_name, normal_db400_args) else: pase_cli_lib_db400_c_main += ' sqlrc = ILE_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_lib_db400_c_main += ' return sqlrc;' + '\n' pase_cli_lib_db400_c_main += '}' + '\n' libdb400_exp += 'libdb400_' + call_name + '\n' else: pase_cli_only400_h_proto += call_retv + ' ' + call_name + '(' + normal_call_args + ' );' + '\n' pase_cli_custom_h_proto += call_retv + ' ' + 'custom_' + call_name + '(' + normal_call_args + ' );' + '\n' libdb400_exp += call_name + '\n' if c400_CCSID: pase_cli_async_c_main += 'int SQLOverrideCCSID400(int newCCSID)' + '\n' else: pase_cli_async_c_main += call_retv + ' ' + call_name + '(' + normal_call_args + ' )' + '\n' pase_cli_async_c_main += '{' + '\n' pase_cli_async_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n' if call_name == 'SQLAllocEnv': pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_env(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLAllocConnect': pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_connect(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLAllocStmt': pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_stmt(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLAllocHandle': pase_cli_async_c_main += pase_cli_async_c_main_sql_alloc_handle(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLFreeEnv': pase_cli_async_c_main += pase_cli_async_c_main_sql_free_env(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLFreeConnect': pase_cli_async_c_main += pase_cli_async_c_main_sql_free_connect(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLFreeStmt': pase_cli_async_c_main += pase_cli_async_c_main_sql_free_stmt(ile_or_custom_call, call_name, normal_db400_args) elif call_name == 'SQLFreeHandle': pase_cli_async_c_main += pase_cli_async_c_main_sql_free_handle(ile_or_custom_call, call_name, normal_db400_args) elif c400_CCSID: pase_cli_async_c_main += ' sqlrc = custom_' + call_name + '(' + normal_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' int myccsid = init_CCSID400(0);' + '\n' if call_name == 'SQLDisconnect': pase_cli_async_c_main += sql_disconnect_check_persistent('hdbc', 'return SQL_ERROR;', '/* return now */') if argtype1st == 'SQLHENV': if ile_or_custom_call == 'custom_': pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' switch(myccsid) {' + '\n' pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n' pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n' pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' default:' + '\n' pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n' pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' }' + '\n' elif argtype1st == 'SQLHDBC': pase_cli_async_c_main += ' init_table_lock(' + argname1st + ', 0);' + '\n' if ile_or_custom_call == 'custom_': pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' switch(myccsid) {' + '\n' pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n' pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n' pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' default:' + '\n' pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n' pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' init_table_unlock(' + argname1st + ', 0);' + '\n' elif argtype1st == 'SQLHSTMT': pase_cli_async_c_main += ' init_table_lock(' + argname1st + ', 1);' + '\n' if ile_or_custom_call == 'custom_': pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' switch(myccsid) {' + '\n' pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n' pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n' pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' default:' + '\n' pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n' pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' init_table_unlock(' + argname1st + ', 1);' + '\n' elif argtype1st == 'SQLHDESC': pase_cli_async_c_main += ' init_table_lock(' + argname1st + ', 1);' + '\n' if ile_or_custom_call == 'custom_': pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' switch(myccsid) {' + '\n' pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n' pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n' pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' default:' + '\n' pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n' pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' init_table_unlock(' + argname1st + ', 1);' + '\n' else: if ile_or_custom_call == 'custom_': pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' switch(myccsid) {' + '\n' pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n' pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n' pase_cli_async_c_main += ' sqlrc = ' + ile_or_custom_call + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' default:' + '\n' pase_cli_async_c_main += ' sqlrc = libdb400_' + call_name + '(' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n' pase_cli_async_c_main += ' dump_' + call_name + '(sqlrc, ' + normal_db400_args + ' );' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' return sqlrc;' + '\n' pase_cli_async_c_main += '}' + '\n' if c400 and c400_CCSID == False: pase_cli_ile_h_proto += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' );' + '\n' pase_cli_ile_h_struct += 'typedef struct ' + struct_ile_name + ' {' + ILE_struct_types + ' } ' + struct_ile_name + ';' + '\n' pase_cli_ile_c_symbol += 'SQLINTEGER ' + struct_ile_flag + ';' + '\n' pase_cli_ile_c_symbol += 'SQLCHAR ' + struct_ile_buf + '[132];' + '\n' pase_cli_ile_c_main += call_retv + ' ILE_' + call_name + '(' + normal_call_args + ' )' + '\n' pase_cli_ile_c_main += '{' + '\n' pase_cli_ile_c_main += ' int rc = 0;' + '\n' pase_cli_ile_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n' if 'SQLParamData' in call_name: pase_cli_ile_c_main += ile_sql_param_data_copy_var() if 'SQLGetDescField' in call_name: pase_cli_ile_c_main += ile_sql_get_desc_field_copy_var() pase_cli_ile_c_main += ' int actMark = 0;' + '\n' pase_cli_ile_c_main += ' char * ileSymPtr = (char *) NULL;' + '\n' pase_cli_ile_c_main += ' ' + struct_ile_name + ' * arglist = (' + struct_ile_name + ' *) NULL;' + '\n' pase_cli_ile_c_main += ' char buffer[ sizeof(' + struct_ile_name + ') + 16 ];' + '\n' pase_cli_ile_c_main += ' static arg_type_t ' + struct_ile_sig + '[] = {' + ILE_struct_sigs + ', ARG_END };' + '\n' pase_cli_ile_c_main += ' arglist = (' + struct_ile_name + ' *)ROUND_QUAD(buffer);' + '\n' pase_cli_ile_c_main += ' ileSymPtr = (char *)ROUND_QUAD(&' + struct_ile_buf + ');' + '\n' pase_cli_ile_c_main += ' memset(buffer,0,sizeof(buffer));' + '\n' pase_cli_ile_c_main += ' actMark = init_cli_srvpgm();' + '\n' pase_cli_ile_c_main += ' if (!' + struct_ile_flag + ') {' + '\n' pase_cli_ile_c_main += ' rc = _ILESYM((ILEpointer *)ileSymPtr, actMark, "' + call_name + '");' + '\n' pase_cli_ile_c_main += ' if (rc < 0) {' + '\n' pase_cli_ile_c_main += ' return SQL_ERROR;' + '\n' pase_cli_ile_c_main += ' }' + '\n' pase_cli_ile_c_main += ' ' + struct_ile_flag + ' = 1;' + '\n' pase_cli_ile_c_main += ' }' + '\n' pase_cli_ile_c_main += ILE_copyin_args if 'SQLParamData' in call_name: pase_cli_ile_c_main += ile_sql_param_data_copy_in() if 'SQLGetDescField' in call_name: pase_cli_ile_c_main += ile_sql_get_desc_field_copy_in() pase_cli_ile_c_main += ' rc = _ILECALL((ILEpointer *)ileSymPtr, &arglist->base, ' + struct_ile_sig + ', RESULT_INT32);' + '\n' pase_cli_ile_c_main += ' if (rc != ILECALL_NOERROR) {' + '\n' pase_cli_ile_c_main += ' return SQL_ERROR;' + '\n' pase_cli_ile_c_main += ' }' + '\n' if 'SQLParamData' in call_name: pase_cli_ile_c_main += ile_sql_param_data_copy_out() if 'SQLGetDescField' in call_name: pase_cli_ile_c_main += ile_sql_get_desc_field_copy_out() pase_cli_ile_c_main += ' return arglist->base.result.s_int32.r_int32;' + '\n' pase_cli_ile_c_main += '}' + '\n' if call_name == 'SQLAllocEnv': continue elif call_name == 'SQLAllocConnect': continue elif call_name == 'SQLAllocStmt': continue elif call_name == 'SQLAllocHandle': continue elif call_name == 'SQLFreeEnv': continue elif call_name == 'SQLFreeConnect': continue elif call_name == 'SQLFreeStmt': continue elif call_name == 'SQLFreeHandle': continue elif c400_CCSID: continue async_call_args = normal_call_args + ', void * callback' async_struct_types += ' void * callback;' async_copyin_args += ' myptr->callback = callback;' + '\n' tmp__pase_cli_async_comment = '/* void ' + call_name + 'Callback(' + struct_name + '* ); */' pase_cli_async_h_proto_async += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' );' + '\n' pase_cli_async_h_proto_join += tmp_PaseCliAsync_comment + '\n' pase_cli_async_h_proto_join += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag);' + '\n' libdb400_exp += call_name + 'Async' + '\n' libdb400_exp += call_name + 'Join' + '\n' if c400: libdb400_exp += 'ILE_' + call_name + '\n' pase_cli_async_h_struct += 'typedef struct ' + struct_name + ' {' + async_struct_types + ' } ' + struct_name + ';' + '\n' pase_cli_async_c_main += 'void * ' + call_name + 'Thread (void *ptr)' + '\n' pase_cli_async_c_main += '{' + '\n' pase_cli_async_c_main += ' SQLRETURN sqlrc = SQL_SUCCESS;' + '\n' pase_cli_async_c_main += ' int myccsid = init_CCSID400(0);' + '\n' pase_cli_async_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) ptr;' + '\n' if call_name == 'SQLDisconnect': pase_cli_async_c_main += sql_disconnect_check_persistent('myptr->hdbc', 'pthread_exit((void *)myptr);', 'myptr->sqlrc = SQL_ERROR;') if argtype1st == 'SQLHENV': pase_cli_async_c_main += ' /* not lock */' + '\n' elif argtype1st == 'SQLHDBC': pase_cli_async_c_main += ' init_table_lock(myptr->' + argname1st + ', 0);' + '\n' elif argtype1st == 'SQLHSTMT': pase_cli_async_c_main += ' init_table_lock(myptr->' + argname1st + ', 1);' + '\n' elif argtype1st == 'SQLHDESC': pase_cli_async_c_main += ' init_table_lock(myptr->' + argname1st + ', 1);' + '\n' if ile_or_custom_call == 'custom_': pase_cli_async_c_main += ' myptr->sqlrc = ' + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + '\n' else: pase_cli_async_c_main += ' switch(myccsid) {' + '\n' pase_cli_async_c_main += ' case 1208: /* UTF-8 */' + '\n' pase_cli_async_c_main += ' case 1200: /* UTF-16 */' + '\n' pase_cli_async_c_main += ' myptr->sqlrc = ' + ile_or_custom_call + call_name + '(' + async_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' default:' + '\n' pase_cli_async_c_main += ' myptr->sqlrc = libdb400_' + call_name + '(' + async_db400_args + ' );' + '\n' pase_cli_async_c_main += ' break;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' if (init_cli_trace()) {' + '\n' pase_cli_async_c_main += ' dump_' + call_name + '(myptr->sqlrc, ' + async_db400_args + ' );' + '\n' pase_cli_async_c_main += ' }' + '\n' if argtype1st == 'SQLHENV': pase_cli_async_c_main += ' /* not lock */' + '\n' elif argtype1st == 'SQLHDBC': pase_cli_async_c_main += ' init_table_unlock(myptr->' + argname1st + ', 0);' + '\n' elif argtype1st == 'SQLHSTMT': pase_cli_async_c_main += ' init_table_unlock(myptr->' + argname1st + ', 1);' + '\n' elif argtype1st == 'SQLHDESC': pase_cli_async_c_main += ' init_table_unlock(myptr->' + argname1st + ', 1);' + '\n' pase_cli_async_c_main += ' ' + tmp_PaseCliAsync_comment + '\n' pase_cli_async_c_main += ' if (myptr->callback) {' + '\n' pase_cli_async_c_main += ' void (*ptrFunc)(' + struct_name + '* ) = myptr->callback;' + '\n' pase_cli_async_c_main += ' ptrFunc( myptr );' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' pthread_exit((void *)myptr);' + '\n' pase_cli_async_c_main += '}' + '\n' pase_cli_async_c_main += 'pthread_t ' + call_name + 'Async (' + async_call_args + ' )' + '\n' pase_cli_async_c_main += '{' + '\n' pase_cli_async_c_main += ' int rc = 0;' + '\n' pase_cli_async_c_main += ' pthread_t tid = 0;' + '\n' pase_cli_async_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) malloc(sizeof(' + struct_name + '));' + '\n' pase_cli_async_c_main += ' myptr->sqlrc = SQL_SUCCESS;' + '\n' pase_cli_async_c_main += async_copyin_args pase_cli_async_c_main += ' rc = pthread_create(&tid, NULL, ' + call_name + 'Thread, (void *)myptr);' + '\n' pase_cli_async_c_main += ' return tid;' + '\n' pase_cli_async_c_main += '}' + '\n' pase_cli_async_c_main += struct_name + ' * ' + call_name + 'Join (pthread_t tid, SQLINTEGER flag)' + '\n' pase_cli_async_c_main += '{' + '\n' pase_cli_async_c_main += ' ' + struct_name + ' * myptr = (' + struct_name + ' *) NULL;' + '\n' pase_cli_async_c_main += ' int active = 0;' + '\n' if argtype1st == 'SQLHENV': pase_cli_async_c_main += ' /* not lock */' + '\n' elif argtype1st == 'SQLHDBC': pase_cli_async_c_main += ' active = init_table_in_progress(tid, 0);' + '\n' elif argtype1st == 'SQLHSTMT': pase_cli_async_c_main += ' active = init_table_in_progress(tid, 1);' + '\n' elif argtype1st == 'SQLHDESC': pase_cli_async_c_main += ' active = init_table_in_progress(tid, 1);' + '\n' pase_cli_async_c_main += ' if (flag == SQL400_FLAG_JOIN_WAIT || !active) {' + '\n' pase_cli_async_c_main += ' pthread_join(tid,(void**)&myptr);' + '\n' pase_cli_async_c_main += ' } else {' + '\n' pase_cli_async_c_main += ' return (' + struct_name + ' *) NULL;' + '\n' pase_cli_async_c_main += ' }' + '\n' pase_cli_async_c_main += ' return myptr;' + '\n' pase_cli_async_c_main += '}' + '\n' file_pase_incl = '' file_pase_incl += '#include <stdio.h>' + '\n' file_pase_incl += '#include <stdlib.h>' + '\n' file_pase_incl += '#include <unistd.h>' + '\n' file_pase_incl += '#include <dlfcn.h>' + '\n' file_pase_incl += '#include <sqlcli1.h>' + '\n' file_pase_incl += '#include <as400_types.h>' + '\n' file_pase_incl += '#include <as400_protos.h>' + '\n' file_local_incl = '' file_local_incl += '#include "PaseCliInit.h"' + '\n' file_local_incl += '#include "PaseCliAsync.h"' + '\n' file__pase_cli_ile_c = '' file__pase_cli_ile_c += file_pase_incl file__pase_cli_ile_c += file_local_incl file__pase_cli_ile_c += '' + '\n' file__pase_cli_ile_c += ' /* gcc compiler' + '\n' file__pase_cli_ile_c += ' * as400_types.h (edit change required)' + '\n' file__pase_cli_ile_c += ' * #if defined( __GNUC__ )' + '\n' file__pase_cli_ile_c += ' * long double align __attribute__((aligned(16)));' + '\n' file__pase_cli_ile_c += ' * #else ' + '\n' file__pase_cli_ile_c += ' * long double;' + '\n' file__pase_cli_ile_c += ' * #endif ' + '\n' file__pase_cli_ile_c += ' * ' + '\n' file__pase_cli_ile_c += ' * Use we also need cast ulong to match size of pointer 32/64 ' + '\n' file__pase_cli_ile_c += ' * arglist->ohnd.s.addr = (ulong) ohnd;' + '\n' file__pase_cli_ile_c += ' */' + '\n' file__pase_cli_ile_c += '' + '\n' file__pase_cli_ile_c += '#define ROUND_QUAD(x) (((size_t)(x) + 0xf) & ~0xf)' + '\n' file__pase_cli_ile_c += '' + '\n' file__pase_cli_ile_c += PaseCliILE_c_symbol file__pase_cli_ile_c += '' + '\n' file__pase_cli_ile_c += '/* ILE call structures */' + '\n' file__pase_cli_ile_c += '' + '\n' file__pase_cli_ile_c += PaseCliILE_h_struct + '\n' file__pase_cli_ile_c += '' + '\n' file__pase_cli_ile_c += PaseCliILE_c_main file__pase_cli_ile_c += '' + '\n' with open('PaseCliILE_gen.c', 'w') as text_file: text_file.write(file_PaseCliILE_c) file__pase_cli_lib_db400_c = '' file__pase_cli_lib_db400_c += file_pase_incl file__pase_cli_lib_db400_c += file_local_incl file__pase_cli_lib_db400_c += '' + '\n' file__pase_cli_lib_db400_c += '#define DFTCOLSIZE 18' + '\n' file__pase_cli_lib_db400_c += '#define SQL_MAXINTVAL_REASONABLE 131072' + '\n' file__pase_cli_lib_db400_c += '' + '\n' file__pase_cli_lib_db400_c += PaseCliLibDB400_c_symbol file__pase_cli_lib_db400_c += '' + '\n' file__pase_cli_lib_db400_c += non_utf_copy_in() file__pase_cli_lib_db400_c += non_utf_copy_in_free() file__pase_cli_lib_db400_c += non_utf_copy_out() file__pase_cli_lib_db400_c += non_utf_isconvert_ordinal() file__pase_cli_lib_db400_c += '' + '\n' file__pase_cli_lib_db400_c += PaseCliLibDB400_c_main file__pase_cli_lib_db400_c += '' + '\n' with open('PaseCliLibDB400_gen.c', 'w') as text_file: text_file.write(file_PaseCliLibDB400_c) file__pase_cli_async_c = '' file__pase_cli_async_c += file_pase_incl file__pase_cli_async_c += file_local_incl file__pase_cli_async_c += '' + '\n' file__pase_cli_async_c += '' + '\n' file__pase_cli_async_c += PaseCliAsync_c_main with open('PaseCliAsync_gen.c', 'w') as text_file: text_file.write(file_PaseCliAsync_c) file__pase_cli_dump_c = '' file__pase_cli_dump_c += file_pase_incl file__pase_cli_dump_c += file_local_incl file__pase_cli_dump_c += '#include "PaseCliDev.h"' + '\n' file__pase_cli_dump_c += '#include "PaseCliPrintf.h"' + '\n' file__pase_cli_dump_c += '' + '\n' file__pase_cli_dump_c += '' + '\n' file__pase_cli_dump_c += PaseCliDump_c_main with open('PaseCliDump_gen.c', 'w') as text_file: text_file.write(file_PaseCliDump_c) file__pase_cli_async_h = '' file__pase_cli_async_h += '#ifndef _PASECLIASYNC_H' + '\n' file__pase_cli_async_h += '#define _PASECLIASYNC_H' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += file_pase_incl file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '#ifdef __cplusplus' + '\n' file__pase_cli_async_h += 'extern "C" {' + '\n' file__pase_cli_async_h += '#endif' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * Using the driver' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ' + '\n' file__pase_cli_async_h += ' * SQL400Environment -- set the mode of driver' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * === UTF-8 mode, most popular AIX/PASE/Linux ===' + '\n' file__pase_cli_async_h += ' * SQLOverrideCCSID400(1208) -- UTF-8 mode, CLI normal/async direct ILE call' + '\n' file__pase_cli_async_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirect-->DB2' + '\n' file__pase_cli_async_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * === UTF-8 mode, most popular Windows/Java ===' + '\n' file__pase_cli_async_h += ' * SQLOverrideCCSID400(1200) -- UTF-16 mode, CLI normal/async direct ILE call' + '\n' file__pase_cli_async_h += ' * -->SQLExecDirect(Async)-->ILE_SQLExecDirectW-->DB2' + '\n' file__pase_cli_async_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * === PASE default (original libdb400.a) ===' + '\n' file__pase_cli_async_h += ' * SQLOverrideCCSID400(other) -- PASE ccsid, CLI API calls PASE libdb400.a' + '\n' file__pase_cli_async_h += ' * -->SQLExecDirect(Async)-->PASE libdb400.a(SQLExecDirect)-->DB2' + '\n' file__pase_cli_async_h += ' * -->SQLExecDirectW(Async)-->ILE_SQLExecDirectW-->DB2 (*)' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * PASE ccsid setting occurs before any other CLI operations' + '\n' file__pase_cli_async_h += ' * at the environment level. Therefore the driver mode is' + '\n' file__pase_cli_async_h += ' * established (restricted, if you choose). ' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * 1) non-Unicode interfaces (call old libdb400.a, messy stuff):' + '\n' file__pase_cli_async_h += ' * int ccsid = 819;' + '\n' file__pase_cli_async_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * 2) UTF8 interfaces (call direct to ILE DB2):' + '\n' file__pase_cli_async_h += ' * int ccsid = 1208;' + '\n' file__pase_cli_async_h += ' * env attr SQL400_ATTR_PASE_CCSID &ccsid -- set pase ccsid' + '\n' file__pase_cli_async_h += ' * if ccsid == 1208:' + '\n' file__pase_cli_async_h += ' * env attr SQL_ATTR_UTF8 &true -- no conversion required by PASE' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * 3) UTF16 wide interfaces (call direct to ILE DB2):' + '\n' file__pase_cli_async_h += ' * **** NEVER set PASE_CCSID or ATTR_UTF8 in UTF-16 mode. ****' + '\n' file__pase_cli_async_h += ' * So, database exotic ebcdic column and PASE binds c type as WVARCHAR/WCHAR output is UTF16?' + '\n' file__pase_cli_async_h += ' * Yes, the database will do the conversion from EBCDIC to UTF16 for data bound as WVARCHAR/WCHAR.' + '\n' file__pase_cli_async_h += ' * not sure about DBCLOB -- I want to guess that is bound as UTF-16, not 100% sure.' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * IF your data not UTF-8 or UTF-16, interfaces to convert (experimental).' + '\n' file__pase_cli_async_h += ' * SQL400ToUtf8 -- use before passing to CLI normal interfaces' + '\n' file__pase_cli_async_h += ' * SQL400FromUtf8 -- use return output normal CLI (if needed)' + '\n' file__pase_cli_async_h += ' * SQL400ToUtf16 -- use before passing to CLI wide interfaces' + '\n' file__pase_cli_async_h += ' * SQL400FromUtf16 -- use return output wide CLI (if needed)' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * A choice of exported APIs (SQLExecDirect one of many):' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * === CLI APIs UTF-8 or APIWs UTF-16 ===' + '\n' file__pase_cli_async_h += ' * === choose async and/or normal wait ===' + '\n' file__pase_cli_async_h += ' * SQLRETURN SQLExecDirect(..);' + '\n' file__pase_cli_async_h += ' * SQLRETURN SQLExecDirectW(..);' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * == callback or reap/join with async ===' + '\n' file__pase_cli_async_h += ' * pthread_t SQLExecDirectAsync(..);' + '\n' file__pase_cli_async_h += ' * pthread_t SQLExecDirectWAsync(..);' + '\n' file__pase_cli_async_h += ' * void SQLExecDirectCallback(SQLExecDirectStruct* );' + '\n' file__pase_cli_async_h += ' * SQLExecDirectStruct * SQLExecDirectJoin (pthread_t tid, SQLINTEGER flag);' + '\n' file__pase_cli_async_h += ' * void SQLExecDirectWCallback(SQLExecDirectWStruct* );' + '\n' file__pase_cli_async_h += ' * SQLExecDirectWStruct * SQLExecDirectWJoin (pthread_t tid, SQLINTEGER flag);' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * === bypass all, call PASE libdb400.a directly (not recommended) ===' + '\n' file__pase_cli_async_h += ' * SQLRETURN libdb400_SQLExecDirect(..);' + '\n' file__pase_cli_async_h += ' * SQLRETURN libdb400_SQLExecDirectW(..); (*)' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' * === bypass all, call ILE directly (not recommended) ===' + '\n' file__pase_cli_async_h += ' * SQLRETURN ILE_SQLExecDirect(..);' + '\n' file__pase_cli_async_h += ' * SQLRETURN ILE_SQLExecDirectW(..);' + '\n' file__pase_cli_async_h += ' * ' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * CUSTOM interfaces' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* Use:' + '\n' file__pase_cli_async_h += ' * SQL400Environment ( ..., SQLPOINTER options )' + '\n' file__pase_cli_async_h += ' * SQL400Connect ( ..., SQLPOINTER options )' + '\n' file__pase_cli_async_h += ' * SQL400SetAttr ( ..., SQLPOINTER options )' + '\n' file__pase_cli_async_h += ' * CTOR:' + '\n' file__pase_cli_async_h += ' * SQL400AddAttr' + '\n' file__pase_cli_async_h += ' * Struct:' + '\n' file__pase_cli_async_h += ' * SQL400AttrStruct' + '\n' file__pase_cli_async_h += ' * e - EnvAttr' + '\n' file__pase_cli_async_h += ' * c - ConnectAttr' + '\n' file__pase_cli_async_h += ' * s - StmtAttr' + '\n' file__pase_cli_async_h += ' * o - StmtOption' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '/* CLI hidden attributes */' + '\n' file__pase_cli_async_h += '#define SQL400_ATTR_PASE_CCSID 10011' + '\n' file__pase_cli_async_h += '#define SQL400_ATTR_CONN_JDBC 10201' + '\n' file__pase_cli_async_h += '/* stop or not on attribute failure */' + '\n' file__pase_cli_async_h += '#define SQL400_ONERR_CONT 1' + '\n' file__pase_cli_async_h += '#define SQL400_ONERR_STOP 2' + '\n' file__pase_cli_async_h += '/* normal attributes */' + '\n' file__pase_cli_async_h += '#define SQL400_FLAG_IMMED 0' + '\n' file__pase_cli_async_h += '/* post connect attributes */' + '\n' file__pase_cli_async_h += '#define SQL400_FLAG_POST_CONNECT 1' + '\n' file__pase_cli_async_h += '#define SQL400_ATTR_CONN_CHGCURLIB 424201' + '\n' file__pase_cli_async_h += '#define SQL400_ATTR_CONN_CHGLIBL 424202' + '\n' file__pase_cli_async_h += 'typedef struct SQL400AttrStruct {' + '\n' file__pase_cli_async_h += ' SQLINTEGER scope; /* - scope - SQL_HANDLE_ENV|DBC|SRTMT|DESC */' + '\n' file__pase_cli_async_h += ' SQLHANDLE hndl; /* ecso - hndl - CLI handle */' + '\n' file__pase_cli_async_h += ' SQLINTEGER attrib; /* ecso - attrib - CLI attribute */' + '\n' file__pase_cli_async_h += ' SQLPOINTER vParam; /* ecso - vParam - ptr to CLI value */' + '\n' file__pase_cli_async_h += ' SQLINTEGER inlen; /* ecs - inlen - len CLI value (string) */' + '\n' file__pase_cli_async_h += ' SQLINTEGER sqlrc; /* - sqlrc - sql return code */' + '\n' file__pase_cli_async_h += ' SQLINTEGER onerr; /* - onerr - SQL400_ONERR_xxx */' + '\n' file__pase_cli_async_h += ' SQLINTEGER flag; /* - flag - SQL400_FLAG_xxx */' + '\n' file__pase_cli_async_h += '} SQL400AttrStruct;' + '\n' file__pase_cli_async_h += '/* Use:' + '\n' file__pase_cli_async_h += ' * SQL400Execute( ..., SQLPOINTER parms, SQLPOINTER desc_parms)' + '\n' file__pase_cli_async_h += ' * SQL400Fetch (..., SQLPOINTER desc_cols)' + '\n' file__pase_cli_async_h += ' * CTOR:' + '\n' file__pase_cli_async_h += ' * SQL400Describe' + '\n' file__pase_cli_async_h += ' * SQL400AddCVar' + '\n' file__pase_cli_async_h += ' * Struct:' + '\n' file__pase_cli_async_h += ' * SQL400ParamStruct' + '\n' file__pase_cli_async_h += ' * SQL400DescribeStruct' + '\n' file__pase_cli_async_h += ' * p - SQLDescribeParam' + '\n' file__pase_cli_async_h += ' * c - SQLDescribeCol' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '#define SQL400_DESC_PARM 0' + '\n' file__pase_cli_async_h += '#define SQL400_DESC_COL 1' + '\n' file__pase_cli_async_h += '#define SQL400_PARM_IO_FILE 42' + '\n' file__pase_cli_async_h += 'typedef struct SQL400ParamStruct {' + '\n' file__pase_cli_async_h += ' SQLSMALLINT icol; /* icol - param number (in) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT inOutType; /* inOutType - sql C in/out flag (in) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT pfSqlCType; /* pfSqlCType - sql C data type (in) */' + '\n' file__pase_cli_async_h += ' SQLPOINTER pfSqlCValue; /* pfSqlCValue - sql C ptr to data (out) */' + '\n' file__pase_cli_async_h += ' SQLINTEGER * indPtr; /* indPtr - sql strlen/ind (out) */' + '\n' file__pase_cli_async_h += '} SQL400ParamStruct;' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += 'typedef struct SQL400DescStruct {' + '\n' file__pase_cli_async_h += ' SQLSMALLINT itype; /* - itype - descr col/parm (out) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT icol; /* pc - icol - column number (in) */' + '\n' file__pase_cli_async_h += ' SQLCHAR * szColName; /* c - szColName - column name ptr (out) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT cbColNameMax; /* c - cbColNameMax - name max len (in) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT pcbColName; /* c - pcbColName - name size len (out) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT pfSqlType; /* pc - pfSqlType - sql data type (out) */' + '\n' file__pase_cli_async_h += ' SQLINTEGER pcbColDef; /* pc - pcbColDef - sql size column (out) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT pibScale; /* pc - pibScale - decimal digits (out) */' + '\n' file__pase_cli_async_h += ' SQLSMALLINT pfNullable; /* pc - pfNullable - null allowed (out) */' + '\n' file__pase_cli_async_h += ' SQLCHAR bfColName[1024]; /* c - bfColName - column name buf (out) */' + '\n' file__pase_cli_async_h += '} SQL400DescStruct;' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* special SQL400 aggregate functions */' + '\n' file__pase_cli_async_h += '/* do common work for language driver */' + '\n' file__pase_cli_async_h += '/* composite calls to CLI also async */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliOnly400_h_proto file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * NORMAL CLI interfaces' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* === sqlcli.h -- normal CLI interfaces (copy) === ' + '\n' file__pase_cli_async_h += PaseCliAny_h_proto file__pase_cli_async_h += ' * === sqlcli.h === */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * ASYNC CLI interfaces' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* choose either callback or join */' + '\n' file__pase_cli_async_h += '/* following structures returned */' + '\n' file__pase_cli_async_h += '/* caller must free return structure */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliAsync_h_struct + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* join async thread */' + '\n' file__pase_cli_async_h += '/* flag: */' + '\n' file__pase_cli_async_h += '/* SQL400_FLAG_JOIN_WAIT */' + '\n' file__pase_cli_async_h += '/* - block until complete */' + '\n' file__pase_cli_async_h += '/* SQL400_FLAG_JOIN_NO_WAIT */' + '\n' file__pase_cli_async_h += '/* - no block, NULL still executing */' + '\n' file__pase_cli_async_h += '#define SQL400_FLAG_JOIN_WAIT 0' + '\n' file__pase_cli_async_h += '#define SQL400_FLAG_JOIN_NO_WAIT 1' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliAsync_h_proto_join file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* start an async call to DB2 CLI */' + '\n' file__pase_cli_async_h += '/* choose either callback or join */' + '\n' file__pase_cli_async_h += '/* for results returned. */' + '\n' file__pase_cli_async_h += '/* sqlrc returned in structure. */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliAsync_h_proto_async file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * ILE CLI interfaces' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliILE_h_proto file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * LIBDB400.A CLI interfaces (PASE old CLI driver)' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliLibDB400_h_proto file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * trace dump' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliDump_h_proto file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '/* ===================================================' + '\n' file__pase_cli_async_h += ' * INTERNAL USE' + '\n' file__pase_cli_async_h += ' * ===================================================' + '\n' file__pase_cli_async_h += ' */' + '\n' file__pase_cli_async_h += '#ifndef SQL_ATTR_SERVERMODE_SUBSYSTEM' + '\n' file__pase_cli_async_h += '#define SQL_ATTR_SERVERMODE_SUBSYSTEM 10204' + '\n' file__pase_cli_async_h += '#endif' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += PaseCliCustom_h_proto file__pase_cli_async_h += 'SQLRETURN custom_SQLSetEnvCCSID( SQLHANDLE env, int myccsid);' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '' + '\n' file__pase_cli_async_h += '#ifdef __cplusplus ' + '\n' file__pase_cli_async_h += '}' + '\n' file__pase_cli_async_h += '#endif /* __cplusplus */' + '\n' file__pase_cli_async_h += '#endif /* _PASECLIASYNC_H */' + '\n' with open('PaseCliAsync.h', 'w') as text_file: text_file.write(file_PaseCliAsync_h) file_libdb400_exp = '' file_libdb400_exp += '#!libdb400.a(shr.o)' + '\n' file_libdb400_exp += '' + '\n' file_libdb400_exp += '' + '\n' file_libdb400_exp += libdb400_exp file_libdb400_exp += '' + '\n' file_libdb400_exp += '' + '\n' file_libdb400_exp += 'dev_dump' + '\n' file_libdb400_exp += 'dev_go' + '\n' file_libdb400_exp += 'printf_key' + '\n' file_libdb400_exp += 'printf_buffer' + '\n' file_libdb400_exp += 'printf_clear' + '\n' file_libdb400_exp += 'printf_format' + '\n' file_libdb400_exp += 'printf_hexdump' + '\n' file_libdb400_exp += 'printf_stack' + '\n' file_libdb400_exp += 'printf_script' + '\n' file_libdb400_exp += 'printf_script_include' + '\n' file_libdb400_exp += 'printf_script_exclude' + '\n' file_libdb400_exp += 'printf_script_clear' + '\n' file_libdb400_exp += 'printf_force_SIGQUIT' + '\n' file_libdb400_exp += 'printf_sqlrc_status' + '\n' file_libdb400_exp += 'printf_sqlrc_head_foot' + '\n' file_libdb400_exp += 'sprintf_format' + '\n' file_libdb400_exp += '' + '\n' file_libdb400_exp += '' + '\n' with open('libdb400.exp', 'w') as text_file: text_file.write(file_libdb400_exp)
VERSION = (0, 1, 0) __author__ = 'Ivan Sushkov <comeuplater>' __version__ = '.'.join(str(x) for x in VERSION)
version = (0, 1, 0) __author__ = 'Ivan Sushkov <comeuplater>' __version__ = '.'.join((str(x) for x in VERSION))
def zero_matrix(matrix): points = [] for row in range(len(matrix)): for col in range(len(matrix[row])): val = matrix[row][col] if val == 0: points.append((row, col)) for point in points: update_row(matrix, point[0]) update_col(matrix, point[1]) def update_col(matrix, col): for row in range(len(matrix)): matrix[row][col] = 0 def update_row(matrix, row): for col in range(len(matrix[row])): matrix[row][col] = 0 matrix = [[4, 3, 1, 0], [6, 1, 2, 5], [8, 0, 1, 7], [5, 2, 1, 1]] zero_matrix(matrix) print(matrix)
def zero_matrix(matrix): points = [] for row in range(len(matrix)): for col in range(len(matrix[row])): val = matrix[row][col] if val == 0: points.append((row, col)) for point in points: update_row(matrix, point[0]) update_col(matrix, point[1]) def update_col(matrix, col): for row in range(len(matrix)): matrix[row][col] = 0 def update_row(matrix, row): for col in range(len(matrix[row])): matrix[row][col] = 0 matrix = [[4, 3, 1, 0], [6, 1, 2, 5], [8, 0, 1, 7], [5, 2, 1, 1]] zero_matrix(matrix) print(matrix)
Aa,Va=input().split() Ab,Vb=input().split() Aa,Va,Ab,Vb=int(Aa),int(Va),int(Ab),int(Vb) Fb=Ab-Vb while Fb>0 and Va>0: Vb+=1 Va-=1 Fb-=1 print(Va,Vb)
(aa, va) = input().split() (ab, vb) = input().split() (aa, va, ab, vb) = (int(Aa), int(Va), int(Ab), int(Vb)) fb = Ab - Vb while Fb > 0 and Va > 0: vb += 1 va -= 1 fb -= 1 print(Va, Vb)
class NoGeometry(RuntimeError): pass class NoSuperelements(RuntimeError): pass
class Nogeometry(RuntimeError): pass class Nosuperelements(RuntimeError): pass
a = 1 b = 2 c =2 a = 2 class info(): def __init__(self): self.color="red"
a = 1 b = 2 c = 2 a = 2 class Info: def __init__(self): self.color = 'red'
# SPDX-FileCopyrightText: no # SPDX-License-Identifier: CC0-1.0 # # Stubs for part of the Python API from libcalamares # (although the **actual** API is presented through # Boost::Python, not as a bare C-extension) so that # pylint doesn't complain about libcalamares internals. VERSION_SHORT="1.0"
version_short = '1.0'
''' Sorting is useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses as well. In this case, it will make it easier to determine which pair or pairs of elements have the smallest absolute difference between them. For example, if you've got the list [5, 2, 3, 4, 1], sort it as [1, 2, 3, 4, 5] to see that several pairs have the minimum difference of 1: [(1, 2), (2, 3), (3, 4), (4, 5)]. The return array would be [1, 2, 2, 3, 3, 4, 4, 5]. Given a list of unsorted integers, , find the pair of elements that have the smallest absolute difference between them. If there are multiple pairs, find them all. ''' def closestNumbers(arr): arr = sorted(list(set(arr))) m = None ans = [] for i in range(1, len(arr)): diff = arr[i]-arr[i-1] if m is None or m>diff: ans = [arr[i-1], arr[i]] m = diff elif m==diff: ans.append(arr[i-1]) ans.append(arr[i]) return ans if __name__ == '__main__': data = [ [5, 2, 3, 4, 1], ] for l in data: print(closestNumbers(l))
""" Sorting is useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses as well. In this case, it will make it easier to determine which pair or pairs of elements have the smallest absolute difference between them. For example, if you've got the list [5, 2, 3, 4, 1], sort it as [1, 2, 3, 4, 5] to see that several pairs have the minimum difference of 1: [(1, 2), (2, 3), (3, 4), (4, 5)]. The return array would be [1, 2, 2, 3, 3, 4, 4, 5]. Given a list of unsorted integers, , find the pair of elements that have the smallest absolute difference between them. If there are multiple pairs, find them all. """ def closest_numbers(arr): arr = sorted(list(set(arr))) m = None ans = [] for i in range(1, len(arr)): diff = arr[i] - arr[i - 1] if m is None or m > diff: ans = [arr[i - 1], arr[i]] m = diff elif m == diff: ans.append(arr[i - 1]) ans.append(arr[i]) return ans if __name__ == '__main__': data = [[5, 2, 3, 4, 1]] for l in data: print(closest_numbers(l))
def _combinators(_handle, items, n): if n==0: yield [] return for i, item in enumerate(items): this_one = [ item ] for cc in _combinators(_handle, _handle(items, i), n-1): yield this_one + cc def combinations(items, n): ''' take n distinct items, order matters ''' def skipIthItem(items, i): return items[:i] + items[i+1:] return _combinators(skipIthItem, items, n) def uniqueCombinations(items, n): ''' take n distinct items, order is irrelevant ''' def afterIthItem(items, i): return items[i+1:] return _combinators(afterIthItem, items, n) def selections(items, n): ''' take n (not necessarily distinct) items, order matters ''' def keepAllItems(items, i): return items return _combinators(keepAllItems, items, n) def permutations(items): ''' take all items, order matters ''' return combinations(items, len(items))
def _combinators(_handle, items, n): if n == 0: yield [] return for (i, item) in enumerate(items): this_one = [item] for cc in _combinators(_handle, _handle(items, i), n - 1): yield (this_one + cc) def combinations(items, n): """ take n distinct items, order matters """ def skip_ith_item(items, i): return items[:i] + items[i + 1:] return _combinators(skipIthItem, items, n) def unique_combinations(items, n): """ take n distinct items, order is irrelevant """ def after_ith_item(items, i): return items[i + 1:] return _combinators(afterIthItem, items, n) def selections(items, n): """ take n (not necessarily distinct) items, order matters """ def keep_all_items(items, i): return items return _combinators(keepAllItems, items, n) def permutations(items): """ take all items, order matters """ return combinations(items, len(items))
'''6. Write a Python program to count the number of equal numbers from three given integers. Sample Output: 3 2 0 3''' def count(num): if num[0]==num[1] and num[0]==num[2]: ans = 3 elif num[0]==num[1] or num[1]==num[2] or num[0]==num[2]: ans = 2 else: ans = 0 return ans print(count((1, 1, 1))) print(count((1, 2, 2))) print(count((-1, -2, -3))) print(count((-1, -1, -1)))
"""6. Write a Python program to count the number of equal numbers from three given integers. Sample Output: 3 2 0 3""" def count(num): if num[0] == num[1] and num[0] == num[2]: ans = 3 elif num[0] == num[1] or num[1] == num[2] or num[0] == num[2]: ans = 2 else: ans = 0 return ans print(count((1, 1, 1))) print(count((1, 2, 2))) print(count((-1, -2, -3))) print(count((-1, -1, -1)))
class Sources: ''' News class to define News sources Objects ''' def __init__(self, id, name, description): self.id = id self.name = name self.description = description class Articles: ''' Headlines to define News articles class ''' def __init__(self, source, author, title, description, publishedAt, url, urlToImage): self.source = source self.author = author self.title = title self.description = description self.publishedAt = publishedAt self.url = url self.urlToImage = urlToImage
class Sources: """ News class to define News sources Objects """ def __init__(self, id, name, description): self.id = id self.name = name self.description = description class Articles: """ Headlines to define News articles class """ def __init__(self, source, author, title, description, publishedAt, url, urlToImage): self.source = source self.author = author self.title = title self.description = description self.publishedAt = publishedAt self.url = url self.urlToImage = urlToImage
# LEETCODE 121: Best Time to Buy and Sell Stock # # https://leetcode.com/problems/best-time-to-buy-and-sell-stock/ # # Say you have an array for which the ith element is the price of a given stock on day i. # # If you were only permitted to complete at most one transaction # (i.e., buy one and sell one share of the stock), # design an algorithm to find the maximum profit. # # Example 1: # # Input: [7,1,5,3,6,4] # Output: 7 # # Example 2: # # Input: [7,6,4,3,1] # Output: 0 def max_profit(prices): # sanity checks count = len(prices) if count < 2: return 0 # at this point, we have at least 2 data points in prices # what we return profit = 0 # compute differences list diff = [0] for i in range(1, count): diff.append(prices[i] - prices[i-1]) # debug print('Prices:', prices) print('Diff:', diff) # consume differences list is_buy = True for i,_ in enumerate(diff): if is_buy: if (i == 0 and diff[1] > 0) or ( i > 0 and i < count - 2 and diff[i-1] >= 0 and diff[i+1] > 0 and diff[i] <= 0): print('Buy:', prices[i]) profit -= prices[i] is_buy = False else: if (i == count - 1) or ( i < count - 1 and diff[i-1] <= 0 and diff[i+1] < 0 and diff[i] > 0): #print('Sell:', prices[i]) profit += prices[i] is_buy = True # finally return return profit #### # test cases prices = [7,1,5,3,6,4] profit = max_profit(prices) print('prices =', prices, ', profit =', profit) prices = [7,6,4,3,1] profit = max_profit(prices) print('prices =', prices, ', profit =', profit)
def max_profit(prices): count = len(prices) if count < 2: return 0 profit = 0 diff = [0] for i in range(1, count): diff.append(prices[i] - prices[i - 1]) print('Prices:', prices) print('Diff:', diff) is_buy = True for (i, _) in enumerate(diff): if is_buy: if i == 0 and diff[1] > 0 or (i > 0 and i < count - 2 and (diff[i - 1] >= 0) and (diff[i + 1] > 0) and (diff[i] <= 0)): print('Buy:', prices[i]) profit -= prices[i] is_buy = False elif i == count - 1 or (i < count - 1 and diff[i - 1] <= 0 and (diff[i + 1] < 0) and (diff[i] > 0)): profit += prices[i] is_buy = True return profit prices = [7, 1, 5, 3, 6, 4] profit = max_profit(prices) print('prices =', prices, ', profit =', profit) prices = [7, 6, 4, 3, 1] profit = max_profit(prices) print('prices =', prices, ', profit =', profit)
def test_view(invoke, secret): invoke(['decrypt']) decrypted = invoke(['view', secret.encrypted.as_posix()]) plaintext = secret.decrypted.read_text().splitlines() assert decrypted == plaintext
def test_view(invoke, secret): invoke(['decrypt']) decrypted = invoke(['view', secret.encrypted.as_posix()]) plaintext = secret.decrypted.read_text().splitlines() assert decrypted == plaintext
{ 'variables': { 'external_libmediaserver%' : '<!(echo $LIBMEDIASERVER)', 'external_libmediaserver_include_dirs%' : '<!(echo $LIBMEDIASERVER_INCLUDE)', }, "targets": [ { "target_name": "medooze-audio-codecs", "cflags": [ "-march=native", "-fexceptions", "-O3", "-g", "-Wno-unused-function -Wno-comment", "-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT", #"-O0", #"-fsanitize=address" ], "cflags_cc": [ "-fexceptions", "-std=c++17", "-O3", "-g", "-Wno-unused-function", "-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT", "-faligned-new", #"-O0", #"-fsanitize=address,leak" ], "include_dirs" : [ '/usr/include/nodejs/', "<!(node -e \"require('nan')\")" ], "ldflags" : [" -lpthread -lresolv"], "link_settings": { 'libraries': ["-lpthread -lpthread -lresolv -lavcodec -lspeex -lopus"] }, "sources": [ "src/audio-codecs_wrap.cxx", ], "conditions": [ [ "external_libmediaserver == ''", { "include_dirs" : [ 'media-server/include', 'media-server/src', 'media-server/ext/crc32c/include', 'media-server/ext/libdatachannels/src', 'media-server/ext/libdatachannels/src/internal', "media-server/src/g711", "media-server/src/g722", "media-server/src/gsm", "media-server/src/aac", "media-server/src/opus", "media-server/src/speex", "media-server/src/nelly", ], "sources": [ "media-server/src/audioencoder.cpp", "media-server/src/audiodecoder.cpp", "media-server/src/AudioCodecFactory.cpp", "media-server/src/AudioPipe.cpp", "media-server/src/audiotransrater.cpp", "media-server/src/EventLoop.cpp", "media-server/src/MediaFrameListenerBridge.cpp", "media-server/src/rtp/DependencyDescriptor.cpp", "media-server/src/rtp/RTPPacket.cpp", "media-server/src/rtp/RTPPayload.cpp", "media-server/src/rtp/RTPHeader.cpp", "media-server/src/rtp/RTPHeaderExtension.cpp", "media-server/src/rtp/RTPMap.cpp", "media-server/src/g711/pcmucodec.cpp", "media-server/src/g711/pcmacodec.cpp", "media-server/src/g711/g711.cpp", "media-server/src/g722/g722_encode.c", "media-server/src/g722/g722_decode.c", "media-server/src/g722/g722codec.cpp", "media-server/src/gsm/gsmcodec.cpp", "media-server/src/aac/aacencoder.cpp", "media-server/src/aac/aacdecoder.cpp", "media-server/src/opus/opusdecoder.cpp", "media-server/src/opus/opusencoder.cpp", "media-server/src/speex/speexcodec.cpp", "media-server/src/speex/resample.c", "media-server/src/nelly/NellyCodec.cpp", "media-server/src/opus/opusdepacketizer.cpp", "media-server/src/rtp/RTPDepacketizer.cpp", "media-server/src/rtp/RTPIncomingMediaStreamDepacketizer.cpp", ], "conditions" : [ ['OS=="mac"', { "xcode_settings": { "CLANG_CXX_LIBRARY": "libc++", "CLANG_CXX_LANGUAGE_STANDARD": "c++17", "OTHER_CFLAGS": [ "-Wno-aligned-allocation-unavailable","-march=native"] }, }] ] }, { "libraries" : [ "<(external_libmediaserver)" ], "include_dirs" : [ "<@(external_libmediaserver_include_dirs)" ], 'conditions': [ ['OS=="linux"', { "ldflags" : [" -Wl,-Bsymbolic "], }], ['OS=="mac"', { "xcode_settings": { "CLANG_CXX_LIBRARY": "libc++", "CLANG_CXX_LANGUAGE_STANDARD": "c++17", "OTHER_CFLAGS": [ "-Wno-aligned-allocation-unavailable","-march=native"] }, }], ] } ] ] } ] }
{'variables': {'external_libmediaserver%': '<!(echo $LIBMEDIASERVER)', 'external_libmediaserver_include_dirs%': '<!(echo $LIBMEDIASERVER_INCLUDE)'}, 'targets': [{'target_name': 'medooze-audio-codecs', 'cflags': ['-march=native', '-fexceptions', '-O3', '-g', '-Wno-unused-function -Wno-comment', '-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT'], 'cflags_cc': ['-fexceptions', '-std=c++17', '-O3', '-g', '-Wno-unused-function', '-DSPX_RESAMPLE_EXPORT= -DRANDOM_PREFIX=mcu -DOUTSIDE_SPEEX -DFLOATING_POINT', '-faligned-new'], 'include_dirs': ['/usr/include/nodejs/', '<!(node -e "require(\'nan\')")'], 'ldflags': [' -lpthread -lresolv'], 'link_settings': {'libraries': ['-lpthread -lpthread -lresolv -lavcodec -lspeex -lopus']}, 'sources': ['src/audio-codecs_wrap.cxx'], 'conditions': [["external_libmediaserver == ''", {'include_dirs': ['media-server/include', 'media-server/src', 'media-server/ext/crc32c/include', 'media-server/ext/libdatachannels/src', 'media-server/ext/libdatachannels/src/internal', 'media-server/src/g711', 'media-server/src/g722', 'media-server/src/gsm', 'media-server/src/aac', 'media-server/src/opus', 'media-server/src/speex', 'media-server/src/nelly'], 'sources': ['media-server/src/audioencoder.cpp', 'media-server/src/audiodecoder.cpp', 'media-server/src/AudioCodecFactory.cpp', 'media-server/src/AudioPipe.cpp', 'media-server/src/audiotransrater.cpp', 'media-server/src/EventLoop.cpp', 'media-server/src/MediaFrameListenerBridge.cpp', 'media-server/src/rtp/DependencyDescriptor.cpp', 'media-server/src/rtp/RTPPacket.cpp', 'media-server/src/rtp/RTPPayload.cpp', 'media-server/src/rtp/RTPHeader.cpp', 'media-server/src/rtp/RTPHeaderExtension.cpp', 'media-server/src/rtp/RTPMap.cpp', 'media-server/src/g711/pcmucodec.cpp', 'media-server/src/g711/pcmacodec.cpp', 'media-server/src/g711/g711.cpp', 'media-server/src/g722/g722_encode.c', 'media-server/src/g722/g722_decode.c', 'media-server/src/g722/g722codec.cpp', 'media-server/src/gsm/gsmcodec.cpp', 'media-server/src/aac/aacencoder.cpp', 'media-server/src/aac/aacdecoder.cpp', 'media-server/src/opus/opusdecoder.cpp', 'media-server/src/opus/opusencoder.cpp', 'media-server/src/speex/speexcodec.cpp', 'media-server/src/speex/resample.c', 'media-server/src/nelly/NellyCodec.cpp', 'media-server/src/opus/opusdepacketizer.cpp', 'media-server/src/rtp/RTPDepacketizer.cpp', 'media-server/src/rtp/RTPIncomingMediaStreamDepacketizer.cpp'], 'conditions': [['OS=="mac"', {'xcode_settings': {'CLANG_CXX_LIBRARY': 'libc++', 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17', 'OTHER_CFLAGS': ['-Wno-aligned-allocation-unavailable', '-march=native']}}]]}, {'libraries': ['<(external_libmediaserver)'], 'include_dirs': ['<@(external_libmediaserver_include_dirs)'], 'conditions': [['OS=="linux"', {'ldflags': [' -Wl,-Bsymbolic ']}], ['OS=="mac"', {'xcode_settings': {'CLANG_CXX_LIBRARY': 'libc++', 'CLANG_CXX_LANGUAGE_STANDARD': 'c++17', 'OTHER_CFLAGS': ['-Wno-aligned-allocation-unavailable', '-march=native']}}]]}]]}]}
def a(m,limit): turn=len(m) last_spoken = m[-1] while turn < 2020: turn += 1 try: distance = list(reversed(m[:-1])).index(last_spoken)+1 except ValueError: distance = 0 m.append(distance) last_spoken = distance return(m[-1]) def ab(m, limit): d = dict() for i, v in enumerate(m[:-1]): d[v] = i + 1 turn=len(m) last_spoken = m[-1] while turn < limit: if last_spoken in d: distance = turn - d[last_spoken] else: distance = 0 d[last_spoken] = turn turn += 1 last_spoken = distance return(distance) for limit in [2020, 30000000]: print(ab([9,3,1,0,8,4],limit)) print(ab([0,3,6],limit)) print(ab([1,3,2],limit)) print(ab([2,1,3],limit)) print(ab([1,2,3],limit)) print(ab([2,3,1],limit)) print(ab([3,1,2],limit))
def a(m, limit): turn = len(m) last_spoken = m[-1] while turn < 2020: turn += 1 try: distance = list(reversed(m[:-1])).index(last_spoken) + 1 except ValueError: distance = 0 m.append(distance) last_spoken = distance return m[-1] def ab(m, limit): d = dict() for (i, v) in enumerate(m[:-1]): d[v] = i + 1 turn = len(m) last_spoken = m[-1] while turn < limit: if last_spoken in d: distance = turn - d[last_spoken] else: distance = 0 d[last_spoken] = turn turn += 1 last_spoken = distance return distance for limit in [2020, 30000000]: print(ab([9, 3, 1, 0, 8, 4], limit)) print(ab([0, 3, 6], limit)) print(ab([1, 3, 2], limit)) print(ab([2, 1, 3], limit)) print(ab([1, 2, 3], limit)) print(ab([2, 3, 1], limit)) print(ab([3, 1, 2], limit))
# Title : TODO # Objective : TODO # Created by: Wenzurk # Created on: 2018/2/10 # alien_0 = {'color': 'green', 'point': '5'} # alien_1 = {'color': 'yellow', 'point': '10'} # alien_2 = {'color': 'red', 'point': '15'} # # aliens = [alien_0, alien_1, alien_2] # # for alien in aliens: # print(alien) aliens = [] for alien_number in range(30): new_alien = {'color': 'green', 'points': '5', 'speed': 'slow'} aliens.append(new_alien) for alien in aliens[0:3]: if alien['color'] == 'green': alien['color'] = 'yellow' alien['speed'] = 'medium' alien['points'] = 10 elif alien['color'] == 'yellow': alien['color'] = 'red' alien['speed'] = 'fast' alien['points'] = 15 for alien in aliens[:5]: print(alien) print("...") print("Total number of aliens: " + str(len(aliens)))
aliens = [] for alien_number in range(30): new_alien = {'color': 'green', 'points': '5', 'speed': 'slow'} aliens.append(new_alien) for alien in aliens[0:3]: if alien['color'] == 'green': alien['color'] = 'yellow' alien['speed'] = 'medium' alien['points'] = 10 elif alien['color'] == 'yellow': alien['color'] = 'red' alien['speed'] = 'fast' alien['points'] = 15 for alien in aliens[:5]: print(alien) print('...') print('Total number of aliens: ' + str(len(aliens)))
class Fruit: def eat(self): print("Eating..") f=Fruit() f.eat()
class Fruit: def eat(self): print('Eating..') f = fruit() f.eat()
iterable = range(5) # range is the iterable iterator = iter(iterable) # extract iterator from iterable while True: try: n = next(iterator) # Code inside "for" loop print(n, end=" ") n = 5 # Will be overridden by line 5 in next iteration except StopIteration: # iterator signaled it's exhausted break print() # Code after "for" loop
iterable = range(5) iterator = iter(iterable) while True: try: n = next(iterator) print(n, end=' ') n = 5 except StopIteration: break print()
#!/usr/bin/env python # Copyright 2016 Cisco Systems, Inc. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain # a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # class TORClientException(Exception): pass class BasicTORClient(object): def __init__(self, config): pass def get_int_counters(self): return {} def get_vni_counters(self, vni): return {} def get_vni_interface(self, vni, counters): return None def get_vni_for_vlan(self, vlans): return [] def attach_tg_interfaces(self, network_vlans, switch_ports): pass def clear_nve(self): pass def clear_interface(self, vni): pass def close(self): pass def get_version(self): return {}
class Torclientexception(Exception): pass class Basictorclient(object): def __init__(self, config): pass def get_int_counters(self): return {} def get_vni_counters(self, vni): return {} def get_vni_interface(self, vni, counters): return None def get_vni_for_vlan(self, vlans): return [] def attach_tg_interfaces(self, network_vlans, switch_ports): pass def clear_nve(self): pass def clear_interface(self, vni): pass def close(self): pass def get_version(self): return {}
class dir: misc = "misc/" datasets = "datasets/" kerasModels = misc + "kerasModels/" autoencoders = kerasModels + 'autoencoder/' @staticmethod def get_autoencoder_dir_of_latent_size(latentSize): return dir.autoencoders + "ae" + str(latentSize) + '/' class dataset: _directory = dir.datasets _processedDir = _directory + "processed/" _rawDir = _directory + "raw/" _normDir = _directory + "normalized/" _npDir = _directory + "numpy/" synsysSubDir = "synsys/" synsysFileName = "synsysData.csv" #1 time dim; 84 unique sensors; 25 activities @staticmethod def _fix_dir_str(dir): return dir + '/' if dir[-1] != '/' else dir @staticmethod def get_raw(fileName, subDir = synsysSubDir): subDir = dataset._fix_dir_str(subDir) return dataset._rawDir + subDir + fileName @staticmethod def get_processed(fileName, subDir = synsysSubDir): subDir = dataset._fix_dir_str(subDir) return dataset._processedDir + subDir + fileName @staticmethod def get_normalized(fileName, subDir = synsysSubDir): subDir = dataset._fix_dir_str(subDir) return dataset._normDir + subDir + fileName @staticmethod def get_np(fileName, subDir = synsysSubDir): subDir = dataset._fix_dir_str(subDir) return dataset._npDir + subDir + fileName
class Dir: misc = 'misc/' datasets = 'datasets/' keras_models = misc + 'kerasModels/' autoencoders = kerasModels + 'autoencoder/' @staticmethod def get_autoencoder_dir_of_latent_size(latentSize): return dir.autoencoders + 'ae' + str(latentSize) + '/' class Dataset: _directory = dir.datasets _processed_dir = _directory + 'processed/' _raw_dir = _directory + 'raw/' _norm_dir = _directory + 'normalized/' _np_dir = _directory + 'numpy/' synsys_sub_dir = 'synsys/' synsys_file_name = 'synsysData.csv' @staticmethod def _fix_dir_str(dir): return dir + '/' if dir[-1] != '/' else dir @staticmethod def get_raw(fileName, subDir=synsysSubDir): sub_dir = dataset._fix_dir_str(subDir) return dataset._rawDir + subDir + fileName @staticmethod def get_processed(fileName, subDir=synsysSubDir): sub_dir = dataset._fix_dir_str(subDir) return dataset._processedDir + subDir + fileName @staticmethod def get_normalized(fileName, subDir=synsysSubDir): sub_dir = dataset._fix_dir_str(subDir) return dataset._normDir + subDir + fileName @staticmethod def get_np(fileName, subDir=synsysSubDir): sub_dir = dataset._fix_dir_str(subDir) return dataset._npDir + subDir + fileName
print(8%10) x = 'abc_%(key)s_' x %= {'key':'value'} print(x) x = 'Sir %(Name)s ' x %= {'Name':'Lancelot'} print(x)
print(8 % 10) x = 'abc_%(key)s_' x %= {'key': 'value'} print(x) x = 'Sir %(Name)s ' x %= {'Name': 'Lancelot'} print(x)
class Solution: def numJewelsInStones(self, jewels: str, stones: str) -> int: hashmap = {} for x in jewels: hashmap[x] = 0 for x in stones: if x in hashmap: hashmap[x] += 1 return sum(hashmap.values()) class Solution(object): def numJewelsInStones(self, jewels: str, stones: str) -> int: jewels_set = set(jewels) return sum(s in jewels_set for s in stones) # generator
class Solution: def num_jewels_in_stones(self, jewels: str, stones: str) -> int: hashmap = {} for x in jewels: hashmap[x] = 0 for x in stones: if x in hashmap: hashmap[x] += 1 return sum(hashmap.values()) class Solution(object): def num_jewels_in_stones(self, jewels: str, stones: str) -> int: jewels_set = set(jewels) return sum((s in jewels_set for s in stones))
h, w, n = map(int, input().split()) li = list(map(int, input().split())) curw = 0 for i in range(n): if curw + li[i] <= w: curw += li[i] else: print('NO') exit(0) if curw == w: curw %= w h -= 1 if not h: print('YES') exit(0) print('NO')
(h, w, n) = map(int, input().split()) li = list(map(int, input().split())) curw = 0 for i in range(n): if curw + li[i] <= w: curw += li[i] else: print('NO') exit(0) if curw == w: curw %= w h -= 1 if not h: print('YES') exit(0) print('NO')
tax_table = [(10000, 0.1), (20000, 0.2), (None, 0.3)] def get_tax(init_salary, tax_table): tax = 0 salary = init_salary previous_limit = 0 for limit, ratio in tax_table: if limit is None or init_salary < limit: tax += salary * ratio return tax current_salary = limit - previous_limit tax += current_salary * ratio previous_limit = limit salary -= current_salary if __name__ == "__main__": tax = get_tax(31000, tax_table) print("tax: ", tax) assert get_tax(500, tax_table) == 50 assert get_tax(10000, tax_table) == 1000 assert get_tax(10100, tax_table) == 1020 assert get_tax(20000, tax_table) == 3000 assert get_tax(20100, tax_table) == 3030 assert get_tax(30000, tax_table) == 6000 assert get_tax(36000, tax_table) == 7800
tax_table = [(10000, 0.1), (20000, 0.2), (None, 0.3)] def get_tax(init_salary, tax_table): tax = 0 salary = init_salary previous_limit = 0 for (limit, ratio) in tax_table: if limit is None or init_salary < limit: tax += salary * ratio return tax current_salary = limit - previous_limit tax += current_salary * ratio previous_limit = limit salary -= current_salary if __name__ == '__main__': tax = get_tax(31000, tax_table) print('tax: ', tax) assert get_tax(500, tax_table) == 50 assert get_tax(10000, tax_table) == 1000 assert get_tax(10100, tax_table) == 1020 assert get_tax(20000, tax_table) == 3000 assert get_tax(20100, tax_table) == 3030 assert get_tax(30000, tax_table) == 6000 assert get_tax(36000, tax_table) == 7800
fhand = open(input("Enter file name: ")) schools = dict() for ln in fhand: if not ln.startswith('From '): continue ln = ln.split() mailer = ln[1] pos = mailer.find('@') school = mailer[pos+1:] schools[school] = schools.get(school,0) + 1 print(schools)
fhand = open(input('Enter file name: ')) schools = dict() for ln in fhand: if not ln.startswith('From '): continue ln = ln.split() mailer = ln[1] pos = mailer.find('@') school = mailer[pos + 1:] schools[school] = schools.get(school, 0) + 1 print(schools)
def prod2sum(a, b, c, d): firstPair = [abs(a*c + b*d), abs(b*c - a*d)] firstPair.sort() secondPair = [abs(a*c - b*d), abs(b*c + a*d)] secondPair.sort() delta = firstPair[0] - secondPair[0] if delta < 0: return [firstPair, secondPair] elif delta > 0: return [secondPair, firstPair] else: # delta == 0 return [firstPair]
def prod2sum(a, b, c, d): first_pair = [abs(a * c + b * d), abs(b * c - a * d)] firstPair.sort() second_pair = [abs(a * c - b * d), abs(b * c + a * d)] secondPair.sort() delta = firstPair[0] - secondPair[0] if delta < 0: return [firstPair, secondPair] elif delta > 0: return [secondPair, firstPair] else: return [firstPair]
# list example list_test = ["item", 10, "item"] print(list_test) print(list_test[0]) # append item in list list_test.append("testappend") print(list_test) # remove item list list_test.remove("testappend") ## using value, not position print(list) # declaring tuples # tuples are imutables lists # dont possible concatenate tuples and lists tuple2 = ("tuple", "tuple") print(tuple2) concat_tuple = ('one') + ('two') print(concat_tuple) # dictionary # using dictionary for declaring lists with key and value dictionary = {'one': 1, 'two': 2} print(dictionary['one']) print(dictionary.keys()) print(dictionary.values()) # using list for numbers list_number = [1, 2, 3, 4] print(max(list_number)) print(min(list_number)) print(len(list_number)) # count number of itens in list list_cont = [0, 0, 1, 2, 35] print(list_cont.count(0)) # using .index return num of index of element in list # case not found generate error print(list_cont.index(0)) # transform list in tuple or tuple in list new_tuple = tuple(list_test) print(new_tuple) new_list = list(new_tuple) print(new_list) # using set for collection witch uniques elements # A set is an unordered collection of elements # set has no index list_set = {"ade", "ade"} # use { for init set list_set.add("teste") print(list_set)
list_test = ['item', 10, 'item'] print(list_test) print(list_test[0]) list_test.append('testappend') print(list_test) list_test.remove('testappend') print(list) tuple2 = ('tuple', 'tuple') print(tuple2) concat_tuple = 'one' + 'two' print(concat_tuple) dictionary = {'one': 1, 'two': 2} print(dictionary['one']) print(dictionary.keys()) print(dictionary.values()) list_number = [1, 2, 3, 4] print(max(list_number)) print(min(list_number)) print(len(list_number)) list_cont = [0, 0, 1, 2, 35] print(list_cont.count(0)) print(list_cont.index(0)) new_tuple = tuple(list_test) print(new_tuple) new_list = list(new_tuple) print(new_list) list_set = {'ade', 'ade'} list_set.add('teste') print(list_set)
class MaterialGameSettings: alpha_blend = None face_orientation = None invisible = None physics = None text = None use_backface_culling = None
class Materialgamesettings: alpha_blend = None face_orientation = None invisible = None physics = None text = None use_backface_culling = None
class Dinglemouse(object): def __init__(self, queues, capacity): self.queues = list(map(list, queues)) self.cap = capacity self.passengers = [] def theLift(self): queues = self.queues cap = self.cap floors = len(queues) floors_visited = [0] def empty(seq): try: return all(map(empty, seq)) except TypeError: return False def move(start=floors_visited[-1], direction='up'): if empty(queues): return if direction == 'up': floors_to_visit = [x for x in range(start, floors)] else: floors_to_visit = [x for x in range(start, -1, -1)] for floor in floors_to_visit: stop = False remove = [] if floor in self.passengers: stop = True self.passengers = [x for x in self.passengers if x != floor] for waiter in queues[floor]: if direction == 'up': if (waiter > floor): stop = True if len(self.passengers) < cap: self.passengers.append(waiter) remove.append(waiter) else: if (waiter < floor): stop = True if len(self.passengers) < cap: self.passengers.append(waiter) remove.append(waiter) for waiter in remove: queues[floor].remove(waiter) if stop and (floors_visited[-1] != floor): floors_visited.append(floor) if not empty(self.passengers): continue elif empty(queues): if floors_visited[-1] != 0: floors_visited.append(0) break elif (direction == 'up') and empty(queues[floor+1:]): move(start=floor, direction='down') elif (direction == 'down') and empty(queues[:floor]): move(start=floor, direction='up') return move() return floors_visited if __name__ == '__main__': lift = Dinglemouse(((), (), (5, 5, 5), (), (), (), ()), 5) print(lift.theLift()) lift = Dinglemouse(((), (), (1, 1), (), (), (), ()), 5) print(lift.theLift()) lift = Dinglemouse(((), (3,), (4,), (), (5,), (), ()), 5) print(lift.theLift()) lift = Dinglemouse(((), (0,), (), (), (2,), (3,), ()), 5) print(lift.theLift()) lift = Dinglemouse(((3,), (2,), (0,), (2,), (), (), (5,)), 5) print(lift.theLift()) lift = Dinglemouse(((), (), (4, 4, 4, 4), (), (2, 2, 2, 2), (), ()), 2) print(lift.theLift()) lift = Dinglemouse(((3, 3, 3, 3, 3, 3), (), (), (), (), (), ()), 5) print(lift.theLift()) lift = Dinglemouse(( (6, 11, 2, 2), (14, 12, 8, 10, 0), (12, 11, 5, 8), (6, 13, 2), (), (10, 3, 3, 1), (), (12, 12, 12), (14, 6), (13, 7, 1), (2, 7), (3, 1), (), (3, 11, 1, 3), (11, 3, 4, 0, 8)), 4) print(lift.theLift())
class Dinglemouse(object): def __init__(self, queues, capacity): self.queues = list(map(list, queues)) self.cap = capacity self.passengers = [] def the_lift(self): queues = self.queues cap = self.cap floors = len(queues) floors_visited = [0] def empty(seq): try: return all(map(empty, seq)) except TypeError: return False def move(start=floors_visited[-1], direction='up'): if empty(queues): return if direction == 'up': floors_to_visit = [x for x in range(start, floors)] else: floors_to_visit = [x for x in range(start, -1, -1)] for floor in floors_to_visit: stop = False remove = [] if floor in self.passengers: stop = True self.passengers = [x for x in self.passengers if x != floor] for waiter in queues[floor]: if direction == 'up': if waiter > floor: stop = True if len(self.passengers) < cap: self.passengers.append(waiter) remove.append(waiter) elif waiter < floor: stop = True if len(self.passengers) < cap: self.passengers.append(waiter) remove.append(waiter) for waiter in remove: queues[floor].remove(waiter) if stop and floors_visited[-1] != floor: floors_visited.append(floor) if not empty(self.passengers): continue elif empty(queues): if floors_visited[-1] != 0: floors_visited.append(0) break elif direction == 'up' and empty(queues[floor + 1:]): move(start=floor, direction='down') elif direction == 'down' and empty(queues[:floor]): move(start=floor, direction='up') return move() return floors_visited if __name__ == '__main__': lift = dinglemouse(((), (), (5, 5, 5), (), (), (), ()), 5) print(lift.theLift()) lift = dinglemouse(((), (), (1, 1), (), (), (), ()), 5) print(lift.theLift()) lift = dinglemouse(((), (3,), (4,), (), (5,), (), ()), 5) print(lift.theLift()) lift = dinglemouse(((), (0,), (), (), (2,), (3,), ()), 5) print(lift.theLift()) lift = dinglemouse(((3,), (2,), (0,), (2,), (), (), (5,)), 5) print(lift.theLift()) lift = dinglemouse(((), (), (4, 4, 4, 4), (), (2, 2, 2, 2), (), ()), 2) print(lift.theLift()) lift = dinglemouse(((3, 3, 3, 3, 3, 3), (), (), (), (), (), ()), 5) print(lift.theLift()) lift = dinglemouse(((6, 11, 2, 2), (14, 12, 8, 10, 0), (12, 11, 5, 8), (6, 13, 2), (), (10, 3, 3, 1), (), (12, 12, 12), (14, 6), (13, 7, 1), (2, 7), (3, 1), (), (3, 11, 1, 3), (11, 3, 4, 0, 8)), 4) print(lift.theLift())
class DotNotationDict(dict): ''' Dictionary subclass that allows attribute access using dot notation, eg: >>> dnd = DotNotationDict({'test': True}) >>> dnd.test True ''' def __getattr__(self, key): try: return self[key] except KeyError: raise AttributeError("DotNotationDict has no attribute '%s'" % key) def __setattr__(self, key, value): self[key] = value
class Dotnotationdict(dict): """ Dictionary subclass that allows attribute access using dot notation, eg: >>> dnd = DotNotationDict({'test': True}) >>> dnd.test True """ def __getattr__(self, key): try: return self[key] except KeyError: raise attribute_error("DotNotationDict has no attribute '%s'" % key) def __setattr__(self, key, value): self[key] = value
''' Condition group where conditions are set ''' class ConditionGroup(): def __init__(self): self.conditions = [] self.success = 'success' self.failed = 'failed' def add_condition(self, l1, optn, arg, then, else_value): input_json = {'l1': l1, 'optn': optn, 'arg': arg, 'then': then, 'else_value': else_value} self.conditions.append(input_json) @property def conditions(self): return self.conditions def response(self, success, failed): self.success = success self.failed = failed
""" Condition group where conditions are set """ class Conditiongroup: def __init__(self): self.conditions = [] self.success = 'success' self.failed = 'failed' def add_condition(self, l1, optn, arg, then, else_value): input_json = {'l1': l1, 'optn': optn, 'arg': arg, 'then': then, 'else_value': else_value} self.conditions.append(input_json) @property def conditions(self): return self.conditions def response(self, success, failed): self.success = success self.failed = failed
#!/usr/bin/python # -*- coding: utf-8 -*- # # FILE: stop_words.py # # Simple routine that removes stop words from a string # # Copyright by Author. All rights reserved. Not for reuse without # express permissions. # def remove_stops(text=None): new_text = "" nt2 = [] text_list = text.split("\n") for line in text_list: word_list = line.split(' ') l2 = [] for w in word_list: wlower = w.lower() if( not wlower in STOPLIST ): #print "keeping:",w l2.append(w) #else: # print "removing:",w if( l2 ): new_line = u" ".join(l2) nt2.append(new_line) if( len(nt2)==0 ): new_text = "" elif( len(nt2)==1 ): new_text = nt2[0] else: new_text = u"\n".join(nt2) return new_text STOPLIST = { 'n':1, 'necessary':1, 'need':1, 'needed':1, 'needing':1, 'newest':1, 'next':1, 'no':1, 'nobody':1, 'non':1, 'noone':1, 'not':1, 'nothing':1, 'now':1, 'nowhere':1, 'of':1, 'off':1, 'often':1, 'new':1, 'old':1, 'older':1, 'oldest':1, 'on':1, 'once':1, 'one':1, 'only':1, 'open':1, 'again':1, 'among':1, 'already':1, 'about':1, 'above':1, 'against':1, 'alone':1, 'after':1, 'also':1, 'although':1, 'along':1, 'always':1, 'an':1, 'across':1, 'b':1, 'and':1, 'another':1, 'ask':1, 'c':1, 'asking':1, 'asks':1, 'backed':1, 'away':1, 'a':1, 'should':1, 'show':1, 'came':1, 'all':1, 'almost':1, 'before':1, 'began':1, 'back':1, 'backing':1, 'be':1, 'became':1, 'because':1, 'becomes':1, 'been':1, 'at':1, 'behind':1, 'being':1, 'best':1, 'better':1, 'between':1, 'big':1, 'showed':1, 'ended':1, 'ending':1, 'both':1, 'but':1, 'by':1, 'asked':1, 'backs':1, 'can':1, 'cannot':1, 'number':1, 'numbers':1, 'o':1, 'case':1, 'few':1, 'find':1, 'finds':1, 'cases':1, 'clearly':1, 'her':1, 'herself':1, 'come':1, 'could':1, 'd':1, 'did':1, 'here':1, 'beings':1, 'fact':1, 'far':1, 'felt':1, 'become':1, 'first':1, 'for':1, 'four':1, 'from':1, 'full':1, 'fully':1, 'furthers':1, 'gave':1, 'general':1, 'generally':1, 'get':1, 'gets':1, 'gives':1, 'facts':1, 'go':1, 'going':1, 'good':1, 'goods':1, 'certain':1, 'certainly':1, 'clear':1, 'great':1, 'greater':1, 'greatest':1, 'group':1, 'grouped':1, 'grouping':1, 'groups':1, 'h':1, 'got':1, 'has':1, 'g':1, 'have':1, 'having':1, 'he':1, 'further':1, 'furthered':1, 'had':1, 'furthering':1, 'itself':1, 'faces':1, 'highest':1, 'him':1, 'himself':1, 'his':1, 'how':1, 'however':1, 'i':1, 'if':1, 'important':1, 'interests':1, 'into':1, 'is':1, 'it':1, 'its':1, 'j':1, 'anyone':1, 'anything':1, 'anywhere':1, 'are':1, 'area':1, 'areas':1, 'around':1, 'as':1, 'seconds':1, 'see':1, 'seem':1, 'seemed':1, 'seeming':1, 'seems':1, 'sees':1, 'right':1, 'several':1, 'shall':1, 'she':1, 'enough':1, 'even':1, 'evenly':1, 'over':1, 'p':1, 'part':1, 'parted':1, 'parting':1, 'parts':1, 'per':1, 'down':1, 'place':1, 'places':1, 'point':1, 'pointed':1, 'pointing':1, 'points':1, 'possible':1, 'present':1, 'presented':1, 'presenting':1, 'ends':1, 'high':1, 'mrs':1, 'much':1, 'must':1, 'my':1, 'myself':1, 'presents':1, 'down':1, 'problem':1, 'problems':1, 'put':1, 'puts':1, 'q':1, 'quite':1, 'will':1, 'with':1, 'within':1, 'r':1, 're':1, 'rather':1, 'really':1, 'room':1, 'rooms':1, 's':1, 'said':1, 'same':1, 'right':1, 'showing':1, 'shows':1, 'side':1, 'sides':1, 'since':1, 'small':1, 'smaller':1, 'smallest':1, 'so':1, 'some':1, 'somebody':1, 'someone':1, 'something':1, 'somewhere':1, 'state':1, 'states':1, 'such':1, 'sure':1, 't':1, 'take':1, 'taken':1, 'than':1, 'that':1, 'the':1, 'their':1, 'then':1, 'there':1, 'therefore':1, 'these':1, 'x':1, 'thought':1, 'thoughts':1, 'three':1, 'through':1, 'thus':1, 'to':1, 'today':1, 'together':1, 'too':1, 'took':1, 'toward':1, 'turn':1, 'turned':1, 'turning':1, 'turns':1, 'two':1, 'still':1, 'u':1, 'under':1, 'until':1, 'up':1, 'others':1, 'upon':1, 'us':1, 'use':1, 'used':1, 'uses':1, 'v':1, 'very':1, 'w':1, 'want':1, 'wanted':1, 'wanting':1, 'wants':1, 'was':1, 'way':1, 'we':1, 'well':1, 'wells':1, 'went':1, 'were':1, 'what':1, 'when':1, 'where':1, 'whether':1, 'which':1, 'while':1, 'who':1, 'whole':1, 'y':1, 'year':1, 'years':1, 'yet':1, 'you':1, 'everyone':1, 'everything':1, 'everywhere':1, 'young':1, 'younger':1, 'youngest':1, 'your':1, 'yours':1, 'z':1, 'ever':1, 'works':1, 'every':1, 'everybody':1, 'f':1, 'face':1, 'other':1, 'our':1, 'out':1, 'just':1, 'interesting':1, 'high':1, 'might':1, 'k':1, 'keep':1, 'keeps':1, 'give':1, 'given':1, 'higher':1, 'kind':1, 'knew':1, 'know':1, 'known':1, 'knows':1, 'l':1, 'large':1, 'largely':1, 'last':1, 'later':1, 'latest':1, 'least':1, 'less':1, 'needs':1, 'never':1, 'newer':1, 'let':1, 'lets':1, 'like':1, 'likely':1, 'long':1, 'high':1, 'longer':1, 'longest':1, 'm':1, 'made':1, 'make':1, 'making':1, 'man':1, 'many':1, 'may':1, 'me':1, 'member':1, 'members':1, 'men':1, 'more':1, 'in':1, 'interest':1, 'interested':1, 'most':1, 'mostly':1, 'mr':1, 'opened':1, 'opening':1, 'new':1, 'opens':1, 'or':1, 'perhaps':1, 'order':1, 'ordered':1, 'ordering':1, 'orders':1, 'differ':1, 'different':1, 'differently':1, 'do':1, 'does':1, 'done':1, 'downed':1, 'downing':1, 'downs':1, 'they':1, 'thing':1, 'things':1, 'think':1, 'thinks':1, 'this':1, 'those':1, 'ways':1, 'why':1, 'without':1, 'work':1, 'worked':1, 'working':1, 'would':1, 'during':1, 'e':1, 'each':1, 'early':1, 'either':1, 'end':1, 'though':1, 'still':1, 'whose':1, 'saw':1, 'say':1, 'says':1, 'them':1, 'second':1, 'any':1, 'anybody':1, '@':1, '...':1, ';':1, ':':1, '&amp;':1, '!':1, '-':1, '.':1, 'rt':1, 'via':1, '0':1, '1':1, '2':1, '3':1, '4':1, '5':1, '6':1, '7':1, '8':1, '9':1 }
def remove_stops(text=None): new_text = '' nt2 = [] text_list = text.split('\n') for line in text_list: word_list = line.split(' ') l2 = [] for w in word_list: wlower = w.lower() if not wlower in STOPLIST: l2.append(w) if l2: new_line = u' '.join(l2) nt2.append(new_line) if len(nt2) == 0: new_text = '' elif len(nt2) == 1: new_text = nt2[0] else: new_text = u'\n'.join(nt2) return new_text stoplist = {'n': 1, 'necessary': 1, 'need': 1, 'needed': 1, 'needing': 1, 'newest': 1, 'next': 1, 'no': 1, 'nobody': 1, 'non': 1, 'noone': 1, 'not': 1, 'nothing': 1, 'now': 1, 'nowhere': 1, 'of': 1, 'off': 1, 'often': 1, 'new': 1, 'old': 1, 'older': 1, 'oldest': 1, 'on': 1, 'once': 1, 'one': 1, 'only': 1, 'open': 1, 'again': 1, 'among': 1, 'already': 1, 'about': 1, 'above': 1, 'against': 1, 'alone': 1, 'after': 1, 'also': 1, 'although': 1, 'along': 1, 'always': 1, 'an': 1, 'across': 1, 'b': 1, 'and': 1, 'another': 1, 'ask': 1, 'c': 1, 'asking': 1, 'asks': 1, 'backed': 1, 'away': 1, 'a': 1, 'should': 1, 'show': 1, 'came': 1, 'all': 1, 'almost': 1, 'before': 1, 'began': 1, 'back': 1, 'backing': 1, 'be': 1, 'became': 1, 'because': 1, 'becomes': 1, 'been': 1, 'at': 1, 'behind': 1, 'being': 1, 'best': 1, 'better': 1, 'between': 1, 'big': 1, 'showed': 1, 'ended': 1, 'ending': 1, 'both': 1, 'but': 1, 'by': 1, 'asked': 1, 'backs': 1, 'can': 1, 'cannot': 1, 'number': 1, 'numbers': 1, 'o': 1, 'case': 1, 'few': 1, 'find': 1, 'finds': 1, 'cases': 1, 'clearly': 1, 'her': 1, 'herself': 1, 'come': 1, 'could': 1, 'd': 1, 'did': 1, 'here': 1, 'beings': 1, 'fact': 1, 'far': 1, 'felt': 1, 'become': 1, 'first': 1, 'for': 1, 'four': 1, 'from': 1, 'full': 1, 'fully': 1, 'furthers': 1, 'gave': 1, 'general': 1, 'generally': 1, 'get': 1, 'gets': 1, 'gives': 1, 'facts': 1, 'go': 1, 'going': 1, 'good': 1, 'goods': 1, 'certain': 1, 'certainly': 1, 'clear': 1, 'great': 1, 'greater': 1, 'greatest': 1, 'group': 1, 'grouped': 1, 'grouping': 1, 'groups': 1, 'h': 1, 'got': 1, 'has': 1, 'g': 1, 'have': 1, 'having': 1, 'he': 1, 'further': 1, 'furthered': 1, 'had': 1, 'furthering': 1, 'itself': 1, 'faces': 1, 'highest': 1, 'him': 1, 'himself': 1, 'his': 1, 'how': 1, 'however': 1, 'i': 1, 'if': 1, 'important': 1, 'interests': 1, 'into': 1, 'is': 1, 'it': 1, 'its': 1, 'j': 1, 'anyone': 1, 'anything': 1, 'anywhere': 1, 'are': 1, 'area': 1, 'areas': 1, 'around': 1, 'as': 1, 'seconds': 1, 'see': 1, 'seem': 1, 'seemed': 1, 'seeming': 1, 'seems': 1, 'sees': 1, 'right': 1, 'several': 1, 'shall': 1, 'she': 1, 'enough': 1, 'even': 1, 'evenly': 1, 'over': 1, 'p': 1, 'part': 1, 'parted': 1, 'parting': 1, 'parts': 1, 'per': 1, 'down': 1, 'place': 1, 'places': 1, 'point': 1, 'pointed': 1, 'pointing': 1, 'points': 1, 'possible': 1, 'present': 1, 'presented': 1, 'presenting': 1, 'ends': 1, 'high': 1, 'mrs': 1, 'much': 1, 'must': 1, 'my': 1, 'myself': 1, 'presents': 1, 'down': 1, 'problem': 1, 'problems': 1, 'put': 1, 'puts': 1, 'q': 1, 'quite': 1, 'will': 1, 'with': 1, 'within': 1, 'r': 1, 're': 1, 'rather': 1, 'really': 1, 'room': 1, 'rooms': 1, 's': 1, 'said': 1, 'same': 1, 'right': 1, 'showing': 1, 'shows': 1, 'side': 1, 'sides': 1, 'since': 1, 'small': 1, 'smaller': 1, 'smallest': 1, 'so': 1, 'some': 1, 'somebody': 1, 'someone': 1, 'something': 1, 'somewhere': 1, 'state': 1, 'states': 1, 'such': 1, 'sure': 1, 't': 1, 'take': 1, 'taken': 1, 'than': 1, 'that': 1, 'the': 1, 'their': 1, 'then': 1, 'there': 1, 'therefore': 1, 'these': 1, 'x': 1, 'thought': 1, 'thoughts': 1, 'three': 1, 'through': 1, 'thus': 1, 'to': 1, 'today': 1, 'together': 1, 'too': 1, 'took': 1, 'toward': 1, 'turn': 1, 'turned': 1, 'turning': 1, 'turns': 1, 'two': 1, 'still': 1, 'u': 1, 'under': 1, 'until': 1, 'up': 1, 'others': 1, 'upon': 1, 'us': 1, 'use': 1, 'used': 1, 'uses': 1, 'v': 1, 'very': 1, 'w': 1, 'want': 1, 'wanted': 1, 'wanting': 1, 'wants': 1, 'was': 1, 'way': 1, 'we': 1, 'well': 1, 'wells': 1, 'went': 1, 'were': 1, 'what': 1, 'when': 1, 'where': 1, 'whether': 1, 'which': 1, 'while': 1, 'who': 1, 'whole': 1, 'y': 1, 'year': 1, 'years': 1, 'yet': 1, 'you': 1, 'everyone': 1, 'everything': 1, 'everywhere': 1, 'young': 1, 'younger': 1, 'youngest': 1, 'your': 1, 'yours': 1, 'z': 1, 'ever': 1, 'works': 1, 'every': 1, 'everybody': 1, 'f': 1, 'face': 1, 'other': 1, 'our': 1, 'out': 1, 'just': 1, 'interesting': 1, 'high': 1, 'might': 1, 'k': 1, 'keep': 1, 'keeps': 1, 'give': 1, 'given': 1, 'higher': 1, 'kind': 1, 'knew': 1, 'know': 1, 'known': 1, 'knows': 1, 'l': 1, 'large': 1, 'largely': 1, 'last': 1, 'later': 1, 'latest': 1, 'least': 1, 'less': 1, 'needs': 1, 'never': 1, 'newer': 1, 'let': 1, 'lets': 1, 'like': 1, 'likely': 1, 'long': 1, 'high': 1, 'longer': 1, 'longest': 1, 'm': 1, 'made': 1, 'make': 1, 'making': 1, 'man': 1, 'many': 1, 'may': 1, 'me': 1, 'member': 1, 'members': 1, 'men': 1, 'more': 1, 'in': 1, 'interest': 1, 'interested': 1, 'most': 1, 'mostly': 1, 'mr': 1, 'opened': 1, 'opening': 1, 'new': 1, 'opens': 1, 'or': 1, 'perhaps': 1, 'order': 1, 'ordered': 1, 'ordering': 1, 'orders': 1, 'differ': 1, 'different': 1, 'differently': 1, 'do': 1, 'does': 1, 'done': 1, 'downed': 1, 'downing': 1, 'downs': 1, 'they': 1, 'thing': 1, 'things': 1, 'think': 1, 'thinks': 1, 'this': 1, 'those': 1, 'ways': 1, 'why': 1, 'without': 1, 'work': 1, 'worked': 1, 'working': 1, 'would': 1, 'during': 1, 'e': 1, 'each': 1, 'early': 1, 'either': 1, 'end': 1, 'though': 1, 'still': 1, 'whose': 1, 'saw': 1, 'say': 1, 'says': 1, 'them': 1, 'second': 1, 'any': 1, 'anybody': 1, '@': 1, '...': 1, ';': 1, ':': 1, '&amp;': 1, '!': 1, '-': 1, '.': 1, 'rt': 1, 'via': 1, '0': 1, '1': 1, '2': 1, '3': 1, '4': 1, '5': 1, '6': 1, '7': 1, '8': 1, '9': 1}
class Error(Exception): def __init__(self, s, context=None, exception=None): Exception.__init__(self, s) self.context = context self.exception = exception
class Error(Exception): def __init__(self, s, context=None, exception=None): Exception.__init__(self, s) self.context = context self.exception = exception
print("Enter 'quit' when done\n") while True: # ask for card number credit_num = input("Number: ") # allow user to end program if credit_num.casefold() == "quit": break # if input given isn't numeric re-ask for number while not credit_num.isdigit(): print("\nEnter numbers only please\n") credit_num = input("Number: ") if credit_num == "quit": break if credit_num == "quit": break # reset values to 0 number_count = 0 validity = 0 # Luhn's Algorithm for verifying if card number is valid for number in credit_num[-2::-2]: for digit in str(int(number) * 2): number_count += int(digit) for number in credit_num[-1::-2]: number_count += int(number) # check if number is easily divisible by 10 (Luhn's Algorithm) if number_count % 10 == 0: validity += 1 # identify type of card and if number length validates card type if int(credit_num[0:2]) in [34, 37] and len(credit_num) == 15: card_type = "American Express" validity += 1 elif int(credit_num[0:2]) in [51, 52, 53, 54, 55] and len(credit_num) == 16: card_type = "MasterCard" validity += 1 elif int(credit_num[0]) == 4 and len(credit_num) in [13, 16]: card_type = "Visa" validity += 1 # print either the card type or invalid if validity == 2: print(card_type + "\n") else: print("Invalid\n")
print("Enter 'quit' when done\n") while True: credit_num = input('Number: ') if credit_num.casefold() == 'quit': break while not credit_num.isdigit(): print('\nEnter numbers only please\n') credit_num = input('Number: ') if credit_num == 'quit': break if credit_num == 'quit': break number_count = 0 validity = 0 for number in credit_num[-2::-2]: for digit in str(int(number) * 2): number_count += int(digit) for number in credit_num[-1::-2]: number_count += int(number) if number_count % 10 == 0: validity += 1 if int(credit_num[0:2]) in [34, 37] and len(credit_num) == 15: card_type = 'American Express' validity += 1 elif int(credit_num[0:2]) in [51, 52, 53, 54, 55] and len(credit_num) == 16: card_type = 'MasterCard' validity += 1 elif int(credit_num[0]) == 4 and len(credit_num) in [13, 16]: card_type = 'Visa' validity += 1 if validity == 2: print(card_type + '\n') else: print('Invalid\n')
class Solution: def winnerOfGame(self, colors: str) -> bool: # print(colors[:-1]) count1, count2 = 0, 0 for i in range(1, len(colors)-1): if colors[i-1] == colors[i] == colors[i+1] == "A": count1 += 1 elif colors[i-1] == colors[i] == colors[i+1] == "B": count2 += 1 return count1 > count2
class Solution: def winner_of_game(self, colors: str) -> bool: (count1, count2) = (0, 0) for i in range(1, len(colors) - 1): if colors[i - 1] == colors[i] == colors[i + 1] == 'A': count1 += 1 elif colors[i - 1] == colors[i] == colors[i + 1] == 'B': count2 += 1 return count1 > count2
#!/usr/bin/env python3 #!/usr/bin/python print(" this".strip())
print(' this'.strip())
# Super Plumber # # November 26, 2020 # By Robin Nash # November 26 2020 # y,x = r,c = 6,5 data = [] ##for i in range(y): ## data.append(input()) ##data = ['..3.......', '..........', '..7.**....', '.9**...1..', '..8..9....'] grid = [\ '.**.1',\ '.*9..',\ '.5...',\ '.....',\ '.....',\ '.....',] x,y = c,r = 4,4 grid = [\ '...1',\ '..9.',\ '.5..',\ '....'] grid = ['*'*(x+2)]+['*'+row+'*' for row in grid]+['*'*(x+2)] def buildWallDown(grid,r=1,c=1): if r == len(grid)-1: return grid if c == len(grid[0])-1: return buildWallDown(grid,r+1,1) if grid[r][c-1] == grid[r][c+1] == grid[r-1][c] == '*': grid[r] = grid[r][:c]+'*'+grid[r][c+1:] return buildWallDown(grid,r,c+1) def buildWallUp(grid,r=r,c=1): if r == 0 and c == len(grid[0])-1: return grid if c == len(grid[0])-1: return buildWallUp(grid,r-1,1) if grid[r][c-1] == grid[r][c+1] == grid[r+1][c] == '*': grid[r] = grid[r][:c]+'*'+grid[r][c+1:] return buildWallUp(grid,r,c+1) def buildWallUp(grid,y=r-1,x=1): if x == len(grid[0])-1: return grid if x == len(grid[0])-2 and y==len(grid)-2: #Skip last cell y -= 1 if y == 0: return buildWallUp(grid, r, x+1) if grid[y][x-1] == grid[y][x+1] == grid[y+1][x] == '*': grid[y] = grid[y][:x]+'*'+grid[y][x+1:] return buildWallUp(grid,y-1,x) def buildWalls(grid,y=r-1,x=1,up = True): if x == len(grid[0])-1: return grid if not up else buildWalls(grid,y=1,x=1,up=False) if x == len(grid[0])-2 and y==len(grid)-2 and up: #Skip last cell up y -= 1 if y == 0 or y == r+2: return buildWalls(grid, r if up else 1, x+1,up) if grid[y][x-1] == grid[y][x+1] == grid[y-1 + 2*int(up)][x] == '*': grid[y] = grid[y][:x]+'*'+grid[y][x+1:] return buildWalls(grid,y+1 -2*int(up),x,up) dp = [[0 for i in grid[0]] for y in grid] def dynamic(dp,x=1): if x == len(grid)-1: return dp up = [0 for i in range(len(dp))] down = up[:] for y in range(1,len(grid)-1): if grid[y][x] == '*': continue down[y] = dp[y][x-1]+down[y-1]+int(grid[y][x]) if grid[y][x].isdigit() else 0 for y in range(len(grid)-2,0,-1): if grid[y][x] =='*': continue up[y] = dp[y][x-1]+up[y+1]+ int(grid[y][x]) if grid[y][x].isdigit() else 0 for y in range(1,len(grid)-1): dp[y][x] = max(up[y],down[y]) ## print(up) print(down) return dynamic(dp,x+1) ##grid = buildWallDown(grid) grid = buildWalls(grid) dp = dynamic(dp) for y in range(len(grid)): ## print("".join(row)) print("".join(map(str,dp[y]))) ##int('*') if '*'.isdigit() else 0 #1606431716.206388
(y, x) = (r, c) = (6, 5) data = [] grid = ['.**.1', '.*9..', '.5...', '.....', '.....', '.....'] (x, y) = (c, r) = (4, 4) grid = ['...1', '..9.', '.5..', '....'] grid = ['*' * (x + 2)] + ['*' + row + '*' for row in grid] + ['*' * (x + 2)] def build_wall_down(grid, r=1, c=1): if r == len(grid) - 1: return grid if c == len(grid[0]) - 1: return build_wall_down(grid, r + 1, 1) if grid[r][c - 1] == grid[r][c + 1] == grid[r - 1][c] == '*': grid[r] = grid[r][:c] + '*' + grid[r][c + 1:] return build_wall_down(grid, r, c + 1) def build_wall_up(grid, r=r, c=1): if r == 0 and c == len(grid[0]) - 1: return grid if c == len(grid[0]) - 1: return build_wall_up(grid, r - 1, 1) if grid[r][c - 1] == grid[r][c + 1] == grid[r + 1][c] == '*': grid[r] = grid[r][:c] + '*' + grid[r][c + 1:] return build_wall_up(grid, r, c + 1) def build_wall_up(grid, y=r - 1, x=1): if x == len(grid[0]) - 1: return grid if x == len(grid[0]) - 2 and y == len(grid) - 2: y -= 1 if y == 0: return build_wall_up(grid, r, x + 1) if grid[y][x - 1] == grid[y][x + 1] == grid[y + 1][x] == '*': grid[y] = grid[y][:x] + '*' + grid[y][x + 1:] return build_wall_up(grid, y - 1, x) def build_walls(grid, y=r - 1, x=1, up=True): if x == len(grid[0]) - 1: return grid if not up else build_walls(grid, y=1, x=1, up=False) if x == len(grid[0]) - 2 and y == len(grid) - 2 and up: y -= 1 if y == 0 or y == r + 2: return build_walls(grid, r if up else 1, x + 1, up) if grid[y][x - 1] == grid[y][x + 1] == grid[y - 1 + 2 * int(up)][x] == '*': grid[y] = grid[y][:x] + '*' + grid[y][x + 1:] return build_walls(grid, y + 1 - 2 * int(up), x, up) dp = [[0 for i in grid[0]] for y in grid] def dynamic(dp, x=1): if x == len(grid) - 1: return dp up = [0 for i in range(len(dp))] down = up[:] for y in range(1, len(grid) - 1): if grid[y][x] == '*': continue down[y] = dp[y][x - 1] + down[y - 1] + int(grid[y][x]) if grid[y][x].isdigit() else 0 for y in range(len(grid) - 2, 0, -1): if grid[y][x] == '*': continue up[y] = dp[y][x - 1] + up[y + 1] + int(grid[y][x]) if grid[y][x].isdigit() else 0 for y in range(1, len(grid) - 1): dp[y][x] = max(up[y], down[y]) print(down) return dynamic(dp, x + 1) grid = build_walls(grid) dp = dynamic(dp) for y in range(len(grid)): print(''.join(map(str, dp[y])))
# Copyright (c) 2013 The Native Client Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. { 'includes': [ '../../../../build/common.gypi', ], 'conditions': [ ['target_arch=="ia32" or target_arch=="x64"', { 'targets': [ { 'target_name': 'ncval_new', 'type': 'executable', 'sources': ['ncval.cc', 'elf_load.cc'], 'dependencies': [ '<(DEPTH)/native_client/src/shared/platform/platform.gyp:platform', '<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_core', '<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_reporters', '<(DEPTH)/native_client/src/trusted/validator_ragel/rdfa_validator.gyp:rdfa_validator', ], }, ] }], ], }
{'includes': ['../../../../build/common.gypi'], 'conditions': [['target_arch=="ia32" or target_arch=="x64"', {'targets': [{'target_name': 'ncval_new', 'type': 'executable', 'sources': ['ncval.cc', 'elf_load.cc'], 'dependencies': ['<(DEPTH)/native_client/src/shared/platform/platform.gyp:platform', '<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_core', '<(DEPTH)/native_client/src/trusted/validator_arm/validator_arm.gyp:arm_validator_reporters', '<(DEPTH)/native_client/src/trusted/validator_ragel/rdfa_validator.gyp:rdfa_validator']}]}]]}
# Create a list of strings: fellowship fellowship = ['frodo', 'samwise', 'merry', 'aragorn', 'legolas', 'boromir', 'gimli'] # Create list comprehension: new_fellowship new_fellowship = [member if len(member) >= 7 else "" for member in fellowship] # Print the new list print(new_fellowship)
fellowship = ['frodo', 'samwise', 'merry', 'aragorn', 'legolas', 'boromir', 'gimli'] new_fellowship = [member if len(member) >= 7 else '' for member in fellowship] print(new_fellowship)
#string literals print('this is a sample string') #concatenation - The print() function inserts a space between elements separated by a comma. name = "Zen" print("My name is", name) #The second is by concatenating the contents into a new string, with the help of +. name = "Zen" print("My name is " + name) number = 5 print('My number is', number) # print('My number is'+ number) throws an error # Type Casting or Explicit Type Conversion # print("Hello" + 42) # output: TypeError print("Hello" + str(42)) # output: Hello 42 total = 35 user_val = "26" # total = total + user_val output: TypeError total = total + int(user_val) # total will be 61 # f-strings: Python 3.6 introduced f-strings for string interpolation. To construct a f-string, place an f right before the opening quotation. Then within the string, place any variables within curly brackets. first_name = "Zen" last_name = "Coder" age = 27 print(f"My name is {first_name} {last_name} and I am {age} years old.") # string.format() Prior to f-strings, string interpolation was accomplished with the .format() method. first_name = "Zen" last_name = "Coder" age = 27 print("My name is {} {} and I am {} years old.".format(first_name, last_name, age)) # output: My name is Zen Coder and I am 27 years old. print("My name is {} {} and I am {} years old.".format(age, first_name, last_name)) # output: My name is 27 Zen and I am Coder years old. # %-formatting - an even older method, the % symbol is used to indicate a placeholder, a %s for a string and %d for a number. hw = "Hello %s" % "world" # with literal values py = "I love Python %d" % 3 print(hw, py) # output: Hello world I love Python 3 name = "Zen" age = 27 print("My name is %s and I'm %d" % (name, age)) # or with variables # output: My name is Zen and I'm 27 # Built in methods x = "hello world" print(x.title()) # output: "Hello World"
print('this is a sample string') name = 'Zen' print('My name is', name) name = 'Zen' print('My name is ' + name) number = 5 print('My number is', number) print('Hello' + str(42)) total = 35 user_val = '26' total = total + int(user_val) first_name = 'Zen' last_name = 'Coder' age = 27 print(f'My name is {first_name} {last_name} and I am {age} years old.') first_name = 'Zen' last_name = 'Coder' age = 27 print('My name is {} {} and I am {} years old.'.format(first_name, last_name, age)) print('My name is {} {} and I am {} years old.'.format(age, first_name, last_name)) hw = 'Hello %s' % 'world' py = 'I love Python %d' % 3 print(hw, py) name = 'Zen' age = 27 print("My name is %s and I'm %d" % (name, age)) x = 'hello world' print(x.title()) 'Hello World'
EXPIRED_UPDATE = 240 CLUMP_TIMEOUT = 1 ACTIVE_TIMEOUT = 0.005 BULK_BOUND = 4
expired_update = 240 clump_timeout = 1 active_timeout = 0.005 bulk_bound = 4
KEEP_RATE = 0.8 #Rate of dropping out in the dropout layer LOG_DIR = "../ops_logs" #Directory where the logs would be stored for visualization of the training #Neural network constants cat1_dir = "../categories/treematter/ingroup/" cat2_dir = "../categories/plywood/ingroup/" cat3_dir = "../categories/cardboard/ingroup/" cat4_dir = "../categories/bottles/ingroup/" cat5_dir = "../categories/trashbag/ingroup/" cat6_dir = "../categories/blackbag/ingroup/" CAT1 = "treematter" CAT2 = "plywood" CAT3 = "cardboard" CAT4 = "bottles" CAT5 = "trashbag" CAT6 = "blackbag" CAT1_ONEHOT = [1,0,0,0,0,0] CAT2_ONEHOT = [0,1,0,0,0,0] CAT3_ONEHOT = [0,0,1,0,0,0] CAT4_ONEHOT = [0,0,0,1,0,0] CAT5_ONEHOT = [0,0,0,0,1,0] CAT6_ONEHOT = [0,0,0,0,0,1] LEARNING_RATE = 0.001 #Learning rate for training the CNN CNN_LOCAL1 = 64 #Number of features output for conv layer 1 CLASSES = 6 CNN_EPOCHS = 10000 CNN_FULL1 = 200 #Number of features output for fully connected layer1 FULL_IMGSIZE = 500 IMG_SIZE = 28 IMG_DEPTH = 3 BATCH_SIZE = 300 MIN_DENSITY = 10000 SPATIAL_RADIUS = 5 RANGE_RADIUS = 5
keep_rate = 0.8 log_dir = '../ops_logs' cat1_dir = '../categories/treematter/ingroup/' cat2_dir = '../categories/plywood/ingroup/' cat3_dir = '../categories/cardboard/ingroup/' cat4_dir = '../categories/bottles/ingroup/' cat5_dir = '../categories/trashbag/ingroup/' cat6_dir = '../categories/blackbag/ingroup/' cat1 = 'treematter' cat2 = 'plywood' cat3 = 'cardboard' cat4 = 'bottles' cat5 = 'trashbag' cat6 = 'blackbag' cat1_onehot = [1, 0, 0, 0, 0, 0] cat2_onehot = [0, 1, 0, 0, 0, 0] cat3_onehot = [0, 0, 1, 0, 0, 0] cat4_onehot = [0, 0, 0, 1, 0, 0] cat5_onehot = [0, 0, 0, 0, 1, 0] cat6_onehot = [0, 0, 0, 0, 0, 1] learning_rate = 0.001 cnn_local1 = 64 classes = 6 cnn_epochs = 10000 cnn_full1 = 200 full_imgsize = 500 img_size = 28 img_depth = 3 batch_size = 300 min_density = 10000 spatial_radius = 5 range_radius = 5
class Solution: def numDistinct(self, s: str, t: str) -> int: dp = [] for i in range(len(s) + 1): dp.append([0] * (len(t) + 1)) dp[0][0] = 1 for i in range(len(s) + 1): dp[i][0] = 1 for a in range(1, len(t) + 1): for b in range(a, len(s) + 1): if s[b - 1] == t[a - 1]: dp[b][a] = dp[b - 1][a - 1] + dp[b - 1][a] else: dp[b][a] = dp[b - 1][a] return dp[-1][-1]
class Solution: def num_distinct(self, s: str, t: str) -> int: dp = [] for i in range(len(s) + 1): dp.append([0] * (len(t) + 1)) dp[0][0] = 1 for i in range(len(s) + 1): dp[i][0] = 1 for a in range(1, len(t) + 1): for b in range(a, len(s) + 1): if s[b - 1] == t[a - 1]: dp[b][a] = dp[b - 1][a - 1] + dp[b - 1][a] else: dp[b][a] = dp[b - 1][a] return dp[-1][-1]
expected_output = { "outside": { "ipv4": { "neighbors": { "10.10.1.1": { "ip": "10.10.1.1", "link_layer_address": "aa11.bbff.ee55", "age": "alias", }, "10.10.1.1/1": { "ip": "10.10.1.1", "prefix_length": "1", "link_layer_address": "aa11.bbff.ee55", "age": "-", }, } } }, "pod100": { "ipv4": { "neighbors": { "10.10.1.1": { "ip": "10.10.1.1", "link_layer_address": "aa11.bbff.ee55", "age": "2222", } } } }, }
expected_output = {'outside': {'ipv4': {'neighbors': {'10.10.1.1': {'ip': '10.10.1.1', 'link_layer_address': 'aa11.bbff.ee55', 'age': 'alias'}, '10.10.1.1/1': {'ip': '10.10.1.1', 'prefix_length': '1', 'link_layer_address': 'aa11.bbff.ee55', 'age': '-'}}}}, 'pod100': {'ipv4': {'neighbors': {'10.10.1.1': {'ip': '10.10.1.1', 'link_layer_address': 'aa11.bbff.ee55', 'age': '2222'}}}}}
def Reverse(l): newL = [] for i in range(len(l)): index = len(l) - i - 1 #Trying to make for(int i=l.length()-1; i>=0; i--) but in python newL.insert(i, l[index]) return newL l = [1,2,3,4,5,6,7,8,9,10] new_l = Reverse(l) print(new_l)
def reverse(l): new_l = [] for i in range(len(l)): index = len(l) - i - 1 newL.insert(i, l[index]) return newL l = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] new_l = reverse(l) print(new_l)
class Utilities: @staticmethod def swap(a, b, arr): arr[a], arr[b] = arr[b], arr[a] return arr
class Utilities: @staticmethod def swap(a, b, arr): (arr[a], arr[b]) = (arr[b], arr[a]) return arr
class Solution: def kidsWithCandies(self, candies: list[int], extraCandies: int) -> list[bool]: result = list(map(lambda x: True if x+extraCandies >= max(candies) else False, candies)) return result # Time Complexity = O(1)
class Solution: def kids_with_candies(self, candies: list[int], extraCandies: int) -> list[bool]: result = list(map(lambda x: True if x + extraCandies >= max(candies) else False, candies)) return result
# AC 26/08/2019 17:58:21 IST # n = int(input()) print(n)
n = int(input()) print(n)
def Range(first, second=None, step=1): if second is None: current = 0 end = first else: current = first end = second while not (current >= end and step > 0 or current <= end and step < 0): yield current current += step def print_space(str): print("{}".format(str), end=' ') for i in Range(10): print_space(i) print() for i in Range(3, 18): print_space(i) print() for i in Range(2, 15, 2): print_space(i) print() for i in Range(10, 0, -1): print_space(i)
def range(first, second=None, step=1): if second is None: current = 0 end = first else: current = first end = second while not (current >= end and step > 0 or (current <= end and step < 0)): yield current current += step def print_space(str): print('{}'.format(str), end=' ') for i in range(10): print_space(i) print() for i in range(3, 18): print_space(i) print() for i in range(2, 15, 2): print_space(i) print() for i in range(10, 0, -1): print_space(i)
#from baconsarnie.io.window import Window #__all__ = ["io", "Window"] __all__ = ["io"]
__all__ = ['io']
{ 'target_defaults': { 'default_configuration': 'Release', 'configurations': { 'Debug': { 'cflags': ['-g3', '-O0'], 'msvs_settings': { 'VCLinkerTool': { 'GenerateDebugInformation': 'true', 'LinkIncremental': 2 } } }, 'Release': { 'cflags': ['-O2', '-W', '-Wall', '-Wextra', '-ansi', '-pedantic'], 'msvs_settings': { 'VCCLCompilerTool': { 'Optimization': 3, # -O3 'FavorSizeOrSpeed': 1, # favor speed }, 'VCLinkerTool': { 'OptimizeReferences': 2, # /OPT:REF } } }, }, }, "targets": [ { "target_name": "<(module_name)", 'lflags': ['-lm'], "include_dirs": [ "zopfli/src/zopfli", "zopfli/src/zopflipng", "<!(node -e \"require('nan')\")" ], "sources": [ "src/zopfli-binding.cc", "src/png/zopflipng.cc", "zopfli/src/zopfli/blocksplitter.c", "zopfli/src/zopfli/cache.c", "zopfli/src/zopfli/deflate.c", "zopfli/src/zopfli/gzip_container.c", "zopfli/src/zopfli/hash.c", "zopfli/src/zopfli/katajainen.c", "zopfli/src/zopfli/lz77.c", "zopfli/src/zopfli/squeeze.c", "zopfli/src/zopfli/tree.c", "zopfli/src/zopfli/util.c", "zopfli/src/zopfli/zlib_container.c", "zopfli/src/zopfli/zopfli_lib.c", "zopfli/src/zopflipng/zopflipng_lib.cc", "zopfli/src/zopflipng/lodepng/lodepng.cpp", "zopfli/src/zopflipng/lodepng/lodepng_util.cpp" ], "cflags": [ "-Wall", "-O3" ] }, { "target_name": "action_after_build", "type": "none", "dependencies": [ "<(module_name)" ], "copies": [ { "files": [ "<(PRODUCT_DIR)/<(module_name).node" ], "destination": "<(module_path)" } ] } ] }
{'target_defaults': {'default_configuration': 'Release', 'configurations': {'Debug': {'cflags': ['-g3', '-O0'], 'msvs_settings': {'VCLinkerTool': {'GenerateDebugInformation': 'true', 'LinkIncremental': 2}}}, 'Release': {'cflags': ['-O2', '-W', '-Wall', '-Wextra', '-ansi', '-pedantic'], 'msvs_settings': {'VCCLCompilerTool': {'Optimization': 3, 'FavorSizeOrSpeed': 1}, 'VCLinkerTool': {'OptimizeReferences': 2}}}}}, 'targets': [{'target_name': '<(module_name)', 'lflags': ['-lm'], 'include_dirs': ['zopfli/src/zopfli', 'zopfli/src/zopflipng', '<!(node -e "require(\'nan\')")'], 'sources': ['src/zopfli-binding.cc', 'src/png/zopflipng.cc', 'zopfli/src/zopfli/blocksplitter.c', 'zopfli/src/zopfli/cache.c', 'zopfli/src/zopfli/deflate.c', 'zopfli/src/zopfli/gzip_container.c', 'zopfli/src/zopfli/hash.c', 'zopfli/src/zopfli/katajainen.c', 'zopfli/src/zopfli/lz77.c', 'zopfli/src/zopfli/squeeze.c', 'zopfli/src/zopfli/tree.c', 'zopfli/src/zopfli/util.c', 'zopfli/src/zopfli/zlib_container.c', 'zopfli/src/zopfli/zopfli_lib.c', 'zopfli/src/zopflipng/zopflipng_lib.cc', 'zopfli/src/zopflipng/lodepng/lodepng.cpp', 'zopfli/src/zopflipng/lodepng/lodepng_util.cpp'], 'cflags': ['-Wall', '-O3']}, {'target_name': 'action_after_build', 'type': 'none', 'dependencies': ['<(module_name)'], 'copies': [{'files': ['<(PRODUCT_DIR)/<(module_name).node'], 'destination': '<(module_path)'}]}]}
class Board(): # Initialize Board def __init__(self): '''Initialize the tiles with private attributes''' self.__tiles = list(map(str, range(9))) # Get tile value def get_tile(self, index:int): '''Getter for the tile''' if self.__tiles[index] not in list(map(str, range(9))): return self.__tiles[index] else: return str(int(self.__tiles[index])+1) # Add symbol def set_tile(self, symbol, coordinate:int): '''Setter for the tile''' if self.__tiles[coordinate] not in list(map(str, range(9))): return False self.__tiles[coordinate] = symbol return True # Print board def possible_moves(self): '''Returns a list of unoccupied tiles in the board''' return [ index+1 for index in range(len(self.__tiles)) if self.__tiles[index] in list(map(str, range(9)))] # Win condition def check_board(self, symbol): '''Check if the player won, cause a draw, or doesn't cause either''' possible_combination = [ self.__tiles[:3], self.__tiles[3:6], self.__tiles[6:], self.__tiles[::3],self.__tiles[1::3], self.__tiles[2::3], self.__tiles[0::4], self.__tiles[2:8:2] ] if len(list(filter(lambda x: x==[symbol]*3, possible_combination)))>0: return symbol elif not len(list(filter(lambda x: x in list(map(str, range(9))),self.__tiles))): return 'DRAW' else: return False
class Board: def __init__(self): """Initialize the tiles with private attributes""" self.__tiles = list(map(str, range(9))) def get_tile(self, index: int): """Getter for the tile""" if self.__tiles[index] not in list(map(str, range(9))): return self.__tiles[index] else: return str(int(self.__tiles[index]) + 1) def set_tile(self, symbol, coordinate: int): """Setter for the tile""" if self.__tiles[coordinate] not in list(map(str, range(9))): return False self.__tiles[coordinate] = symbol return True def possible_moves(self): """Returns a list of unoccupied tiles in the board""" return [index + 1 for index in range(len(self.__tiles)) if self.__tiles[index] in list(map(str, range(9)))] def check_board(self, symbol): """Check if the player won, cause a draw, or doesn't cause either""" possible_combination = [self.__tiles[:3], self.__tiles[3:6], self.__tiles[6:], self.__tiles[::3], self.__tiles[1::3], self.__tiles[2::3], self.__tiles[0::4], self.__tiles[2:8:2]] if len(list(filter(lambda x: x == [symbol] * 3, possible_combination))) > 0: return symbol elif not len(list(filter(lambda x: x in list(map(str, range(9))), self.__tiles))): return 'DRAW' else: return False
# Parsing file using list comprehension file1 = open("test.txt", "r") output = [i for i in file1 if "All" in i] print(output)
file1 = open('test.txt', 'r') output = [i for i in file1 if 'All' in i] print(output)
''' Description : Use Of Forloop With Hardcoded Value Function Date : 15 Feb 2021 Function Author : Prasad Dangare Input : Int Output : str ''' def display(): print("Output of For loop") icnt = 0 for icnt in range(10, 1, -1): print(icnt) else: print("End of For loop") def main(): display() if __name__ == "__main__": main()
""" Description : Use Of Forloop With Hardcoded Value Function Date : 15 Feb 2021 Function Author : Prasad Dangare Input : Int Output : str """ def display(): print('Output of For loop') icnt = 0 for icnt in range(10, 1, -1): print(icnt) else: print('End of For loop') def main(): display() if __name__ == '__main__': main()
# Grocery list class class GroceryList: def __init__(self, initial_items=[]): # Use a set, so that we don't get duplicates self.grocery_list = set(initial_items) def add(self, item): # Use the lower case of the item so we don't get duplicates self.grocery_list.add(item.lower()) def remove(self, item): self.grocery_list.remove(item.lower()) def contains(self, item): return item.lower() in self.grocery_list def items(self): return list(self.grocery_list) ################# # Example usage my_list = GroceryList() my_list.add("strawberries") my_list.add("wine") my_list.add("gouda cheese") if not my_list.contains("Crackers"): my_list.add("crackers") my_list.add("beer") my_list.remove("beer") print("My list has: ") for item in my_list.items(): print ("\t",item)
class Grocerylist: def __init__(self, initial_items=[]): self.grocery_list = set(initial_items) def add(self, item): self.grocery_list.add(item.lower()) def remove(self, item): self.grocery_list.remove(item.lower()) def contains(self, item): return item.lower() in self.grocery_list def items(self): return list(self.grocery_list) my_list = grocery_list() my_list.add('strawberries') my_list.add('wine') my_list.add('gouda cheese') if not my_list.contains('Crackers'): my_list.add('crackers') my_list.add('beer') my_list.remove('beer') print('My list has: ') for item in my_list.items(): print('\t', item)
{ 'includes': [ 'common.gypi', ], 'target_defaults': { 'conditions': [ ['skia_os != "win"', { 'sources/': [ ['exclude', '_win.(h|cpp)$'], ], }], ['skia_os != "mac"', { 'sources/': [ ['exclude', '_mac.(h|cpp)$'], ], }], ['skia_os != "linux"', { 'sources/': [ ['exclude', '_unix.(h|cpp)$'], ], }], ['skia_os != "ios"', { 'sources/': [ ['exclude', '_iOS.(h|cpp)$'], ], }], ['skia_os != "android"', { 'sources/': [ ['exclude', '_android.(h|cpp)$'], ], }], [ 'skia_os == "android"', { 'defines': [ 'GR_ANDROID_BUILD=1', ], }], [ 'skia_os == "mac"', { 'defines': [ 'GR_MAC_BUILD=1', ], }], [ 'skia_os == "linux"', { 'defines': [ 'GR_LINUX_BUILD=1', ], }], [ 'skia_os == "ios"', { 'defines': [ 'GR_IOS_BUILD=1', ], }], [ 'skia_os == "win"', { 'defines': [ 'GR_WIN32_BUILD=1', ], }], # nullify the targets in this gyp file if skia_gpu is 0 [ 'skia_gpu == 0', { 'sources/': [ ['exclude', '.*'], ], 'defines/': [ ['exclude', '.*'], ], 'include_dirs/': [ ['exclude', '.*'], ], 'link_settings': { 'libraries/': [ ['exclude', '.*'], ], }, 'direct_dependent_settings': { 'defines/': [ ['exclude', '.*'], ], 'include_dirs/': [ ['exclude', '.*'], ], }, }], ], 'direct_dependent_settings': { 'conditions': [ [ 'skia_os == "android"', { 'defines': [ 'GR_ANDROID_BUILD=1', ], }], [ 'skia_os == "mac"', { 'defines': [ 'GR_MAC_BUILD=1', ], }], [ 'skia_os == "linux"', { 'defines': [ 'GR_LINUX_BUILD=1', ], }], [ 'skia_os == "ios"', { 'defines': [ 'GR_IOS_BUILD=1', ], }], [ 'skia_os == "win"', { 'defines': [ 'GR_WIN32_BUILD=1', 'GR_GL_FUNCTION_TYPE=__stdcall', ], }], ], 'include_dirs': [ '../deps/skia/include/gpu', ], }, }, 'targets': [ { 'target_name': 'skgr', 'type': 'static_library', 'include_dirs': [ '../deps/skia/include/config', '../deps/skia/include/core', '../deps/skia/src/core', '../deps/skia/include/gpu', '../deps/skia/src/gpu', ], 'dependencies': [ 'angle.gyp:*', ], 'export_dependent_settings': [ 'angle.gyp:*', ], 'sources': [ '../deps/skia/include/gpu/SkGpuCanvas.h', '../deps/skia/include/gpu/SkGpuDevice.h', '../deps/skia/include/gpu/SkGr.h', '../deps/skia/include/gpu/SkGrPixelRef.h', '../deps/skia/include/gpu/SkGrTexturePixelRef.h', '../deps/skia/include/gpu/gl/SkGLContext.h', '../deps/skia/include/gpu/gl/SkMesaGLContext.h', '../deps/skia/include/gpu/gl/SkANGLEGLContext.h', '../deps/skia/include/gpu/gl/SkNativeGLContext.h', '../deps/skia/include/gpu/gl/SkNullGLContext.h', '../deps/skia/include/gpu/gl/SkDebugGLContext.h', '../deps/skia/src/gpu/SkGpuCanvas.cpp', '../deps/skia/src/gpu/SkGpuDevice.cpp', '../deps/skia/src/gpu/SkGr.cpp', '../deps/skia/src/gpu/SkGrFontScaler.cpp', '../deps/skia/src/gpu/SkGrPixelRef.cpp', '../deps/skia/src/gpu/SkGrTexturePixelRef.cpp', '../deps/skia/src/gpu/gl/SkGLContext.cpp', '../deps/skia/src/gpu/gl/SkNullGLContext.cpp', '../deps/skia/src/gpu/gl/debug/SkDebugGLContext.cpp', '../deps/skia/src/gpu/gl/mac/SkNativeGLContext_mac.cpp', '../deps/skia/src/gpu/gl/win/SkNativeGLContext_win.cpp', '../deps/skia/src/gpu/gl/unix/SkNativeGLContext_unix.cpp', '../deps/skia/src/gpu/gl/mesa/SkMesaGLContext.cpp', '../deps/skia/src/gpu/gl/angle/SkANGLEGLContext.cpp', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', '../deps/skia/src/gpu/android/SkNativeGLContext_android.cpp', ], 'conditions': [ [ 'not skia_mesa', { 'sources!': [ '../deps/skia/src/gpu/gl/mesa/SkMesaGLContext.cpp', ], }], [ 'skia_mesa and skia_os == "mac"', { 'include_dirs': [ '$(SDKROOT)/usr/X11/include/', ], }], [ 'not skia_angle', { 'sources!': [ '../deps/skia/include/gpu/gl/SkANGLEGLContext.h', '../deps/skia/src/gpu/gl/angle/SkANGLEGLContext.cpp', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', ], }], ], }, { 'target_name': 'gr', 'type': 'static_library', 'include_dirs': [ '../deps/skia/include/core', '../deps/skia/include/config', '../deps/skia/include/gpu', '../deps/skia/src/core', # SkRasterClip.h '../deps/skia/src/gpu' ], 'dependencies': [ 'angle.gyp:*', ], 'export_dependent_settings': [ 'angle.gyp:*', ], 'sources': [ '../deps/skia/include/gpu/GrAARectRenderer.h', '../deps/skia/include/gpu/GrClipData.h', '../deps/skia/include/gpu/GrColor.h', '../deps/skia/include/gpu/GrConfig.h', '../deps/skia/include/gpu/GrContext.h', '../deps/skia/include/gpu/GrContextFactory.h', '../deps/skia/include/gpu/GrCustomStage.h', '../deps/skia/include/gpu/GrCustomStageUnitTest.h', '../deps/skia/include/gpu/GrFontScaler.h', '../deps/skia/include/gpu/GrGlyph.h', '../deps/skia/include/gpu/GrInstanceCounter.h', '../deps/skia/include/gpu/GrKey.h', '../deps/skia/include/gpu/GrMatrix.h', '../deps/skia/include/gpu/GrNoncopyable.h', '../deps/skia/include/gpu/GrPaint.h', '../deps/skia/include/gpu/GrPoint.h', '../deps/skia/include/gpu/GrProgramStageFactory.h', '../deps/skia/include/gpu/GrRect.h', '../deps/skia/include/gpu/GrRefCnt.h', '../deps/skia/include/gpu/GrRenderTarget.h', '../deps/skia/include/gpu/GrResource.h', '../deps/skia/include/gpu/GrSamplerState.h', '../deps/skia/include/gpu/GrScalar.h', '../deps/skia/include/gpu/GrSurface.h', '../deps/skia/include/gpu/GrTextContext.h', '../deps/skia/include/gpu/GrTexture.h', '../deps/skia/include/gpu/GrTypes.h', '../deps/skia/include/gpu/GrUserConfig.h', '../deps/skia/include/gpu/gl/GrGLConfig.h', '../deps/skia/include/gpu/gl/GrGLConfig_chrome.h', '../deps/skia/include/gpu/gl/GrGLFunctions.h', '../deps/skia/include/gpu/gl/GrGLInterface.h', '../deps/skia/src/gpu/GrAAHairLinePathRenderer.cpp', '../deps/skia/src/gpu/GrAAHairLinePathRenderer.h', '../deps/skia/src/gpu/GrAAConvexPathRenderer.cpp', '../deps/skia/src/gpu/GrAAConvexPathRenderer.h', '../deps/skia/src/gpu/GrAARectRenderer.cpp', '../deps/skia/src/gpu/GrAddPathRenderers_default.cpp', '../deps/skia/src/gpu/GrAllocator.h', '../deps/skia/src/gpu/GrAllocPool.h', '../deps/skia/src/gpu/GrAllocPool.cpp', '../deps/skia/src/gpu/GrAtlas.cpp', '../deps/skia/src/gpu/GrAtlas.h', '../deps/skia/src/gpu/GrBinHashKey.h', '../deps/skia/src/gpu/GrBufferAllocPool.cpp', '../deps/skia/src/gpu/GrBufferAllocPool.h', '../deps/skia/src/gpu/GrClipData.cpp', '../deps/skia/src/gpu/GrContext.cpp', '../deps/skia/src/gpu/GrCustomStage.cpp', '../deps/skia/src/gpu/GrDefaultPathRenderer.cpp', '../deps/skia/src/gpu/GrDefaultPathRenderer.h', '../deps/skia/src/gpu/GrDrawState.h', '../deps/skia/src/gpu/GrDrawTarget.cpp', '../deps/skia/src/gpu/GrDrawTarget.h', '../deps/skia/src/gpu/GrGeometryBuffer.h', '../deps/skia/src/gpu/GrClipMaskManager.h', '../deps/skia/src/gpu/GrClipMaskManager.cpp', '../deps/skia/src/gpu/GrGpu.cpp', '../deps/skia/src/gpu/GrGpu.h', '../deps/skia/src/gpu/GrGpuFactory.cpp', '../deps/skia/src/gpu/GrGpuVertex.h', '../deps/skia/src/gpu/GrIndexBuffer.h', '../deps/skia/src/gpu/GrInOrderDrawBuffer.cpp', '../deps/skia/src/gpu/GrInOrderDrawBuffer.h', '../deps/skia/src/gpu/GrMatrix.cpp', '../deps/skia/src/gpu/GrMemory.cpp', '../deps/skia/src/gpu/GrMemoryPool.cpp', '../deps/skia/src/gpu/GrMemoryPool.h', '../deps/skia/src/gpu/GrPath.h', '../deps/skia/src/gpu/GrPathRendererChain.cpp', '../deps/skia/src/gpu/GrPathRendererChain.h', '../deps/skia/src/gpu/GrPathRenderer.cpp', '../deps/skia/src/gpu/GrPathRenderer.h', '../deps/skia/src/gpu/GrPathUtils.cpp', '../deps/skia/src/gpu/GrPathUtils.h', '../deps/skia/src/gpu/GrPlotMgr.h', '../deps/skia/src/gpu/GrRandom.h', '../deps/skia/src/gpu/GrRectanizer.cpp', '../deps/skia/src/gpu/GrRectanizer.h', '../deps/skia/src/gpu/GrRedBlackTree.h', '../deps/skia/src/gpu/GrRenderTarget.cpp', '../deps/skia/src/gpu/GrResource.cpp', '../deps/skia/src/gpu/GrResourceCache.cpp', '../deps/skia/src/gpu/GrResourceCache.h', '../deps/skia/src/gpu/GrStencil.cpp', '../deps/skia/src/gpu/GrStencil.h', '../deps/skia/src/gpu/GrStencilAndCoverPathRenderer.cpp', '../deps/skia/src/gpu/GrStencilAndCoverPathRenderer.h', '../deps/skia/src/gpu/GrStencilBuffer.cpp', '../deps/skia/src/gpu/GrStencilBuffer.h', '../deps/skia/src/gpu/GrTBSearch.h', '../deps/skia/src/gpu/GrTDArray.h', '../deps/skia/src/gpu/GrSWMaskHelper.cpp', '../deps/skia/src/gpu/GrSWMaskHelper.h', '../deps/skia/src/gpu/GrSoftwarePathRenderer.cpp', '../deps/skia/src/gpu/GrSoftwarePathRenderer.h', '../deps/skia/src/gpu/GrSurface.cpp', '../deps/skia/src/gpu/GrTemplates.h', '../deps/skia/src/gpu/GrTextContext.cpp', '../deps/skia/src/gpu/GrTextStrike.cpp', '../deps/skia/src/gpu/GrTextStrike.h', '../deps/skia/src/gpu/GrTextStrike_impl.h', '../deps/skia/src/gpu/GrTexture.cpp', '../deps/skia/src/gpu/GrTHashCache.h', '../deps/skia/src/gpu/GrTLList.h', '../deps/skia/src/gpu/GrVertexBuffer.h', '../deps/skia/src/gpu/gr_unittests.cpp', '../deps/skia/src/gpu/effects/Gr1DKernelEffect.h', '../deps/skia/src/gpu/effects/GrColorTableEffect.cpp', '../deps/skia/src/gpu/effects/GrColorTableEffect.h', '../deps/skia/src/gpu/effects/GrConvolutionEffect.cpp', '../deps/skia/src/gpu/effects/GrConvolutionEffect.h', '../deps/skia/src/gpu/effects/GrMorphologyEffect.cpp', '../deps/skia/src/gpu/effects/GrMorphologyEffect.h', '../deps/skia/src/gpu/effects/GrSingleTextureEffect.cpp', '../deps/skia/src/gpu/effects/GrSingleTextureEffect.h', '../deps/skia/src/gpu/effects/GrTextureDomainEffect.cpp', '../deps/skia/src/gpu/effects/GrTextureDomainEffect.h', '../deps/skia/src/gpu/gl/GrGLCaps.cpp', '../deps/skia/src/gpu/gl/GrGLCaps.h', '../deps/skia/src/gpu/gl/GrGLContextInfo.cpp', '../deps/skia/src/gpu/gl/GrGLContextInfo.h', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNullInterface.cpp', '../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLDefaultInterface_native.cpp', '../deps/skia/src/gpu/gl/GrGLDefines.h', '../deps/skia/src/gpu/gl/GrGLIndexBuffer.cpp', '../deps/skia/src/gpu/gl/GrGLIndexBuffer.h', '../deps/skia/src/gpu/gl/GrGLInterface.cpp', '../deps/skia/src/gpu/gl/GrGLIRect.h', '../deps/skia/src/gpu/gl/GrGLPath.cpp', '../deps/skia/src/gpu/gl/GrGLPath.h', '../deps/skia/src/gpu/gl/GrGLProgram.cpp', '../deps/skia/src/gpu/gl/GrGLProgram.h', '../deps/skia/src/gpu/gl/GrGLProgramStage.cpp', '../deps/skia/src/gpu/gl/GrGLProgramStage.h', '../deps/skia/src/gpu/gl/GrGLRenderTarget.cpp', '../deps/skia/src/gpu/gl/GrGLRenderTarget.h', '../deps/skia/src/gpu/gl/GrGLShaderBuilder.cpp', '../deps/skia/src/gpu/gl/GrGLShaderBuilder.h', '../deps/skia/src/gpu/gl/GrGLShaderVar.h', '../deps/skia/src/gpu/gl/GrGLSL.cpp', '../deps/skia/src/gpu/gl/GrGLSL.h', '../deps/skia/src/gpu/gl/GrGLStencilBuffer.cpp', '../deps/skia/src/gpu/gl/GrGLStencilBuffer.h', '../deps/skia/src/gpu/gl/GrGLTexture.cpp', '../deps/skia/src/gpu/gl/GrGLTexture.h', '../deps/skia/src/gpu/gl/GrGLUtil.cpp', '../deps/skia/src/gpu/gl/GrGLUtil.h', '../deps/skia/src/gpu/gl/GrGLUniformManager.cpp', '../deps/skia/src/gpu/gl/GrGLUniformManager.h', '../deps/skia/src/gpu/gl/GrGLUniformHandle.h', '../deps/skia/src/gpu/gl/GrGLVertexBuffer.cpp', '../deps/skia/src/gpu/gl/GrGLVertexBuffer.h', '../deps/skia/src/gpu/gl/GrGpuGL.cpp', '../deps/skia/src/gpu/gl/GrGpuGL.h', '../deps/skia/src/gpu/gl/GrGpuGL_program.cpp', '../deps/skia/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp', '../deps/skia/src/gpu/gl/debug/GrFakeRefObj.h', '../deps/skia/src/gpu/gl/debug/GrBufferObj.h', '../deps/skia/src/gpu/gl/debug/GrBufferObj.cpp', '../deps/skia/src/gpu/gl/debug/GrFBBindableObj.h', '../deps/skia/src/gpu/gl/debug/GrRenderBufferObj.h', '../deps/skia/src/gpu/gl/debug/GrTextureObj.h', '../deps/skia/src/gpu/gl/debug/GrTextureObj.cpp', '../deps/skia/src/gpu/gl/debug/GrTextureUnitObj.h', '../deps/skia/src/gpu/gl/debug/GrTextureUnitObj.cpp', '../deps/skia/src/gpu/gl/debug/GrFrameBufferObj.h', '../deps/skia/src/gpu/gl/debug/GrFrameBufferObj.cpp', '../deps/skia/src/gpu/gl/debug/GrShaderObj.h', '../deps/skia/src/gpu/gl/debug/GrShaderObj.cpp', '../deps/skia/src/gpu/gl/debug/GrProgramObj.h', '../deps/skia/src/gpu/gl/debug/GrProgramObj.cpp', '../deps/skia/src/gpu/gl/debug/GrDebugGL.h', '../deps/skia/src/gpu/gl/debug/GrDebugGL.cpp', '../deps/skia/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp', '../deps/skia/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp', '../deps/skia/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp', '../deps/skia/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', '../deps/skia/src/gpu/android/GrGLCreateNativeInterface_android.cpp', ], 'defines': [ 'GR_IMPLEMENTATION=1', ], 'conditions': [ [ 'skia_nv_path_rendering', { 'defines': [ 'GR_GL_USE_NV_PATH_RENDERING=1', ], }], [ 'skia_os == "linux"', { 'sources!': [ '../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', ], 'link_settings': { 'libraries': [ '-lGL', '-lX11', ], }, }], [ 'skia_mesa and skia_os == "linux"', { 'link_settings': { 'libraries': [ '-lOSMesa', ], }, }], [ 'skia_os == "mac"', { 'link_settings': { 'libraries': [ '$(SDKROOT)/System/Library/Frameworks/OpenGL.framework', ], }, 'sources!': [ '../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', ], }], [ 'skia_mesa and skia_os == "mac"', { 'link_settings': { 'libraries': [ '$(SDKROOT)/usr/X11/lib/libOSMesa.dylib', ], }, 'include_dirs': [ '$(SDKROOT)/usr/X11/include/', ], }], [ 'not skia_mesa', { 'sources!': [ '../deps/skia/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp', ], }], [ 'skia_os == "win"', { 'sources!': [ '../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', ], }], [ 'not skia_angle', { 'sources!': [ '../deps/skia/include/gpu/gl/SkANGLEGLContext.h', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', '../deps/skia/src/gpu/gl/angle/SkANGLEGLContext.cpp', ], }], [ 'skia_os == "android"', { 'sources!': [ '../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', ], 'link_settings': { 'libraries': [ '-lGLESv2', '-lEGL', ], }, }], ], }, ], } # Local Variables: # tab-width:2 # indent-tabs-mode:nil # End: # vim: set expandtab tabstop=2 shiftwidth=2:
{'includes': ['common.gypi'], 'target_defaults': {'conditions': [['skia_os != "win"', {'sources/': [['exclude', '_win.(h|cpp)$']]}], ['skia_os != "mac"', {'sources/': [['exclude', '_mac.(h|cpp)$']]}], ['skia_os != "linux"', {'sources/': [['exclude', '_unix.(h|cpp)$']]}], ['skia_os != "ios"', {'sources/': [['exclude', '_iOS.(h|cpp)$']]}], ['skia_os != "android"', {'sources/': [['exclude', '_android.(h|cpp)$']]}], ['skia_os == "android"', {'defines': ['GR_ANDROID_BUILD=1']}], ['skia_os == "mac"', {'defines': ['GR_MAC_BUILD=1']}], ['skia_os == "linux"', {'defines': ['GR_LINUX_BUILD=1']}], ['skia_os == "ios"', {'defines': ['GR_IOS_BUILD=1']}], ['skia_os == "win"', {'defines': ['GR_WIN32_BUILD=1']}], ['skia_gpu == 0', {'sources/': [['exclude', '.*']], 'defines/': [['exclude', '.*']], 'include_dirs/': [['exclude', '.*']], 'link_settings': {'libraries/': [['exclude', '.*']]}, 'direct_dependent_settings': {'defines/': [['exclude', '.*']], 'include_dirs/': [['exclude', '.*']]}}]], 'direct_dependent_settings': {'conditions': [['skia_os == "android"', {'defines': ['GR_ANDROID_BUILD=1']}], ['skia_os == "mac"', {'defines': ['GR_MAC_BUILD=1']}], ['skia_os == "linux"', {'defines': ['GR_LINUX_BUILD=1']}], ['skia_os == "ios"', {'defines': ['GR_IOS_BUILD=1']}], ['skia_os == "win"', {'defines': ['GR_WIN32_BUILD=1', 'GR_GL_FUNCTION_TYPE=__stdcall']}]], 'include_dirs': ['../deps/skia/include/gpu']}}, 'targets': [{'target_name': 'skgr', 'type': 'static_library', 'include_dirs': ['../deps/skia/include/config', '../deps/skia/include/core', '../deps/skia/src/core', '../deps/skia/include/gpu', '../deps/skia/src/gpu'], 'dependencies': ['angle.gyp:*'], 'export_dependent_settings': ['angle.gyp:*'], 'sources': ['../deps/skia/include/gpu/SkGpuCanvas.h', '../deps/skia/include/gpu/SkGpuDevice.h', '../deps/skia/include/gpu/SkGr.h', '../deps/skia/include/gpu/SkGrPixelRef.h', '../deps/skia/include/gpu/SkGrTexturePixelRef.h', '../deps/skia/include/gpu/gl/SkGLContext.h', '../deps/skia/include/gpu/gl/SkMesaGLContext.h', '../deps/skia/include/gpu/gl/SkANGLEGLContext.h', '../deps/skia/include/gpu/gl/SkNativeGLContext.h', '../deps/skia/include/gpu/gl/SkNullGLContext.h', '../deps/skia/include/gpu/gl/SkDebugGLContext.h', '../deps/skia/src/gpu/SkGpuCanvas.cpp', '../deps/skia/src/gpu/SkGpuDevice.cpp', '../deps/skia/src/gpu/SkGr.cpp', '../deps/skia/src/gpu/SkGrFontScaler.cpp', '../deps/skia/src/gpu/SkGrPixelRef.cpp', '../deps/skia/src/gpu/SkGrTexturePixelRef.cpp', '../deps/skia/src/gpu/gl/SkGLContext.cpp', '../deps/skia/src/gpu/gl/SkNullGLContext.cpp', '../deps/skia/src/gpu/gl/debug/SkDebugGLContext.cpp', '../deps/skia/src/gpu/gl/mac/SkNativeGLContext_mac.cpp', '../deps/skia/src/gpu/gl/win/SkNativeGLContext_win.cpp', '../deps/skia/src/gpu/gl/unix/SkNativeGLContext_unix.cpp', '../deps/skia/src/gpu/gl/mesa/SkMesaGLContext.cpp', '../deps/skia/src/gpu/gl/angle/SkANGLEGLContext.cpp', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', '../deps/skia/src/gpu/android/SkNativeGLContext_android.cpp'], 'conditions': [['not skia_mesa', {'sources!': ['../deps/skia/src/gpu/gl/mesa/SkMesaGLContext.cpp']}], ['skia_mesa and skia_os == "mac"', {'include_dirs': ['$(SDKROOT)/usr/X11/include/']}], ['not skia_angle', {'sources!': ['../deps/skia/include/gpu/gl/SkANGLEGLContext.h', '../deps/skia/src/gpu/gl/angle/SkANGLEGLContext.cpp', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp']}]]}, {'target_name': 'gr', 'type': 'static_library', 'include_dirs': ['../deps/skia/include/core', '../deps/skia/include/config', '../deps/skia/include/gpu', '../deps/skia/src/core', '../deps/skia/src/gpu'], 'dependencies': ['angle.gyp:*'], 'export_dependent_settings': ['angle.gyp:*'], 'sources': ['../deps/skia/include/gpu/GrAARectRenderer.h', '../deps/skia/include/gpu/GrClipData.h', '../deps/skia/include/gpu/GrColor.h', '../deps/skia/include/gpu/GrConfig.h', '../deps/skia/include/gpu/GrContext.h', '../deps/skia/include/gpu/GrContextFactory.h', '../deps/skia/include/gpu/GrCustomStage.h', '../deps/skia/include/gpu/GrCustomStageUnitTest.h', '../deps/skia/include/gpu/GrFontScaler.h', '../deps/skia/include/gpu/GrGlyph.h', '../deps/skia/include/gpu/GrInstanceCounter.h', '../deps/skia/include/gpu/GrKey.h', '../deps/skia/include/gpu/GrMatrix.h', '../deps/skia/include/gpu/GrNoncopyable.h', '../deps/skia/include/gpu/GrPaint.h', '../deps/skia/include/gpu/GrPoint.h', '../deps/skia/include/gpu/GrProgramStageFactory.h', '../deps/skia/include/gpu/GrRect.h', '../deps/skia/include/gpu/GrRefCnt.h', '../deps/skia/include/gpu/GrRenderTarget.h', '../deps/skia/include/gpu/GrResource.h', '../deps/skia/include/gpu/GrSamplerState.h', '../deps/skia/include/gpu/GrScalar.h', '../deps/skia/include/gpu/GrSurface.h', '../deps/skia/include/gpu/GrTextContext.h', '../deps/skia/include/gpu/GrTexture.h', '../deps/skia/include/gpu/GrTypes.h', '../deps/skia/include/gpu/GrUserConfig.h', '../deps/skia/include/gpu/gl/GrGLConfig.h', '../deps/skia/include/gpu/gl/GrGLConfig_chrome.h', '../deps/skia/include/gpu/gl/GrGLFunctions.h', '../deps/skia/include/gpu/gl/GrGLInterface.h', '../deps/skia/src/gpu/GrAAHairLinePathRenderer.cpp', '../deps/skia/src/gpu/GrAAHairLinePathRenderer.h', '../deps/skia/src/gpu/GrAAConvexPathRenderer.cpp', '../deps/skia/src/gpu/GrAAConvexPathRenderer.h', '../deps/skia/src/gpu/GrAARectRenderer.cpp', '../deps/skia/src/gpu/GrAddPathRenderers_default.cpp', '../deps/skia/src/gpu/GrAllocator.h', '../deps/skia/src/gpu/GrAllocPool.h', '../deps/skia/src/gpu/GrAllocPool.cpp', '../deps/skia/src/gpu/GrAtlas.cpp', '../deps/skia/src/gpu/GrAtlas.h', '../deps/skia/src/gpu/GrBinHashKey.h', '../deps/skia/src/gpu/GrBufferAllocPool.cpp', '../deps/skia/src/gpu/GrBufferAllocPool.h', '../deps/skia/src/gpu/GrClipData.cpp', '../deps/skia/src/gpu/GrContext.cpp', '../deps/skia/src/gpu/GrCustomStage.cpp', '../deps/skia/src/gpu/GrDefaultPathRenderer.cpp', '../deps/skia/src/gpu/GrDefaultPathRenderer.h', '../deps/skia/src/gpu/GrDrawState.h', '../deps/skia/src/gpu/GrDrawTarget.cpp', '../deps/skia/src/gpu/GrDrawTarget.h', '../deps/skia/src/gpu/GrGeometryBuffer.h', '../deps/skia/src/gpu/GrClipMaskManager.h', '../deps/skia/src/gpu/GrClipMaskManager.cpp', '../deps/skia/src/gpu/GrGpu.cpp', '../deps/skia/src/gpu/GrGpu.h', '../deps/skia/src/gpu/GrGpuFactory.cpp', '../deps/skia/src/gpu/GrGpuVertex.h', '../deps/skia/src/gpu/GrIndexBuffer.h', '../deps/skia/src/gpu/GrInOrderDrawBuffer.cpp', '../deps/skia/src/gpu/GrInOrderDrawBuffer.h', '../deps/skia/src/gpu/GrMatrix.cpp', '../deps/skia/src/gpu/GrMemory.cpp', '../deps/skia/src/gpu/GrMemoryPool.cpp', '../deps/skia/src/gpu/GrMemoryPool.h', '../deps/skia/src/gpu/GrPath.h', '../deps/skia/src/gpu/GrPathRendererChain.cpp', '../deps/skia/src/gpu/GrPathRendererChain.h', '../deps/skia/src/gpu/GrPathRenderer.cpp', '../deps/skia/src/gpu/GrPathRenderer.h', '../deps/skia/src/gpu/GrPathUtils.cpp', '../deps/skia/src/gpu/GrPathUtils.h', '../deps/skia/src/gpu/GrPlotMgr.h', '../deps/skia/src/gpu/GrRandom.h', '../deps/skia/src/gpu/GrRectanizer.cpp', '../deps/skia/src/gpu/GrRectanizer.h', '../deps/skia/src/gpu/GrRedBlackTree.h', '../deps/skia/src/gpu/GrRenderTarget.cpp', '../deps/skia/src/gpu/GrResource.cpp', '../deps/skia/src/gpu/GrResourceCache.cpp', '../deps/skia/src/gpu/GrResourceCache.h', '../deps/skia/src/gpu/GrStencil.cpp', '../deps/skia/src/gpu/GrStencil.h', '../deps/skia/src/gpu/GrStencilAndCoverPathRenderer.cpp', '../deps/skia/src/gpu/GrStencilAndCoverPathRenderer.h', '../deps/skia/src/gpu/GrStencilBuffer.cpp', '../deps/skia/src/gpu/GrStencilBuffer.h', '../deps/skia/src/gpu/GrTBSearch.h', '../deps/skia/src/gpu/GrTDArray.h', '../deps/skia/src/gpu/GrSWMaskHelper.cpp', '../deps/skia/src/gpu/GrSWMaskHelper.h', '../deps/skia/src/gpu/GrSoftwarePathRenderer.cpp', '../deps/skia/src/gpu/GrSoftwarePathRenderer.h', '../deps/skia/src/gpu/GrSurface.cpp', '../deps/skia/src/gpu/GrTemplates.h', '../deps/skia/src/gpu/GrTextContext.cpp', '../deps/skia/src/gpu/GrTextStrike.cpp', '../deps/skia/src/gpu/GrTextStrike.h', '../deps/skia/src/gpu/GrTextStrike_impl.h', '../deps/skia/src/gpu/GrTexture.cpp', '../deps/skia/src/gpu/GrTHashCache.h', '../deps/skia/src/gpu/GrTLList.h', '../deps/skia/src/gpu/GrVertexBuffer.h', '../deps/skia/src/gpu/gr_unittests.cpp', '../deps/skia/src/gpu/effects/Gr1DKernelEffect.h', '../deps/skia/src/gpu/effects/GrColorTableEffect.cpp', '../deps/skia/src/gpu/effects/GrColorTableEffect.h', '../deps/skia/src/gpu/effects/GrConvolutionEffect.cpp', '../deps/skia/src/gpu/effects/GrConvolutionEffect.h', '../deps/skia/src/gpu/effects/GrMorphologyEffect.cpp', '../deps/skia/src/gpu/effects/GrMorphologyEffect.h', '../deps/skia/src/gpu/effects/GrSingleTextureEffect.cpp', '../deps/skia/src/gpu/effects/GrSingleTextureEffect.h', '../deps/skia/src/gpu/effects/GrTextureDomainEffect.cpp', '../deps/skia/src/gpu/effects/GrTextureDomainEffect.h', '../deps/skia/src/gpu/gl/GrGLCaps.cpp', '../deps/skia/src/gpu/gl/GrGLCaps.h', '../deps/skia/src/gpu/gl/GrGLContextInfo.cpp', '../deps/skia/src/gpu/gl/GrGLContextInfo.h', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNullInterface.cpp', '../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLDefaultInterface_native.cpp', '../deps/skia/src/gpu/gl/GrGLDefines.h', '../deps/skia/src/gpu/gl/GrGLIndexBuffer.cpp', '../deps/skia/src/gpu/gl/GrGLIndexBuffer.h', '../deps/skia/src/gpu/gl/GrGLInterface.cpp', '../deps/skia/src/gpu/gl/GrGLIRect.h', '../deps/skia/src/gpu/gl/GrGLPath.cpp', '../deps/skia/src/gpu/gl/GrGLPath.h', '../deps/skia/src/gpu/gl/GrGLProgram.cpp', '../deps/skia/src/gpu/gl/GrGLProgram.h', '../deps/skia/src/gpu/gl/GrGLProgramStage.cpp', '../deps/skia/src/gpu/gl/GrGLProgramStage.h', '../deps/skia/src/gpu/gl/GrGLRenderTarget.cpp', '../deps/skia/src/gpu/gl/GrGLRenderTarget.h', '../deps/skia/src/gpu/gl/GrGLShaderBuilder.cpp', '../deps/skia/src/gpu/gl/GrGLShaderBuilder.h', '../deps/skia/src/gpu/gl/GrGLShaderVar.h', '../deps/skia/src/gpu/gl/GrGLSL.cpp', '../deps/skia/src/gpu/gl/GrGLSL.h', '../deps/skia/src/gpu/gl/GrGLStencilBuffer.cpp', '../deps/skia/src/gpu/gl/GrGLStencilBuffer.h', '../deps/skia/src/gpu/gl/GrGLTexture.cpp', '../deps/skia/src/gpu/gl/GrGLTexture.h', '../deps/skia/src/gpu/gl/GrGLUtil.cpp', '../deps/skia/src/gpu/gl/GrGLUtil.h', '../deps/skia/src/gpu/gl/GrGLUniformManager.cpp', '../deps/skia/src/gpu/gl/GrGLUniformManager.h', '../deps/skia/src/gpu/gl/GrGLUniformHandle.h', '../deps/skia/src/gpu/gl/GrGLVertexBuffer.cpp', '../deps/skia/src/gpu/gl/GrGLVertexBuffer.h', '../deps/skia/src/gpu/gl/GrGpuGL.cpp', '../deps/skia/src/gpu/gl/GrGpuGL.h', '../deps/skia/src/gpu/gl/GrGpuGL_program.cpp', '../deps/skia/src/gpu/gl/debug/GrGLCreateDebugInterface.cpp', '../deps/skia/src/gpu/gl/debug/GrFakeRefObj.h', '../deps/skia/src/gpu/gl/debug/GrBufferObj.h', '../deps/skia/src/gpu/gl/debug/GrBufferObj.cpp', '../deps/skia/src/gpu/gl/debug/GrFBBindableObj.h', '../deps/skia/src/gpu/gl/debug/GrRenderBufferObj.h', '../deps/skia/src/gpu/gl/debug/GrTextureObj.h', '../deps/skia/src/gpu/gl/debug/GrTextureObj.cpp', '../deps/skia/src/gpu/gl/debug/GrTextureUnitObj.h', '../deps/skia/src/gpu/gl/debug/GrTextureUnitObj.cpp', '../deps/skia/src/gpu/gl/debug/GrFrameBufferObj.h', '../deps/skia/src/gpu/gl/debug/GrFrameBufferObj.cpp', '../deps/skia/src/gpu/gl/debug/GrShaderObj.h', '../deps/skia/src/gpu/gl/debug/GrShaderObj.cpp', '../deps/skia/src/gpu/gl/debug/GrProgramObj.h', '../deps/skia/src/gpu/gl/debug/GrProgramObj.cpp', '../deps/skia/src/gpu/gl/debug/GrDebugGL.h', '../deps/skia/src/gpu/gl/debug/GrDebugGL.cpp', '../deps/skia/src/gpu/gl/mac/GrGLCreateNativeInterface_mac.cpp', '../deps/skia/src/gpu/gl/win/GrGLCreateNativeInterface_win.cpp', '../deps/skia/src/gpu/gl/unix/GrGLCreateNativeInterface_unix.cpp', '../deps/skia/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', '../deps/skia/src/gpu/android/GrGLCreateNativeInterface_android.cpp'], 'defines': ['GR_IMPLEMENTATION=1'], 'conditions': [['skia_nv_path_rendering', {'defines': ['GR_GL_USE_NV_PATH_RENDERING=1']}], ['skia_os == "linux"', {'sources!': ['../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp'], 'link_settings': {'libraries': ['-lGL', '-lX11']}}], ['skia_mesa and skia_os == "linux"', {'link_settings': {'libraries': ['-lOSMesa']}}], ['skia_os == "mac"', {'link_settings': {'libraries': ['$(SDKROOT)/System/Library/Frameworks/OpenGL.framework']}, 'sources!': ['../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp']}], ['skia_mesa and skia_os == "mac"', {'link_settings': {'libraries': ['$(SDKROOT)/usr/X11/lib/libOSMesa.dylib']}, 'include_dirs': ['$(SDKROOT)/usr/X11/include/']}], ['not skia_mesa', {'sources!': ['../deps/skia/src/gpu/gl/mesa/GrGLCreateMesaInterface.cpp']}], ['skia_os == "win"', {'sources!': ['../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp']}], ['not skia_angle', {'sources!': ['../deps/skia/include/gpu/gl/SkANGLEGLContext.h', '../deps/skia/src/gpu/gl/angle/GrGLCreateANGLEInterface.cpp', '../deps/skia/src/gpu/gl/angle/SkANGLEGLContext.cpp']}], ['skia_os == "android"', {'sources!': ['../deps/skia/src/gpu/gl/GrGLDefaultInterface_none.cpp', '../deps/skia/src/gpu/gl/GrGLCreateNativeInterface_none.cpp'], 'link_settings': {'libraries': ['-lGLESv2', '-lEGL']}}]]}]}
def pares(num): valores_pares = 0 for n in num: if n % 2 == 0: valores_pares += 1 return print(f'{valores_pares} valor(es) par(es)') def impares(num): valores_impares = 0 for n in num: if n % 2 != 0: valores_impares += 1 return print(f'{valores_impares} valor(es) impar(es)') def positivos(num): valores_positivos = 0 for n in num: if n > 0: valores_positivos += 1 return print(f'{valores_positivos} valor(es) positivo(s)') def negativos(num): valores_negativos = 0 for n in num: if n < 0: valores_negativos += 1 return print(f'{valores_negativos} valor(es) negativo(s)') def entrada(): numeros = list() for i in range(5): numeros.append(int(input())) return numeros numbers = entrada() pares(numbers) impares(numbers) positivos(numbers) negativos(numbers)
def pares(num): valores_pares = 0 for n in num: if n % 2 == 0: valores_pares += 1 return print(f'{valores_pares} valor(es) par(es)') def impares(num): valores_impares = 0 for n in num: if n % 2 != 0: valores_impares += 1 return print(f'{valores_impares} valor(es) impar(es)') def positivos(num): valores_positivos = 0 for n in num: if n > 0: valores_positivos += 1 return print(f'{valores_positivos} valor(es) positivo(s)') def negativos(num): valores_negativos = 0 for n in num: if n < 0: valores_negativos += 1 return print(f'{valores_negativos} valor(es) negativo(s)') def entrada(): numeros = list() for i in range(5): numeros.append(int(input())) return numeros numbers = entrada() pares(numbers) impares(numbers) positivos(numbers) negativos(numbers)
def insertShiftArray(list,val): list[int(len(list)/2):int(len(list)/2)] = [val] return list
def insert_shift_array(list, val): list[int(len(list) / 2):int(len(list) / 2)] = [val] return list
class Solution: def findMaxLength(self, nums: List[int]) -> int: c = 0 res = 0 dic = {0:-1} for i in range(len(nums)): n = nums[i] if n == 1 : c += 1 else: c -= 1 if c in dic : res = max(res, i - dic[c]) else:dic[c] = i return res
class Solution: def find_max_length(self, nums: List[int]) -> int: c = 0 res = 0 dic = {0: -1} for i in range(len(nums)): n = nums[i] if n == 1: c += 1 else: c -= 1 if c in dic: res = max(res, i - dic[c]) else: dic[c] = i return res
# No Bugs in Production (NBP) Library # https://github.com/aenachescu/nbplib # # Licensed under the MIT License <http://opensource.org/licenses/MIT>. # SPDX-License-Identifier: MIT # Copyright (c) 2019-2020 Alin Enachescu <https://github.com/aenachescu> # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. supportedCompilersDict = { "gcc-5": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-5" }, "gcc-6": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-6" }, "gcc-7": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-7" }, "gcc-8": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-8" }, "gcc-9": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-9" }, "g++-5": { "standards": [ "-std=c++03", "-std=c++11", "-std=c++14", "-std=c++17" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-5" }, "g++-6": { "standards": [ "-std=c++03", "-std=c++11", "-std=c++14", "-std=c++17" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-6" }, "g++-7": { "standards": [ "-std=c++03", "-std=c++11", "-std=c++14", "-std=c++17" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-7" }, "g++-8": { "standards": [ "-std=c++03", "-std=c++11", "-std=c++14", "-std=c++17" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-8" }, "g++-9": { "standards": [ "-std=c++03", "-std=c++11", "-std=c++14", "-std=c++17" ], "platforms": [ "-m32", "-m64"], "gcov_tool": "gcov-9" }, "clang-5.0": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64" ], "gcov_tool": "scripts/clang_cov/clang_cov_5.sh", "gcov_tool_absolute_path": True }, "clang-6.0": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64" ], "gcov_tool": "scripts/clang_cov/clang_cov_6.sh", "gcov_tool_absolute_path": True }, "clang-7": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64" ], "gcov_tool": "scripts/clang_cov/clang_cov_7.sh", "gcov_tool_absolute_path": True }, "clang-8": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64" ], "gcov_tool": "scripts/clang_cov/clang_cov_8.sh", "gcov_tool_absolute_path": True }, "clang-9": { "standards": [ "-std=c99", "-std=c11" ], "platforms": [ "-m32", "-m64" ], "gcov_tool": "scripts/clang_cov/clang_cov_9.sh", "gcov_tool_absolute_path": True }, }
supported_compilers_dict = {'gcc-5': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-5'}, 'gcc-6': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-6'}, 'gcc-7': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-7'}, 'gcc-8': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-8'}, 'gcc-9': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-9'}, 'g++-5': {'standards': ['-std=c++03', '-std=c++11', '-std=c++14', '-std=c++17'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-5'}, 'g++-6': {'standards': ['-std=c++03', '-std=c++11', '-std=c++14', '-std=c++17'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-6'}, 'g++-7': {'standards': ['-std=c++03', '-std=c++11', '-std=c++14', '-std=c++17'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-7'}, 'g++-8': {'standards': ['-std=c++03', '-std=c++11', '-std=c++14', '-std=c++17'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-8'}, 'g++-9': {'standards': ['-std=c++03', '-std=c++11', '-std=c++14', '-std=c++17'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'gcov-9'}, 'clang-5.0': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'scripts/clang_cov/clang_cov_5.sh', 'gcov_tool_absolute_path': True}, 'clang-6.0': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'scripts/clang_cov/clang_cov_6.sh', 'gcov_tool_absolute_path': True}, 'clang-7': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'scripts/clang_cov/clang_cov_7.sh', 'gcov_tool_absolute_path': True}, 'clang-8': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'scripts/clang_cov/clang_cov_8.sh', 'gcov_tool_absolute_path': True}, 'clang-9': {'standards': ['-std=c99', '-std=c11'], 'platforms': ['-m32', '-m64'], 'gcov_tool': 'scripts/clang_cov/clang_cov_9.sh', 'gcov_tool_absolute_path': True}}
# This sample tests annotated types on global variables. # This should generate an error because the declared # type below does not match the assigned type. glob_var1 = 4 # This should generate an error because the declared # type doesn't match the later declared type. glob_var1 = Exception() # type: str glob_var1 = Exception() # type: Exception # This should generate an error because the assigned # type doesn't match the declared type. glob_var1 = "hello" # type: Exception # This should generate an error. glob_var2 = 5 def func1(): global glob_var1 global glob_var2 # This should generate an error. glob_var1 = 3 glob_var2 = "hello" # type: str
glob_var1 = 4 glob_var1 = exception() glob_var1 = exception() glob_var1 = 'hello' glob_var2 = 5 def func1(): global glob_var1 global glob_var2 glob_var1 = 3 glob_var2 = 'hello'
numbers = [5, 5, 5, 6, 7, 4, 6, 10] uniques = [] for number in numbers: if number not in uniques: uniques.append(number) print(uniques)
numbers = [5, 5, 5, 6, 7, 4, 6, 10] uniques = [] for number in numbers: if number not in uniques: uniques.append(number) print(uniques)
technologies = {} while True: line = input() if "end" == line: break technology, courses_tokens = line.split(" - ") if technology not in technologies: technologies[technology] = {} courses_tokens = [(course, int(participants)) for course, participants in [token.split(':') for token in courses_tokens.split(", ")]] for course, participants in courses_tokens: technologies[technology].setdefault(course, 0) technologies[technology][course] += participants def get_total_participants(tech): return sum(tech.values()) technologies = sorted(technologies.items(), key=lambda key: -get_total_participants(key[1])) print(f"Most popular: {technologies[0][0]} ({get_total_participants(technologies[0][1])} participants)") print(f"Least popular: {technologies[-1][0]} ({get_total_participants(technologies[-1][1])} participants)") for technology, courses in technologies: print(f"{technology} ({get_total_participants(courses)} participants):") for course, participants in sorted(courses.items(), key=lambda x: -x[1]): print(f"--{course} -> {participants}")
technologies = {} while True: line = input() if 'end' == line: break (technology, courses_tokens) = line.split(' - ') if technology not in technologies: technologies[technology] = {} courses_tokens = [(course, int(participants)) for (course, participants) in [token.split(':') for token in courses_tokens.split(', ')]] for (course, participants) in courses_tokens: technologies[technology].setdefault(course, 0) technologies[technology][course] += participants def get_total_participants(tech): return sum(tech.values()) technologies = sorted(technologies.items(), key=lambda key: -get_total_participants(key[1])) print(f'Most popular: {technologies[0][0]} ({get_total_participants(technologies[0][1])} participants)') print(f'Least popular: {technologies[-1][0]} ({get_total_participants(technologies[-1][1])} participants)') for (technology, courses) in technologies: print(f'{technology} ({get_total_participants(courses)} participants):') for (course, participants) in sorted(courses.items(), key=lambda x: -x[1]): print(f'--{course} -> {participants}')
variavel = 'valor' def func(): print(variavel) def func2(): variavel = 'Outro valor' print(variavel) func() func2() print(variavel)
variavel = 'valor' def func(): print(variavel) def func2(): variavel = 'Outro valor' print(variavel) func() func2() print(variavel)
# # PySNMP MIB module ROOMALERT4E-MIB (http://snmplabs.com/pysmi) # ASN.1 source file:///Users/davwang4/Dev/mibs.snmplabs.com/asn1/ROOMALERT4E-MIB # Produced by pysmi-0.3.4 at Wed May 1 14:58:20 2019 # On host DAVWANG4-M-1475 platform Darwin version 18.5.0 by user davwang4 # Using Python version 3.7.3 (default, Mar 27 2019, 09:23:15) # Integer, OctetString, ObjectIdentifier = mibBuilder.importSymbols("ASN1", "Integer", "OctetString", "ObjectIdentifier") NamedValues, = mibBuilder.importSymbols("ASN1-ENUMERATION", "NamedValues") ConstraintsIntersection, SingleValueConstraint, ValueRangeConstraint, ConstraintsUnion, ValueSizeConstraint = mibBuilder.importSymbols("ASN1-REFINEMENT", "ConstraintsIntersection", "SingleValueConstraint", "ValueRangeConstraint", "ConstraintsUnion", "ValueSizeConstraint") NotificationGroup, ModuleCompliance = mibBuilder.importSymbols("SNMPv2-CONF", "NotificationGroup", "ModuleCompliance") MibScalar, MibTable, MibTableRow, MibTableColumn, NotificationType, IpAddress, Bits, Counter32, Gauge32, Unsigned32, enterprises, TimeTicks, MibIdentifier, iso, NotificationType, Integer32, ObjectIdentity, ModuleIdentity, Counter64 = mibBuilder.importSymbols("SNMPv2-SMI", "MibScalar", "MibTable", "MibTableRow", "MibTableColumn", "NotificationType", "IpAddress", "Bits", "Counter32", "Gauge32", "Unsigned32", "enterprises", "TimeTicks", "MibIdentifier", "iso", "NotificationType", "Integer32", "ObjectIdentity", "ModuleIdentity", "Counter64") DisplayString, TextualConvention = mibBuilder.importSymbols("SNMPv2-TC", "DisplayString", "TextualConvention") avtech = MibIdentifier((1, 3, 6, 1, 4, 1, 20916)) products = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1)) ROOMALERT4E = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6)) sensors = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1)) signaltower = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2)) traps = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 3)) internal = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1)) temperature = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 1)) humidity = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 2)) heat_index = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 3)).setLabel("heat-index") digital = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2)) digital_sen1 = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1)).setLabel("digital-sen1") digital_sen2 = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2)).setLabel("digital-sen2") switch = MibIdentifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 3)) internal_tempf = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 1, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("internal-tempf").setMaxAccess("readonly") if mibBuilder.loadTexts: internal_tempf.setStatus('mandatory') if mibBuilder.loadTexts: internal_tempf.setDescription('The internal temperature reading in Fahrenheit. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') internal_tempc = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 1, 2), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("internal-tempc").setMaxAccess("readonly") if mibBuilder.loadTexts: internal_tempc.setStatus('mandatory') if mibBuilder.loadTexts: internal_tempc.setDescription('The internal temperature reading in Celsius. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') internal_humidity = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 2, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("internal-humidity").setMaxAccess("readonly") if mibBuilder.loadTexts: internal_humidity.setStatus('mandatory') if mibBuilder.loadTexts: internal_humidity.setDescription('The internal relative humidity reading in %RH. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') internal_heat_index = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 3, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("internal-heat-index").setMaxAccess("readonly") if mibBuilder.loadTexts: internal_heat_index.setStatus('mandatory') if mibBuilder.loadTexts: internal_heat_index.setDescription('The internal heat index reading in Fahrenheit. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') digital_sen1_1 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen1-1").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen1_1.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_1.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Celsius. If this sensor is a Digital Power Sensor, this value represents the Current reading in Amperage.') digital_sen1_2 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 2), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen1-2").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen1_2.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_2.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Power reading in Watts.') digital_sen1_3 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 3), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen1-3").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen1_3.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_3.setDescription('If this sensor is a Temp/Humidity sensor, this value represents the current relative humidity in % Relative Humidity. If this sensor is a Digital Power Sensor, this value represents the Voltage reading in Volts.') digital_sen1_4 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 4), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen1-4").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen1_4.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_4.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current heat index in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Reference reading in Volts.') digital_sen2_1 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen2-1").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen2_1.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_1.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Celsius. If this sensor is a Digital Power Sensor, this value represents the Current reading in Amperage.') digital_sen2_2 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 2), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen2-2").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen2_2.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_2.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Power reading in Watts.') digital_sen2_3 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 3), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen2-3").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen2_3.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_3.setDescription('If this sensor is a Temp/Humidity sensor, this value represents the current relative humidity in % Relative Humidity. If this sensor is a Digital Power Sensor, this value represents the Voltage reading in Volts.') digital_sen2_4 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 4), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 65535))).setLabel("digital-sen2-4").setMaxAccess("readonly") if mibBuilder.loadTexts: digital_sen2_4.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_4.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current heat index in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Reference reading in Volts.') switch_sen1 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 3, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setLabel("switch-sen1").setMaxAccess("readonly") if mibBuilder.loadTexts: switch_sen1.setStatus('mandatory') if mibBuilder.loadTexts: switch_sen1.setDescription('The reading for switch sensor 1 (0 = OPEN, 1 = CLOSED).') red_led = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 1), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setLabel("red-led").setMaxAccess("readwrite") if mibBuilder.loadTexts: red_led.setStatus('current') if mibBuilder.loadTexts: red_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') amber_led = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 2), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setLabel("amber-led").setMaxAccess("readwrite") if mibBuilder.loadTexts: amber_led.setStatus('current') if mibBuilder.loadTexts: amber_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') green_led = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 3), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setLabel("green-led").setMaxAccess("readwrite") if mibBuilder.loadTexts: green_led.setStatus('current') if mibBuilder.loadTexts: green_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') blue_led = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 4), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setLabel("blue-led").setMaxAccess("readwrite") if mibBuilder.loadTexts: blue_led.setStatus('current') if mibBuilder.loadTexts: blue_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') white_led = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 5), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setLabel("white-led").setMaxAccess("readwrite") if mibBuilder.loadTexts: white_led.setStatus('current') if mibBuilder.loadTexts: white_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') alarm1 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 6), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setMaxAccess("readwrite") if mibBuilder.loadTexts: alarm1.setStatus('current') if mibBuilder.loadTexts: alarm1.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') alarm2 = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 7), Integer32().subtype(subtypeSpec=ValueRangeConstraint(0, 1))).setMaxAccess("readwrite") if mibBuilder.loadTexts: alarm2.setStatus('current') if mibBuilder.loadTexts: alarm2.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') alarmmessage = MibScalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 3, 1), OctetString()).setMaxAccess("readonly") if mibBuilder.loadTexts: alarmmessage.setStatus('mandatory') if mibBuilder.loadTexts: alarmmessage.setDescription('Last Alarm Message') room_alert_4e_snmp_trap = NotificationType((1, 3, 6, 1, 4, 1, 20916, 1, 6) + (0,2)).setLabel("room-alert-4e-snmp-trap").setObjects(("ROOMALERT4E-MIB", "alarmmessage")) if mibBuilder.loadTexts: room_alert_4e_snmp_trap.setDescription('A room-alert-4e-snmp-trap indicates that an alarm condition has occurred on the sensor indicated by the alarmmessage variable.') mibBuilder.exportSymbols("ROOMALERT4E-MIB", digital_sen2_4=digital_sen2_4, alarm2=alarm2, digital_sen1_3=digital_sen1_3, internal=internal, green_led=green_led, digital_sen1_4=digital_sen1_4, red_led=red_led, blue_led=blue_led, digital=digital, temperature=temperature, white_led=white_led, signaltower=signaltower, digital_sen1_1=digital_sen1_1, digital_sen1_2=digital_sen1_2, sensors=sensors, ROOMALERT4E=ROOMALERT4E, internal_tempf=internal_tempf, internal_humidity=internal_humidity, internal_heat_index=internal_heat_index, room_alert_4e_snmp_trap=room_alert_4e_snmp_trap, digital_sen2_1=digital_sen2_1, traps=traps, products=products, digital_sen2_3=digital_sen2_3, alarm1=alarm1, switch_sen1=switch_sen1, heat_index=heat_index, humidity=humidity, switch=switch, avtech=avtech, alarmmessage=alarmmessage, digital_sen2=digital_sen2, digital_sen2_2=digital_sen2_2, digital_sen1=digital_sen1, amber_led=amber_led, internal_tempc=internal_tempc)
(integer, octet_string, object_identifier) = mibBuilder.importSymbols('ASN1', 'Integer', 'OctetString', 'ObjectIdentifier') (named_values,) = mibBuilder.importSymbols('ASN1-ENUMERATION', 'NamedValues') (constraints_intersection, single_value_constraint, value_range_constraint, constraints_union, value_size_constraint) = mibBuilder.importSymbols('ASN1-REFINEMENT', 'ConstraintsIntersection', 'SingleValueConstraint', 'ValueRangeConstraint', 'ConstraintsUnion', 'ValueSizeConstraint') (notification_group, module_compliance) = mibBuilder.importSymbols('SNMPv2-CONF', 'NotificationGroup', 'ModuleCompliance') (mib_scalar, mib_table, mib_table_row, mib_table_column, notification_type, ip_address, bits, counter32, gauge32, unsigned32, enterprises, time_ticks, mib_identifier, iso, notification_type, integer32, object_identity, module_identity, counter64) = mibBuilder.importSymbols('SNMPv2-SMI', 'MibScalar', 'MibTable', 'MibTableRow', 'MibTableColumn', 'NotificationType', 'IpAddress', 'Bits', 'Counter32', 'Gauge32', 'Unsigned32', 'enterprises', 'TimeTicks', 'MibIdentifier', 'iso', 'NotificationType', 'Integer32', 'ObjectIdentity', 'ModuleIdentity', 'Counter64') (display_string, textual_convention) = mibBuilder.importSymbols('SNMPv2-TC', 'DisplayString', 'TextualConvention') avtech = mib_identifier((1, 3, 6, 1, 4, 1, 20916)) products = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1)) roomalert4_e = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6)) sensors = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1)) signaltower = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2)) traps = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 3)) internal = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1)) temperature = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 1)) humidity = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 2)) heat_index = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 3)).setLabel('heat-index') digital = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2)) digital_sen1 = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1)).setLabel('digital-sen1') digital_sen2 = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2)).setLabel('digital-sen2') switch = mib_identifier((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 3)) internal_tempf = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 1, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('internal-tempf').setMaxAccess('readonly') if mibBuilder.loadTexts: internal_tempf.setStatus('mandatory') if mibBuilder.loadTexts: internal_tempf.setDescription('The internal temperature reading in Fahrenheit. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') internal_tempc = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 1, 2), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('internal-tempc').setMaxAccess('readonly') if mibBuilder.loadTexts: internal_tempc.setStatus('mandatory') if mibBuilder.loadTexts: internal_tempc.setDescription('The internal temperature reading in Celsius. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') internal_humidity = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 2, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('internal-humidity').setMaxAccess('readonly') if mibBuilder.loadTexts: internal_humidity.setStatus('mandatory') if mibBuilder.loadTexts: internal_humidity.setDescription('The internal relative humidity reading in %RH. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') internal_heat_index = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 1, 3, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('internal-heat-index').setMaxAccess('readonly') if mibBuilder.loadTexts: internal_heat_index.setStatus('mandatory') if mibBuilder.loadTexts: internal_heat_index.setDescription('The internal heat index reading in Fahrenheit. Because the SNMP Protocol does not support floating point numbers, values are scaled by 100 and should be divided by 100 to get the actual value.') digital_sen1_1 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen1-1').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen1_1.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_1.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Celsius. If this sensor is a Digital Power Sensor, this value represents the Current reading in Amperage.') digital_sen1_2 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 2), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen1-2').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen1_2.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_2.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Power reading in Watts.') digital_sen1_3 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 3), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen1-3').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen1_3.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_3.setDescription('If this sensor is a Temp/Humidity sensor, this value represents the current relative humidity in % Relative Humidity. If this sensor is a Digital Power Sensor, this value represents the Voltage reading in Volts.') digital_sen1_4 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 1, 4), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen1-4').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen1_4.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen1_4.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current heat index in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Reference reading in Volts.') digital_sen2_1 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen2-1').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen2_1.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_1.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Celsius. If this sensor is a Digital Power Sensor, this value represents the Current reading in Amperage.') digital_sen2_2 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 2), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen2-2').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen2_2.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_2.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current temperature in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Power reading in Watts.') digital_sen2_3 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 3), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen2-3').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen2_3.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_3.setDescription('If this sensor is a Temp/Humidity sensor, this value represents the current relative humidity in % Relative Humidity. If this sensor is a Digital Power Sensor, this value represents the Voltage reading in Volts.') digital_sen2_4 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 2, 2, 4), integer32().subtype(subtypeSpec=value_range_constraint(0, 65535))).setLabel('digital-sen2-4').setMaxAccess('readonly') if mibBuilder.loadTexts: digital_sen2_4.setStatus('mandatory') if mibBuilder.loadTexts: digital_sen2_4.setDescription('If this sensor is a Temperature or Temp/Humidity sensor, this value represents the current heat index in Fahrenheit. If this sensor is a Digital Power Sensor, this value represents the Reference reading in Volts.') switch_sen1 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 1, 3, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setLabel('switch-sen1').setMaxAccess('readonly') if mibBuilder.loadTexts: switch_sen1.setStatus('mandatory') if mibBuilder.loadTexts: switch_sen1.setDescription('The reading for switch sensor 1 (0 = OPEN, 1 = CLOSED).') red_led = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 1), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setLabel('red-led').setMaxAccess('readwrite') if mibBuilder.loadTexts: red_led.setStatus('current') if mibBuilder.loadTexts: red_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') amber_led = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 2), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setLabel('amber-led').setMaxAccess('readwrite') if mibBuilder.loadTexts: amber_led.setStatus('current') if mibBuilder.loadTexts: amber_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') green_led = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 3), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setLabel('green-led').setMaxAccess('readwrite') if mibBuilder.loadTexts: green_led.setStatus('current') if mibBuilder.loadTexts: green_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') blue_led = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 4), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setLabel('blue-led').setMaxAccess('readwrite') if mibBuilder.loadTexts: blue_led.setStatus('current') if mibBuilder.loadTexts: blue_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') white_led = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 5), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setLabel('white-led').setMaxAccess('readwrite') if mibBuilder.loadTexts: white_led.setStatus('current') if mibBuilder.loadTexts: white_led.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') alarm1 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 6), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setMaxAccess('readwrite') if mibBuilder.loadTexts: alarm1.setStatus('current') if mibBuilder.loadTexts: alarm1.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') alarm2 = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 2, 7), integer32().subtype(subtypeSpec=value_range_constraint(0, 1))).setMaxAccess('readwrite') if mibBuilder.loadTexts: alarm2.setStatus('current') if mibBuilder.loadTexts: alarm2.setDescription('The status of this Signal Tower element (0 = OFF, 1 = ON).') alarmmessage = mib_scalar((1, 3, 6, 1, 4, 1, 20916, 1, 6, 3, 1), octet_string()).setMaxAccess('readonly') if mibBuilder.loadTexts: alarmmessage.setStatus('mandatory') if mibBuilder.loadTexts: alarmmessage.setDescription('Last Alarm Message') room_alert_4e_snmp_trap = notification_type((1, 3, 6, 1, 4, 1, 20916, 1, 6) + (0, 2)).setLabel('room-alert-4e-snmp-trap').setObjects(('ROOMALERT4E-MIB', 'alarmmessage')) if mibBuilder.loadTexts: room_alert_4e_snmp_trap.setDescription('A room-alert-4e-snmp-trap indicates that an alarm condition has occurred on the sensor indicated by the alarmmessage variable.') mibBuilder.exportSymbols('ROOMALERT4E-MIB', digital_sen2_4=digital_sen2_4, alarm2=alarm2, digital_sen1_3=digital_sen1_3, internal=internal, green_led=green_led, digital_sen1_4=digital_sen1_4, red_led=red_led, blue_led=blue_led, digital=digital, temperature=temperature, white_led=white_led, signaltower=signaltower, digital_sen1_1=digital_sen1_1, digital_sen1_2=digital_sen1_2, sensors=sensors, ROOMALERT4E=ROOMALERT4E, internal_tempf=internal_tempf, internal_humidity=internal_humidity, internal_heat_index=internal_heat_index, room_alert_4e_snmp_trap=room_alert_4e_snmp_trap, digital_sen2_1=digital_sen2_1, traps=traps, products=products, digital_sen2_3=digital_sen2_3, alarm1=alarm1, switch_sen1=switch_sen1, heat_index=heat_index, humidity=humidity, switch=switch, avtech=avtech, alarmmessage=alarmmessage, digital_sen2=digital_sen2, digital_sen2_2=digital_sen2_2, digital_sen1=digital_sen1, amber_led=amber_led, internal_tempc=internal_tempc)
dist = 0 speed = 0 lastTime = 0 while(True): try: inp = input() if not inp: raise ValueError except ValueError: break except EOFError: break arr = inp.split(' ') if (len(arr) == 1): outp = True else: outp = False time = arr[0].split(':') currtime = int(time[0])*3600 + int(time[1])*60 + int(time[2]) - 1 diff = currtime - lastTime dist += speed * (diff / 3600) # print(time) # print(currtime) if outp: # print(diff * 60) print(arr[0] + ' ' + '%.2f' % dist + ' km') else: speed = int(arr[1]) lastTime = currtime
dist = 0 speed = 0 last_time = 0 while True: try: inp = input() if not inp: raise ValueError except ValueError: break except EOFError: break arr = inp.split(' ') if len(arr) == 1: outp = True else: outp = False time = arr[0].split(':') currtime = int(time[0]) * 3600 + int(time[1]) * 60 + int(time[2]) - 1 diff = currtime - lastTime dist += speed * (diff / 3600) if outp: print(arr[0] + ' ' + '%.2f' % dist + ' km') else: speed = int(arr[1]) last_time = currtime
class Solution: # 1st solution # O(1) time | O(1) space def isPowerOfTwo(self, n: int) -> bool: x = 1 while x < n: x *= 2 return x == n # 2nd solution # O(1) time | O(1) space def isPowerOfTwo(self, n: int) -> bool: return n > 0 and not (n & n-1)
class Solution: def is_power_of_two(self, n: int) -> bool: x = 1 while x < n: x *= 2 return x == n def is_power_of_two(self, n: int) -> bool: return n > 0 and (not n & n - 1)
''' # Pass command for i in range (0,9): if i == 3: pass print (" Pass Here", end = '') else: print (f" {i}", end = '') ''' # String Commands myString = "India is my country" myString2 = "I love my India" print (myString.index("is")) print (myString.find("is")) print (myString.isalpha()) print (myString.isalnum()) print (myString.isdecimal()) print (myString.islower()) print (myString.isupper()) print (myString.isdigit()) print (myString.isspace()) print (myString.isidentifier()) print (myString.isnumeric()) print (myString.istitle()) print (myString.join(myString2)) S1 = "Kerivada Makkale" S2 = "Anjooran" print(S1.join(S2)) print (len(S1)) print (S1.lower()) print (S1.upper()) print (S1.replace("Kerivada","Odivada")) print (S1.strip()) print (S1.split()) print (S1.startswith("Kerivada")) print (S1.swapcase())
""" # Pass command for i in range (0,9): if i == 3: pass print (" Pass Here", end = '') else: print (f" {i}", end = '') """ my_string = 'India is my country' my_string2 = 'I love my India' print(myString.index('is')) print(myString.find('is')) print(myString.isalpha()) print(myString.isalnum()) print(myString.isdecimal()) print(myString.islower()) print(myString.isupper()) print(myString.isdigit()) print(myString.isspace()) print(myString.isidentifier()) print(myString.isnumeric()) print(myString.istitle()) print(myString.join(myString2)) s1 = 'Kerivada Makkale' s2 = 'Anjooran' print(S1.join(S2)) print(len(S1)) print(S1.lower()) print(S1.upper()) print(S1.replace('Kerivada', 'Odivada')) print(S1.strip()) print(S1.split()) print(S1.startswith('Kerivada')) print(S1.swapcase())
# Issue #38 in Python 2.7 # Problem is distinguishing 'continue' from 'jump_back' # in assembly instructions. # Here, we hack looking for two jump backs # followed by the end of the except. This # is a big hack. for a in [__name__]: try:len(a) except:continue # The above has JUMP_ABSOLUTE in it. # This has JUMP_FORWARD instead. for a in [__name__]: try:len(a) except:continue y = 2
for a in [__name__]: try: len(a) except: continue for a in [__name__]: try: len(a) except: continue y = 2
App.open("java -jar C:/JabRef-4.2-fat.jar") wait(30) click("1529632189350.png") wait(2) click("1529632296782.png") wait(2) click("1529632312432.png") wait(2) click("1529632554435.png") wait(2) click("1529632574104.png") wait(2) click("1529632589427.png") wait(2) click("1529632601277.png") wait(2) click("1529632757740.png")
App.open('java -jar C:/JabRef-4.2-fat.jar') wait(30) click('1529632189350.png') wait(2) click('1529632296782.png') wait(2) click('1529632312432.png') wait(2) click('1529632554435.png') wait(2) click('1529632574104.png') wait(2) click('1529632589427.png') wait(2) click('1529632601277.png') wait(2) click('1529632757740.png')
class Solution: @staticmethod def jewels_and_stones(jewels: str, stones: str) -> int: count = 0 for i in stones: if i in jewels: count += 1 continue return count J = "z" S = "ZZ" solution = Solution() print(solution.jewels_and_stones(J, S))
class Solution: @staticmethod def jewels_and_stones(jewels: str, stones: str) -> int: count = 0 for i in stones: if i in jewels: count += 1 continue return count j = 'z' s = 'ZZ' solution = solution() print(solution.jewels_and_stones(J, S))
'''A simple calculator using a dictionary to look up functions for operators''' def add(n1, n2): return n1 + n2 def mult(n1, n2): return n1 * n2 opers = { '+': add, '*': mult } print("Enter expressions like 23 * 10 or 2 - 5") while True: expr = input('> ') if expr: try: (op1, op, op2) = expr.split(' ') print(opers[op](int(op1), int(op2))) except Exception: print("Sorry, I couldn't make sense of that") else: break
"""A simple calculator using a dictionary to look up functions for operators""" def add(n1, n2): return n1 + n2 def mult(n1, n2): return n1 * n2 opers = {'+': add, '*': mult} print('Enter expressions like 23 * 10 or 2 - 5') while True: expr = input('> ') if expr: try: (op1, op, op2) = expr.split(' ') print(opers[op](int(op1), int(op2))) except Exception: print("Sorry, I couldn't make sense of that") else: break
#read the input test cases into a list (of lists) test_file = open("input_test_case", "r") test_file = [element.strip() for element in test_file] test_case_count = int(test_file[0]) test_cases = [[] for col in range(test_case_count)]; test_case_count = 0 test_file = test_file[2:] for idx, element in enumerate(test_file): if (len(element)): test_cases[test_case_count].append(element) else: test_case_count += 1 #process each case individually for case in test_cases: #calculate length of the file file_len = 0 for fragment in case: file_len += len(fragment) file_len //= (len(case)//2) #create an array of dicts. for all possible fragments dict_array = [ {} for frag_size in range(file_len) ] for fragment in case: if (fragment in dict_array[len(fragment)]): dict_array[len(fragment)-1][fragment] += 1 else: dict_array[len(fragment)-1][fragment] = 1 dict_array = [ list(element) for element in dict_array ] #go through each of the sizes, and create all possible combinations of a file comb_array = [ set() for case_count in range(file_len//2) ] for idx in range(file_len//2): word_size = idx + 1; if ( word_size == file_len//2 and (not file_len%2) ): if (len(dict_array[word_size-1]) == 1): comb_array[idx].add(2*dict_array[word_size-1][0]) else: for rep in range(0, 1+1): comb_array[idx].add("".join(dict_array[word_size-1])) dict_array[word_size-1].reverse() else: for idx_1, element_1 in enumerate(dict_array[word_size-1]): for idx_2, element_2 in enumerate(dict_array[file_len-word_size-1]): comb_array[idx].add(element_1 + element_2); comb_array[idx].add(element_2 + element_1) #we find the only combination that's common across ALL the words final_set = set(); for comb_set in comb_array: if (comb_set): #check if 'final' set is empty if (not final_set): final_set = final_set.union(comb_set) else: final_set.intersection_update(comb_set) #break out of loop if only one selection remains if (len(final_set) == 1): break #we print all possibilities (in case there are multiple) print(list(final_set)[0]) print(""); #NOTE: there can be MULTIPLE solutions (and we need to print only ONE of them), and that might NOT neccesarily #match uDebug's solution(s), but this solutino IS correct
test_file = open('input_test_case', 'r') test_file = [element.strip() for element in test_file] test_case_count = int(test_file[0]) test_cases = [[] for col in range(test_case_count)] test_case_count = 0 test_file = test_file[2:] for (idx, element) in enumerate(test_file): if len(element): test_cases[test_case_count].append(element) else: test_case_count += 1 for case in test_cases: file_len = 0 for fragment in case: file_len += len(fragment) file_len //= len(case) // 2 dict_array = [{} for frag_size in range(file_len)] for fragment in case: if fragment in dict_array[len(fragment)]: dict_array[len(fragment) - 1][fragment] += 1 else: dict_array[len(fragment) - 1][fragment] = 1 dict_array = [list(element) for element in dict_array] comb_array = [set() for case_count in range(file_len // 2)] for idx in range(file_len // 2): word_size = idx + 1 if word_size == file_len // 2 and (not file_len % 2): if len(dict_array[word_size - 1]) == 1: comb_array[idx].add(2 * dict_array[word_size - 1][0]) else: for rep in range(0, 1 + 1): comb_array[idx].add(''.join(dict_array[word_size - 1])) dict_array[word_size - 1].reverse() else: for (idx_1, element_1) in enumerate(dict_array[word_size - 1]): for (idx_2, element_2) in enumerate(dict_array[file_len - word_size - 1]): comb_array[idx].add(element_1 + element_2) comb_array[idx].add(element_2 + element_1) final_set = set() for comb_set in comb_array: if comb_set: if not final_set: final_set = final_set.union(comb_set) else: final_set.intersection_update(comb_set) if len(final_set) == 1: break print(list(final_set)[0]) print('')
# # Copyright 2022 Erwan Mahe (github.com/erwanM974) # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses/LICENSE-2.0 # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # timeout_in_seconds = 10 # multi_trace_number_per_loop_height = 5 # multitrace_outer_loop_ns = [x for x in range(1,41)] # multi_trace_obs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10] # hsfs = ["hid_wtloc","hid_noloc","sim_wtloc","sim_noloc"] # sensor_example_lifelines = ["CSI","CI","SM","LSM","CSM","CR","CA","SOS"]
timeout_in_seconds = 10 multi_trace_number_per_loop_height = 5 multitrace_outer_loop_ns = [x for x in range(1, 41)] multi_trace_obs = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10] hsfs = ['hid_wtloc', 'hid_noloc', 'sim_wtloc', 'sim_noloc'] sensor_example_lifelines = ['CSI', 'CI', 'SM', 'LSM', 'CSM', 'CR', 'CA', 'SOS']
''' Bifurcaciones Estructura.- if CONDICION: INSTRUCCIONES [elif CONDICION: INSTRUCCIONES else: INSTRUCCIONES ] **Las palabras en mayusculas indican estatutos variables (no siempre son los mismos) y lo que esta en corchetes es opcional. Puede haber mas de un elif. ''' #Ejemplos matricula=20 temperatura=40 if matricula%2==0: print('La matricula es par') else: print('La matricula es impar') if temperatura<15: print('Tengo frio') elif temperatura>=15 and temperatura<26: print('Esta agradable') elif temperatura>=26 and temperatura<35: print('Tengo calor') else: print('Tengo mucho calor')
""" Bifurcaciones Estructura.- if CONDICION: INSTRUCCIONES [elif CONDICION: INSTRUCCIONES else: INSTRUCCIONES ] **Las palabras en mayusculas indican estatutos variables (no siempre son los mismos) y lo que esta en corchetes es opcional. Puede haber mas de un elif. """ matricula = 20 temperatura = 40 if matricula % 2 == 0: print('La matricula es par') else: print('La matricula es impar') if temperatura < 15: print('Tengo frio') elif temperatura >= 15 and temperatura < 26: print('Esta agradable') elif temperatura >= 26 and temperatura < 35: print('Tengo calor') else: print('Tengo mucho calor')
# Python program to display the Fibonacci sequence def fibonacci(n): if n <= 1: return n else: return(fibonacci(n-1) + fibonacci(n-2)) N = input() if N <= 0: print("Plese enter a positive integer") else: print("Fibonacci sequence:") for i in range(N): print(fibonacci(i))
def fibonacci(n): if n <= 1: return n else: return fibonacci(n - 1) + fibonacci(n - 2) n = input() if N <= 0: print('Plese enter a positive integer') else: print('Fibonacci sequence:') for i in range(N): print(fibonacci(i))
__author__ = ''' Dawson Reid (dreid93@gmail.com) ''' VALID_CURRENCY = ['CAD', 'BTC', 'LTC'] VALID_CURRENCY_PAIRS = ['BTCCAD', 'LTCCAD', 'BTCLTC'] DATE_FORMAT = '%Y-%m-%d' VALID_WITHDRAW_CURRENCY = ['BTC', 'LTC']
__author__ = '\nDawson Reid (dreid93@gmail.com)\n' valid_currency = ['CAD', 'BTC', 'LTC'] valid_currency_pairs = ['BTCCAD', 'LTCCAD', 'BTCLTC'] date_format = '%Y-%m-%d' valid_withdraw_currency = ['BTC', 'LTC']
# https://leetcode.com/problems/number-of-rectangles-that-can-form-the-largest-square ''' Time Complexity: O(N) Space Complexity: O(N) ''' def count_good_rectangles(rectangles): max_len, all_max_lens = 0, [] for rec in rectangles: square_len = min(rec[0], rec[1]) max_len = max(max_len, square_len) all_max_lens.append(square_len) counter = 0 for length in all_max_lens: if length == max_len: counter += 1 return counter def count_good_rectangles_optimized(rectangles): max_len, counter = 0, 0 for rec in rectangles: square_len = min(rec[0], rec[1]) if square_len > max_len: max_len = square_len counter = 0 if square_len == max_len: counter += 1 return counter
""" Time Complexity: O(N) Space Complexity: O(N) """ def count_good_rectangles(rectangles): (max_len, all_max_lens) = (0, []) for rec in rectangles: square_len = min(rec[0], rec[1]) max_len = max(max_len, square_len) all_max_lens.append(square_len) counter = 0 for length in all_max_lens: if length == max_len: counter += 1 return counter def count_good_rectangles_optimized(rectangles): (max_len, counter) = (0, 0) for rec in rectangles: square_len = min(rec[0], rec[1]) if square_len > max_len: max_len = square_len counter = 0 if square_len == max_len: counter += 1 return counter
num_to_word = { 0: '', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 50: 'fifty', 60: 'sixty', 70: 'seventy', 80: 'eighty', 90: 'ninety', 100: 'hundred', 1000: 'thousand' } def number_to_word(n): if 20 >= n > 0: return num_to_word[n] # 21 - 99 if n < 100: n_ten = n // 10 n_one = n - (n_ten * 10) return f'{num_to_word[n_ten * 10]} {num_to_word[n_one]}' # 101 - 999 if n < 1000: n_hundred = n // 100 n_ten = (n // 10) - (n_hundred * 10) n_one = n - (n_hundred * 100) - (n_ten * 10) word = f'{num_to_word[n_hundred]} hundred' if n_ten == 0 and n_one == 0: return word elif n_ten == 0 and n_one > 0: word += f' and {num_to_word[n_one]}' elif n_ten == 1 and n_one > 0: word += f' and {num_to_word[10 * n_ten + n_one]}' else: word += f' and {num_to_word[n_ten * 10]} {num_to_word[n_one]}' return word # 1000 if n == 100 or n == 1000: return f'one {num_to_word[n]}' # We don't support anything else :\ return None def count_number_chars(n): word = number_to_word(n) return len(word.replace(' ', '')) def compute(): total = 0 for i in range(1, 1001): print(number_to_word(i)) total += count_number_chars(i) return total if __name__ == '__main__': print(compute())
num_to_word = {0: '', 1: 'one', 2: 'two', 3: 'three', 4: 'four', 5: 'five', 6: 'six', 7: 'seven', 8: 'eight', 9: 'nine', 10: 'ten', 11: 'eleven', 12: 'twelve', 13: 'thirteen', 14: 'fourteen', 15: 'fifteen', 16: 'sixteen', 17: 'seventeen', 18: 'eighteen', 19: 'nineteen', 20: 'twenty', 30: 'thirty', 40: 'forty', 50: 'fifty', 60: 'sixty', 70: 'seventy', 80: 'eighty', 90: 'ninety', 100: 'hundred', 1000: 'thousand'} def number_to_word(n): if 20 >= n > 0: return num_to_word[n] if n < 100: n_ten = n // 10 n_one = n - n_ten * 10 return f'{num_to_word[n_ten * 10]} {num_to_word[n_one]}' if n < 1000: n_hundred = n // 100 n_ten = n // 10 - n_hundred * 10 n_one = n - n_hundred * 100 - n_ten * 10 word = f'{num_to_word[n_hundred]} hundred' if n_ten == 0 and n_one == 0: return word elif n_ten == 0 and n_one > 0: word += f' and {num_to_word[n_one]}' elif n_ten == 1 and n_one > 0: word += f' and {num_to_word[10 * n_ten + n_one]}' else: word += f' and {num_to_word[n_ten * 10]} {num_to_word[n_one]}' return word if n == 100 or n == 1000: return f'one {num_to_word[n]}' return None def count_number_chars(n): word = number_to_word(n) return len(word.replace(' ', '')) def compute(): total = 0 for i in range(1, 1001): print(number_to_word(i)) total += count_number_chars(i) return total if __name__ == '__main__': print(compute())
# 1.2 Check Permutation: # Given two strings, write a method to decide if one is a permutation of the other. # https://github.com/joaomh/Cracking-the-Code-Interview-Python # My solution def Permutation(str1, str2): str1 = str1.lower() str2 = str2.lower() for character in str1: if character is ' ': pass elif character in str2: str2 = str2.replace(character, '', 1) else: return False if len(str2.replace(' ','')) == 0: return True else: return False # Test print("Pass" if Permutation('he llo','elhlo') else "Fail") print("Pass" if Permutation('he was there','theresaweh') else "Fail")
def permutation(str1, str2): str1 = str1.lower() str2 = str2.lower() for character in str1: if character is ' ': pass elif character in str2: str2 = str2.replace(character, '', 1) else: return False if len(str2.replace(' ', '')) == 0: return True else: return False print('Pass' if permutation('he llo', 'elhlo') else 'Fail') print('Pass' if permutation('he was there', 'theresaweh') else 'Fail')
n = int(input()) data = [] for _ in range(n): x, y = map(str, input().split()) data.append([int(x), y]) sorted_data = sorted(data, key=lambda item : item[0]) for x, y in sorted_data: print('{0} {1}'.format(x, y))
n = int(input()) data = [] for _ in range(n): (x, y) = map(str, input().split()) data.append([int(x), y]) sorted_data = sorted(data, key=lambda item: item[0]) for (x, y) in sorted_data: print('{0} {1}'.format(x, y))