Best Python code snippet using robotframework
ipums_1940_classes.py
Source:ipums_1940_classes.py
...15 try:16 return float(i)17 except (TypeError, ValueError) as e:18 return None19def safe_str(i):20 try:21 return str(i)22 except (TypeError, ValueError) as e:23 return None24class H_validator:25 @classmethod26 def is_valid_RECTYPE(self,x):27 """Record type"""28 return True29 @classmethod30 def is_valid_YEAR(self,x):31 """Census year"""32 return True33 @classmethod34 def is_valid_DATANUM(self,x):35 """Data set number"""36 return True37 @classmethod38 def is_valid_SERIAL(self,x):39 """Household serial number"""40 return True41 @classmethod42 def is_valid_NUMPREC(self,x):43 """Number of person records following"""44 return True45 @classmethod46 def is_valid_SUBSAMP(self,x):47 """Subsample number"""48 return True49 @classmethod50 def is_valid_HHWT(self,x):51 """Household weight"""52 return True53 @classmethod54 def is_valid_NUMPERHH(self,x):55 """Number of persons in household"""56 return True57 @classmethod58 def is_valid_HHTYPE(self,x):59 """Household Type"""60 return True61 @classmethod62 def is_valid_DWELLING(self,x):63 """Dwelling serial number"""64 return True65 @classmethod66 def is_valid_SLPERNUM(self,x):67 """Sample-line person number"""68 return True69 @classmethod70 def is_valid_CPI99(self,x):71 """CPI-U adjustment factor to 1999 dollars"""72 return True73 @classmethod74 def is_valid_REGION(self,x):75 """Census region and division"""76 return True77 @classmethod78 def is_valid_STATEICP(self,x):79 """State (ICPSR code)"""80 return True81 @classmethod82 def is_valid_STATEFIP(self,x):83 """State (FIPS code)"""84 return True85 @classmethod86 def is_valid_COUNTY(self,x):87 """County"""88 return True89 @classmethod90 def is_valid_URBAN(self,x):91 """Urban/rural status"""92 return True93 @classmethod94 def is_valid_METRO(self,x):95 """Metropolitan status"""96 return True97 @classmethod98 def is_valid_METAREA(self,x):99 """Metropolitan area [general version]"""100 return True101 @classmethod102 def is_valid_METAREAD(self,x):103 """Metropolitan area [detailed version]"""104 return True105 @classmethod106 def is_valid_CITY(self,x):107 """City"""108 return True109 @classmethod110 def is_valid_CITYPOP(self,x):111 """City population"""112 return True113 @classmethod114 def is_valid_SIZEPL(self,x):115 """Size of place"""116 return True117 @classmethod118 def is_valid_URBPOP(self,x):119 """Population of urban places"""120 return True121 @classmethod122 def is_valid_SEA(self,x):123 """State Economic Area"""124 return True125 @classmethod126 def is_valid_WARD(self,x):127 """Ward"""128 return True129 @classmethod130 def is_valid_CNTRY(self,x):131 """Country"""132 return True133 @classmethod134 def is_valid_GQ(self,x):135 """Group quarters status"""136 return True137 @classmethod138 def is_valid_GQTYPE(self,x):139 """Group quarters type [general version]"""140 return True141 @classmethod142 def is_valid_GQTYPED(self,x):143 """Group quarters type [detailed version]"""144 return True145 @classmethod146 def is_valid_GQFUNDS(self,x):147 """Group quarters funding"""148 return True149 @classmethod150 def is_valid_FARM(self,x):151 """Farm status"""152 return True153 @classmethod154 def is_valid_OWNERSHP(self,x):155 """Ownership of dwelling (tenure) [general version]"""156 return True157 @classmethod158 def is_valid_OWNERSHPD(self,x):159 """Ownership of dwelling (tenure) [detailed version]"""160 return True161 @classmethod162 def is_valid_RENT(self,x):163 """Monthly contract rent"""164 return True165 @classmethod166 def is_valid_VALUEH(self,x):167 """House value"""168 return True169 @classmethod170 def is_valid_NFAMS(self,x):171 """Number of families in household"""172 return True173 @classmethod174 def is_valid_NSUBFAM(self,x):175 """Number of subfamilies in household"""176 return True177 @classmethod178 def is_valid_NCOUPLES(self,x):179 """Number of couples in household"""180 return True181 @classmethod182 def is_valid_NMOTHERS(self,x):183 """Number of mothers in household"""184 return True185 @classmethod186 def is_valid_NFATHERS(self,x):187 """Number of fathers in household"""188 return True189 @classmethod190 def is_valid_MULTGEN(self,x):191 """Multigenerational household [general version]"""192 return True193 @classmethod194 def is_valid_MULTGEND(self,x):195 """Multigenerational household [detailed version]"""196 return True197 @classmethod198 def is_valid_ENUMDIST(self,x):199 """Enumeration district"""200 return True201 @classmethod202 def is_valid_SUPDIST(self,x):203 """Supervisor's district number"""204 return True205 @classmethod206 def is_valid_RESPOND(self,x):207 """Respondent's relationship to household head"""208 return True209 @classmethod210 def is_valid_SPLIT(self,x):211 """Large group quarters that was split up (100% datasets)"""212 return True213 @classmethod214 def is_valid_SPLITHID(self,x):215 """Household serial number, before large group quarters were split up (100% datasets)"""216 return True217 @classmethod218 def is_valid_SPLITNUM(self,x):219 """Number of person records in household, before large group quarters were split up (100% datasets)"""220 return True221 @classmethod222 def is_valid_SPLIT40(self,x):223 """Large group quarters that was split up, 1940 100%"""224 return True225 @classmethod226 def is_valid_SERIAL40(self,x):227 """Household serial number, before large group quarters were split up, 1940 100%"""228 return True229 @classmethod230 def is_valid_NUMPREC40(self,x):231 """Number of person records in household, before large group quarters were split up, 1940 100%"""232 return True233 @classmethod234 def is_valid_EDMISS(self,x):235 """Identifies households in missing data enumeration districts"""236 return True237 @classmethod238 def validate_pipe_delimited(self,x):239 fields = x.split('|')240 if len(fields)!=53: return False241 if is_valid_RECTYPE(fields[1]) == False: return False242 if is_valid_YEAR(fields[2]) == False: return False243 if is_valid_DATANUM(fields[3]) == False: return False244 if is_valid_SERIAL(fields[4]) == False: return False245 if is_valid_NUMPREC(fields[5]) == False: return False246 if is_valid_SUBSAMP(fields[6]) == False: return False247 if is_valid_HHWT(fields[7]) == False: return False248 if is_valid_NUMPERHH(fields[8]) == False: return False249 if is_valid_HHTYPE(fields[9]) == False: return False250 if is_valid_DWELLING(fields[10]) == False: return False251 if is_valid_SLPERNUM(fields[11]) == False: return False252 if is_valid_CPI99(fields[12]) == False: return False253 if is_valid_REGION(fields[13]) == False: return False254 if is_valid_STATEICP(fields[14]) == False: return False255 if is_valid_STATEFIP(fields[15]) == False: return False256 if is_valid_COUNTY(fields[16]) == False: return False257 if is_valid_URBAN(fields[17]) == False: return False258 if is_valid_METRO(fields[18]) == False: return False259 if is_valid_METAREA(fields[19]) == False: return False260 if is_valid_METAREAD(fields[20]) == False: return False261 if is_valid_CITY(fields[21]) == False: return False262 if is_valid_CITYPOP(fields[22]) == False: return False263 if is_valid_SIZEPL(fields[23]) == False: return False264 if is_valid_URBPOP(fields[24]) == False: return False265 if is_valid_SEA(fields[25]) == False: return False266 if is_valid_WARD(fields[26]) == False: return False267 if is_valid_CNTRY(fields[27]) == False: return False268 if is_valid_GQ(fields[28]) == False: return False269 if is_valid_GQTYPE(fields[29]) == False: return False270 if is_valid_GQTYPED(fields[30]) == False: return False271 if is_valid_GQFUNDS(fields[31]) == False: return False272 if is_valid_FARM(fields[32]) == False: return False273 if is_valid_OWNERSHP(fields[33]) == False: return False274 if is_valid_OWNERSHPD(fields[34]) == False: return False275 if is_valid_RENT(fields[35]) == False: return False276 if is_valid_VALUEH(fields[36]) == False: return False277 if is_valid_NFAMS(fields[37]) == False: return False278 if is_valid_NSUBFAM(fields[38]) == False: return False279 if is_valid_NCOUPLES(fields[39]) == False: return False280 if is_valid_NMOTHERS(fields[40]) == False: return False281 if is_valid_NFATHERS(fields[41]) == False: return False282 if is_valid_MULTGEN(fields[42]) == False: return False283 if is_valid_MULTGEND(fields[43]) == False: return False284 if is_valid_ENUMDIST(fields[44]) == False: return False285 if is_valid_SUPDIST(fields[45]) == False: return False286 if is_valid_RESPOND(fields[46]) == False: return False287 if is_valid_SPLIT(fields[47]) == False: return False288 if is_valid_SPLITHID(fields[48]) == False: return False289 if is_valid_SPLITNUM(fields[49]) == False: return False290 if is_valid_SPLIT40(fields[50]) == False: return False291 if is_valid_SERIAL40(fields[51]) == False: return False292 if is_valid_NUMPREC40(fields[52]) == False: return False293 if is_valid_EDMISS(fields[53]) == False: return False294 return True295class H:296 __slots__ = ['RECTYPE', 'YEAR', 'DATANUM', 'SERIAL', 'NUMPREC', 'SUBSAMP', 'HHWT', 'NUMPERHH', 'HHTYPE', 'DWELLING', 'SLPERNUM', 'CPI99', 'REGION', 'STATEICP', 'STATEFIP', 'COUNTY', 'URBAN', 'METRO', 'METAREA', 'METAREAD', 'CITY', 'CITYPOP', 'SIZEPL', 'URBPOP', 'SEA', 'WARD', 'CNTRY', 'GQ', 'GQTYPE', 'GQTYPED', 'GQFUNDS', 'FARM', 'OWNERSHP', 'OWNERSHPD', 'RENT', 'VALUEH', 'NFAMS', 'NSUBFAM', 'NCOUPLES', 'NMOTHERS', 'NFATHERS', 'MULTGEN', 'MULTGEND', 'ENUMDIST', 'SUPDIST', 'RESPOND', 'SPLIT', 'SPLITHID', 'SPLITNUM', 'SPLIT40', 'SERIAL40', 'NUMPREC40', 'EDMISS']297 def __repr__(self):298 return 'H<RECTYPE:{},YEAR:{},DATANUM:{},SERIAL:{},NUMPREC:{},SUBSAMP:{},HHWT:{},NUMPERHH:{},HHTYPE:{},DWELLING:{},SLPERNUM:{},CPI99:{},REGION:{},STATEICP:{},STATEFIP:{},COUNTY:{},URBAN:{},METRO:{},METAREA:{},METAREAD:{},CITY:{},CITYPOP:{},SIZEPL:{},URBPOP:{},SEA:{},WARD:{},CNTRY:{},GQ:{},GQTYPE:{},GQTYPED:{},GQFUNDS:{},FARM:{},OWNERSHP:{},OWNERSHPD:{},RENT:{},VALUEH:{},NFAMS:{},NSUBFAM:{},NCOUPLES:{},NMOTHERS:{},NFATHERS:{},MULTGEN:{},MULTGEND:{},ENUMDIST:{},SUPDIST:{},RESPOND:{},SPLIT:{},SPLITHID:{},SPLITNUM:{},SPLIT40:{},SERIAL40:{},NUMPREC40:{},EDMISS:{}>'.format(self.RECTYPE,self.YEAR,self.DATANUM,self.SERIAL,self.NUMPREC,self.SUBSAMP,self.HHWT,self.NUMPERHH,self.HHTYPE,self.DWELLING,self.SLPERNUM,self.CPI99,self.REGION,self.STATEICP,self.STATEFIP,self.COUNTY,self.URBAN,self.METRO,self.METAREA,self.METAREAD,self.CITY,self.CITYPOP,self.SIZEPL,self.URBPOP,self.SEA,self.WARD,self.CNTRY,self.GQ,self.GQTYPE,self.GQTYPED,self.GQFUNDS,self.FARM,self.OWNERSHP,self.OWNERSHPD,self.RENT,self.VALUEH,self.NFAMS,self.NSUBFAM,self.NCOUPLES,self.NMOTHERS,self.NFATHERS,self.MULTGEN,self.MULTGEND,self.ENUMDIST,self.SUPDIST,self.RESPOND,self.SPLIT,self.SPLITHID,self.SPLITNUM,self.SPLIT40,self.SERIAL40,self.NUMPREC40,self.EDMISS)299 def __init__(self,line=None):300 if line: 301 if '|' in line: 302 self.parse_pipe_delimited(line)303 else:304 self.parse_position_specified(line)305 @classmethod306 def name(self):307 return 'H'308 def parse_pipe_delimited(self,line):309 fields = line.split('|')310 if len(fields)!=53:311 raise ValueError(f'expected 53 fields, found {len(fields)}')312 self.RECTYPE = fields[0]313 self.YEAR = fields[1]314 self.DATANUM = fields[2]315 self.SERIAL = fields[3]316 self.NUMPREC = fields[4]317 self.SUBSAMP = fields[5]318 self.HHWT = fields[6]319 self.NUMPERHH = fields[7]320 self.HHTYPE = fields[8]321 self.DWELLING = fields[9]322 self.SLPERNUM = fields[10]323 self.CPI99 = fields[11]324 self.REGION = fields[12]325 self.STATEICP = fields[13]326 self.STATEFIP = fields[14]327 self.COUNTY = fields[15]328 self.URBAN = fields[16]329 self.METRO = fields[17]330 self.METAREA = fields[18]331 self.METAREAD = fields[19]332 self.CITY = fields[20]333 self.CITYPOP = fields[21]334 self.SIZEPL = fields[22]335 self.URBPOP = fields[23]336 self.SEA = fields[24]337 self.WARD = fields[25]338 self.CNTRY = fields[26]339 self.GQ = fields[27]340 self.GQTYPE = fields[28]341 self.GQTYPED = fields[29]342 self.GQFUNDS = fields[30]343 self.FARM = fields[31]344 self.OWNERSHP = fields[32]345 self.OWNERSHPD = fields[33]346 self.RENT = fields[34]347 self.VALUEH = fields[35]348 self.NFAMS = fields[36]349 self.NSUBFAM = fields[37]350 self.NCOUPLES = fields[38]351 self.NMOTHERS = fields[39]352 self.NFATHERS = fields[40]353 self.MULTGEN = fields[41]354 self.MULTGEND = fields[42]355 self.ENUMDIST = fields[43]356 self.SUPDIST = fields[44]357 self.RESPOND = fields[45]358 self.SPLIT = fields[46]359 self.SPLITHID = fields[47]360 self.SPLITNUM = fields[48]361 self.SPLIT40 = fields[49]362 self.SERIAL40 = fields[50]363 self.NUMPREC40 = fields[51]364 self.EDMISS = fields[52]365 def parse_position_specified(self,line):366 self.RECTYPE = line[0:1]367 self.YEAR = line[1:5]368 self.DATANUM = line[5:7]369 self.SERIAL = line[7:15]370 self.NUMPREC = line[15:17]371 self.SUBSAMP = line[17:19]372 self.HHWT = line[19:29]373 self.NUMPERHH = line[29:33]374 self.HHTYPE = line[33:34]375 self.DWELLING = line[34:42]376 self.SLPERNUM = line[42:44]377 self.CPI99 = line[44:49]378 self.REGION = line[49:51]379 self.STATEICP = line[51:53]380 self.STATEFIP = line[53:55]381 self.COUNTY = line[55:59]382 self.URBAN = line[59:60]383 self.METRO = line[60:61]384 self.METAREA = line[61:64]385 self.METAREAD = line[64:68]386 self.CITY = line[68:72]387 self.CITYPOP = line[72:77]388 self.SIZEPL = line[77:79]389 self.URBPOP = line[79:84]390 self.SEA = line[84:87]391 self.WARD = line[87:90]392 self.CNTRY = line[90:93]393 self.GQ = line[93:94]394 self.GQTYPE = line[94:95]395 self.GQTYPED = line[95:98]396 self.GQFUNDS = line[98:100]397 self.FARM = line[100:101]398 self.OWNERSHP = line[101:102]399 self.OWNERSHPD = line[102:104]400 self.RENT = line[104:108]401 self.VALUEH = line[108:115]402 self.NFAMS = line[115:117]403 self.NSUBFAM = line[117:118]404 self.NCOUPLES = line[118:119]405 self.NMOTHERS = line[119:120]406 self.NFATHERS = line[120:121]407 self.MULTGEN = line[121:122]408 self.MULTGEND = line[122:124]409 self.ENUMDIST = line[124:128]410 self.SUPDIST = line[128:131]411 self.RESPOND = line[131:132]412 self.SPLIT = line[132:133]413 self.SPLITHID = line[133:141]414 self.SPLITNUM = line[141:145]415 self.SPLIT40 = line[145:146]416 self.SERIAL40 = line[146:154]417 self.NUMPREC40 = line[154:158]418 self.EDMISS = line[158:159]419 def validate(self):420 """Return True if the object data validates"""421 if not H_validator.is_valid_RECTYPE(self.RECTYPE): return False422 if not H_validator.is_valid_YEAR(self.YEAR): return False423 if not H_validator.is_valid_DATANUM(self.DATANUM): return False424 if not H_validator.is_valid_SERIAL(self.SERIAL): return False425 if not H_validator.is_valid_NUMPREC(self.NUMPREC): return False426 if not H_validator.is_valid_SUBSAMP(self.SUBSAMP): return False427 if not H_validator.is_valid_HHWT(self.HHWT): return False428 if not H_validator.is_valid_NUMPERHH(self.NUMPERHH): return False429 if not H_validator.is_valid_HHTYPE(self.HHTYPE): return False430 if not H_validator.is_valid_DWELLING(self.DWELLING): return False431 if not H_validator.is_valid_SLPERNUM(self.SLPERNUM): return False432 if not H_validator.is_valid_CPI99(self.CPI99): return False433 if not H_validator.is_valid_REGION(self.REGION): return False434 if not H_validator.is_valid_STATEICP(self.STATEICP): return False435 if not H_validator.is_valid_STATEFIP(self.STATEFIP): return False436 if not H_validator.is_valid_COUNTY(self.COUNTY): return False437 if not H_validator.is_valid_URBAN(self.URBAN): return False438 if not H_validator.is_valid_METRO(self.METRO): return False439 if not H_validator.is_valid_METAREA(self.METAREA): return False440 if not H_validator.is_valid_METAREAD(self.METAREAD): return False441 if not H_validator.is_valid_CITY(self.CITY): return False442 if not H_validator.is_valid_CITYPOP(self.CITYPOP): return False443 if not H_validator.is_valid_SIZEPL(self.SIZEPL): return False444 if not H_validator.is_valid_URBPOP(self.URBPOP): return False445 if not H_validator.is_valid_SEA(self.SEA): return False446 if not H_validator.is_valid_WARD(self.WARD): return False447 if not H_validator.is_valid_CNTRY(self.CNTRY): return False448 if not H_validator.is_valid_GQ(self.GQ): return False449 if not H_validator.is_valid_GQTYPE(self.GQTYPE): return False450 if not H_validator.is_valid_GQTYPED(self.GQTYPED): return False451 if not H_validator.is_valid_GQFUNDS(self.GQFUNDS): return False452 if not H_validator.is_valid_FARM(self.FARM): return False453 if not H_validator.is_valid_OWNERSHP(self.OWNERSHP): return False454 if not H_validator.is_valid_OWNERSHPD(self.OWNERSHPD): return False455 if not H_validator.is_valid_RENT(self.RENT): return False456 if not H_validator.is_valid_VALUEH(self.VALUEH): return False457 if not H_validator.is_valid_NFAMS(self.NFAMS): return False458 if not H_validator.is_valid_NSUBFAM(self.NSUBFAM): return False459 if not H_validator.is_valid_NCOUPLES(self.NCOUPLES): return False460 if not H_validator.is_valid_NMOTHERS(self.NMOTHERS): return False461 if not H_validator.is_valid_NFATHERS(self.NFATHERS): return False462 if not H_validator.is_valid_MULTGEN(self.MULTGEN): return False463 if not H_validator.is_valid_MULTGEND(self.MULTGEND): return False464 if not H_validator.is_valid_ENUMDIST(self.ENUMDIST): return False465 if not H_validator.is_valid_SUPDIST(self.SUPDIST): return False466 if not H_validator.is_valid_RESPOND(self.RESPOND): return False467 if not H_validator.is_valid_SPLIT(self.SPLIT): return False468 if not H_validator.is_valid_SPLITHID(self.SPLITHID): return False469 if not H_validator.is_valid_SPLITNUM(self.SPLITNUM): return False470 if not H_validator.is_valid_SPLIT40(self.SPLIT40): return False471 if not H_validator.is_valid_SERIAL40(self.SERIAL40): return False472 if not H_validator.is_valid_NUMPREC40(self.NUMPREC40): return False473 if not H_validator.is_valid_EDMISS(self.EDMISS): return False474 return True475 def validate_reason(self):476 reason=[]477 if not H_validator.is_valid_RECTYPE(self.RECTYPE): reason.append('RECTYPE ('+str(self.RECTYPE)+') out of range ()')478 if not H_validator.is_valid_YEAR(self.YEAR): reason.append('YEAR ('+str(self.YEAR)+') out of range ()')479 if not H_validator.is_valid_DATANUM(self.DATANUM): reason.append('DATANUM ('+str(self.DATANUM)+') out of range ()')480 if not H_validator.is_valid_SERIAL(self.SERIAL): reason.append('SERIAL ('+str(self.SERIAL)+') out of range ()')481 if not H_validator.is_valid_NUMPREC(self.NUMPREC): reason.append('NUMPREC ('+str(self.NUMPREC)+') out of range ()')482 if not H_validator.is_valid_SUBSAMP(self.SUBSAMP): reason.append('SUBSAMP ('+str(self.SUBSAMP)+') out of range ()')483 if not H_validator.is_valid_HHWT(self.HHWT): reason.append('HHWT ('+str(self.HHWT)+') out of range ()')484 if not H_validator.is_valid_NUMPERHH(self.NUMPERHH): reason.append('NUMPERHH ('+str(self.NUMPERHH)+') out of range ()')485 if not H_validator.is_valid_HHTYPE(self.HHTYPE): reason.append('HHTYPE ('+str(self.HHTYPE)+') out of range ()')486 if not H_validator.is_valid_DWELLING(self.DWELLING): reason.append('DWELLING ('+str(self.DWELLING)+') out of range ()')487 if not H_validator.is_valid_SLPERNUM(self.SLPERNUM): reason.append('SLPERNUM ('+str(self.SLPERNUM)+') out of range ()')488 if not H_validator.is_valid_CPI99(self.CPI99): reason.append('CPI99 ('+str(self.CPI99)+') out of range ()')489 if not H_validator.is_valid_REGION(self.REGION): reason.append('REGION ('+str(self.REGION)+') out of range ()')490 if not H_validator.is_valid_STATEICP(self.STATEICP): reason.append('STATEICP ('+str(self.STATEICP)+') out of range ()')491 if not H_validator.is_valid_STATEFIP(self.STATEFIP): reason.append('STATEFIP ('+str(self.STATEFIP)+') out of range ()')492 if not H_validator.is_valid_COUNTY(self.COUNTY): reason.append('COUNTY ('+str(self.COUNTY)+') out of range ()')493 if not H_validator.is_valid_URBAN(self.URBAN): reason.append('URBAN ('+str(self.URBAN)+') out of range ()')494 if not H_validator.is_valid_METRO(self.METRO): reason.append('METRO ('+str(self.METRO)+') out of range ()')495 if not H_validator.is_valid_METAREA(self.METAREA): reason.append('METAREA ('+str(self.METAREA)+') out of range ()')496 if not H_validator.is_valid_METAREAD(self.METAREAD): reason.append('METAREAD ('+str(self.METAREAD)+') out of range ()')497 if not H_validator.is_valid_CITY(self.CITY): reason.append('CITY ('+str(self.CITY)+') out of range ()')498 if not H_validator.is_valid_CITYPOP(self.CITYPOP): reason.append('CITYPOP ('+str(self.CITYPOP)+') out of range ()')499 if not H_validator.is_valid_SIZEPL(self.SIZEPL): reason.append('SIZEPL ('+str(self.SIZEPL)+') out of range ()')500 if not H_validator.is_valid_URBPOP(self.URBPOP): reason.append('URBPOP ('+str(self.URBPOP)+') out of range ()')501 if not H_validator.is_valid_SEA(self.SEA): reason.append('SEA ('+str(self.SEA)+') out of range ()')502 if not H_validator.is_valid_WARD(self.WARD): reason.append('WARD ('+str(self.WARD)+') out of range ()')503 if not H_validator.is_valid_CNTRY(self.CNTRY): reason.append('CNTRY ('+str(self.CNTRY)+') out of range ()')504 if not H_validator.is_valid_GQ(self.GQ): reason.append('GQ ('+str(self.GQ)+') out of range ()')505 if not H_validator.is_valid_GQTYPE(self.GQTYPE): reason.append('GQTYPE ('+str(self.GQTYPE)+') out of range ()')506 if not H_validator.is_valid_GQTYPED(self.GQTYPED): reason.append('GQTYPED ('+str(self.GQTYPED)+') out of range ()')507 if not H_validator.is_valid_GQFUNDS(self.GQFUNDS): reason.append('GQFUNDS ('+str(self.GQFUNDS)+') out of range ()')508 if not H_validator.is_valid_FARM(self.FARM): reason.append('FARM ('+str(self.FARM)+') out of range ()')509 if not H_validator.is_valid_OWNERSHP(self.OWNERSHP): reason.append('OWNERSHP ('+str(self.OWNERSHP)+') out of range ()')510 if not H_validator.is_valid_OWNERSHPD(self.OWNERSHPD): reason.append('OWNERSHPD ('+str(self.OWNERSHPD)+') out of range ()')511 if not H_validator.is_valid_RENT(self.RENT): reason.append('RENT ('+str(self.RENT)+') out of range ()')512 if not H_validator.is_valid_VALUEH(self.VALUEH): reason.append('VALUEH ('+str(self.VALUEH)+') out of range ()')513 if not H_validator.is_valid_NFAMS(self.NFAMS): reason.append('NFAMS ('+str(self.NFAMS)+') out of range ()')514 if not H_validator.is_valid_NSUBFAM(self.NSUBFAM): reason.append('NSUBFAM ('+str(self.NSUBFAM)+') out of range ()')515 if not H_validator.is_valid_NCOUPLES(self.NCOUPLES): reason.append('NCOUPLES ('+str(self.NCOUPLES)+') out of range ()')516 if not H_validator.is_valid_NMOTHERS(self.NMOTHERS): reason.append('NMOTHERS ('+str(self.NMOTHERS)+') out of range ()')517 if not H_validator.is_valid_NFATHERS(self.NFATHERS): reason.append('NFATHERS ('+str(self.NFATHERS)+') out of range ()')518 if not H_validator.is_valid_MULTGEN(self.MULTGEN): reason.append('MULTGEN ('+str(self.MULTGEN)+') out of range ()')519 if not H_validator.is_valid_MULTGEND(self.MULTGEND): reason.append('MULTGEND ('+str(self.MULTGEND)+') out of range ()')520 if not H_validator.is_valid_ENUMDIST(self.ENUMDIST): reason.append('ENUMDIST ('+str(self.ENUMDIST)+') out of range ()')521 if not H_validator.is_valid_SUPDIST(self.SUPDIST): reason.append('SUPDIST ('+str(self.SUPDIST)+') out of range ()')522 if not H_validator.is_valid_RESPOND(self.RESPOND): reason.append('RESPOND ('+str(self.RESPOND)+') out of range ()')523 if not H_validator.is_valid_SPLIT(self.SPLIT): reason.append('SPLIT ('+str(self.SPLIT)+') out of range ()')524 if not H_validator.is_valid_SPLITHID(self.SPLITHID): reason.append('SPLITHID ('+str(self.SPLITHID)+') out of range ()')525 if not H_validator.is_valid_SPLITNUM(self.SPLITNUM): reason.append('SPLITNUM ('+str(self.SPLITNUM)+') out of range ()')526 if not H_validator.is_valid_SPLIT40(self.SPLIT40): reason.append('SPLIT40 ('+str(self.SPLIT40)+') out of range ()')527 if not H_validator.is_valid_SERIAL40(self.SERIAL40): reason.append('SERIAL40 ('+str(self.SERIAL40)+') out of range ()')528 if not H_validator.is_valid_NUMPREC40(self.NUMPREC40): reason.append('NUMPREC40 ('+str(self.NUMPREC40)+') out of range ()')529 if not H_validator.is_valid_EDMISS(self.EDMISS): reason.append('EDMISS ('+str(self.EDMISS)+') out of range ()')530 return ', '.join(reason)531 def SparkSQLRow(self):532 """Return a SparkSQL Row object for this object."""533 from pyspark.sql import Row534 return Row(535 rectype=safe_str(self.RECTYPE),536 year=safe_str(self.YEAR),537 datanum=safe_str(self.DATANUM),538 serial=safe_str(self.SERIAL),539 numprec=safe_str(self.NUMPREC),540 subsamp=safe_str(self.SUBSAMP),541 hhwt=safe_str(self.HHWT),542 numperhh=safe_str(self.NUMPERHH),543 hhtype=safe_str(self.HHTYPE),544 dwelling=safe_str(self.DWELLING),545 slpernum=safe_str(self.SLPERNUM),546 cpi99=safe_str(self.CPI99),547 region=safe_str(self.REGION),548 stateicp=safe_str(self.STATEICP),549 statefip=safe_str(self.STATEFIP),550 county=safe_str(self.COUNTY),551 urban=safe_str(self.URBAN),552 metro=safe_str(self.METRO),553 metarea=safe_str(self.METAREA),554 metaread=safe_str(self.METAREAD),555 city=safe_str(self.CITY),556 citypop=safe_str(self.CITYPOP),557 sizepl=safe_str(self.SIZEPL),558 urbpop=safe_str(self.URBPOP),559 sea=safe_str(self.SEA),560 ward=safe_str(self.WARD),561 cntry=safe_str(self.CNTRY),562 gq=safe_str(self.GQ),563 gqtype=safe_str(self.GQTYPE),564 gqtyped=safe_str(self.GQTYPED),565 gqfunds=safe_str(self.GQFUNDS),566 farm=safe_str(self.FARM),567 ownershp=safe_str(self.OWNERSHP),568 ownershpd=safe_str(self.OWNERSHPD),569 rent=safe_str(self.RENT),570 valueh=safe_str(self.VALUEH),571 nfams=safe_str(self.NFAMS),572 nsubfam=safe_str(self.NSUBFAM),573 ncouples=safe_str(self.NCOUPLES),574 nmothers=safe_str(self.NMOTHERS),575 nfathers=safe_str(self.NFATHERS),576 multgen=safe_str(self.MULTGEN),577 multgend=safe_str(self.MULTGEND),578 enumdist=safe_str(self.ENUMDIST),579 supdist=safe_str(self.SUPDIST),580 respond=safe_str(self.RESPOND),581 split=safe_str(self.SPLIT),582 splithid=safe_str(self.SPLITHID),583 splitnum=safe_str(self.SPLITNUM),584 split40=safe_str(self.SPLIT40),585 serial40=safe_str(self.SERIAL40),586 numprec40=safe_str(self.NUMPREC40),587 edmiss=safe_str(self.EDMISS),588 )589def leftpad(x,width):590 return ' '*(width-len(str(x)))+str(x)591def between(a,b,c,width):592 return leftpad(a,width) <= leftpad(b,width) <= leftpad(c,width)593def safe_int(i):594 try:595 return int(i)596 except (TypeError, ValueError) as e:597 return None598def safe_float(i):599 try:600 return float(i)601 except (TypeError, ValueError) as e:602 return None603def safe_str(i):604 try:605 return str(i)606 except (TypeError, ValueError) as e:607 return None608class P_validator:609 @classmethod610 def is_valid_RECTYPE(self,x):611 """Record type"""612 return True613 @classmethod614 def is_valid_YEAR(self,x):615 """Census year"""616 return True617 @classmethod618 def is_valid_DATANUM(self,x):619 """Data set number"""620 return True621 @classmethod622 def is_valid_SERIAL(self,x):623 """Household serial number"""624 return True625 @classmethod626 def is_valid_PERNUM(self,x):627 """Person number in sample unit"""628 return True629 @classmethod630 def is_valid_PERWT(self,x):631 """Person weight"""632 return True633 @classmethod634 def is_valid_SLWT(self,x):635 """Sample-line weight"""636 return True637 @classmethod638 def is_valid_SLREC(self,x):639 """Sample-line person identifier"""640 return True641 @classmethod642 def is_valid_RESPONDT(self,x):643 """Respondent indicator"""644 return True645 @classmethod646 def is_valid_FAMUNIT(self,x):647 """Family unit membership"""648 return True649 @classmethod650 def is_valid_FAMSIZE(self,x):651 """Number of own family members in household"""652 return True653 @classmethod654 def is_valid_SUBFAM(self,x):655 """Subfamily membership"""656 return True657 @classmethod658 def is_valid_SFTYPE(self,x):659 """Subfamily type"""660 return True661 @classmethod662 def is_valid_SFRELATE(self,x):663 """Relationship within subfamily"""664 return True665 @classmethod666 def is_valid_MOMLOC(self,x):667 """Mother's location in the household"""668 return True669 @classmethod670 def is_valid_STEPMOM(self,x):671 """Probable step/adopted mother"""672 return True673 @classmethod674 def is_valid_MOMRULE_HIST(self,x):675 """"""676 return True677 @classmethod678 def is_valid_POPLOC(self,x):679 """Father's location in the household"""680 return True681 @classmethod682 def is_valid_STEPPOP(self,x):683 """Probable step/adopted father"""684 return True685 @classmethod686 def is_valid_POPRULE_HIST(self,x):687 """"""688 return True689 @classmethod690 def is_valid_SPLOC(self,x):691 """Spouse's location in household"""692 return True693 @classmethod694 def is_valid_SPRULE_HIST(self,x):695 """"""696 return True697 @classmethod698 def is_valid_NCHILD(self,x):699 """Number of own children in the household"""700 return True701 @classmethod702 def is_valid_NCHLT5(self,x):703 """Number of own children under age 5 in household"""704 return True705 @classmethod706 def is_valid_NSIBS(self,x):707 """Number of own siblings in household"""708 return True709 @classmethod710 def is_valid_ELDCH(self,x):711 """Age of eldest own child in household"""712 return True713 @classmethod714 def is_valid_YNGCH(self,x):715 """Age of youngest own child in household"""716 return True717 @classmethod718 def is_valid_RELATE(self,x):719 """Relationship to household head [general version]"""720 return True721 @classmethod722 def is_valid_RELATED(self,x):723 """Relationship to household head [detailed version]"""724 return True725 @classmethod726 def is_valid_SEX(self,x):727 """Sex"""728 return True729 @classmethod730 def is_valid_AGE(self,x):731 """Age"""732 return True733 @classmethod734 def is_valid_AGEMONTH(self,x):735 """Age in months"""736 return True737 @classmethod738 def is_valid_MARST(self,x):739 """Marital status"""740 return True741 @classmethod742 def is_valid_MARRNO(self,x):743 """Times married"""744 return True745 @classmethod746 def is_valid_AGEMARR(self,x):747 """Age at first marriage"""748 return True749 @classmethod750 def is_valid_CHBORN(self,x):751 """Children ever born"""752 return True753 @classmethod754 def is_valid_RACE(self,x):755 """Race [general version]"""756 return True757 @classmethod758 def is_valid_RACED(self,x):759 """Race [detailed version]"""760 return True761 @classmethod762 def is_valid_HISPAN(self,x):763 """Hispanic origin [general version]"""764 return True765 @classmethod766 def is_valid_HISPAND(self,x):767 """Hispanic origin [detailed version]"""768 return True769 @classmethod770 def is_valid_BPL(self,x):771 """Birthplace [general version]"""772 return True773 @classmethod774 def is_valid_BPLD(self,x):775 """Birthplace [detailed version]"""776 return True777 @classmethod778 def is_valid_MBPL(self,x):779 """Mother's birthplace [general version]"""780 return True781 @classmethod782 def is_valid_MBPLD(self,x):783 """Mother's birthplace [detailed version]"""784 return True785 @classmethod786 def is_valid_FBPL(self,x):787 """Father's birthplace [general version]"""788 return True789 @classmethod790 def is_valid_FBPLD(self,x):791 """Father's birthplace [detailed version]"""792 return True793 @classmethod794 def is_valid_NATIVITY(self,x):795 """Foreign birthplace or parentage"""796 return True797 @classmethod798 def is_valid_CITIZEN(self,x):799 """Citizenship status"""800 return True801 @classmethod802 def is_valid_MTONGUE(self,x):803 """Mother tongue [general version]"""804 return True805 @classmethod806 def is_valid_MTONGUED(self,x):807 """Mother tongue [detailed version]"""808 return True809 @classmethod810 def is_valid_SPANNAME(self,x):811 """Spanish surname"""812 return True813 @classmethod814 def is_valid_HISPRULE(self,x):815 """Hispanic origin rule"""816 return True817 @classmethod818 def is_valid_SCHOOL(self,x):819 """School attendance"""820 return True821 @classmethod822 def is_valid_HIGRADE(self,x):823 """Highest grade of schooling [general version]"""824 return True825 @classmethod826 def is_valid_HIGRADED(self,x):827 """Highest grade of schooling [detailed version]"""828 return True829 @classmethod830 def is_valid_EDUC(self,x):831 """Educational attainment [general version]"""832 return True833 @classmethod834 def is_valid_EDUCD(self,x):835 """Educational attainment [detailed version]"""836 return True837 @classmethod838 def is_valid_EMPSTAT(self,x):839 """Employment status [general version]"""840 return True841 @classmethod842 def is_valid_EMPSTATD(self,x):843 """Employment status [detailed version]"""844 return True845 @classmethod846 def is_valid_LABFORCE(self,x):847 """Labor force status"""848 return True849 @classmethod850 def is_valid_OCC(self,x):851 """Occupation"""852 return True853 @classmethod854 def is_valid_OCC1950(self,x):855 """Occupation, 1950 basis"""856 return True857 @classmethod858 def is_valid_IND(self,x):859 """Industry"""860 return True861 @classmethod862 def is_valid_IND1950(self,x):863 """Industry, 1950 basis"""864 return True865 @classmethod866 def is_valid_CLASSWKR(self,x):867 """Class of worker [general version]"""868 return True869 @classmethod870 def is_valid_CLASSWKRD(self,x):871 """Class of worker [detailed version]"""872 return True873 @classmethod874 def is_valid_WKSWORK1(self,x):875 """Weeks worked last year"""876 return True877 @classmethod878 def is_valid_WKSWORK2(self,x):879 """Weeks worked last year, intervalled"""880 return True881 @classmethod882 def is_valid_HRSWORK1(self,x):883 """Hours worked last week"""884 return True885 @classmethod886 def is_valid_HRSWORK2(self,x):887 """Hours worked last week, intervalled"""888 return True889 @classmethod890 def is_valid_DURUNEMP(self,x):891 """Continuous weeks unemployed"""892 return True893 @classmethod894 def is_valid_UOCC(self,x):895 """Usual occupation"""896 return True897 @classmethod898 def is_valid_UOCC95(self,x):899 """Usual occupation, 1950 classification"""900 return True901 @classmethod902 def is_valid_UIND(self,x):903 """Usual industry"""904 return True905 @classmethod906 def is_valid_UCLASSWK(self,x):907 """Usual class of worker"""908 return True909 @classmethod910 def is_valid_INCWAGE(self,x):911 """Wage and salary income"""912 return True913 @classmethod914 def is_valid_INCNONWG(self,x):915 """Had non-wage/salary income over $50"""916 return True917 @classmethod918 def is_valid_OCCSCORE(self,x):919 """Occupational income score"""920 return True921 @classmethod922 def is_valid_SEI(self,x):923 """Duncan Socioeconomic Index"""924 return True925 @classmethod926 def is_valid_PRESGL(self,x):927 """Occupational prestige score, Siegel"""928 return True929 @classmethod930 def is_valid_ERSCOR50(self,x):931 """Occupational earnings score, 1950 basis"""932 return True933 @classmethod934 def is_valid_EDSCOR50(self,x):935 """Occupational education score, 1950 basis"""936 return True937 @classmethod938 def is_valid_NPBOSS50(self,x):939 """Nam-Powers-Boyd occupational status score, 1950 basis"""940 return True941 @classmethod942 def is_valid_MIGRATE5(self,x):943 """Migration status, 5 years [general version]"""944 return True945 @classmethod946 def is_valid_MIGRATE5D(self,x):947 """Migration status, 5 years [detailed version]"""948 return True949 @classmethod950 def is_valid_MIGPLAC5(self,x):951 """State or country of residence 5 years ago"""952 return True953 @classmethod954 def is_valid_MIGMET5(self,x):955 """Metropolitan area of residence 5 years ago"""956 return True957 @classmethod958 def is_valid_MIGTYPE5(self,x):959 """Metropolitan status 5 years ago"""960 return True961 @classmethod962 def is_valid_MIGCITY5(self,x):963 """City of residence 5 years ago"""964 return True965 @classmethod966 def is_valid_MIGSEA5(self,x):967 """SEA of residence 5 years ago"""968 return True969 @classmethod970 def is_valid_SAMEPLAC(self,x):971 """Lived same incorporated place 5 years ago"""972 return True973 @classmethod974 def is_valid_SAMESEA5(self,x):975 """Lived same SEA 5 years ago"""976 return True977 @classmethod978 def is_valid_MIGCOUNTY(self,x):979 """County of residence 5 years ago"""980 return True981 @classmethod982 def is_valid_VETSTAT(self,x):983 """Veteran status [general version]"""984 return True985 @classmethod986 def is_valid_VETSTATD(self,x):987 """Veteran status [detailed version]"""988 return True989 @classmethod990 def is_valid_VET1940(self,x):991 """Veteran status, 1940"""992 return True993 @classmethod994 def is_valid_VETWWI(self,x):995 """Veteran, served during WWI era"""996 return True997 @classmethod998 def is_valid_VETPER(self,x):999 """Veteran period of service, 1940"""1000 return True1001 @classmethod1002 def is_valid_VETCHILD(self,x):1003 """Mortality status of child's veteran father"""1004 return True1005 @classmethod1006 def is_valid_HISTID(self,x):1007 """Consistent historical data person identifier"""1008 return True1009 @classmethod1010 def is_valid_SURSIM(self,x):1011 """Surname similarity"""1012 return True1013 @classmethod1014 def is_valid_SSENROLL(self,x):1015 """Social Security enrollment"""1016 return True1017 @classmethod1018 def validate_pipe_delimited(self,x):1019 fields = x.split('|')1020 if len(fields)!=102: return False1021 if is_valid_RECTYPE(fields[1]) == False: return False1022 if is_valid_YEAR(fields[2]) == False: return False1023 if is_valid_DATANUM(fields[3]) == False: return False1024 if is_valid_SERIAL(fields[4]) == False: return False1025 if is_valid_PERNUM(fields[5]) == False: return False1026 if is_valid_PERWT(fields[6]) == False: return False1027 if is_valid_SLWT(fields[7]) == False: return False1028 if is_valid_SLREC(fields[8]) == False: return False1029 if is_valid_RESPONDT(fields[9]) == False: return False1030 if is_valid_FAMUNIT(fields[10]) == False: return False1031 if is_valid_FAMSIZE(fields[11]) == False: return False1032 if is_valid_SUBFAM(fields[12]) == False: return False1033 if is_valid_SFTYPE(fields[13]) == False: return False1034 if is_valid_SFRELATE(fields[14]) == False: return False1035 if is_valid_MOMLOC(fields[15]) == False: return False1036 if is_valid_STEPMOM(fields[16]) == False: return False1037 if is_valid_MOMRULE_HIST(fields[17]) == False: return False1038 if is_valid_POPLOC(fields[18]) == False: return False1039 if is_valid_STEPPOP(fields[19]) == False: return False1040 if is_valid_POPRULE_HIST(fields[20]) == False: return False1041 if is_valid_SPLOC(fields[21]) == False: return False1042 if is_valid_SPRULE_HIST(fields[22]) == False: return False1043 if is_valid_NCHILD(fields[23]) == False: return False1044 if is_valid_NCHLT5(fields[24]) == False: return False1045 if is_valid_NSIBS(fields[25]) == False: return False1046 if is_valid_ELDCH(fields[26]) == False: return False1047 if is_valid_YNGCH(fields[27]) == False: return False1048 if is_valid_RELATE(fields[28]) == False: return False1049 if is_valid_RELATED(fields[29]) == False: return False1050 if is_valid_SEX(fields[30]) == False: return False1051 if is_valid_AGE(fields[31]) == False: return False1052 if is_valid_AGEMONTH(fields[32]) == False: return False1053 if is_valid_MARST(fields[33]) == False: return False1054 if is_valid_MARRNO(fields[34]) == False: return False1055 if is_valid_AGEMARR(fields[35]) == False: return False1056 if is_valid_CHBORN(fields[36]) == False: return False1057 if is_valid_RACE(fields[37]) == False: return False1058 if is_valid_RACED(fields[38]) == False: return False1059 if is_valid_HISPAN(fields[39]) == False: return False1060 if is_valid_HISPAND(fields[40]) == False: return False1061 if is_valid_BPL(fields[41]) == False: return False1062 if is_valid_BPLD(fields[42]) == False: return False1063 if is_valid_MBPL(fields[43]) == False: return False1064 if is_valid_MBPLD(fields[44]) == False: return False1065 if is_valid_FBPL(fields[45]) == False: return False1066 if is_valid_FBPLD(fields[46]) == False: return False1067 if is_valid_NATIVITY(fields[47]) == False: return False1068 if is_valid_CITIZEN(fields[48]) == False: return False1069 if is_valid_MTONGUE(fields[49]) == False: return False1070 if is_valid_MTONGUED(fields[50]) == False: return False1071 if is_valid_SPANNAME(fields[51]) == False: return False1072 if is_valid_HISPRULE(fields[52]) == False: return False1073 if is_valid_SCHOOL(fields[53]) == False: return False1074 if is_valid_HIGRADE(fields[54]) == False: return False1075 if is_valid_HIGRADED(fields[55]) == False: return False1076 if is_valid_EDUC(fields[56]) == False: return False1077 if is_valid_EDUCD(fields[57]) == False: return False1078 if is_valid_EMPSTAT(fields[58]) == False: return False1079 if is_valid_EMPSTATD(fields[59]) == False: return False1080 if is_valid_LABFORCE(fields[60]) == False: return False1081 if is_valid_OCC(fields[61]) == False: return False1082 if is_valid_OCC1950(fields[62]) == False: return False1083 if is_valid_IND(fields[63]) == False: return False1084 if is_valid_IND1950(fields[64]) == False: return False1085 if is_valid_CLASSWKR(fields[65]) == False: return False1086 if is_valid_CLASSWKRD(fields[66]) == False: return False1087 if is_valid_WKSWORK1(fields[67]) == False: return False1088 if is_valid_WKSWORK2(fields[68]) == False: return False1089 if is_valid_HRSWORK1(fields[69]) == False: return False1090 if is_valid_HRSWORK2(fields[70]) == False: return False1091 if is_valid_DURUNEMP(fields[71]) == False: return False1092 if is_valid_UOCC(fields[72]) == False: return False1093 if is_valid_UOCC95(fields[73]) == False: return False1094 if is_valid_UIND(fields[74]) == False: return False1095 if is_valid_UCLASSWK(fields[75]) == False: return False1096 if is_valid_INCWAGE(fields[76]) == False: return False1097 if is_valid_INCNONWG(fields[77]) == False: return False1098 if is_valid_OCCSCORE(fields[78]) == False: return False1099 if is_valid_SEI(fields[79]) == False: return False1100 if is_valid_PRESGL(fields[80]) == False: return False1101 if is_valid_ERSCOR50(fields[81]) == False: return False1102 if is_valid_EDSCOR50(fields[82]) == False: return False1103 if is_valid_NPBOSS50(fields[83]) == False: return False1104 if is_valid_MIGRATE5(fields[84]) == False: return False1105 if is_valid_MIGRATE5D(fields[85]) == False: return False1106 if is_valid_MIGPLAC5(fields[86]) == False: return False1107 if is_valid_MIGMET5(fields[87]) == False: return False1108 if is_valid_MIGTYPE5(fields[88]) == False: return False1109 if is_valid_MIGCITY5(fields[89]) == False: return False1110 if is_valid_MIGSEA5(fields[90]) == False: return False1111 if is_valid_SAMEPLAC(fields[91]) == False: return False1112 if is_valid_SAMESEA5(fields[92]) == False: return False1113 if is_valid_MIGCOUNTY(fields[93]) == False: return False1114 if is_valid_VETSTAT(fields[94]) == False: return False1115 if is_valid_VETSTATD(fields[95]) == False: return False1116 if is_valid_VET1940(fields[96]) == False: return False1117 if is_valid_VETWWI(fields[97]) == False: return False1118 if is_valid_VETPER(fields[98]) == False: return False1119 if is_valid_VETCHILD(fields[99]) == False: return False1120 if is_valid_HISTID(fields[100]) == False: return False1121 if is_valid_SURSIM(fields[101]) == False: return False1122 if is_valid_SSENROLL(fields[102]) == False: return False1123 return True1124class P:1125 __slots__ = ['RECTYPE', 'YEAR', 'DATANUM', 'SERIAL', 'PERNUM', 'PERWT', 'SLWT', 'SLREC', 'RESPONDT', 'FAMUNIT', 'FAMSIZE', 'SUBFAM', 'SFTYPE', 'SFRELATE', 'MOMLOC', 'STEPMOM', 'MOMRULE_HIST', 'POPLOC', 'STEPPOP', 'POPRULE_HIST', 'SPLOC', 'SPRULE_HIST', 'NCHILD', 'NCHLT5', 'NSIBS', 'ELDCH', 'YNGCH', 'RELATE', 'RELATED', 'SEX', 'AGE', 'AGEMONTH', 'MARST', 'MARRNO', 'AGEMARR', 'CHBORN', 'RACE', 'RACED', 'HISPAN', 'HISPAND', 'BPL', 'BPLD', 'MBPL', 'MBPLD', 'FBPL', 'FBPLD', 'NATIVITY', 'CITIZEN', 'MTONGUE', 'MTONGUED', 'SPANNAME', 'HISPRULE', 'SCHOOL', 'HIGRADE', 'HIGRADED', 'EDUC', 'EDUCD', 'EMPSTAT', 'EMPSTATD', 'LABFORCE', 'OCC', 'OCC1950', 'IND', 'IND1950', 'CLASSWKR', 'CLASSWKRD', 'WKSWORK1', 'WKSWORK2', 'HRSWORK1', 'HRSWORK2', 'DURUNEMP', 'UOCC', 'UOCC95', 'UIND', 'UCLASSWK', 'INCWAGE', 'INCNONWG', 'OCCSCORE', 'SEI', 'PRESGL', 'ERSCOR50', 'EDSCOR50', 'NPBOSS50', 'MIGRATE5', 'MIGRATE5D', 'MIGPLAC5', 'MIGMET5', 'MIGTYPE5', 'MIGCITY5', 'MIGSEA5', 'SAMEPLAC', 'SAMESEA5', 'MIGCOUNTY', 'VETSTAT', 'VETSTATD', 'VET1940', 'VETWWI', 'VETPER', 'VETCHILD', 'HISTID', 'SURSIM', 'SSENROLL']1126 def __repr__(self):1127 return 'P<RECTYPE:{},YEAR:{},DATANUM:{},SERIAL:{},PERNUM:{},PERWT:{},SLWT:{},SLREC:{},RESPONDT:{},FAMUNIT:{},FAMSIZE:{},SUBFAM:{},SFTYPE:{},SFRELATE:{},MOMLOC:{},STEPMOM:{},MOMRULE_HIST:{},POPLOC:{},STEPPOP:{},POPRULE_HIST:{},SPLOC:{},SPRULE_HIST:{},NCHILD:{},NCHLT5:{},NSIBS:{},ELDCH:{},YNGCH:{},RELATE:{},RELATED:{},SEX:{},AGE:{},AGEMONTH:{},MARST:{},MARRNO:{},AGEMARR:{},CHBORN:{},RACE:{},RACED:{},HISPAN:{},HISPAND:{},BPL:{},BPLD:{},MBPL:{},MBPLD:{},FBPL:{},FBPLD:{},NATIVITY:{},CITIZEN:{},MTONGUE:{},MTONGUED:{},SPANNAME:{},HISPRULE:{},SCHOOL:{},HIGRADE:{},HIGRADED:{},EDUC:{},EDUCD:{},EMPSTAT:{},EMPSTATD:{},LABFORCE:{},OCC:{},OCC1950:{},IND:{},IND1950:{},CLASSWKR:{},CLASSWKRD:{},WKSWORK1:{},WKSWORK2:{},HRSWORK1:{},HRSWORK2:{},DURUNEMP:{},UOCC:{},UOCC95:{},UIND:{},UCLASSWK:{},INCWAGE:{},INCNONWG:{},OCCSCORE:{},SEI:{},PRESGL:{},ERSCOR50:{},EDSCOR50:{},NPBOSS50:{},MIGRATE5:{},MIGRATE5D:{},MIGPLAC5:{},MIGMET5:{},MIGTYPE5:{},MIGCITY5:{},MIGSEA5:{},SAMEPLAC:{},SAMESEA5:{},MIGCOUNTY:{},VETSTAT:{},VETSTATD:{},VET1940:{},VETWWI:{},VETPER:{},VETCHILD:{},HISTID:{},SURSIM:{},SSENROLL:{}>'.format(self.RECTYPE,self.YEAR,self.DATANUM,self.SERIAL,self.PERNUM,self.PERWT,self.SLWT,self.SLREC,self.RESPONDT,self.FAMUNIT,self.FAMSIZE,self.SUBFAM,self.SFTYPE,self.SFRELATE,self.MOMLOC,self.STEPMOM,self.MOMRULE_HIST,self.POPLOC,self.STEPPOP,self.POPRULE_HIST,self.SPLOC,self.SPRULE_HIST,self.NCHILD,self.NCHLT5,self.NSIBS,self.ELDCH,self.YNGCH,self.RELATE,self.RELATED,self.SEX,self.AGE,self.AGEMONTH,self.MARST,self.MARRNO,self.AGEMARR,self.CHBORN,self.RACE,self.RACED,self.HISPAN,self.HISPAND,self.BPL,self.BPLD,self.MBPL,self.MBPLD,self.FBPL,self.FBPLD,self.NATIVITY,self.CITIZEN,self.MTONGUE,self.MTONGUED,self.SPANNAME,self.HISPRULE,self.SCHOOL,self.HIGRADE,self.HIGRADED,self.EDUC,self.EDUCD,self.EMPSTAT,self.EMPSTATD,self.LABFORCE,self.OCC,self.OCC1950,self.IND,self.IND1950,self.CLASSWKR,self.CLASSWKRD,self.WKSWORK1,self.WKSWORK2,self.HRSWORK1,self.HRSWORK2,self.DURUNEMP,self.UOCC,self.UOCC95,self.UIND,self.UCLASSWK,self.INCWAGE,self.INCNONWG,self.OCCSCORE,self.SEI,self.PRESGL,self.ERSCOR50,self.EDSCOR50,self.NPBOSS50,self.MIGRATE5,self.MIGRATE5D,self.MIGPLAC5,self.MIGMET5,self.MIGTYPE5,self.MIGCITY5,self.MIGSEA5,self.SAMEPLAC,self.SAMESEA5,self.MIGCOUNTY,self.VETSTAT,self.VETSTATD,self.VET1940,self.VETWWI,self.VETPER,self.VETCHILD,self.HISTID,self.SURSIM,self.SSENROLL)1128 def __init__(self,line=None):1129 if line: 1130 if '|' in line: 1131 self.parse_pipe_delimited(line)1132 else:1133 self.parse_position_specified(line)1134 @classmethod1135 def name(self):1136 return 'P'1137 def parse_pipe_delimited(self,line):1138 fields = line.split('|')1139 if len(fields)!=102:1140 raise ValueError(f'expected 102 fields, found {len(fields)}')1141 self.RECTYPE = fields[0]1142 self.YEAR = fields[1]1143 self.DATANUM = fields[2]1144 self.SERIAL = fields[3]1145 self.PERNUM = fields[4]1146 self.PERWT = fields[5]1147 self.SLWT = fields[6]1148 self.SLREC = fields[7]1149 self.RESPONDT = fields[8]1150 self.FAMUNIT = fields[9]1151 self.FAMSIZE = fields[10]1152 self.SUBFAM = fields[11]1153 self.SFTYPE = fields[12]1154 self.SFRELATE = fields[13]1155 self.MOMLOC = fields[14]1156 self.STEPMOM = fields[15]1157 self.MOMRULE_HIST = fields[16]1158 self.POPLOC = fields[17]1159 self.STEPPOP = fields[18]1160 self.POPRULE_HIST = fields[19]1161 self.SPLOC = fields[20]1162 self.SPRULE_HIST = fields[21]1163 self.NCHILD = fields[22]1164 self.NCHLT5 = fields[23]1165 self.NSIBS = fields[24]1166 self.ELDCH = fields[25]1167 self.YNGCH = fields[26]1168 self.RELATE = fields[27]1169 self.RELATED = fields[28]1170 self.SEX = fields[29]1171 self.AGE = fields[30]1172 self.AGEMONTH = fields[31]1173 self.MARST = fields[32]1174 self.MARRNO = fields[33]1175 self.AGEMARR = fields[34]1176 self.CHBORN = fields[35]1177 self.RACE = fields[36]1178 self.RACED = fields[37]1179 self.HISPAN = fields[38]1180 self.HISPAND = fields[39]1181 self.BPL = fields[40]1182 self.BPLD = fields[41]1183 self.MBPL = fields[42]1184 self.MBPLD = fields[43]1185 self.FBPL = fields[44]1186 self.FBPLD = fields[45]1187 self.NATIVITY = fields[46]1188 self.CITIZEN = fields[47]1189 self.MTONGUE = fields[48]1190 self.MTONGUED = fields[49]1191 self.SPANNAME = fields[50]1192 self.HISPRULE = fields[51]1193 self.SCHOOL = fields[52]1194 self.HIGRADE = fields[53]1195 self.HIGRADED = fields[54]1196 self.EDUC = fields[55]1197 self.EDUCD = fields[56]1198 self.EMPSTAT = fields[57]1199 self.EMPSTATD = fields[58]1200 self.LABFORCE = fields[59]1201 self.OCC = fields[60]1202 self.OCC1950 = fields[61]1203 self.IND = fields[62]1204 self.IND1950 = fields[63]1205 self.CLASSWKR = fields[64]1206 self.CLASSWKRD = fields[65]1207 self.WKSWORK1 = fields[66]1208 self.WKSWORK2 = fields[67]1209 self.HRSWORK1 = fields[68]1210 self.HRSWORK2 = fields[69]1211 self.DURUNEMP = fields[70]1212 self.UOCC = fields[71]1213 self.UOCC95 = fields[72]1214 self.UIND = fields[73]1215 self.UCLASSWK = fields[74]1216 self.INCWAGE = fields[75]1217 self.INCNONWG = fields[76]1218 self.OCCSCORE = fields[77]1219 self.SEI = fields[78]1220 self.PRESGL = fields[79]1221 self.ERSCOR50 = fields[80]1222 self.EDSCOR50 = fields[81]1223 self.NPBOSS50 = fields[82]1224 self.MIGRATE5 = fields[83]1225 self.MIGRATE5D = fields[84]1226 self.MIGPLAC5 = fields[85]1227 self.MIGMET5 = fields[86]1228 self.MIGTYPE5 = fields[87]1229 self.MIGCITY5 = fields[88]1230 self.MIGSEA5 = fields[89]1231 self.SAMEPLAC = fields[90]1232 self.SAMESEA5 = fields[91]1233 self.MIGCOUNTY = fields[92]1234 self.VETSTAT = fields[93]1235 self.VETSTATD = fields[94]1236 self.VET1940 = fields[95]1237 self.VETWWI = fields[96]1238 self.VETPER = fields[97]1239 self.VETCHILD = fields[98]1240 self.HISTID = fields[99]1241 self.SURSIM = fields[100]1242 self.SSENROLL = fields[101]1243 def parse_position_specified(self,line):1244 self.RECTYPE = line[0:1]1245 self.YEAR = line[1:5]1246 self.DATANUM = line[5:7]1247 self.SERIAL = line[7:15]1248 self.PERNUM = line[15:19]1249 self.PERWT = line[19:29]1250 self.SLWT = line[29:39]1251 self.SLREC = line[39:40]1252 self.RESPONDT = line[40:41]1253 self.FAMUNIT = line[41:43]1254 self.FAMSIZE = line[43:45]1255 self.SUBFAM = line[45:46]1256 self.SFTYPE = line[46:47]1257 self.SFRELATE = line[47:48]1258 self.MOMLOC = line[48:50]1259 self.STEPMOM = line[50:51]1260 self.MOMRULE_HIST = line[51:52]1261 self.POPLOC = line[52:54]1262 self.STEPPOP = line[54:55]1263 self.POPRULE_HIST = line[55:56]1264 self.SPLOC = line[56:58]1265 self.SPRULE_HIST = line[58:59]1266 self.NCHILD = line[59:60]1267 self.NCHLT5 = line[60:61]1268 self.NSIBS = line[61:62]1269 self.ELDCH = line[62:64]1270 self.YNGCH = line[64:66]1271 self.RELATE = line[66:68]1272 self.RELATED = line[68:72]1273 self.SEX = line[72:73]1274 self.AGE = line[73:76]1275 self.AGEMONTH = line[76:78]1276 self.MARST = line[78:79]1277 self.MARRNO = line[79:80]1278 self.AGEMARR = line[80:82]1279 self.CHBORN = line[82:84]1280 self.RACE = line[84:85]1281 self.RACED = line[85:88]1282 self.HISPAN = line[88:89]1283 self.HISPAND = line[89:92]1284 self.BPL = line[92:95]1285 self.BPLD = line[95:100]1286 self.MBPL = line[100:103]1287 self.MBPLD = line[103:108]1288 self.FBPL = line[108:111]1289 self.FBPLD = line[111:116]1290 self.NATIVITY = line[116:117]1291 self.CITIZEN = line[117:118]1292 self.MTONGUE = line[118:120]1293 self.MTONGUED = line[120:124]1294 self.SPANNAME = line[124:125]1295 self.HISPRULE = line[125:126]1296 self.SCHOOL = line[126:127]1297 self.HIGRADE = line[127:129]1298 self.HIGRADED = line[129:132]1299 self.EDUC = line[132:134]1300 self.EDUCD = line[134:137]1301 self.EMPSTAT = line[137:138]1302 self.EMPSTATD = line[138:140]1303 self.LABFORCE = line[140:141]1304 self.OCC = line[141:145]1305 self.OCC1950 = line[145:148]1306 self.IND = line[148:152]1307 self.IND1950 = line[152:155]1308 self.CLASSWKR = line[155:156]1309 self.CLASSWKRD = line[156:158]1310 self.WKSWORK1 = line[158:160]1311 self.WKSWORK2 = line[160:161]1312 self.HRSWORK1 = line[161:163]1313 self.HRSWORK2 = line[163:164]1314 self.DURUNEMP = line[164:167]1315 self.UOCC = line[167:170]1316 self.UOCC95 = line[170:173]1317 self.UIND = line[173:176]1318 self.UCLASSWK = line[176:177]1319 self.INCWAGE = line[177:183]1320 self.INCNONWG = line[183:184]1321 self.OCCSCORE = line[184:186]1322 self.SEI = line[186:188]1323 self.PRESGL = line[188:191]1324 self.ERSCOR50 = line[191:195]1325 self.EDSCOR50 = line[195:199]1326 self.NPBOSS50 = line[199:203]1327 self.MIGRATE5 = line[203:204]1328 self.MIGRATE5D = line[204:206]1329 self.MIGPLAC5 = line[206:209]1330 self.MIGMET5 = line[209:213]1331 self.MIGTYPE5 = line[213:214]1332 self.MIGCITY5 = line[214:218]1333 self.MIGSEA5 = line[218:221]1334 self.SAMEPLAC = line[221:222]1335 self.SAMESEA5 = line[222:223]1336 self.MIGCOUNTY = line[223:227]1337 self.VETSTAT = line[227:228]1338 self.VETSTATD = line[228:230]1339 self.VET1940 = line[230:231]1340 self.VETWWI = line[231:232]1341 self.VETPER = line[232:233]1342 self.VETCHILD = line[233:234]1343 self.HISTID = line[234:270]1344 self.SURSIM = line[270:272]1345 self.SSENROLL = line[272:273]1346 def validate(self):1347 """Return True if the object data validates"""1348 if not P_validator.is_valid_RECTYPE(self.RECTYPE): return False1349 if not P_validator.is_valid_YEAR(self.YEAR): return False1350 if not P_validator.is_valid_DATANUM(self.DATANUM): return False1351 if not P_validator.is_valid_SERIAL(self.SERIAL): return False1352 if not P_validator.is_valid_PERNUM(self.PERNUM): return False1353 if not P_validator.is_valid_PERWT(self.PERWT): return False1354 if not P_validator.is_valid_SLWT(self.SLWT): return False1355 if not P_validator.is_valid_SLREC(self.SLREC): return False1356 if not P_validator.is_valid_RESPONDT(self.RESPONDT): return False1357 if not P_validator.is_valid_FAMUNIT(self.FAMUNIT): return False1358 if not P_validator.is_valid_FAMSIZE(self.FAMSIZE): return False1359 if not P_validator.is_valid_SUBFAM(self.SUBFAM): return False1360 if not P_validator.is_valid_SFTYPE(self.SFTYPE): return False1361 if not P_validator.is_valid_SFRELATE(self.SFRELATE): return False1362 if not P_validator.is_valid_MOMLOC(self.MOMLOC): return False1363 if not P_validator.is_valid_STEPMOM(self.STEPMOM): return False1364 if not P_validator.is_valid_MOMRULE_HIST(self.MOMRULE_HIST): return False1365 if not P_validator.is_valid_POPLOC(self.POPLOC): return False1366 if not P_validator.is_valid_STEPPOP(self.STEPPOP): return False1367 if not P_validator.is_valid_POPRULE_HIST(self.POPRULE_HIST): return False1368 if not P_validator.is_valid_SPLOC(self.SPLOC): return False1369 if not P_validator.is_valid_SPRULE_HIST(self.SPRULE_HIST): return False1370 if not P_validator.is_valid_NCHILD(self.NCHILD): return False1371 if not P_validator.is_valid_NCHLT5(self.NCHLT5): return False1372 if not P_validator.is_valid_NSIBS(self.NSIBS): return False1373 if not P_validator.is_valid_ELDCH(self.ELDCH): return False1374 if not P_validator.is_valid_YNGCH(self.YNGCH): return False1375 if not P_validator.is_valid_RELATE(self.RELATE): return False1376 if not P_validator.is_valid_RELATED(self.RELATED): return False1377 if not P_validator.is_valid_SEX(self.SEX): return False1378 if not P_validator.is_valid_AGE(self.AGE): return False1379 if not P_validator.is_valid_AGEMONTH(self.AGEMONTH): return False1380 if not P_validator.is_valid_MARST(self.MARST): return False1381 if not P_validator.is_valid_MARRNO(self.MARRNO): return False1382 if not P_validator.is_valid_AGEMARR(self.AGEMARR): return False1383 if not P_validator.is_valid_CHBORN(self.CHBORN): return False1384 if not P_validator.is_valid_RACE(self.RACE): return False1385 if not P_validator.is_valid_RACED(self.RACED): return False1386 if not P_validator.is_valid_HISPAN(self.HISPAN): return False1387 if not P_validator.is_valid_HISPAND(self.HISPAND): return False1388 if not P_validator.is_valid_BPL(self.BPL): return False1389 if not P_validator.is_valid_BPLD(self.BPLD): return False1390 if not P_validator.is_valid_MBPL(self.MBPL): return False1391 if not P_validator.is_valid_MBPLD(self.MBPLD): return False1392 if not P_validator.is_valid_FBPL(self.FBPL): return False1393 if not P_validator.is_valid_FBPLD(self.FBPLD): return False1394 if not P_validator.is_valid_NATIVITY(self.NATIVITY): return False1395 if not P_validator.is_valid_CITIZEN(self.CITIZEN): return False1396 if not P_validator.is_valid_MTONGUE(self.MTONGUE): return False1397 if not P_validator.is_valid_MTONGUED(self.MTONGUED): return False1398 if not P_validator.is_valid_SPANNAME(self.SPANNAME): return False1399 if not P_validator.is_valid_HISPRULE(self.HISPRULE): return False1400 if not P_validator.is_valid_SCHOOL(self.SCHOOL): return False1401 if not P_validator.is_valid_HIGRADE(self.HIGRADE): return False1402 if not P_validator.is_valid_HIGRADED(self.HIGRADED): return False1403 if not P_validator.is_valid_EDUC(self.EDUC): return False1404 if not P_validator.is_valid_EDUCD(self.EDUCD): return False1405 if not P_validator.is_valid_EMPSTAT(self.EMPSTAT): return False1406 if not P_validator.is_valid_EMPSTATD(self.EMPSTATD): return False1407 if not P_validator.is_valid_LABFORCE(self.LABFORCE): return False1408 if not P_validator.is_valid_OCC(self.OCC): return False1409 if not P_validator.is_valid_OCC1950(self.OCC1950): return False1410 if not P_validator.is_valid_IND(self.IND): return False1411 if not P_validator.is_valid_IND1950(self.IND1950): return False1412 if not P_validator.is_valid_CLASSWKR(self.CLASSWKR): return False1413 if not P_validator.is_valid_CLASSWKRD(self.CLASSWKRD): return False1414 if not P_validator.is_valid_WKSWORK1(self.WKSWORK1): return False1415 if not P_validator.is_valid_WKSWORK2(self.WKSWORK2): return False1416 if not P_validator.is_valid_HRSWORK1(self.HRSWORK1): return False1417 if not P_validator.is_valid_HRSWORK2(self.HRSWORK2): return False1418 if not P_validator.is_valid_DURUNEMP(self.DURUNEMP): return False1419 if not P_validator.is_valid_UOCC(self.UOCC): return False1420 if not P_validator.is_valid_UOCC95(self.UOCC95): return False1421 if not P_validator.is_valid_UIND(self.UIND): return False1422 if not P_validator.is_valid_UCLASSWK(self.UCLASSWK): return False1423 if not P_validator.is_valid_INCWAGE(self.INCWAGE): return False1424 if not P_validator.is_valid_INCNONWG(self.INCNONWG): return False1425 if not P_validator.is_valid_OCCSCORE(self.OCCSCORE): return False1426 if not P_validator.is_valid_SEI(self.SEI): return False1427 if not P_validator.is_valid_PRESGL(self.PRESGL): return False1428 if not P_validator.is_valid_ERSCOR50(self.ERSCOR50): return False1429 if not P_validator.is_valid_EDSCOR50(self.EDSCOR50): return False1430 if not P_validator.is_valid_NPBOSS50(self.NPBOSS50): return False1431 if not P_validator.is_valid_MIGRATE5(self.MIGRATE5): return False1432 if not P_validator.is_valid_MIGRATE5D(self.MIGRATE5D): return False1433 if not P_validator.is_valid_MIGPLAC5(self.MIGPLAC5): return False1434 if not P_validator.is_valid_MIGMET5(self.MIGMET5): return False1435 if not P_validator.is_valid_MIGTYPE5(self.MIGTYPE5): return False1436 if not P_validator.is_valid_MIGCITY5(self.MIGCITY5): return False1437 if not P_validator.is_valid_MIGSEA5(self.MIGSEA5): return False1438 if not P_validator.is_valid_SAMEPLAC(self.SAMEPLAC): return False1439 if not P_validator.is_valid_SAMESEA5(self.SAMESEA5): return False1440 if not P_validator.is_valid_MIGCOUNTY(self.MIGCOUNTY): return False1441 if not P_validator.is_valid_VETSTAT(self.VETSTAT): return False1442 if not P_validator.is_valid_VETSTATD(self.VETSTATD): return False1443 if not P_validator.is_valid_VET1940(self.VET1940): return False1444 if not P_validator.is_valid_VETWWI(self.VETWWI): return False1445 if not P_validator.is_valid_VETPER(self.VETPER): return False1446 if not P_validator.is_valid_VETCHILD(self.VETCHILD): return False1447 if not P_validator.is_valid_HISTID(self.HISTID): return False1448 if not P_validator.is_valid_SURSIM(self.SURSIM): return False1449 if not P_validator.is_valid_SSENROLL(self.SSENROLL): return False1450 return True1451 def validate_reason(self):1452 reason=[]1453 if not P_validator.is_valid_RECTYPE(self.RECTYPE): reason.append('RECTYPE ('+str(self.RECTYPE)+') out of range ()')1454 if not P_validator.is_valid_YEAR(self.YEAR): reason.append('YEAR ('+str(self.YEAR)+') out of range ()')1455 if not P_validator.is_valid_DATANUM(self.DATANUM): reason.append('DATANUM ('+str(self.DATANUM)+') out of range ()')1456 if not P_validator.is_valid_SERIAL(self.SERIAL): reason.append('SERIAL ('+str(self.SERIAL)+') out of range ()')1457 if not P_validator.is_valid_PERNUM(self.PERNUM): reason.append('PERNUM ('+str(self.PERNUM)+') out of range ()')1458 if not P_validator.is_valid_PERWT(self.PERWT): reason.append('PERWT ('+str(self.PERWT)+') out of range ()')1459 if not P_validator.is_valid_SLWT(self.SLWT): reason.append('SLWT ('+str(self.SLWT)+') out of range ()')1460 if not P_validator.is_valid_SLREC(self.SLREC): reason.append('SLREC ('+str(self.SLREC)+') out of range ()')1461 if not P_validator.is_valid_RESPONDT(self.RESPONDT): reason.append('RESPONDT ('+str(self.RESPONDT)+') out of range ()')1462 if not P_validator.is_valid_FAMUNIT(self.FAMUNIT): reason.append('FAMUNIT ('+str(self.FAMUNIT)+') out of range ()')1463 if not P_validator.is_valid_FAMSIZE(self.FAMSIZE): reason.append('FAMSIZE ('+str(self.FAMSIZE)+') out of range ()')1464 if not P_validator.is_valid_SUBFAM(self.SUBFAM): reason.append('SUBFAM ('+str(self.SUBFAM)+') out of range ()')1465 if not P_validator.is_valid_SFTYPE(self.SFTYPE): reason.append('SFTYPE ('+str(self.SFTYPE)+') out of range ()')1466 if not P_validator.is_valid_SFRELATE(self.SFRELATE): reason.append('SFRELATE ('+str(self.SFRELATE)+') out of range ()')1467 if not P_validator.is_valid_MOMLOC(self.MOMLOC): reason.append('MOMLOC ('+str(self.MOMLOC)+') out of range ()')1468 if not P_validator.is_valid_STEPMOM(self.STEPMOM): reason.append('STEPMOM ('+str(self.STEPMOM)+') out of range ()')1469 if not P_validator.is_valid_MOMRULE_HIST(self.MOMRULE_HIST): reason.append('MOMRULE_HIST ('+str(self.MOMRULE_HIST)+') out of range ()')1470 if not P_validator.is_valid_POPLOC(self.POPLOC): reason.append('POPLOC ('+str(self.POPLOC)+') out of range ()')1471 if not P_validator.is_valid_STEPPOP(self.STEPPOP): reason.append('STEPPOP ('+str(self.STEPPOP)+') out of range ()')1472 if not P_validator.is_valid_POPRULE_HIST(self.POPRULE_HIST): reason.append('POPRULE_HIST ('+str(self.POPRULE_HIST)+') out of range ()')1473 if not P_validator.is_valid_SPLOC(self.SPLOC): reason.append('SPLOC ('+str(self.SPLOC)+') out of range ()')1474 if not P_validator.is_valid_SPRULE_HIST(self.SPRULE_HIST): reason.append('SPRULE_HIST ('+str(self.SPRULE_HIST)+') out of range ()')1475 if not P_validator.is_valid_NCHILD(self.NCHILD): reason.append('NCHILD ('+str(self.NCHILD)+') out of range ()')1476 if not P_validator.is_valid_NCHLT5(self.NCHLT5): reason.append('NCHLT5 ('+str(self.NCHLT5)+') out of range ()')1477 if not P_validator.is_valid_NSIBS(self.NSIBS): reason.append('NSIBS ('+str(self.NSIBS)+') out of range ()')1478 if not P_validator.is_valid_ELDCH(self.ELDCH): reason.append('ELDCH ('+str(self.ELDCH)+') out of range ()')1479 if not P_validator.is_valid_YNGCH(self.YNGCH): reason.append('YNGCH ('+str(self.YNGCH)+') out of range ()')1480 if not P_validator.is_valid_RELATE(self.RELATE): reason.append('RELATE ('+str(self.RELATE)+') out of range ()')1481 if not P_validator.is_valid_RELATED(self.RELATED): reason.append('RELATED ('+str(self.RELATED)+') out of range ()')1482 if not P_validator.is_valid_SEX(self.SEX): reason.append('SEX ('+str(self.SEX)+') out of range ()')1483 if not P_validator.is_valid_AGE(self.AGE): reason.append('AGE ('+str(self.AGE)+') out of range ()')1484 if not P_validator.is_valid_AGEMONTH(self.AGEMONTH): reason.append('AGEMONTH ('+str(self.AGEMONTH)+') out of range ()')1485 if not P_validator.is_valid_MARST(self.MARST): reason.append('MARST ('+str(self.MARST)+') out of range ()')1486 if not P_validator.is_valid_MARRNO(self.MARRNO): reason.append('MARRNO ('+str(self.MARRNO)+') out of range ()')1487 if not P_validator.is_valid_AGEMARR(self.AGEMARR): reason.append('AGEMARR ('+str(self.AGEMARR)+') out of range ()')1488 if not P_validator.is_valid_CHBORN(self.CHBORN): reason.append('CHBORN ('+str(self.CHBORN)+') out of range ()')1489 if not P_validator.is_valid_RACE(self.RACE): reason.append('RACE ('+str(self.RACE)+') out of range ()')1490 if not P_validator.is_valid_RACED(self.RACED): reason.append('RACED ('+str(self.RACED)+') out of range ()')1491 if not P_validator.is_valid_HISPAN(self.HISPAN): reason.append('HISPAN ('+str(self.HISPAN)+') out of range ()')1492 if not P_validator.is_valid_HISPAND(self.HISPAND): reason.append('HISPAND ('+str(self.HISPAND)+') out of range ()')1493 if not P_validator.is_valid_BPL(self.BPL): reason.append('BPL ('+str(self.BPL)+') out of range ()')1494 if not P_validator.is_valid_BPLD(self.BPLD): reason.append('BPLD ('+str(self.BPLD)+') out of range ()')1495 if not P_validator.is_valid_MBPL(self.MBPL): reason.append('MBPL ('+str(self.MBPL)+') out of range ()')1496 if not P_validator.is_valid_MBPLD(self.MBPLD): reason.append('MBPLD ('+str(self.MBPLD)+') out of range ()')1497 if not P_validator.is_valid_FBPL(self.FBPL): reason.append('FBPL ('+str(self.FBPL)+') out of range ()')1498 if not P_validator.is_valid_FBPLD(self.FBPLD): reason.append('FBPLD ('+str(self.FBPLD)+') out of range ()')1499 if not P_validator.is_valid_NATIVITY(self.NATIVITY): reason.append('NATIVITY ('+str(self.NATIVITY)+') out of range ()')1500 if not P_validator.is_valid_CITIZEN(self.CITIZEN): reason.append('CITIZEN ('+str(self.CITIZEN)+') out of range ()')1501 if not P_validator.is_valid_MTONGUE(self.MTONGUE): reason.append('MTONGUE ('+str(self.MTONGUE)+') out of range ()')1502 if not P_validator.is_valid_MTONGUED(self.MTONGUED): reason.append('MTONGUED ('+str(self.MTONGUED)+') out of range ()')1503 if not P_validator.is_valid_SPANNAME(self.SPANNAME): reason.append('SPANNAME ('+str(self.SPANNAME)+') out of range ()')1504 if not P_validator.is_valid_HISPRULE(self.HISPRULE): reason.append('HISPRULE ('+str(self.HISPRULE)+') out of range ()')1505 if not P_validator.is_valid_SCHOOL(self.SCHOOL): reason.append('SCHOOL ('+str(self.SCHOOL)+') out of range ()')1506 if not P_validator.is_valid_HIGRADE(self.HIGRADE): reason.append('HIGRADE ('+str(self.HIGRADE)+') out of range ()')1507 if not P_validator.is_valid_HIGRADED(self.HIGRADED): reason.append('HIGRADED ('+str(self.HIGRADED)+') out of range ()')1508 if not P_validator.is_valid_EDUC(self.EDUC): reason.append('EDUC ('+str(self.EDUC)+') out of range ()')1509 if not P_validator.is_valid_EDUCD(self.EDUCD): reason.append('EDUCD ('+str(self.EDUCD)+') out of range ()')1510 if not P_validator.is_valid_EMPSTAT(self.EMPSTAT): reason.append('EMPSTAT ('+str(self.EMPSTAT)+') out of range ()')1511 if not P_validator.is_valid_EMPSTATD(self.EMPSTATD): reason.append('EMPSTATD ('+str(self.EMPSTATD)+') out of range ()')1512 if not P_validator.is_valid_LABFORCE(self.LABFORCE): reason.append('LABFORCE ('+str(self.LABFORCE)+') out of range ()')1513 if not P_validator.is_valid_OCC(self.OCC): reason.append('OCC ('+str(self.OCC)+') out of range ()')1514 if not P_validator.is_valid_OCC1950(self.OCC1950): reason.append('OCC1950 ('+str(self.OCC1950)+') out of range ()')1515 if not P_validator.is_valid_IND(self.IND): reason.append('IND ('+str(self.IND)+') out of range ()')1516 if not P_validator.is_valid_IND1950(self.IND1950): reason.append('IND1950 ('+str(self.IND1950)+') out of range ()')1517 if not P_validator.is_valid_CLASSWKR(self.CLASSWKR): reason.append('CLASSWKR ('+str(self.CLASSWKR)+') out of range ()')1518 if not P_validator.is_valid_CLASSWKRD(self.CLASSWKRD): reason.append('CLASSWKRD ('+str(self.CLASSWKRD)+') out of range ()')1519 if not P_validator.is_valid_WKSWORK1(self.WKSWORK1): reason.append('WKSWORK1 ('+str(self.WKSWORK1)+') out of range ()')1520 if not P_validator.is_valid_WKSWORK2(self.WKSWORK2): reason.append('WKSWORK2 ('+str(self.WKSWORK2)+') out of range ()')1521 if not P_validator.is_valid_HRSWORK1(self.HRSWORK1): reason.append('HRSWORK1 ('+str(self.HRSWORK1)+') out of range ()')1522 if not P_validator.is_valid_HRSWORK2(self.HRSWORK2): reason.append('HRSWORK2 ('+str(self.HRSWORK2)+') out of range ()')1523 if not P_validator.is_valid_DURUNEMP(self.DURUNEMP): reason.append('DURUNEMP ('+str(self.DURUNEMP)+') out of range ()')1524 if not P_validator.is_valid_UOCC(self.UOCC): reason.append('UOCC ('+str(self.UOCC)+') out of range ()')1525 if not P_validator.is_valid_UOCC95(self.UOCC95): reason.append('UOCC95 ('+str(self.UOCC95)+') out of range ()')1526 if not P_validator.is_valid_UIND(self.UIND): reason.append('UIND ('+str(self.UIND)+') out of range ()')1527 if not P_validator.is_valid_UCLASSWK(self.UCLASSWK): reason.append('UCLASSWK ('+str(self.UCLASSWK)+') out of range ()')1528 if not P_validator.is_valid_INCWAGE(self.INCWAGE): reason.append('INCWAGE ('+str(self.INCWAGE)+') out of range ()')1529 if not P_validator.is_valid_INCNONWG(self.INCNONWG): reason.append('INCNONWG ('+str(self.INCNONWG)+') out of range ()')1530 if not P_validator.is_valid_OCCSCORE(self.OCCSCORE): reason.append('OCCSCORE ('+str(self.OCCSCORE)+') out of range ()')1531 if not P_validator.is_valid_SEI(self.SEI): reason.append('SEI ('+str(self.SEI)+') out of range ()')1532 if not P_validator.is_valid_PRESGL(self.PRESGL): reason.append('PRESGL ('+str(self.PRESGL)+') out of range ()')1533 if not P_validator.is_valid_ERSCOR50(self.ERSCOR50): reason.append('ERSCOR50 ('+str(self.ERSCOR50)+') out of range ()')1534 if not P_validator.is_valid_EDSCOR50(self.EDSCOR50): reason.append('EDSCOR50 ('+str(self.EDSCOR50)+') out of range ()')1535 if not P_validator.is_valid_NPBOSS50(self.NPBOSS50): reason.append('NPBOSS50 ('+str(self.NPBOSS50)+') out of range ()')1536 if not P_validator.is_valid_MIGRATE5(self.MIGRATE5): reason.append('MIGRATE5 ('+str(self.MIGRATE5)+') out of range ()')1537 if not P_validator.is_valid_MIGRATE5D(self.MIGRATE5D): reason.append('MIGRATE5D ('+str(self.MIGRATE5D)+') out of range ()')1538 if not P_validator.is_valid_MIGPLAC5(self.MIGPLAC5): reason.append('MIGPLAC5 ('+str(self.MIGPLAC5)+') out of range ()')1539 if not P_validator.is_valid_MIGMET5(self.MIGMET5): reason.append('MIGMET5 ('+str(self.MIGMET5)+') out of range ()')1540 if not P_validator.is_valid_MIGTYPE5(self.MIGTYPE5): reason.append('MIGTYPE5 ('+str(self.MIGTYPE5)+') out of range ()')1541 if not P_validator.is_valid_MIGCITY5(self.MIGCITY5): reason.append('MIGCITY5 ('+str(self.MIGCITY5)+') out of range ()')1542 if not P_validator.is_valid_MIGSEA5(self.MIGSEA5): reason.append('MIGSEA5 ('+str(self.MIGSEA5)+') out of range ()')1543 if not P_validator.is_valid_SAMEPLAC(self.SAMEPLAC): reason.append('SAMEPLAC ('+str(self.SAMEPLAC)+') out of range ()')1544 if not P_validator.is_valid_SAMESEA5(self.SAMESEA5): reason.append('SAMESEA5 ('+str(self.SAMESEA5)+') out of range ()')1545 if not P_validator.is_valid_MIGCOUNTY(self.MIGCOUNTY): reason.append('MIGCOUNTY ('+str(self.MIGCOUNTY)+') out of range ()')1546 if not P_validator.is_valid_VETSTAT(self.VETSTAT): reason.append('VETSTAT ('+str(self.VETSTAT)+') out of range ()')1547 if not P_validator.is_valid_VETSTATD(self.VETSTATD): reason.append('VETSTATD ('+str(self.VETSTATD)+') out of range ()')1548 if not P_validator.is_valid_VET1940(self.VET1940): reason.append('VET1940 ('+str(self.VET1940)+') out of range ()')1549 if not P_validator.is_valid_VETWWI(self.VETWWI): reason.append('VETWWI ('+str(self.VETWWI)+') out of range ()')1550 if not P_validator.is_valid_VETPER(self.VETPER): reason.append('VETPER ('+str(self.VETPER)+') out of range ()')1551 if not P_validator.is_valid_VETCHILD(self.VETCHILD): reason.append('VETCHILD ('+str(self.VETCHILD)+') out of range ()')1552 if not P_validator.is_valid_HISTID(self.HISTID): reason.append('HISTID ('+str(self.HISTID)+') out of range ()')1553 if not P_validator.is_valid_SURSIM(self.SURSIM): reason.append('SURSIM ('+str(self.SURSIM)+') out of range ()')1554 if not P_validator.is_valid_SSENROLL(self.SSENROLL): reason.append('SSENROLL ('+str(self.SSENROLL)+') out of range ()')1555 return ', '.join(reason)1556 def SparkSQLRow(self):1557 """Return a SparkSQL Row object for this object."""1558 from pyspark.sql import Row1559 return Row(1560 rectype=safe_str(self.RECTYPE),1561 year=safe_str(self.YEAR),1562 datanum=safe_str(self.DATANUM),1563 serial=safe_str(self.SERIAL),1564 pernum=safe_str(self.PERNUM),1565 perwt=safe_str(self.PERWT),1566 slwt=safe_str(self.SLWT),1567 slrec=safe_str(self.SLREC),1568 respondt=safe_str(self.RESPONDT),1569 famunit=safe_str(self.FAMUNIT),1570 famsize=safe_str(self.FAMSIZE),1571 subfam=safe_str(self.SUBFAM),1572 sftype=safe_str(self.SFTYPE),1573 sfrelate=safe_str(self.SFRELATE),1574 momloc=safe_str(self.MOMLOC),1575 stepmom=safe_str(self.STEPMOM),1576 momrule_hist=safe_str(self.MOMRULE_HIST),1577 poploc=safe_str(self.POPLOC),1578 steppop=safe_str(self.STEPPOP),1579 poprule_hist=safe_str(self.POPRULE_HIST),1580 sploc=safe_str(self.SPLOC),1581 sprule_hist=safe_str(self.SPRULE_HIST),1582 nchild=safe_str(self.NCHILD),1583 nchlt5=safe_str(self.NCHLT5),1584 nsibs=safe_str(self.NSIBS),1585 eldch=safe_str(self.ELDCH),1586 yngch=safe_str(self.YNGCH),1587 relate=safe_str(self.RELATE),1588 related=safe_str(self.RELATED),1589 sex=safe_str(self.SEX),1590 age=safe_str(self.AGE),1591 agemonth=safe_str(self.AGEMONTH),1592 marst=safe_str(self.MARST),1593 marrno=safe_str(self.MARRNO),1594 agemarr=safe_str(self.AGEMARR),1595 chborn=safe_str(self.CHBORN),1596 race=safe_str(self.RACE),1597 raced=safe_str(self.RACED),1598 hispan=safe_str(self.HISPAN),1599 hispand=safe_str(self.HISPAND),1600 bpl=safe_str(self.BPL),1601 bpld=safe_str(self.BPLD),1602 mbpl=safe_str(self.MBPL),1603 mbpld=safe_str(self.MBPLD),1604 fbpl=safe_str(self.FBPL),1605 fbpld=safe_str(self.FBPLD),1606 nativity=safe_str(self.NATIVITY),1607 citizen=safe_str(self.CITIZEN),1608 mtongue=safe_str(self.MTONGUE),1609 mtongued=safe_str(self.MTONGUED),1610 spanname=safe_str(self.SPANNAME),1611 hisprule=safe_str(self.HISPRULE),1612 school=safe_str(self.SCHOOL),1613 higrade=safe_str(self.HIGRADE),1614 higraded=safe_str(self.HIGRADED),1615 educ=safe_str(self.EDUC),1616 educd=safe_str(self.EDUCD),1617 empstat=safe_str(self.EMPSTAT),1618 empstatd=safe_str(self.EMPSTATD),1619 labforce=safe_str(self.LABFORCE),1620 occ=safe_str(self.OCC),1621 occ1950=safe_str(self.OCC1950),1622 ind=safe_str(self.IND),1623 ind1950=safe_str(self.IND1950),1624 classwkr=safe_str(self.CLASSWKR),1625 classwkrd=safe_str(self.CLASSWKRD),1626 wkswork1=safe_str(self.WKSWORK1),1627 wkswork2=safe_str(self.WKSWORK2),1628 hrswork1=safe_str(self.HRSWORK1),1629 hrswork2=safe_str(self.HRSWORK2),1630 durunemp=safe_str(self.DURUNEMP),1631 uocc=safe_str(self.UOCC),1632 uocc95=safe_str(self.UOCC95),1633 uind=safe_str(self.UIND),1634 uclasswk=safe_str(self.UCLASSWK),1635 incwage=safe_str(self.INCWAGE),1636 incnonwg=safe_str(self.INCNONWG),1637 occscore=safe_str(self.OCCSCORE),1638 sei=safe_str(self.SEI),1639 presgl=safe_str(self.PRESGL),1640 erscor50=safe_str(self.ERSCOR50),1641 edscor50=safe_str(self.EDSCOR50),1642 npboss50=safe_str(self.NPBOSS50),1643 migrate5=safe_str(self.MIGRATE5),1644 migrate5d=safe_str(self.MIGRATE5D),1645 migplac5=safe_str(self.MIGPLAC5),1646 migmet5=safe_str(self.MIGMET5),1647 migtype5=safe_str(self.MIGTYPE5),1648 migcity5=safe_str(self.MIGCITY5),1649 migsea5=safe_str(self.MIGSEA5),1650 sameplac=safe_str(self.SAMEPLAC),1651 samesea5=safe_str(self.SAMESEA5),1652 migcounty=safe_str(self.MIGCOUNTY),1653 vetstat=safe_str(self.VETSTAT),1654 vetstatd=safe_str(self.VETSTATD),1655 vet1940=safe_str(self.VET1940),1656 vetwwi=safe_str(self.VETWWI),1657 vetper=safe_str(self.VETPER),1658 vetchild=safe_str(self.VETCHILD),1659 histid=safe_str(self.HISTID),1660 sursim=safe_str(self.SURSIM),1661 ssenroll=safe_str(self.SSENROLL),1662 )1663SPEC_CLASS_OBJECTS = [H(),P()]1664null = None...
test_reflect.py
Source:test_reflect.py
...405 Tests for L{reflect.safe_str} function.406 """407 def test_workingStr(self):408 x = [1, 2, 3]409 self.assertEqual(reflect.safe_str(x), str(x))410 def test_brokenStr(self):411 b = Breakable()412 b.breakStr = True413 reflect.safe_str(b)414 def test_workingAscii(self):415 """416 L{safe_str} for C{str} with ascii-only data should return the417 value unchanged.418 """419 x = 'a'420 self.assertEqual(reflect.safe_str(x), 'a')421 def test_workingUtf8_2(self):422 """423 L{safe_str} for C{str} with utf-8 encoded data should return the424 value unchanged.425 """426 x = b't\xc3\xbcst'427 self.assertEqual(reflect.safe_str(x), x)428 def test_workingUtf8_3(self):429 """430 L{safe_str} for C{bytes} with utf-8 encoded data should return431 the value decoded into C{str}.432 """433 x = b't\xc3\xbcst'434 self.assertEqual(reflect.safe_str(x), x.decode('utf-8'))435 if _PY3:436 # TODO: after something like python.compat.nativeUtf8String is437 # introduced, use that one for assertEqual. Then we can combine438 # test_workingUtf8_* tests into one without needing _PY3.439 # nativeUtf8String is needed for Python 3 anyway.440 test_workingUtf8_2.skip = ("Skip Python 2 specific test for utf-8 str")441 else:442 test_workingUtf8_3.skip = (443 "Skip Python 3 specific test for utf-8 bytes")444 def test_brokenUtf8(self):445 """446 Use str() for non-utf8 bytes: "b'non-utf8'"447 """448 x = b'\xff'449 xStr = reflect.safe_str(x)450 self.assertEqual(xStr, str(x))451 def test_brokenRepr(self):452 b = Breakable()453 b.breakRepr = True454 reflect.safe_str(b)455 def test_brokenClassStr(self):456 class X(BTBase):457 breakStr = True458 reflect.safe_str(X)459 reflect.safe_str(X())460 def test_brokenClassRepr(self):461 class X(BTBase):462 breakRepr = True463 reflect.safe_str(X)464 reflect.safe_str(X())465 def test_brokenClassAttribute(self):466 """467 If an object raises an exception when accessing its C{__class__}468 attribute, L{reflect.safe_str} uses C{type} to retrieve the class469 object.470 """471 b = NoClassAttr()472 b.breakStr = True473 bStr = reflect.safe_str(b)474 self.assertIn("NoClassAttr instance at 0x", bStr)475 self.assertIn(os.path.splitext(__file__)[0], bStr)476 self.assertIn("RuntimeError: str!", bStr)477 def test_brokenClassNameAttribute(self):478 """479 If a class raises an exception when accessing its C{__name__} attribute480 B{and} when calling its C{__str__} implementation, L{reflect.safe_str}481 returns 'BROKEN CLASS' instead of the class name.482 """483 class X(BTBase):484 breakName = True485 xStr = reflect.safe_str(X())486 self.assertIn("<BROKEN CLASS AT 0x", xStr)487 self.assertIn(os.path.splitext(__file__)[0], xStr)488 self.assertIn("RuntimeError: str!", xStr)489class FilenameToModuleTests(TestCase):490 """491 Test L{filenameToModuleName} detection.492 """493 def setUp(self):494 self.path = os.path.join(self.mktemp(), "fakepackage", "test")495 os.makedirs(self.path)496 with open(os.path.join(self.path, "__init__.py"), "w") as f:497 f.write("")498 with open(os.path.join(os.path.dirname(self.path), "__init__.py"),499 "w") as f:...
junit_xml.py
Source:junit_xml.py
...93 self.type = type94 if exc_info:95 self.exc_name = exc_name(exc_info)96 self.message = exc_message(exc_info)97 self.traceback = safe_str(''.join(98 traceback.format_exception(*exc_info)))99 else:100 self.exc_name = self.message = self.traceback = ''101 @classmethod102 def from_testcase(cls, testcase, took, type=None, exc_info=None):103 name = testcase.id().split('.')[-1]104 return cls(name, took, type, exc_info)105 def write_xml(self, stream):106 stream.write(' <testcase name="%s" time="%.3f"' % (self.name,107 self.took))108 if not self.type:109 # test was successful110 stream.write('/>\n')111 return112 stream.write('>\n <%s type="%s" message=%s><![CDATA[%s]]></%s>\n' %113 (self.type, self.exc_name, saxutils.quoteattr(self.message),114 escape_cdata(self.traceback), self.type))115 stream.write(' </testcase>\n')116class Tee(StringIO):117 """Writes data to this StringIO and a separate stream"""118 def __init__(self, stream):119 StringIO.__init__(self)120 self.stream = stream121 def write(self, data):122 StringIO.write(self, data)123 self.stream.write(data)124 def flush(self):125 StringIO.flush(self)126 self.stream.flush()127def write_testsuite_xml(stream, tests, errors, failures, skipped, name, took):128 """Write the XML header (<testsuite/>)"""129 stream.write('<?xml version="1.0" encoding="utf-8"?>\n')130 stream.write('<testsuite tests="%d" errors="%d" failures="%d" ' %131 (tests, errors, failures))132 stream.write('skipped="%d" name="%s" time="%.3f">\n' % (skipped, name,133 took))134def write_stdouterr_xml(stream, stdout, stderr):135 """Write the stdout/err tags"""136 if stdout:137 stream.write(' <system-out><![CDATA[%s]]></system-out>\n' %138 escape_cdata(safe_str(stdout)))139 if stderr:140 stream.write(' <system-err><![CDATA[%s]]></system-err>\n' %141 escape_cdata(safe_str(stderr)))142def write_direct_test(junit_xml_dir, name, took, type=None, exc_info=None,143 stdout=None, stderr=None):144 """Write XML for a regrtest 'direct' test; a test which was ran on145 import (which we label as __main__.__import__)146 """147 return write_manual_test(junit_xml_dir, '%s.__main__' % name, '__import__',148 took, type, exc_info, stdout, stderr)149def write_doctest(junit_xml_dir, name, took, type=None, exc_info=None,150 stdout=None, stderr=None):151 """Write XML for a regrtest doctest, labeled as __main__.__doc__"""152 return write_manual_test(junit_xml_dir, '%s.__main__' % name, '__doc__',153 took, type, exc_info, stdout, stderr)154def write_manual_test(junit_xml_dir, module_name, test_name, took, type=None,155 exc_info=None, stdout=None, stderr=None):156 """Manually write XML for one test, outside of unittest"""157 errors = type == 'error' and 1 or 0158 failures = type == 'failure' and 1 or 0159 skipped = type == 'skipped' and 1 or 0160 ensure_dir(junit_xml_dir)161 stream = open(os.path.join(junit_xml_dir, 'TEST-%s.xml' % module_name),162 'w')163 write_testsuite_xml(stream, 1, errors, failures, skipped, module_name,164 took)165 info = TestInfo(test_name, took, type, exc_info)166 info.write_xml(stream)167 write_stdouterr_xml(stream, stdout, stderr)168 stream.write('</testsuite>')169 stream.close()170def ensure_dir(dir):171 """Ensure dir exists"""172 if not os.path.exists(dir):173 os.mkdir(dir)174def exc_name(exc_info):175 """Determine the full name of the exception that caused exc_info"""176 exc = exc_info[1]177 name = getattr(exc.__class__, '__module__', '')178 if name:179 name += '.'180 return name + exc.__class__.__name__181def exc_message(exc_info):182 """Safely return a short message passed through safe_str describing183 exc_info, being careful of unicode values.184 """185 exc = exc_info[1]186 if exc is None:187 return safe_str(exc_info[0])188 if isinstance(exc, BaseException) and isinstance(exc.message, unicode):189 return safe_str(exc.message)190 try:191 return safe_str(str(exc))192 except UnicodeEncodeError:193 try:194 val = unicode(exc)195 return safe_str(val)196 except UnicodeDecodeError:197 return '?'198def escape_cdata(cdata):199 """Escape a string for an XML CDATA section"""200 return cdata.replace(']]>', ']]>]]><![CDATA[')201def safe_str(base):202 """Return a str valid for UTF-8 XML from a basestring"""203 if isinstance(base, unicode):204 return remove_evil(base.encode('utf-8', 'replace'))205 return remove_evil(base.decode('utf-8', 'replace').encode('utf-8',206 'replace'))207def remove_evil(string):208 """Remove control characters from a string"""...
elezioni_storiche_italia_-_assemblea_costituente.py
Source:elezioni_storiche_italia_-_assemblea_costituente.py
...14 except UnicodeDecodeError:15 # obj is byte string16 ascii_text = str(obj).encode('string_escape')17 return unicode(ascii_text)18def safe_str(obj):19 """ return the byte string representation of obj """20 try:21 return str(obj)22 except UnicodeEncodeError:23 # obj is unicode24 return unicode(obj).encode('unicode_escape')25def to_dict(aind,aval):26 ret = {}27 for i in range(len(aind)):28 ret[aind[i]] = aval[i]29 return ret30for election in elections:31 print election32 # print base_url+election33 u = urllib2.urlopen(base_url+election).read()34 s = pq(u)35 for date_url in s(dates_finder):36 ud = pq(date_url)37 date = ud.attr('title')38 lev1 = ""39 lev2 = ""40 lev3 = ""41 hr = ud.attr('href')42 print date43 i = urllib2.urlopen(BASE+hr).read()44 d = pq(i)45 for l1 in d(level_finder):46 l1 = pq(l1)47 lev1 = l1.attr('title')48 print lev149 l2u = l1.attr('href')50 print BASE+l2u51 l2c = urllib2.urlopen(BASE+l2u).read()52 f = pq(l2c)53 for l2 in f(level_finder): 54 l2 = pq(l2)55 lev2 = l2.attr('title')56 print ">", lev257 l3u = l2.attr('href')58 print BASE+l3u59 l3c = urllib2.urlopen(BASE+l3u).read()60 g = pq(l3c)61 for l3 in g(level_finder): 62 l3 = pq(l3)63 lev3 = l3.attr('title')64 print ">>", lev365 l4u = l3.attr('href')66 l4c = urllib2.urlopen(BASE+l4u).read()67 h = pq(l4c)68 for l4 in h(level_finder): 69 l4 = pq(l4)70 lev4 = l4.attr('title')71 print ">>>", lev472 rdu = l4.attr('href')73 rdc = urllib2.urlopen(BASE+rdu).read()74 j = pq(rdc)75 print j('.dati_riepilogo td' )[0]76 elettori = pq(j('.dati_riepilogo td')[0]).text()77 votanti = pq(j('.dati_riepilogo td')[2]).text()78 bianche = pq(j('.dati_riepilogo td')[5]).text()79 nulle = pq(j('.dati_riepilogo td')[7]).text()80 keys= ["date","l1","l2","l3","l4", "elettori", "votanti", "partito", "voti" ]81 scraperwiki.sqlite.save(unique_keys = keys, data= to_dict(keys, [date,safe_str(lev1),safe_str(lev2),safe_str(lev3),safe_str(lev4), elettori, votanti, "BLANK", bianche]))82 scraperwiki.sqlite.save(unique_keys = keys, data= to_dict(keys, [date,safe_str(lev1),safe_str(lev2),safe_str(lev3),safe_str(lev4), elettori, votanti, "NULL", nulle]))83 for party in j('.dati tr').not_('.totalecomplessivovoti'):84 k = pq(party)85 if len(k('th'))==1:86 img = pq(k.children()[0])87 panme = pq(k.children()[1]).text()88 votes = pq(k.children()[2]).text()89 90 data = {}91 scraperwiki.sqlite.save(unique_keys = keys, data= to_dict(keys, [date,safe_str(lev1),safe_str(lev2),safe_str(lev3), safe_str(lev4), elettori, votanti, safe_str(panme), votes ]))import scraperwiki92import urllib293elections = ["A"]94referendum = "F"95dates_finder = ".lista_date a"96level_finder = '.right-panel .sezione ul li a'97BASE = "http://elezionistorico.interno.it"98base_url = BASE+"/index.php?tpel="99from pyquery import PyQuery as pq100def safe_unicode(obj, *args):101 """ return the unicode representation of obj """102 try:103 return unicode(obj, *args)104 except UnicodeDecodeError:105 # obj is byte string106 ascii_text = str(obj).encode('string_escape')107 return unicode(ascii_text)108def safe_str(obj):109 """ return the byte string representation of obj """110 try:111 return str(obj)112 except UnicodeEncodeError:113 # obj is unicode114 return unicode(obj).encode('unicode_escape')115def to_dict(aind,aval):116 ret = {}117 for i in range(len(aind)):118 ret[aind[i]] = aval[i]119 return ret120for election in elections:121 print election122 # print base_url+election123 u = urllib2.urlopen(base_url+election).read()124 s = pq(u)125 for date_url in s(dates_finder):126 ud = pq(date_url)127 date = ud.attr('title')128 lev1 = ""129 lev2 = ""130 lev3 = ""131 hr = ud.attr('href')132 print date133 i = urllib2.urlopen(BASE+hr).read()134 d = pq(i)135 for l1 in d(level_finder):136 l1 = pq(l1)137 lev1 = l1.attr('title')138 print lev1139 l2u = l1.attr('href')140 print BASE+l2u141 l2c = urllib2.urlopen(BASE+l2u).read()142 f = pq(l2c)143 for l2 in f(level_finder): 144 l2 = pq(l2)145 lev2 = l2.attr('title')146 print ">", lev2147 l3u = l2.attr('href')148 print BASE+l3u149 l3c = urllib2.urlopen(BASE+l3u).read()150 g = pq(l3c)151 for l3 in g(level_finder): 152 l3 = pq(l3)153 lev3 = l3.attr('title')154 print ">>", lev3155 l4u = l3.attr('href')156 l4c = urllib2.urlopen(BASE+l4u).read()157 h = pq(l4c)158 for l4 in h(level_finder): 159 l4 = pq(l4)160 lev4 = l4.attr('title')161 print ">>>", lev4162 rdu = l4.attr('href')163 rdc = urllib2.urlopen(BASE+rdu).read()164 j = pq(rdc)165 print j('.dati_riepilogo td' )[0]166 elettori = pq(j('.dati_riepilogo td')[0]).text()167 votanti = pq(j('.dati_riepilogo td')[2]).text()168 bianche = pq(j('.dati_riepilogo td')[5]).text()169 nulle = pq(j('.dati_riepilogo td')[7]).text()170 keys= ["date","l1","l2","l3","l4", "elettori", "votanti", "partito", "voti" ]171 scraperwiki.sqlite.save(unique_keys = keys, data= to_dict(keys, [date,safe_str(lev1),safe_str(lev2),safe_str(lev3),safe_str(lev4), elettori, votanti, "BLANK", bianche]))172 scraperwiki.sqlite.save(unique_keys = keys, data= to_dict(keys, [date,safe_str(lev1),safe_str(lev2),safe_str(lev3),safe_str(lev4), elettori, votanti, "NULL", nulle]))173 for party in j('.dati tr').not_('.totalecomplessivovoti'):174 k = pq(party)175 if len(k('th'))==1:176 img = pq(k.children()[0])177 panme = pq(k.children()[1]).text()178 votes = pq(k.children()[2]).text()179 180 data = {}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!