Advertisement
Guest User

Untitled

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