<s> """<STR_LIT>""" <EOL> import re <EOL> import urllib <EOL> from lookups import Lookup <EOL> from diagnostics import Diagnostics <EOL> from core import GsxObject , GsxError , validate <EOL> def models ( ) : <EOL> """<STR_LIT>""" <EOL> import os <EOL> import yaml <EOL> filepath = os . path . join ( os . path . dirname ( __file__ ) , "<STR_LIT>" ) <EOL> return yaml . load ( open ( filepath , '<STR_LIT:r>' ) ) <EOL> class Product ( object ) : <EOL> """<STR_LIT>""" <EOL> sn = '<STR_LIT>' <EOL> description = '<STR_LIT>' <EOL> def __init__ ( self , sn , ** kwargs ) : <EOL> if validate ( sn , '<STR_LIT>' ) : <EOL> self . alternateDeviceId = sn <EOL> self . _gsx = GsxObject ( alternateDeviceId = sn ) <EOL> else : <EOL> self . serialNumber = sn <EOL> self . _gsx = GsxObject ( serialNumber = sn ) <EOL> self . _gsx . _namespace = "<STR_LIT>" <EOL> def model ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . _gsx . _submit ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . configDescription = result . configDescription <EOL> self . productLine = result . productLine <EOL> self . configCode = result . configCode <EOL> return result <EOL> def warranty ( self , parts = [ ] , date_received = None , ship_to = None ) : <EOL> """<STR_LIT>""" <EOL> if self . should_check_activation : <EOL> ad = self . activation ( ) <EOL> self . _gsx . serialNumber = ad . serialNumber <EOL> self . _gsx . unset ( '<STR_LIT>' ) <EOL> if ship_to is not None : <EOL> self . _gsx . shipTo = ship_to <EOL> try : <EOL> self . _gsx . partNumbers = [ ] <EOL> for k , v in parts : <EOL> part = GsxObject ( partNumber = k , comptiaCode = v ) <EOL> self . _gsx . partNumbers . append ( part ) <EOL> except Exception : <EOL> pass <EOL> if date_received is not None : <EOL> self . _gsx . unitReceivedDate = date_received <EOL> self . _gsx . _submit ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . warrantyDetails = self . _gsx . _req . objects <EOL> self . imageURL = self . warrantyDetails . imageURL <EOL> self . productDescription = self . warrantyDetails . productDescription <EOL> self . description = self . productDescription . lstrip ( '<STR_LIT>' ) <EOL> self . repair_strategies = [ ] <EOL> try : <EOL> for i in self . warrantyDetails . availableRepairStrategies : <EOL> self . repair_strategies . append ( i . availableRepairStrategy ) <EOL> except ( AttributeError , TypeError ) : <EOL> pass <EOL> return self . warrantyDetails <EOL> def parts ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return Lookup ( serialNumber = self . serialNumber ) . parts ( ) <EOL> except AttributeError : <EOL> return Lookup ( productName = self . productName ) . parts ( ) <EOL> def repairs ( self ) : <EOL> """<STR_LIT>""" <EOL> return Lookup ( serialNumber = self . serialNumber ) . repairs ( ) <EOL> def diagnostics ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self , "<STR_LIT>" ) : <EOL> diags = Diagnostics ( alternateDeviceId = self . alternateDeviceId ) <EOL> else : <EOL> diags = Diagnostics ( serialNumber = self . serialNumber ) <EOL> return diags . fetch ( ) <EOL> def fetch_image ( self , url = None ) : <EOL> """<STR_LIT>""" <EOL> url = url or self . imageURL <EOL> if url is None : <EOL> raise GsxError ( "<STR_LIT>" ) <EOL> try : <EOL> return urllib . urlretrieve ( url ) [ <NUM_LIT:0> ] <EOL> except Exception as e : <EOL> raise GsxError ( "<STR_LIT>" % e ) <EOL> def activation ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _gsx . _namespace = "<STR_LIT>" <EOL> return self . _gsx . _submit ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> @ property <EOL> def fmip_status ( self , wty = None ) : <EOL> if wty is None : <EOL> wty = self . warrantyDetails <EOL> if wty is None : <EOL> raise GsxError ( '<STR_LIT>' ) <EOL> return wty . activationLockStatus or '<STR_LIT>' <EOL> @ property <EOL> def fmip_is_active ( self ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' in self . fmip_status <EOL> def is_unlocked ( self , ad = None ) : <EOL> """<STR_LIT>""" <EOL> policy = ad . nextTetherPolicyDetails or '<STR_LIT>' <EOL> return ad . unlocked or ( "<STR_LIT>" in policy ) <EOL> @ property <EOL> def is_locked ( self ) : <EOL> return not self . is_unlocked ( ) <EOL> @ property <EOL> def should_check_activation ( self ) : <EOL> """<STR_LIT>""" <EOL> return hasattr ( self , "<STR_LIT>" ) and not hasattr ( self , "<STR_LIT>" ) <EOL> @ property <EOL> def is_mac ( self ) : <EOL> return re . match ( r'<STR_LIT>' , self . description ) <EOL> @ property <EOL> def is_iphone ( self ) : <EOL> return self . description . startswith ( '<STR_LIT>' ) <EOL> @ property <EOL> def is_ipad ( self ) : <EOL> return self . description . startswith ( '<STR_LIT>' ) <EOL> @ property <EOL> def is_ios ( self ) : <EOL> return self . is_iphone or self . is_ipad <EOL> @ property <EOL> def is_valid ( self ) : <EOL> return self . is_ios or self . is_mac <EOL> @ property <EOL> def has_warranty ( self ) : <EOL> return self . warrantyDetails . limitedWarranty <EOL> @ property <EOL> def is_vintage ( self ) : <EOL> title = self . warrantyDetails . productDescription or '<STR_LIT>' <EOL> return title . startswith ( '<STR_LIT>' ) <EOL> @ property <EOL> def parts_covered ( self ) : <EOL> return self . warrantyDetails . partCovered is True <EOL> @ property <EOL> def labor_covered ( self ) : <EOL> return self . warrantyDetails . laborCovered is True <EOL> @ property <EOL> def parts_and_labor_covered ( self ) : <EOL> return self . parts_covered and self . labor_covered <EOL> @ property <EOL> def has_onsite ( self ) : <EOL> from datetime import date <EOL> try : <EOL> return date . today ( ) < self . warrantyDetails . onsiteEndDate <EOL> except Exception : <EOL> return False <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import sys <EOL> import doctest <EOL> import logging <EOL> from core import connect <EOL> logging . basicConfig ( level = logging . DEBUG ) <EOL> connect ( * sys . argv [ <NUM_LIT:1> : ] ) <EOL> doctest . testmod ( ) </s>
