Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
460
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.86 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. #coloquei o (object), não sei porque, mas classes recebem isso por padrão
  5. class topicData(object):
  6.   # declarei as paradinhas no construtor pra não dar erro se alguém chamar um
  7.   # get sem ter dado set
  8.   def __init__(self):
  9.     self.board = ''
  10.     self.thread = ''
  11.     self.message = ''
  12.     self.name = ''
  13.     self.email = ''
  14.     self.file = ''
  15.  
  16.   def setBoard(self, board):
  17.     self.board = board
  18.  
  19.   def getBoard(self):
  20.     return self.board
  21.  
  22.   def setThread(self, thread):
  23.     self.thread = thread
  24.  
  25.   def getThread(self):
  26.     return self.thread
  27.  
  28.   def setMessage(self, message):
  29.     self.message = message
  30.  
  31.   def getMessages(self):
  32.     return self.message
  33.  
  34.   def setName(self, name):
  35.     self.name = name
  36.  
  37.   def getName(self):
  38.     return self.name
  39.  
  40.   def setEmail(self, email):
  41.     self.email = email
  42.  
  43.   def getEmail(self):
  44.     return self.email
  45.  
  46.   def setFile(self, filePath):
  47.     self.file = filePath
  48.  
  49.   def getFile(self):
  50.     return self.file
  51.  
  52. class CustomParser:
  53.   def validateARGS(args, argType):
  54.     if (args!=NONE and args!=argType and (args!="-b" and args!="-t" and args!="-m" and args!="-n" and args!="-e" and args!="-f")):
  55.       return TRUE
  56.     elif (args!=NONE and args==argType):
  57.       return TRUE
  58.     else:
  59.       return FALSE
  60.  
  61.   def checkListPOS():
  62.     try:
  63.       if (lista[count]==NONE):
  64.         return TRUE
  65.       else:
  66.         return FALSE
  67.     except:
  68.       return FALSE
  69.  
  70.   def argTypeSET(argType, ptrList, args):
  71.     if(argType=="-b"):
  72.       ptrList.setBoard = args
  73.     elif(argType=="-t"):
  74.       ptrList.setThread = args
  75.     elif(argType=="-m"):
  76.       ptrList.setMessage = args
  77.     elif(argType=="-n"):
  78.       ptrList.setName = args
  79.     elif(argType=="-e"):
  80.       ptrList.setEmail = args
  81.     elif(argType=="-f"):
  82.       ptrList.setFile = args
  83.  
  84.   def parser(argType, argvsub):
  85.     count = 0
  86.     for args in argvsub:
  87.       if (validateARGS(args, argType)):
  88.         bllPOS=checkListaPOS(count)
  89.         if (bllPOS):
  90.           ptrList=topicData()
  91.           self.lista.append( ptrList )
  92.         else:
  93.           ptrList=lista[count]
  94.         count+=1
  95.         argTypeSET(argType, ptrList, args)
  96.       else:
  97.         break
  98.  
  99.   def getList(self):
  100.     return self.lista
  101.  
  102.   def __init__(argsv):
  103.     for args in argv:
  104.       if (args=="-b"):
  105.         parser("-b", args[1:])
  106.       elif (args=="-t"):
  107.         parser("-t", args[1:])
  108.       elif (args=="-m"):
  109.         parser("-m", args[1:])
  110.       elif (args=="-n"):
  111.         parser("-n", args[1:])
  112.       elif (args=="-e"):
  113.         parser("-e", args[1:])
  114.       elif (args=="-f"):
  115.         parser("-f", args[1:])
  116.  
  117. def testarObjeto():
  118.   testOBJ = topicData()
  119.   testOBJ.setBoard="board"
  120.   testOBJ.setThread="threadNumber"
  121.   testOBJ.setMessage="message"
  122.   testOBJ.setName="Nome"
  123.   testOBJ.setEmail="teste@gmail.com"
  124.   testOBJ.setFile="Coisinha.jpg"
  125.  
  126.   # Esse print deve estar zuado
  127.   print("{0}, {1}, {2}, {3}, {4}, {5}".format(testOBJ.getBoard(), testOBJ.getThread(), testOBJ.getMessage(), testOBJ.getEmail(), testOBJ.getFile(), testOBJ.getName()))
  128.  
  129. def testarParser():
  130.   stringteste="python.py -b board1 board2 board3 -t thread1 thread2 thread3 -m oixakulinha1 oixerxinho2 oimiguxinhu3 -e teste1@gmail.com teste2@gmail.com teste3@gmail.com -f arquivo1.jpg, arquivo2.jpg, arquivo3.jpg"
  131.   objParser = CustomParser(stringteste[1:])
  132.   listaTeste = objParser.getLista()
  133.   for listaTST in listaTeste:
  134.     # E esse também
  135.     print("board: {0}\nthread: {1}\nmessage: {2}\nemail: {3}\nfile: {4}\nname: {5}\n\n".format(listaTST.board, listaTST.thread, listaTS.message, listaTST.email, listaTST.file, listaTST.name))
  136.  
  137.  
  138. def testarMODULOS():
  139.   try:
  140.     testarObjeto()
  141.   except:
  142.     print("erro no testarObjeto()")
  143.  
  144.   try:
  145.     testarParser()
  146.   except:
  147.     print("erro no testarParser()")
  148.  
  149.  
  150. print("teste")
  151. testarMODULOS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement