; M>c@sdZdkZdkZdkZdkZdkZdkZdfdYZdfdYZeZ dfdYZ e dZ dS( s: engine module for pyching classes and utility functions NsHexagramcBstZdZdZRS(s single Hexagram data structure template, private class should only be accessed as an attribute of an instance of the Hexagrams class (below) this class is defined at module level to enable pickling of Hexagrams instances cCs:d|_d|_ddddddg|_t|_dS(Nsi(sselfsnumbersnames lineValuessNones infoSource(sself((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys__init__/s  (s__name__s __module__s__doc__s__init__(((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pysHexagram(s sPychingAppDetailscBs,tZdZddZdZdZRS(s] holds information about a running instance of the pyching application, public class icCsd|_d|_ti|_ti|_|iti |_ |i d|_ |i |_ tii|i d|_d|_d|_d|_d|if|_d |_d |_dS( NspyChings1.2.1s.pychings pychingrcs.psvs.#@~s.~@#spyching_save_fileselguavas@users.sourceforge.netshttp://pyching.sourceforge.net(sselfstitlesversionssyssplatformsossnamesosTypes GetProgramDirssepsexecPaths GetUserCfgDirs configPathssavePathspathsjoins configFiles saveFileExtsinternalImageExtsinternalHtmlExts saveFileIDs emailAddresss webAddress(sselfscreateConfigDir((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys__init__:s         cCsDtdjotiit}ntiitid}|SdS(s return the filesystem directory where this program file resides. (ie the applications exec or import directory.) s__main__iN(s__name__sosspathsdirnames__file__sappDirsabspathssys(sselfsappDir((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys GetProgramDirJs  cCstiid}|djo@tii| o(d|d}tii|d}q_n|djoti }ntii ||}tii| oIyti |Wqt j o%d|d}tii|qXn|SdS(sr Creates (if required) and returns a filesystem directory for storing user config files. s~s0 Warning: HOME environment variable points to s but the path does not exist. s3 Warning: unable to create user config directory s N(sosspaths expandusersuserDirsexistsswarnssyssstderrswritesgetcwdsjoinscfgDirsmkdirsIOError(sselfscfgDirswarnsuserDir((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys GetUserCfgDirUs"  (s__name__s __module__s__doc__s__init__s GetProgramDirs GetUserCfgDir(((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pysPychingAppDetails6s   s HexagramscBsYtZdZddZdZdZdZdZdZdZ d Z RS( s: holds both Hexagrams for a reading, public class scoincCs@d|_||_t|_t|_d|_g|_dS(s initialise self by setting oracle type defaults to coin, if specified must be a valid oracle type (coin or yarrow) siN( sselfsquestions oracleTypesoraclesHexagramshex1shex2s currentLinescurrentOracleValues(sselfs oracleType((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys__init__xs     cCsN |ddddddgjoddfSn |ddddddgjoddfSn |ddddddgjoddfSn |ddddddgjod d fSn |ddddddgjod d fSnj |ddddddgjod dfSn= |ddddddgjoddfSn |ddddddgjoddfSn |ddddddgjoddfSn |ddddddgjoddfSn |ddddddgjoddfSn\ |ddddddgjoddfSn/ |ddddddgjoddfSn |ddddddgjoddfSn|ddddddgjodd fSn|ddddddgjod!d"fSn{|ddddddgjod#d$fSnN|ddddddgjod%d&fSn!|ddddddgjod'd(fSn|ddddddgjod)d*fSn|ddddddgjod+d,fSn|ddddddgjod-dfSnm|ddddddgjod.d/fSn@|ddddddgjod0d1fSn|ddddddgjod2d3fSn|ddddddgjod4d5fSn|ddddddgjod6d7fSn|ddddddgjod8d9fSn_|ddddddgjod:d;fSn2|ddddddgjod<dfSn|ddddddgjod=d>fSn|ddddddgjod?d@fSn|ddddddgjodAdBfSn~|ddddddgjodCdDfSnQ|ddddddgjodEdFfSn$|ddddddgjodGdHfSn|ddddddgjodIdJfSn|ddddddgjodKdLfSn|ddddddgjodMdfSnp|ddddddgjodNdOfSnC|ddddddgjodPdQfSn|ddddddgjodRdSfSn|ddddddgjodTdUfSn|ddddddgjodVdWfSn|ddddddgjodXdYfSnb|ddddddgjodZd[fSn5|ddddddgjod\d]fSn|ddddddgjod^d_fSn|ddddddgjod`dafSn|ddddddgjodbdcfSn|ddddddgjodddefSnT|ddddddgjodfdgfSn'|ddddddgjodhd fSn|ddddddgjodidjfSn|ddddddgjodkdlfSn|ddddddgjodmdnfSns|ddddddgjododpfSnF|ddddddgjodqdrfSn|ddddddgjodsdtfSn|ddddddgjodudOfSn|ddddddgjodvdwfSn|ddddddgjodxdyfSne|ddddddgjodzd{fSn8|ddddddgjod|d}fSn d~dfSdS(s  lookup hex name and number, private method hexKey value should be a list of the non-moving line numbers for the Hexagram being enquired upon (Hex?.Key) returns a list of Hexagram details in the form [number, name] is1sTch'ienis2sKouns3sT'ouns4sMongs5sHsus6sSongs7sCheus8sPis9s Siao Tch'ous10sLis11sT'ais12sP'is13sTong Jens14sTa Yous15sTchiens16sYus17sSoueis18sKous19sLins20sKouans21sChe Hos22s23sPos24sFous25sWou Wangs26s Ta Tch'ous27sIs28sTa Kouos29sK'ans30s31sHsiens32sHongs33sTouns34s Ta Tch'ouangs35sTchins36sMing Yis37s Tchia Jens38sK'oueis39s40sTchiehs41sSouns42sYis43sKouais44sKeous45sTs'oueis46sChengs47sK'ouns48sTsings49sKeus50sTings51sTchens52sKens53s54s Kouei Meis55sFongs56sLus57sHsuans58sToueis59sHouans60s61s Tchong Fous62s Siao Kouos63s Tchi Tchis64sWei Tchiis lookup errorN(shexKey(sselfshexKey((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys__GetHexDetailsscCs<|idjoti}|idjo:|ddg|ddg|ddgg|_ntd|i|ii |i<|id|_n|idjoddddddg}d}x^|ii D]P}|djod||siiii ispyching_int_data.insdata()N(sselfs currentLineswhrandomschoicesrcsoraclescurrentOracleValuessreduceshex1s lineValuesshex1Keysisitems_Hexagrams__GetHexDetailssnumbersnames infoSourceshex2(sselfsisitemshex1Keysrc((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pysNewLines@ :"    !   'cCs ||_dS(sf used to set the Hexagrams.question attribute from outside this module, public method N(s questionTextsselfsquestion(sselfs questionText((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys SetQuestionscCstiiddjo/tiiti otitiqHnyr|djoDti|i |i |i |i |i|if}t|d|n|djot|}nWntj o nDX|djo5|\}|_ |_ |_ |_ |_|_|SndS(s  store or load a Hexagrams instance to/from disk file using the utility routine Storage(), private method this private method should be called from the public load and save routines below. action should be 'save' or 'load' . s~ssavesdatasloadN(sosspaths expandusersexistsspychingssavePathsmkdirsactions saveFileIDsselfsquestionsoracleshex1shex2s currentLinescurrentOracleValuesshexDatasStoragesfilesIOError(sselfsfilesactionshexDatas saveFileID((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys __HexStorages 0  -cCs1y|i|dWntj o nXdS(s save instance data to disk file, public method this function should be called in a try: except IOError: block, to handle potential disk IO errors ssaveN(sselfs_Hexagrams__HexStoragesfilesIOError(sselfsfile((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pysSaves cCs7y|i|d}Wntj o nX|SdS(s load instance data from disk file, public method, returns savefile version this function should be called in a try: except IOError: block, to handle potential disk IO errors sloadN(sselfs_Hexagrams__HexStoragesfilesversionsIOError(sselfsfilesversion((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pysLoad&s cCs7hdd<dd<dd<dd<d d <}hd d <d d<dd<dd<dd<dd<}hdd<dd<dd<dd<d d <}g}|idti|ii d dti|ii ddti|i i d d|i i dxt dddD]}|djo:d|iijpd|iijo d}qwd }nd!}|idti||d dd"||ii|dti||ii|d#|||i i|d||i i|d$q$W|id%|idti|}|Sd&S('s create a multi-line text representation of the reading as a formatted string, public method, returns the string is---X---is-------is--- ---i s---O---isisbottomissecondisthirdisfourthisfifthstopmosts(6 moving yin)s(7 yang)s(8 yin)s(9 moving yang)s s is is becomes s no moving liness s is s N(s lineStringss linePositionss lineTypesstextReadingPartssappendsstringsljustsselfshex1snumbersnameshex2srangesis lineValuess separatorsrjustsquestionsjoins textReading(sselfs lineTypess linePositionss textReadingsis lineStringsstextReadingPartss separator((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys ReadingAsText6s"3<3i &  ( s__name__s __module__s__doc__s__init__s_Hexagrams__GetHexDetailssNewLines SetQuestions_Hexagrams__HexStoragesSavesLoads ReadingAsText(((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys Hexagramsts   L $    cCs|o d}nd}yt||}Wntj o ngXzWy2|oti||nti|}|SWn|o dqdnXWd|i XdS(s store or load data to/from file using pickler data should be a list of data items if storing, or None if loading returns an unpickled list of data items on successful load this function should be called in a try: except IOError: except pychingPickleError: except pychingUnpickleError: block, to handle potential disk IO and pickle/unpickle errors swsrspychingPickleErrorspychingUnpickleErrorN( sdatasopenTypesopensfiles pickleFilesIOErrorspicklesdumpsloads pickleDatasclose(sfilesdatasopenTypes pickleDatas pickleFile((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pysStorage]s&   ( s__doc__ssyssossstringswhrandomspicklestimesHexagramsPychingAppDetailsspychings HexagramssNonesStorage( sPychingAppDetailsswhrandomsstringspicklesStorages HexagramsssyssHexagramstimesosspyching((s7/mnt/gmirror/ports/games/pyching/work/pyching_engine.pys?s 6: