Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.49 KB | None | 0 0
  1. class topicData:
  2.   def setBoard(self, board):
  3.     self.board = board;
  4.  
  5.   def getBoard(self):
  6.     return self.board;
  7.  
  8.   def setThread(self, thread):
  9.     self.thread = thread;
  10.  
  11.   def getThread(self):
  12.     return self.thread;  
  13.  
  14.   def setMessage(self, message):
  15.     self.message = message;
  16.  
  17.   def getMessages(self):
  18.     return self.message;
  19.  
  20.   def setName(self, name):
  21.     self.name = name;
  22.  
  23.   def getName(self):
  24.     return self.name;
  25.  
  26.   def setEmail(self, email):
  27.     self.email = email;
  28.  
  29.   def getEmail(self):
  30.     return self.email;
  31.  
  32.   def setFile(self, filePath):
  33.     self.file = filePath;
  34.  
  35.   def getFile(self):
  36.     return self.file;
  37.  
  38. class CustomParser:
  39.   def validateARGS(args, argType):
  40.     if (args!=NONE and args!=argType and (args!="-b" and args!="-t" and args!="-m" and args!="-n" and args!="-e" and args!="-f")):
  41.       return TRUE;
  42.     elif (args!=NONE and args==argType):
  43.       return TRUE;
  44.     else:
  45.       return FALSE;
  46.  
  47.   def checkListPOS():
  48.     try:
  49.       if (lista[count]==NONE):
  50.         return TRUE;
  51.       else:
  52.         return FALSE;
  53.     except:
  54.       return FALSE;
  55.  
  56.   def argTypeSET(argType, ptrList, args):
  57.     if(argType=="-b"):
  58.       ptrList.setBoard = args;
  59.     elif(argType=="-t"):
  60.       ptrList.setThread = args;
  61.     elif(argType=="-m"):
  62.       ptrList.setMessage = args;
  63.     elif(argType=="-n"):
  64.       ptrList.setName = args;
  65.     elif(argType=="-e"):
  66.       ptrList.setEmail = args;
  67.     elif(argType=="-f"):
  68.       ptrList.setFile = args;
  69.  
  70.   def parser(argType, argvsub):
  71.     count = 0;
  72.     for args in argvsub:
  73.       if (validateARGS(args, argType)):
  74.         bllPOS=checkListaPOS(count);
  75.         if (bllPOS):
  76.           ptrList=topicData()
  77.           self.lista.append( ptrList );
  78.         else:
  79.           ptrList=lista[count];
  80.         count+=1;
  81.         argTypeSET(argType, ptrList, args);
  82.       else:
  83.         break;
  84.  
  85.   def getList(self):
  86.     return self.lista;
  87.  
  88.   def __init__(argsv):
  89.     for args in argv:
  90.       if (args=="-b"):
  91.         parser("-b", args[1:]);
  92.       elif (args=="-t"):
  93.         parser("-t", args[1:]);
  94.       elif (args=="-m"):
  95.         parser("-m", args[1:]);
  96.       elif (args=="-n"):
  97.         parser("-n", args[1:]);
  98.       elif (args=="-e"):
  99.         parser("-e", args[1:]);
  100.       elif (args=="-f"):
  101.         parser("-f", args[1:]);
  102.  
  103. def testarObjeto():
  104.   testOBJ = topicData();
  105.   testeOBJ.setBoard="board";
  106.   testeOBJ.setThread="threadNumber";
  107.   testeOBJ.setMessage="message";
  108.   testeOBJ.setName="Nome";
  109.   testeOBJ.setEmail="teste@gmail.com";
  110.   testeOBJ.setFile="Coisinha.jpg";
  111.   print("{0}, {1}, {2}, {3}, {4}, {5}".format(testeOBJ.getBoard(), testeOBJ.getThread(), testeOBJ.getMessage(), testeOBJ.getEmail(), testeOBJ.getFile(), testeOBJ.getName()));
  112.  
  113. def testarParser():
  114.   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";
  115.   objParser = CustomParser(stringteste[1:]);
  116.   listaTeste = objParser.getLista();
  117.   for listaTST in listaTeste:
  118.     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));
  119.  
  120.  
  121. def testarMODULOS():
  122.   try:
  123.     testarObjeto();
  124.   except:
  125.     print("erro no testarObjeto()");
  126.  
  127.   try:
  128.     testarParser();
  129.   except:
  130.     print("erro no testarParser()");
  131.  
  132.  
  133. print("teste");
  134. testarMODULOS();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement