--- http_interactions: - request: method: get uri: http://builds.emberjs.com/beta/ember-data.js body: encoding: US-ASCII string: '' headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - '*/*' User-Agent: - Ruby Host: - builds.emberjs.com response: status: code: 200 message: OK headers: X-Amz-Id-2: - EqJNLOiuj9KP0f8g6Ia70sBXxamim+Mk3d9wD3c3WMAxMTePx8+pYmI3+aJ9zWfk X-Amz-Request-Id: - 961EE02CE9A84E17 Date: - Mon, 17 Feb 2014 11:44:55 GMT Last-Modified: - Sun, 26 Jan 2014 02:03:33 GMT Etag: - '"4e6b873fdc5cf10ec70bef695bf07589"' Content-Type: - text/javascript Content-Length: - '280957' Server: - AmazonS3 body: encoding: ASCII-8BIT string: !binary |- LyohCiAqIEBvdmVydmlldyAgRW1iZXIgRGF0YQogKiBAY29weXJpZ2h0IENv cHlyaWdodCAyMDExLTIwMTQgVGlsZGUgSW5jLiBhbmQgY29udHJpYnV0b3Jz LgogKiAgICAgICAgICAgIFBvcnRpb25zIENvcHlyaWdodCAyMDExIExpdmlu Z1NvY2lhbCBJbmMuCiAqIEBsaWNlbnNlICAgTGljZW5zZWQgdW5kZXIgTUlU IGxpY2Vuc2UgKHNlZSBsaWNlbnNlLmpzKQogKiBAdmVyc2lvbiAgIDEuMC4w LWJldGEuNgogKi8KCgooZnVuY3Rpb24oKSB7CnZhciBkZWZpbmUsIHJlcXVp cmVNb2R1bGU7CgooZnVuY3Rpb24oKSB7CiAgdmFyIHJlZ2lzdHJ5ID0ge30s IHNlZW4gPSB7fTsKCiAgZGVmaW5lID0gZnVuY3Rpb24obmFtZSwgZGVwcywg Y2FsbGJhY2spIHsKICAgIHJlZ2lzdHJ5W25hbWVdID0geyBkZXBzOiBkZXBz LCBjYWxsYmFjazogY2FsbGJhY2sgfTsKICB9OwoKICByZXF1aXJlTW9kdWxl ID0gZnVuY3Rpb24obmFtZSkgewogICAgaWYgKHNlZW5bbmFtZV0pIHsgcmV0 dXJuIHNl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ybiBhIEpTT04gaGFzaCBvZiB5b3Vy IGNob29zaW5nLgoKICAgIGBgYGphdmFzY3JpcHQKICAgIEFwcC5Qb3N0U2Vy aWFsaXplciA9IERTLkpTT05TZXJpYWxpemVyLmV4dGVuZCh7CiAgICAgIHNl cmlhbGl6ZTogZnVuY3Rpb24ocG9zdCwgb3B0aW9ucykgewogICAgICAgIHZh ciBqc29uID0gewogICAgICAgICAgUE9TVF9UVEw6IHBvc3QuZ2V0KCd0aXRs ZScpLAogICAgICAgICAgUE9TVF9CRFk6IHBvc3QuZ2V0KCdib2R5JyksCiAg ICAgICAgICBQT1NUX0NNUzogcG9zdC5nZXQoJ2NvbW1lbnRzJykubWFwUHJv cGVydHkoJ2lkJykKICAgICAgICB9CgogICAgICAgIGlmIChvcHRpb25zLmlu Y2x1ZGVJZCkgewogICAgICAgICAganNvbi5QT1NUX0lEXyA9IHBvc3QuZ2V0 KCdpZCcpOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIGpzb247CiAgICAg IH0KICAgIH0pOwogICAgYGBgCgogICAgIyMgQ3VzdG9taXppbmcgYW4gQXBw LVdpZGUgU2VyaWFsaXplcgoKICAgIElmIHlvdSB3YW50IHRvIGRlZmluZSBh IHNlcmlhbGl6ZXIgZm9yIHlvdXIgZW50aXJlCiAgICBhcHBsaWNhdGlvbiwg eW91J2xsIHByb2JhYmx5IHdhbnQgdG8gdXNlIGBlYWNoQXR0cmlidXRlYAog ICAgYW5kIGBlYWNoUmVsYXRpb25zaGlwYCBvbiB0aGUgcmVjb3JkLgoKICAg IGBgYGphdmFzY3JpcHQKICAgIEFwcC5BcHBsaWNhdGlvblNlcmlhbGl6ZXIg PSBEUy5KU09OU2VyaWFsaXplci5leHRlbmQoewogICAgICBzZXJpYWxpemU6 IGZ1bmN0aW9uKHJlY29yZCwgb3B0aW9ucykgewogICAgICAgIHZhciBqc29u ID0ge307CgogICAgICAgIHJlY29yZC5lYWNoQXR0cmlidXRlKGZ1bmN0aW9u KG5hbWUpIHsKICAgICAgICAgIGpzb25bc2VydmVyQXR0cmlidXRlTmFtZShu YW1lKV0gPSByZWNvcmQuZ2V0KG5hbWUpOwogICAgICAgIH0pCgogICAgICAg IHJlY29yZC5lYWNoUmVsYXRpb25zaGlwKGZ1bmN0aW9uKG5hbWUsIHJlbGF0 aW9uc2hpcCkgewogICAgICAgICAgaWYgKHJlbGF0aW9uc2hpcC5raW5kID09 PSAnaGFzTWFueScpIHsKICAgICAgICAgICAganNvbltzZXJ2ZXJIYXNNYW55 TmFtZShuYW1lKV0gPSByZWNvcmQuZ2V0KG5hbWUpLm1hcEJ5KCdpZCcpOwog ICAgICAgICAgfQogICAgICAgIH0pOwoKICAgICAgICBpZiAob3B0aW9ucy5p bmNsdWRlSWQpIHsKICAgICAgICAgIGpzb24uSURfID0gcmVjb3JkLmdldCgn aWQnKTsKICAgICAgICB9CgogICAgICAgIHJldHVybiBqc29uOwogICAgICB9 CiAgICB9KTsKCiAgICBmdW5jdGlvbiBzZXJ2ZXJBdHRyaWJ1dGVOYW1lKGF0 dHJpYnV0ZSkgewogICAgICByZXR1cm4gYXR0cmlidXRlLnVuZGVyc2NvcmUo KS50b1VwcGVyQ2FzZSgpOwogICAgfQoKICAgIGZ1bmN0aW9uIHNlcnZlckhh c01hbnlOYW1lKG5hbWUpIHsKICAgICAgcmV0dXJuIHNlcnZlckF0dHJpYnV0 ZU5hbWUobmFtZS5zaW5ndWxhcml6ZSgpKSArICJfSURTIjsKICAgIH0KICAg IGBgYAoKICAgIFRoaXMgc2VyaWFsaXplciB3aWxsIGdlbmVyYXRlIEpTT04g dGhhdCBsb29rcyBsaWtlIHRoaXM6CgogICAgYGBgamF2YXNjcmlwdAogICAg ewogICAgICAiVElUTEUiOiAiUmFpbHMgaXMgb21ha2FzZSIsCiAgICAgICJC T0RZIjogIlllcC4gT21ha2FzZS4iLAogICAgICAiQ09NTUVOVF9JRFMiOiBb IDEsIDIsIDMgXQogICAgfQogICAgYGBgCgogICAgIyMgVHdlYWtpbmcgdGhl IERlZmF1bHQgSlNPTgoKICAgIElmIHlvdSBqdXN0IHdhbnQgdG8gZG8gc29t ZSBzbWFsbCB0d2Vha3Mgb24gdGhlIGRlZmF1bHQgSlNPTiwKICAgIHlvdSBj YW4gY2FsbCBzdXBlciBmaXJzdCBhbmQgbWFrZSB0aGUgdHdlYWtzIG9uIHRo ZSByZXR1cm5lZAogICAgSlNPTi4KCiAgICBgYGBqYXZhc2NyaXB0CiAgICBB cHAuUG9zdFNlcmlhbGl6ZXIgPSBEUy5KU09OU2VyaWFsaXplci5leHRlbmQo ewogICAgICBzZXJpYWxpemU6IGZ1bmN0aW9uKHJlY29yZCwgb3B0aW9ucykg ewogICAgICAgIHZhciBqc29uID0gdGhpcy5fc3VwZXIuYXBwbHkodGhpcywg YXJndW1lbnRzKTsKCiAgICAgICAganNvbi5zdWJqZWN0ID0ganNvbi50aXRs ZTsKICAgICAgICBkZWxldGUganNvbi50aXRsZTsKCiAgICAgICAgcmV0dXJu IGpzb247CiAgICAgIH0KICAgIH0pOwogICAgYGBgCgogICAgQG1ldGhvZCBz ZXJpYWxpemUKICAgIEBwYXJhbSB7c3ViY2xhc3Mgb2YgRFMuTW9kZWx9IHJl Y29yZAogICAgQHBhcmFtIHtPYmplY3R9IG9wdGlvbnMKICAgIEByZXR1cm4g e09iamVjdH0ganNvbgogICovCiAgc2VyaWFsaXplOiBmdW5jdGlvbihyZWNv cmQsIG9wdGlvbnMpIHsKICAgIHZhciBqc29uID0ge307CgogICAgaWYgKG9w dGlvbnMgJiYgb3B0aW9ucy5pbmNsdWRlSWQpIHsKICAgICAgdmFyIGlkID0g Z2V0KHJlY29yZCwgJ2lkJyk7CgogICAgICBpZiAoaWQpIHsKICAgICAgICBq c29uW2dldCh0aGlzLCAncHJpbWFyeUtleScpXSA9IGlkOwogICAgICB9CiAg ICB9CgogICAgcmVjb3JkLmVhY2hBdHRyaWJ1dGUoZnVuY3Rpb24oa2V5LCBh dHRyaWJ1dGUpIHsKIC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AgRXhhbXBsZQoKICAgYGBgamF2 YXNjcmlwdAogICBBcHAuUG9zdFNlcmlhbGl6ZXIgPSBEUy5KU09OU2VyaWFs aXplci5leHRlbmQoewogICAgIHNlcmlhbGl6ZUJlbG9uZ3NUbzogZnVuY3Rp b24ocmVjb3JkLCBqc29uLCByZWxhdGlvbnNoaXApIHsKICAgICAgIHZhciBr ZXkgPSByZWxhdGlvbnNoaXAua2V5OwoKICAgICAgIHZhciBiZWxvbmdzVG8g PSBnZXQocmVjb3JkLCBrZXkpOwoKICAgICAgIGtleSA9IHRoaXMua2V5Rm9y UmVsYXRpb25zaGlwID8gdGhpcy5rZXlGb3JSZWxhdGlvbnNoaXAoa2V5LCAi YmVsb25nc1RvIikgOiBrZXk7CgogICAgICAganNvbltrZXldID0gRW1iZXIu aXNOb25lKGJlbG9uZ3NUbykgPyBiZWxvbmdzVG8gOiBiZWxvbmdzVG8udG9K U09OKCk7CiAgICAgfQogICB9KTsKICAgYGBgCgogICBAbWV0aG9kIHNlcmlh bGl6ZUJlbG9uZ3NUbwogICBAcGFyYW0ge0RTLk1vZGVsfSByZWNvcmQKICAg QHBhcmFtIHtPYmplY3R9IGpzb24KICAgQHBhcmFtIHtPYmplY3R9IHJlbGF0 aW9uc2hpcAogICovCiAgc2VyaWFsaXplQmVsb25nc1RvOiBmdW5jdGlvbihy ZWNvcmQsIGpzb24sIHJlbGF0aW9uc2hpcCkgewogICAgdmFyIGtleSA9IHJl bGF0aW9uc2hpcC5rZXk7CgogICAgdmFyIGJlbG9uZ3NUbyA9IGdldChyZWNv cmQsIGtleSk7CgogICAga2V5ID0gdGhpcy5rZXlGb3JSZWxhdGlvbnNoaXAg PyB0aGlzLmtleUZvclJlbGF0aW9uc2hpcChrZXksICJiZWxvbmdzVG8iKSA6 IGtleTsKCiAgICBpZiAoaXNOb25lKGJlbG9uZ3NUbykpIHsKICAgICAganNv bltrZXldID0gYmVsb25nc1RvOwogICAgfSBlbHNlIHsKICAgICAganNvbltr ZXldID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lcmlhbGl6ZXI7CgogICAgdmFyIHB1 c2hEYXRhID0gewogICAgICBwb3N0czogWwogICAgICAgIHtpZDogMSwgcG9z dF90aXRsZTogIkdyZWF0IHBvc3QiLCBjb21tZW50X2lkczogWzJdfQogICAg ICBdLAogICAgICBjb21tZW50czogWwogICAgICAgIHtpZDogMiwgY29tbWVu dF9ib2R5OiAiSW5zaWdodGZ1bCBjb21tZW50In0KICAgICAgXQogICAgfQoK ICAgIHN0b3JlLnB1c2hQYXlsb2FkKCdwb3N0JywgcHVzaERhdGEpOwogICAg YGBgCgogICAgQG1ldGhvZCBwdXNoUGF5bG9hZAogICAgQHBhcmFtIHtTdHJp bmd9IHR5cGUKICAgIEBwYXJhbSB7T2JqZWN0fSBwYXlsb2FkCiAgICBAcmV0 dXJuIHtEUy5Nb2RlbH0gdGhlIHJlY29yZCB0aGF0IHdhcyBjcmVhdGVkIG9y IHVwZGF0ZWQuCiAgKi8KICBwdXNoUGF5bG9hZDogZnVuY3Rpb24gKHR5cGUs IHBheWxvYWQpIHsKICAgIHZhciBzZXJpYWxpemVyOwogICAgaWYgKCFwYXls b2FkKSB7CiAgICAgIHBheWxvYWQgPSB0eXBlOwogICAgICBzZXJpYWxpemVy ID0gZGVmYXVsdFNlcmlhbGl6ZXIodGhpcy5jb250YWluZXIpOwogICAgICBF bWJlci5hc3NlcnQoIllvdSBjYW5ub3QgdXNlIGBzdG9yZSNwdXNoUGF5bG9h ZGAgd2l0aG91dCBhIHR5cGUgdW5sZXNzIHlvdXIgZGVmYXVsdCBzZXJpYWxp emVyIGRlZmluZXMgYHB1c2hQYXlsb2FkYCIsIHNlcmlhbGl6ZXIucHVzaFBh eWxvYWQpOwogICAgfSBlbHNlIHsKICAgICAgc2VyaWFsaXplciA9IHRoaXMu c2VyaWFsaXplckZvcih0eXBlKTsKICAgIH0KICAgIHNlcmlhbGl6ZXIucHVz aFBheWxvYWQodGhpcywgcGF5bG9hZCk7CiAgfSwKCiAgdXBkYXRlOiBmdW5j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2V0KCdu YW1lJyk7IC8vICdUb21zdGVyJwogIH0pOwogIGBgYAoKICBAY2xhc3MgUHJv bWlzZU9iamVjdAogIEBuYW1lc3BhY2UgRFMKICBAZXh0ZW5kcyBFbWJlci5P YmplY3RQcm94eQogIEB1c2VzIEVtYmVyLlByb21pc2VQcm94eU1peGluCiov CkRTLlByb21pc2VPYmplY3QgPSBFbWJlci5PYmplY3RQcm94eS5leHRlbmQo RW1iZXIuUHJvbWlzZVByb3h5TWl4aW4pOwoKZnVuY3Rpb24gcHJvbWlzZU9i amVjdChwcm9taXNlKSB7CiAgcmV0dXJuIERTLlByb21pc2VPYmplY3QuY3Jl YXRlKHsgcHJvbWlzZTogcHJvbWlzZSB9KTsKfQoKZnVuY3Rpb24gcHJvbWlz ZUFycmF5KHByb21pc2UpIHsKICByZXR1cm4gRFMuUHJvbWlzZUFycmF5LmNy ZWF0ZSh7IHByb21pc2U6IHByb21pc2UgfSk7Cn0KCmZ1bmN0aW9uIGlzVGhl bmFibGUob2JqZWN0KSB7CiAgcmV0dXJuIG9iamVjdCAmJiB0eXBlb2Ygb2Jq ZWN0LnRoZW4gPT09ICdmdW5jdGlvbic7Cn0KCmZ1bmN0aW9uIHNlcmlhbGl6 ZXJGb3IoY29udGFpbmVyLCB0eXBlLCBkZWZhdWx0U2VyaWFsaXplcikgewog IHJldHVybiBjb250YWluZXIubG9va3VwKCdzZXJpYWxpemVyOicrdHlwZSkg fHwKICAgICAgICAgICAgICAgICBjb250YWluZXIubG9va3VwKCdzZXJpYWxp emVyOmFwcGxpY2F0aW9uJykgfHwKICAgICAgICAgICAgICAgICBjb250YWlu ZXIubG9va3VwKCdzZXJpYWxpemVyOicgKyBkZWZhdWx0U2VyaWFsaXplcikg fHwKICAgICAgICAgICAgICAgICBjb250YWluZXIubG9va3VwKCdzZXJpYWxp emVyOi1kZWZhdWx0Jyk7Cn0KCmZ1bmN0aW9uIGRlZmF1bHRTZXJpYWxpemVy KGNvbnRhaW5lcikgewogIHJldHVybiBjb250YWluZXIubG9va3VwKCdzZXJp YWxpemVyOmFwcGxpY2F0aW9uJykgfHwKICAgICAgICAgY29udGFpbmVyLmxv b2t1cCgnc2VyaWFsaXplcjotZGVmYXVsdCcpOwp9CgpmdW5jdGlvbiBzZXJp YWxpemVyRm9yQWRhcHRlcihhZGFwdGVyLCB0eXBlKSB7CiAgdmFyIHNlcmlh bGl6ZXIgPSBhZGFwdGVyLnNlcmlhbGl6ZXIsCiAgICAgIGRlZmF1bHRTZXJp YWxpemVyID0gYWRhcHRlci5kZWZhdWx0U2VyaWFsaXplciwKICAgICAgY29u dGFpbmVyID0gYWRhcHRlci5jb250YWluZXI7CgogIGlmIChjb250YWluZXIg JiYgc2VyaWFsaXplciA9PT0gdW5kZWZpbmVkKSB7CiAgICBzZXJpYWxpemVy ID0gc2VyaWFsaXplckZvcihjb250YWluZXIsIHR5cGUudHlwZUtleSwgZGVm YXVsdFNlcmlhbGl6ZXIpOwogIH0KCiAgaWYgKHNlcmlhbGl6ZXIgPT09IG51 bGwgfHwgc2VyaWFsaXplciA9PT0gdW5kZWZpbmVkKSB7CiAgICBzZXJpYWxp emVyID0gewogICAgICBleHRyYWN0OiBmdW5jdGlvbihzdG9yZSwgdHlwZSwg cGF5bG9hZCkgeyByZXR1cm4gcGF5bG9hZDsgfQogICAgfTsKICB9CgogIHJl dHVybiBzZXJpYWxpemVyOwp9CgpmdW5jdGlvbiBfZmluZChhZGFwdGVyLCBz dG9yZSwgdHlwZSwgaWQpIHsKICB2YXIgcHJvbWlzZSA9IGFkYXB0ZXIuZmlu ZChzdG9yZSwgdHlwZSwgaWQpLAogICAgICBzZXJpYWxpemVyID0gc2VyaWFs aXplckZvckFkYXB0ZXIoYWRhcHRlciwgdHlwZSk7CgogIHJldHVybiByZXNv bHZlKHByb21pc2UsICJEUzogSGFuZGxlIEFkYXB0ZXIjZmluZCBvZiAiICsg dHlwZSArICIgd2l0aCBpZDogIiArIGlkKS50aGVuKGZ1bmN0aW9uKHBheWx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xlIGlzIHNwZW50IGluc2lkZSBzdWJzdGF0 ZXMKICAvLyBvZiB0aGUgYGxvYWRlZGAgc3RhdGUuCiAgbG9hZGVkOiB7CiAg ICBpbml0aWFsU3RhdGU6ICdzYXZlZCcsCgogICAgLy8gRkxBR1MKICAgIGlz TG9hZGVkOiB0cnVlLAoKICAgIC8vIFNVQlNUQVRFUwoKICAgIC8vIElmIHRo ZXJlIGFyZSBubyBsb2NhbCBjaGFuZ2VzIHRvIGEgcmVjb3JkLCBpdCByZW1h aW5zCiAgICAvLyBpbiB0aGUgYHNhdmVkYCBzdGF0ZS4KICAgIHNhdmVkOiB7 CiAgICAgIHNldHVwOiBmdW5jdGlvbihyZWNvcmQpIHsKICAgICAgICB2YXIg YXR0cnMgPSByZWNvcmQuX2F0dHJpYnV0ZXMsCiAgICAgICAgICAgIGlzRGly dHkgPSBmYWxzZTsKCiAgICAgICAgZm9yICh2YXIgcHJvcCBpbiBhdHRycykg ewogICAgICAgICAgaWYgKGF0dHJzLmhhc093blByb3BlcnR5KHByb3ApKSB7 CiAgICAgICAgICAgIGlzRGlydHkgPSB0cnVlOwogICAgICAgICAgICBicmVh azsKICAgICAgICAgIH0KICAgICAgICB9CgogICAgICAgIGlmIChpc0RpcnR5 KSB7CiAgICAgICAgICByZWNvcmQuYWRhcHRlckRpZERpcnR5KCk7CiAgICAg ICAgfQogICAgICB9LAoKICAgICAgLy8gRVZFTlRTCiAgICAgIGRpZFNldFBy b3BlcnR5OiBkaWRTZXRQcm9wZXJ0eSwKCiAgICAgIHB1c2hlZERhdGE6IEVt YmVyLkssCgogICAgICBiZWNvbWVEaXJ0eTogZnVuY3Rpb24ocmVjb3JkKSB7 CiAgICAgICAgcmVjb3JkLnRyYW5zaXRpb25UbygndXBkYXRlZC51bmNvbW1p dHRlZCcpOwogICAgICB9LAoKICAgICAgd2lsbENvbW1pdDogZnVuY3Rpb24o cmVjb3JkKSB7CiAgICAgICAgcmVjb3JkLnRyYW5zaXRpb25UbygndXBkY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1vZGVsRGVsZXRlUm91dGUgPSBFbWJlci5Sb3V0 ZS5leHRlbmQoewogICAgICBhY3Rpb25zOiB7CiAgICAgICAgc29mdERlbGV0 ZTogZnVuY3Rpb24oKSB7CiAgICAgICAgICB0aGlzLmdldCgnbW9kZWwnKS5k ZWxldGVSZWNvcmQoKTsKICAgICAgICB9LAogICAgICAgIGNvbmZpcm06IGZ1 bmN0aW9uKCkgewogICAgICAgICAgdGhpcy5nZXQoJ21vZGVsJykuc2F2ZSgp OwogICAgICAgIH0sCiAgICAgICAgdW5kbzogZnVuY3Rpb24oKSB7CiAgICAg ICAgICB0aGlzLmdldCgnbW9kZWwnKS5yb2xsYmFjaygpOwogICAgICAgIH0K ICAgICAgfQogICAgfSk7CiAgICBgYGAKCiAgICBAbWV0aG9kIGRlbGV0ZVJl Y29yZAogICovCiAgZGVsZXRlUmVjb3JkOiBmdW5jdGlvbigpIHsKICAgIHRo aXMuc2VuZCgnZGVsZXRlUmVjb3JkJyk7CiAgfSwKCiAgLyoqCiAgICBTYW1l IGFzIGBkZWxldGVSZWNvcmRgLCBidXQgc2F2ZXMgdGhlIHJlY29yZCBpbW1l ZGlhdGVseS4KCiAgICBFeGFtcGxlCgogICAgYGBgamF2YXNjcmlwdAogICAg QXBwLk1vZGVsRGVsZXRlUm91dGUgPSBFbWJlci5Sb3V0ZS5leHRlbmQoewog ICAgICBhY3Rpb25zOiB7CiAgICAgICAgZGVsZXRlOiBmdW5jdGlvbigpIHsK ICAgICAgICAgIHZhciBjb250cm9sbGVyID0gdGhpcy5jb250cm9sbGVyOwog ICAgICAgICAgdGhpcy5nZXQoJ21vZGVsJykuZGVzdHJveVJlY29yZCgpLnRo ZW4oZnVuY3Rpb24oKSB7CiAgICAgICAgICAgIGNvbnRyb2xsZXIudHJhbnNp dGlvblRvUm91dGUoJ21vZGVsLmluZGV4Jyk7CiAgICAgICAgICB9KTsKICAg ICAgICB9CiAgICAgIH0KICAgIH0pOwogICAgYGBgCgogICAgQG1ldGh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IH0KICAgIH0KCiAgICBkZWxldGUgdGhp cy5fY2hhbmdlc1RvU3luY1trZXldOwogIH0pCn0pOwoKfSkoKTsKCgoKKGZ1 bmN0aW9uKCkgewovKioKICBAbW9kdWxlIGVtYmVyLWRhdGEKKi8KCnZhciBn ZXQgPSBFbWJlci5nZXQsIHNldCA9IEVtYmVyLnNldCwgc2V0UHJvcGVydGll cyA9IEVtYmVyLnNldFByb3BlcnRpZXM7CgpmdW5jdGlvbiBhc3luY0hhc01h bnkodHlwZSwgb3B0aW9ucywgbWV0YSkgewogIHJldHVybiBFbWJlci5jb21w dXRlZChmdW5jdGlvbihrZXksIHZhbHVlKSB7CiAgICB2YXIgcmVsYXRpb25z aGlwID0gdGhpcy5fcmVsYXRpb25zaGlwc1trZXldLAogICAgICAgIHByb21p c2VMYWJlbCA9ICJEUzogQXN5bmMgaGFzTWFueSAiICsgdGhpcyArICIgOiAi ICsga2V5OwoKICAgIGlmICghcmVsYXRpb25zaGlwKSB7CiAgICAgIHZhciBy ZXNvbHZlciA9IEVtYmVyLlJTVlAuZGVmZXIocHJvbWlzZUxhYmVsKTsKICAg ICAgcmVsYXRpb25zaGlwID0gYnVpbGRSZWxhdGlvbnNoaXAodGhpcywga2V5 LCBvcHRpb25zLCBmdW5jdGlvbihzdG9yZSwgZGF0YSkgewogICAgICAgIHZh ciBsaW5rID0gZGF0YS5saW5rcyAmJiBkYXRhLmxpbmtzW2tleV07CiAgICAg ICAgdmFyIHJlbDsKICAgICAgICBpZiAobGluaykgewogICAgICAgICAgcmVs ID0gc3RvcmUuZmluZEhhc01hbnkodGhpcywgbGluaywgbWV0YSwgcmVzb2x2 ZXIpOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICByZWwgPSBzdG9yZS5m aW5kTWFueSh0aGlzLCBkYXRhW2tleV0sIG1ldGEudHlwZSwgcmVzb2x2ZXIp OwogICAgICAgIH0KICAgICAgICAvLyBjYWNoZSB0aGUgcHJvbWlzZSBzbyB3 ZSBjYW4gd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XBzIGl0IGhhcyB3aXRoCiAgICB0aGUgbW9kZWwu CgogICAgRm9yIGV4YW1wbGUsIGdpdmVuIGEgbW9kZWwgd2l0aCB0aGlzIGRl ZmluaXRpb246CgogICAgYGBgamF2YXNjcmlwdAogICAgQXBwLkJsb2cgPSBE Uy5Nb2RlbC5leHRlbmQoewogICAgICB1c2VyczogRFMuaGFzTWFueSgndXNl cicpLAogICAgICBvd25lcjogRFMuYmVsb25nc1RvKCd1c2VyJyksCgogICAg ICBwb3N0czogRFMuaGFzTWFueSgncG9zdCcpCiAgICB9KTsKICAgIGBgYAoK ICAgIFRoaXMgcHJvcGVydHkgd291bGQgY29udGFpbiB0aGUgZm9sbG93aW5n OgoKICAgIGBgYGphdmFzY3JpcHQKICAgIHZhciByZWxhdGVkVHlwZXMgPSBF bWJlci5nZXQoQXBwLkJsb2csICdyZWxhdGVkVHlwZXMnKTsKICAgIC8vPT4g WyBBcHAuVXNlciwgQXBwLlBvc3QgXQogICAgYGBgCgogICAgQHByb3BlcnR5 IHJlbGF0ZWRUeXBlcwogICAgQHN0YXRpYwogICAgQHR5cGUgRW1iZXIuQXJy YXkKICAgIEByZWFkT25seQogICovCiAgcmVsYXRlZFR5cGVzOiBFbWJlci5j b21wdXRlZChmdW5jdGlvbigpIHsKICAgIHZhciB0eXBlLAogICAgICAgIHR5 cGVzID0gRW1iZXIuQSgpOwoKICAgIC8vIExvb3AgdGhyb3VnaCBlYWNoIGNv bXB1dGVkIHByb3BlcnR5IG9uIHRoZSBjbGFzcywKICAgIC8vIGFuZCBjcmVh dGUgYW4gYXJyYXkgb2YgdGhlIHVuaXF1ZSB0eXBlcyBpbnZvbHZlZAogICAg Ly8gaW4gcmVsYXRpb25zaGlwcwogICAgdGhpcy5lYWNoQ29tcHV0ZWRQcm9w ZXJ0eShmdW5jdGlvbihuYW1lLCBtZXRhKSB7CiAgICAgIGlmIChtZXRhLmlz UmVsYXRpb25zaGlwKSB7CiAgICAgICAgdHlwZSA9IG1ldGEudH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SKSB7CiAgICAg ICAgICAgIGpxWEhSLnRoZW4gPSBudWxsOyAvLyB0YW1lIGpRdWVyeSdzIGls bCBtYW5uZXJlZCBwcm9taXNlcwogICAgICAgICAgICBFbWJlci5ydW4obnVs bCwgcmVqZWN0LCBqcVhIUik7CiAgICAgICAgICB9KTsKICAgICAgICB9KTsK ICAgICAgfQogICAgfSk7CiAgICBgYGAKCiAgICBAcHJpdmF0ZQogICAgQG1l dGhvZCBmaW5kQWxsCiAgICBAcGFyYW0ge0RTLlN0b3JlfSBzdG9yZQogICAg QHBhcmFtIHtzdWJjbGFzcyBvZiBEUy5Nb2RlbH0gdHlwZQogICAgQHBhcmFt IHtTdHJpbmd9IHNpbmNlVG9rZW4KICAgIEByZXR1cm4ge1Byb21pc2V9IHBy b21pc2UKICAqLwogIGZpbmRBbGw6IG51bGwsCgogIC8qKgogICAgVGhpcyBt ZXRob2QgaXMgY2FsbGVkIHdoZW4geW91IGNhbGwgYGZpbmRgIG9uIHRoZSBz dG9yZSB3aXRoIGEKICAgIHF1ZXJ5IG9iamVjdCBhcyB0aGUgc2Vjb25kIHBh cmFtZXRlciAoaS5lLiBgc3RvcmUuZmluZCgncGVyc29uJywgewogICAgcGFn ZTogMSB9KWApLgoKICAgIEV4YW1wbGUKCiAgICBgYGBqYXZhc2NyaXB0CiAg ICBBcHAuQXBwbGljYXRpb25BZGFwdGVyID0gRFMuQWRhcHRlci5leHRlbmQo ewogICAgICBmaW5kUXVlcnk6IGZ1bmN0aW9uKHN0b3JlLCB0eXBlLCBxdWVy eSkgewogICAgICAgIHZhciB1cmwgPSB0eXBlOwogICAgICAgIHJldHVybiBu ZXcgRW1iZXIuUlNWUC5Qcm9taXNlKGZ1bmN0aW9uKHJlc29sdmUsIHJlamVj dCkgewogICAgICAgICAgalF1ZXJ5LmdldEpTT04odXJsLCBxdWVyeSkudGhl bihmdW5jdGlvbihkYXRhKSB7CiAgICAgICAgICAgIEVtYmVyLnJ1bihudWxs LCByZXNvbHZlLCB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GBqYXZhc2NyaXB0CiAgICB7CiAgICAgICJwb3N0IjogewogICAg ICAgICJpZCI6IDEsCiAgICAgICAgInRpdGxlIjogIlJhaWxzIGlzIG9tYWth c2UiLAogICAgICAgICJjb21tZW50cyI6IFsgMSwgMiBdCiAgICAgIH0sCiAg ICAgICJjb21tZW50cyI6IFt7CiAgICAgICAgIl9pZCI6IDEsCiAgICAgICAg ImJvZHkiOiAiRklSU1QiCiAgICAgIH0sIHsKICAgICAgICAiX2lkIjogMiwK ICAgICAgICAiYm9keSI6ICJSYWlscyBpcyB1bmFnaSIKICAgICAgfV0KICAg IH0KICAgIGBgYAoKICAgIFlvdSB1c2UgYG5vcm1hbGl6ZUhhc2hgIHRvIG5v cm1hbGl6ZSBqdXN0IHRoZSBjb21tZW50czoKCiAgICBgYGBqYXZhc2NyaXB0 CiAgICBBcHAuUG9zdFNlcmlhbGl6ZXIgPSBEUy5SRVNUU2VyaWFsaXplci5l eHRlbmQoewogICAgICBub3JtYWxpemVIYXNoOiB7CiAgICAgICAgY29tbWVu dHM6IGZ1bmN0aW9uKGhhc2gpIHsKICAgICAgICAgIGhhc2guaWQgPSBoYXNo Ll9pZDsKICAgICAgICAgIGRlbGV0ZSBoYXNoLl9pZDsKICAgICAgICAgIHJl dHVybiBoYXNoOwogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICBgYGAK CiAgICBUaGUga2V5IHVuZGVyIGBub3JtYWxpemVIYXNoYCBpcyB1c3VhbGx5 IGp1c3QgdGhlIG9yaWdpbmFsIGtleQogICAgdGhhdCB3YXMgaW4gdGhlIG9y aWdpbmFsIHBheWxvYWQuIEhvd2V2ZXIsIGtleSBuYW1lcyB3aWxsIGJlCiAg ICBpbXBhY3RlZCBieSBhbnkgbW9kaWZpY2F0aW9ucyBkb25lIGluIHRoZSBg bm9ybWFsaXplUGF5bG9hZGAKICAgIG1ldGhvZC4gVGhlIGBEUy5SRVNUU2Vy aWFsaXplcmAncyBkZWZhdWx0IGltcGxlbWVudG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BwYXlsb2FkIGxpa2UgdGhpcyBpbiByZXNwb25zZSB0 byBhIHJlcXVlc3QgZm9yCiAgICBhbGwgcG9zdHM6CgogICAgYGBganMKICAg IHsKICAgICAgIl9lbWJlZGRlZCI6IHsKICAgICAgICAicG9zdCI6IFt7CiAg ICAgICAgICAiaWQiOiAxLAogICAgICAgICAgInRpdGxlIjogIlJhaWxzIGlz IG9tYWthc2UiCiAgICAgICAgfSwgewogICAgICAgICAgImlkIjogMiwKICAg ICAgICAgICJ0aXRsZSI6ICJUaGUgUGFybGV5IExldHRlciIKICAgICAgICB9 XSwKICAgICAgICAiY29tbWVudCI6IFt7CiAgICAgICAgICAiX2lkIjogMSwK ICAgICAgICAgICJjb21tZW50X3RpdGxlIjogIlJhaWxzIGlzIHVuYWdpIgog ICAgICAgICAgInBvc3RfaWQiOiAxCiAgICAgICAgfSwgewogICAgICAgICAg Il9pZCI6IDIsCiAgICAgICAgICAiY29tbWVudF90aXRsZSI6ICJEb24ndCB0 cmVhZCBvbiBtZSIsCiAgICAgICAgICAicG9zdF9pZCI6IDIKICAgICAgICB9 XQogICAgICB9CiAgICB9CiAgICBgYGAKCiAgICBZb3UgY291bGQgaW1wbGVt ZW50IGEgc2VyaWFsaXplciB0aGF0IGxvb2tzIGxpa2UgdGhpcyB0byBnZXQg eW91ciBwYXlsb2FkCiAgICBpbnRvIHNoYXBlOgoKICAgIGBgYGpzCiAgICBB cHAuUG9zdFNlcmlhbGl6ZXIgPSBEUy5SRVNUU2VyaWFsaXplci5leHRlbmQo ewogICAgICAvLyBGaXJzdCwgcmVzdHJ1Y3R1cmUgdGhlIHRvcC1sZXZlbCBz byBpdCdzIG9yZ2FuaXplZCBieSB0eXBlCiAgICAgIC8vIGFuZCB0aGUgY29t bWVudHMgYXJlIGxpc3RlZCB1bmRlciBhIHBvc3QncyBgY29tbWVudHNgIGtl eS4KICAgICAgZXh0cmFjdEFycmF5OiBmdW5jdGlvbihzdG9yZSwgdHlwZSwg cGF5bG9hZCw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cGVGb3JSb290 KHR5cGVLZXkpLAogICAgICAgICAgdHlwZSA9IHN0b3JlLm1vZGVsRm9yKHR5 cGVOYW1lKSwKICAgICAgICAgIHR5cGVTZXJpYWxpemVyID0gc3RvcmUuc2Vy aWFsaXplckZvcih0eXBlKSwKICAgICAgICAgIGlzUHJpbWFyeSA9ICghZm9y Y2VkU2Vjb25kYXJ5ICYmICh0eXBlLnR5cGVLZXkgPT09IHByaW1hcnlUeXBl TmFtZSkpOwoKICAgICAgLypqc2hpbnQgbG9vcGZ1bmM6dHJ1ZSovCiAgICAg IHZhciBub3JtYWxpemVkQXJyYXkgPSBtYXAuY2FsbChwYXlsb2FkW3Byb3Bd LCBmdW5jdGlvbihoYXNoKSB7CiAgICAgICAgcmV0dXJuIHR5cGVTZXJpYWxp emVyLm5vcm1hbGl6ZSh0eXBlLCBoYXNoLCBwcm9wKTsKICAgICAgfSwgdGhp cyk7CgogICAgICBpZiAoaXNQcmltYXJ5KSB7CiAgICAgICAgcHJpbWFyeUFy cmF5ID0gbm9ybWFsaXplZEFycmF5OwogICAgICB9IGVsc2UgewogICAgICAg IHN0b3JlLnB1c2hNYW55KHR5cGVOYW1lLCBub3JtYWxpemVkQXJyYXkpOwog ICAgICB9CiAgICB9CgogICAgcmV0dXJuIHByaW1hcnlBcnJheTsKICB9LAoK ICAvKioKICAgIFRoaXMgbWV0aG9kIGFsbG93cyB5b3UgdG8gcHVzaCBhIHBh eWxvYWQgY29udGFpbmluZyB0b3AtbGV2ZWwKICAgIGNvbGxlY3Rpb25zIG9m IHJlY29yZHMgb3JnYW5pemVkIHBlciB0eXBlLgoKICAgIGBgYGpzCiAgICB7 CiAgICAgICJwb3N0cyI6IFt7CiAgICAgICAgImlkIjogIjEiLAogICAgICAg ICJ0aXRsZSI6ICJSYWlscyBpcyBvbWFrYXNlIiwKICAgICAgICAiYXV0aG9y IiwgIjEiLAogICAgICAgICJjb21tZW50cyI6IFsgIjEiIF0KICAgICAgfV0s CiAgICAgICJjb21t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W5jbHVkZUlkKSB7CiAg ICAgICAgICBqc29uLlBPU1RfSURfID0gcG9zdC5nZXQoJ2lkJyk7CiAgICAg ICAgfQoKICAgICAgICByZXR1cm4ganNvbjsKICAgICAgfQogICAgfSk7CiAg ICBgYGAKCiAgICAjIyBDdXN0b21pemluZyBhbiBBcHAtV2lkZSBTZXJpYWxp emVyCgogICAgSWYgeW91IHdhbnQgdG8gZGVmaW5lIGEgc2VyaWFsaXplciBm b3IgeW91ciBlbnRpcmUKICAgIGFwcGxpY2F0aW9uLCB5b3UnbGwgcHJvYmFi bHkgd2FudCB0byB1c2UgYGVhY2hBdHRyaWJ1dGVgCiAgICBhbmQgYGVhY2hS ZWxhdGlvbnNoaXBgIG9uIHRoZSByZWNvcmQuCgogICAgYGBganMKICAgIEFw cC5BcHBsaWNhdGlvblNlcmlhbGl6ZXIgPSBEUy5SRVNUU2VyaWFsaXplci5l eHRlbmQoewogICAgICBzZXJpYWxpemU6IGZ1bmN0aW9uKHJlY29yZCwgb3B0 aW9ucykgewogICAgICAgIHZhciBqc29uID0ge307CgogICAgICAgIHJlY29y ZC5lYWNoQXR0cmlidXRlKGZ1bmN0aW9uKG5hbWUpIHsKICAgICAgICAgIGpz b25bc2VydmVyQXR0cmlidXRlTmFtZShuYW1lKV0gPSByZWNvcmQuZ2V0KG5h bWUpOwogICAgICAgIH0pCgogICAgICAgIHJlY29yZC5lYWNoUmVsYXRpb25z aGlwKGZ1bmN0aW9uKG5hbWUsIHJlbGF0aW9uc2hpcCkgewogICAgICAgICAg aWYgKHJlbGF0aW9uc2hpcC5raW5kID09PSAnaGFzTWFueScpIHsKICAgICAg ICAgICAganNvbltzZXJ2ZXJIYXNNYW55TmFtZShuYW1lKV0gPSByZWNvcmQu Z2V0KG5hbWUpLm1hcEJ5KCdpZCcpOwogICAgICAgICAgfQogICAgICAgIH0p OwoKICAgICAgICBpZiAob3B0aW9ucy5pbmNsdWRlSWQpIHsKICAgICAgICAg IGpzb24uSURfID0gcmVjb3J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iAgICB2YXIgZ3JvdXBzID0gWwog ICAgICB7CiAgICAgICAgbmFtZTogJ0F0dHJpYnV0ZXMnLAogICAgICAgIHBy b3BlcnRpZXM6IGF0dHJpYnV0ZXMsCiAgICAgICAgZXhwYW5kOiB0cnVlCiAg ICAgIH0sCiAgICAgIHsKICAgICAgICBuYW1lOiAnQmVsb25ncyBUbycsCiAg ICAgICAgcHJvcGVydGllczogcmVsYXRpb25zaGlwcy5iZWxvbmdzVG8sCiAg ICAgICAgZXhwYW5kOiB0cnVlCiAgICAgIH0sCiAgICAgIHsKICAgICAgICBu YW1lOiAnSGFzIE1hbnknLAogICAgICAgIHByb3BlcnRpZXM6IHJlbGF0aW9u c2hpcHMuaGFzTWFueSwKICAgICAgICBleHBhbmQ6IHRydWUKICAgICAgfSwK ICAgICAgewogICAgICAgIG5hbWU6ICdGbGFncycsCiAgICAgICAgcHJvcGVy dGllczogWydpc0xvYWRlZCcsICdpc0RpcnR5JywgJ2lzU2F2aW5nJywgJ2lz RGVsZXRlZCcsICdpc0Vycm9yJywgJ2lzTmV3JywgJ2lzVmFsaWQnXQogICAg ICB9CiAgICBdOwoKICAgIHJldHVybiB7CiAgICAgIHByb3BlcnR5SW5mbzog ewogICAgICAgIC8vIGluY2x1ZGUgYWxsIG90aGVyIG1peGlucyAvIHByb3Bl cnRpZXMgKG5vdCBqdXN0IHRoZSBncm91cGVkIG9uZXMpCiAgICAgICAgaW5j bHVkZU90aGVyUHJvcGVydGllczogdHJ1ZSwKICAgICAgICBncm91cHM6IGdy b3VwcywKICAgICAgICAvLyBkb24ndCBwcmUtY2FsY3VsYXRlIHVubGVzcyBj YWNoZWQKICAgICAgICBleHBlbnNpdmVQcm9wZXJ0aWVzOiBleHBlbnNpdmVQ cm9wZXJ0aWVzCiAgICAgIH0KICAgIH07CiAgfQoKfSk7Cgp9KSgpOwoKCgoo ZnVuY3Rpb24oKSB7Ci8qKgogIEBtb2R1bGUgZW1iZXItZGF0YQoqLwoKfSko KTsKCgoK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ICBmb3IgKHZhciBsaW5rIGluIGxpbmtzKSB7CiAgICAgICAgdmFyIGNhbWVs aXplZExpbmsgPSBjYW1lbGl6ZShsaW5rKTsKCiAgICAgICAgaWYgKGNhbWVs aXplZExpbmsgIT09IGxpbmspIHsKICAgICAgICAgIGxpbmtzW2NhbWVsaXpl ZExpbmtdID0gbGlua3NbbGlua107CiAgICAgICAgICBkZWxldGUgbGlua3Nb bGlua107CiAgICAgICAgfQogICAgICB9CiAgICB9CiAgfSwKCiAgLyoqCiAg ICBOb3JtYWxpemUgdGhlIHBvbHltb3JwaGljIHR5cGUgZnJvbSB0aGUgSlNP Ti4KCiAgICBOb3JtYWxpemU6CiAgICBgYGBqcwogICAgICB7CiAgICAgICAg aWQ6ICIxIgogICAgICAgIG1pbmlvbjogeyB0eXBlOiAiZXZpbF9taW5pb24i LCBpZDogIjEyIn0KICAgICAgfQogICAgYGBgCgogICAgVG86CiAgICBgYGBq cwogICAgICB7CiAgICAgICAgaWQ6ICIxIgogICAgICAgIG1pbmlvbjogeyB0 eXBlOiAiZXZpbE1pbmlvbiIsIGlkOiAiMTIifQogICAgICB9CiAgICBgYGAK CiAgICBAbWV0aG9kIG5vcm1hbGl6ZVJlbGF0aW9uc2hpcHMKICAgIEBwcml2 YXRlCiAgKi8KICBub3JtYWxpemVSZWxhdGlvbnNoaXBzOiBmdW5jdGlvbih0 eXBlLCBoYXNoKSB7CiAgICB2YXIgcGF5bG9hZEtleSwgcGF5bG9hZDsKCiAg ICBpZiAodGhpcy5rZXlGb3JSZWxhdGlvbnNoaXApIHsKICAgICAgdHlwZS5l YWNoUmVsYXRpb25zaGlwKGZ1bmN0aW9uKGtleSwgcmVsYXRpb25zaGlwKSB7 CiAgICAgICAgaWYgKHJlbGF0aW9uc2hpcC5vcHRpb25zLnBvbHltb3JwaGlj KSB7CiAgICAgICAgICBwYXlsb2FkS2V5ID0gdGhpcy5rZXlGb3JBdHRyaWJ1 dGUoa2V5KTsKICAgICAgICAgIHBheWxvYWQgPSBoYXNoW3BheWxvYWRLZXld OwogICAgICAgICAgaWYgKHBheWxvYWQgJiYgcGF5bG9hZC50eXBlKSB7CiAg ICAgICAgICAgIHBheWxvYWQudHlwZSA9IHRoaXMudHlwZUZvclJvb3QocGF5 bG9hZC50eXBlKTsKICAgICAgICAgIH0gZWxzZSBpZiAocGF5bG9hZCAmJiBy ZWxhdGlvbnNoaXAua2luZCA9PT0gImhhc01hbnkiKSB7CiAgICAgICAgICAg IHZhciBzZWxmID0gdGhpczsKICAgICAgICAgICAgZm9yRWFjaChwYXlsb2Fk LCBmdW5jdGlvbihzaW5nbGUpIHsKICAgICAgICAgICAgICBzaW5nbGUudHlw ZSA9IHNlbGYudHlwZUZvclJvb3Qoc2luZ2xlLnR5cGUpOwogICAgICAgICAg ICB9KTsKICAgICAgICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAg cGF5bG9hZEtleSA9IHRoaXMua2V5Rm9yUmVsYXRpb25zaGlwKGtleSwgcmVs YXRpb25zaGlwLmtpbmQpOwogICAgICAgICAgcGF5bG9hZCA9IGhhc2hbcGF5 bG9hZEtleV07CiAgICAgICAgfQoKICAgICAgICBoYXNoW2tleV0gPSBwYXls b2FkOwoKICAgICAgICBpZiAoa2V5ICE9PSBwYXlsb2FkS2V5KSB7CiAgICAg ICAgICBkZWxldGUgaGFzaFtwYXlsb2FkS2V5XTsKICAgICAgICB9CiAgICAg IH0sIHRoaXMpOwogICAgfQogIH0KfSk7Cgp9KSgpOwoKCgooZnVuY3Rpb24o KSB7CnZhciBnZXQgPSBFbWJlci5nZXQ7CnZhciBmb3JFYWNoID0gRW1iZXIu RW51bWVyYWJsZVV0aWxzLmZvckVhY2g7CgovKioKICBUaGUgRW1iZWRkZWRS ZWNvcmRzTWl4aW4gYWxsb3dzIHlvdSB0byBhZGQgZW1iZWRkZWQgcmVjb3Jk IHN1cHBvcnQgdG8geW91cgogIHNlcmlhbGl6ZXJzLgogIFRvIHNldCB1cCBl bWJlZGRlZCBy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, 17 Feb 2014 11:44:59 GMT - request: method: get uri: http://builds.emberjs.com/beta/ember-data.min.js body: encoding: US-ASCII string: '' headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - '*/*' User-Agent: - Ruby Host: - builds.emberjs.com response: status: code: 200 message: OK headers: X-Amz-Id-2: - hvDZkcrX7EydavwfFcAHNvqYCe23n+DLqj0Yt1RwbI0l06/IA4o+xPCT7/5wOAFc X-Amz-Request-Id: - 81506E0D46372679 Date: - Mon, 17 Feb 2014 11:45:01 GMT Last-Modified: - Sun, 26 Jan 2014 02:04:26 GMT Etag: - '"4bc58817f377007755b986a16db4a7c8"' Content-Type: - text/javascript Content-Length: - '71020' Server: - AmazonS3 body: encoding: UTF-8 string: |- /*! * @overview Ember Data * @copyright Copyright 2011-2014 Tilde Inc. and contributors. * Portions Copyright 2011 LivingSocial Inc. * @license Licensed under MIT license (see license.js) * @version 1.0.0-beta.6 */ !function(){var e,t;!function(){var r={},n={};e=function(e,t,n){r[e]={deps:t,callback:n}},t=function(e){if(n[e])return n[e];n[e]={};var i,a,o,s,d;if(i=r[e],!i)throw new Error("Module '"+e+"' not found.");a=i.deps,o=i.callback,s=[];for(var u=0,c=a.length;c>u;u++)"exports"===a[u]?s.push(d={}):s.push(t(a[u]));var l=o.apply(this,s);return n[e]=d||l}}(),function(){var e;"undefined"==typeof e&&(e=Ember.Namespace.create({VERSION:"1.0.0-beta.6"}),"undefined"!=typeof window&&(window.DS=e),Ember.libraries&&Ember.libraries.registerCoreLibrary("Ember Data",e.VERSION))}(),function(){var e=function(e){this.container=e};e.prototype.aliasedFactory=function(e,t){var r=this;return{create:function(){return t&&t(),r.container.lookup(e)}}},e.prototype.registerAlias=function(e,t,r){var n=this.aliasedFactory(t,r);return this.container.register(e,n)},e.prototype.registerDeprecation=function(e,t){var r=function(){Ember.deprecate("You tried to look up '"+e+"', but this has been deprecated in favor of '"+t+"'.",!1)};return this.registerAlias(e,t,r)},e.prototype.registerDeprecations=function(e){for(var t=e.length;t>0;t--){var r=e[t-1],n=r.deprecated,i=r.valid;this.registerDeprecation(n,i)}},DS.ContainerProxy=e}(),function(){function e(e){return function(){return this[e].apply(this,arguments)}}var t=Ember.get,r=(Ember.set,Ember.isNone);DS.JSONSerializer=Ember.Object.extend({primaryKey:"id",applyTransforms:function(e,t){return e.eachTransformedAttribute(function(e,r){var n=this.transformFor(r);t[e]=n.deserialize(t[e])},this),t},normalize:function(e,t){return t?(this.applyTransforms(e,t),t):t},serialize:function(e,r){var n={};if(r&&r.includeId){var i=t(e,"id");i&&(n[t(this,"primaryKey")]=i)}return e.eachAttribute(function(t,r){this.serializeAttribute(e,n,t,r)},this),e.eachRelationship(function(t,r){"belongsTo"===r.kind?this.serializeBelongsTo(e,n,r):"hasMany"===r.kind&&this.serializeHasMany(e,n,r)},this),n},serializeAttribute:function(e,r,n,i){var a=t(this,"attrs"),o=t(e,n),s=i.type;if(s){var d=this.transformFor(s);o=d.serialize(o)}n=a&&a[n]||(this.keyForAttribute?this.keyForAttribute(n):n),r[n]=o},serializeBelongsTo:function(e,n,i){var a=i.key,o=t(e,a);a=this.keyForRelationship?this.keyForRelationship(a,"belongsTo"):a,n[a]=r(o)?o:t(o,"id"),i.options.polymorphic&&this.serializePolymorphicType(e,n,i)},serializeHasMany:function(e,r,n){var i=n.key,a=DS.RelationshipChange.determineRelationshipType(e.constructor,n);("manyToNone"===a||"manyToMany"===a)&&(r[i]=t(e,i).mapBy("id"))},serializePolymorphicType:Ember.K,extract:function(e,t,r,n,i){this.extractMeta(e,t,r);var a="extract"+i.charAt(0).toUpperCase()+i.substr(1);return this[a](e,t,r,n,i)},extractFindAll:e("extractArray"),extractFindQuery:e("extractArray"),extractFindMany:e("extractArray"),extractFindHasMany:e("extractArray"),extractCreateRecord:e("extractSave"),extractUpdateRecord:e("extractSave"),extractDeleteRecord:e("extractSave"),extractFind:e("extractSingle"),extractFindBelongsTo:e("extractSingle"),extractSave:e("extractSingle"),extractSingle:function(e,t,r){return this.normalize(t,r)},extractArray:function(e,t,r){return this.normalize(t,r)},extractMeta:function(e,t,r){r&&r.meta&&(e.metaForType(t,r.meta),delete r.meta)},transformFor:function(e,t){var r=this.container.lookup("transform:"+e);return Ember.assert("Unable to find transform for '"+e+"'",t||!!r),r}})}(),function(){var e=Ember.get,t=Ember.String.capitalize,r=Ember.String.underscore,n=window.DS;n.DebugAdapter=Ember.DataAdapter.extend({getFilters:function(){return[{name:"isNew",desc:"New"},{name:"isModified",desc:"Modified"},{name:"isClean",desc:"Clean"}]},detect:function(e){return e!==n.Model&&n.Model.detect(e)},columnsForType:function(n){var i=[{name:"id",desc:"Id"}],a=0,o=this;return e(n,"attributes").forEach(function(e){if(a++>o.attributeLimit)return!1;var n=t(r(e).replace("_"," "));i.push({name:e,desc:n})}),i},getRecords:function(e){return this.get("store").all(e)},getRecordColumnValues:function(t){var r=this,n=0,i={id:e(t,"id")};return t.eachAttribute(function(a){if(n++>r.attributeLimit)return!1;var o=e(t,a);i[a]=o}),i},getRecordKeywords:function(t){var r=[],n=Ember.A(["id"]);return t.eachAttribute(function(e){n.push(e)}),n.forEach(function(n){r.push(e(t,n))}),r},getRecordFilterValues:function(e){return{isNew:e.get("isNew"),isModified:e.get("isDirty")&&!e.get("isNew"),isClean:!e.get("isDirty")}},getRecordColor:function(e){var t="black";return e.get("isNew")?t="green":e.get("isDirty")&&(t="blue"),t},observeRecord:function(e,t){var r=Ember.A(),n=this,i=Ember.A(["id","isNew","isDirty"]);e.eachAttribute(function(e){i.push(e)}),i.forEach(function(i){var a=function(){t(n.wrapRecord(e))};Ember.addObserver(e,i,a),r.push(function(){Ember.removeObserver(e,i,a)})});var a=function(){r.forEach(function(e){e()})};return a}})}(),function(){DS.Transform=Ember.Object.extend({serialize:Ember.required(),deserialize:Ember.required()})}(),function(){DS.BooleanTransform=DS.Transform.extend({deserialize:function(e){var t=typeof e;return"boolean"===t?e:"string"===t?null!==e.match(/^true$|^t$|^1$/i):"number"===t?1===e:!1},serialize:function(e){return Boolean(e)}})}(),function(){DS.DateTransform=DS.Transform.extend({deserialize:function(e){var t=typeof e;return"string"===t?new Date(Ember.Date.parse(e)):"number"===t?new Date(e):null===e||void 0===e?e:null},serialize:function(e){return e instanceof Date?Number(e):null}})}(),function(){var e=Ember.isEmpty;DS.NumberTransform=DS.Transform.extend({deserialize:function(t){return e(t)?null:Number(t)},serialize:function(t){return e(t)?null:Number(t)}})}(),function(){var e=Ember.isNone;DS.StringTransform=DS.Transform.extend({deserialize:function(t){return e(t)?null:String(t)},serialize:function(t){return e(t)?null:String(t)}})}(),function(){Ember.set;Ember.onLoad("Ember.Application",function(e){e.initializer({name:"store",initialize:function(e,t){t.register("store:main",t.Store||DS.Store);var r=new DS.ContainerProxy(e);r.registerDeprecations([{deprecated:"serializer:_default",valid:"serializer:-default"},{deprecated:"serializer:_rest",valid:"serializer:-rest"},{deprecated:"adapter:_rest",valid:"adapter:-rest"}]),t.register("serializer:-default",DS.JSONSerializer),t.register("serializer:-rest",DS.RESTSerializer),t.register("adapter:-rest",DS.RESTAdapter),e.lookup("store:main")}}),e.initializer({name:"transforms",before:"store",initialize:function(e,t){t.register("transform:boolean",DS.BooleanTransform),t.register("transform:date",DS.DateTransform),t.register("transform:number",DS.NumberTransform),t.register("transform:string",DS.StringTransform)}}),e.initializer({name:"data-adapter",before:"store",initialize:function(e,t){t.register("data-adapter:main",DS.DebugAdapter)}}),e.initializer({name:"injectStore",before:"store",initialize:function(e,t){t.inject("controller","store","store:main"),t.inject("route","store","store:main"),t.inject("serializer","store","store:main"),t.inject("data-adapter","store","store:main")}})})}(),function(){Ember.Date=Ember.Date||{};var e=Date.parse,t=[1,4,5,6,7,10,11];Ember.Date.parse=function(r){var n,i,a=0;if(i=/^(\d{4}|[+\-]\d{6})(?:-(\d{2})(?:-(\d{2}))?)?(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{3}))?)?(?:(Z)|([+\-])(\d{2})(?::(\d{2}))?)?)?$/.exec(r)){for(var o,s=0;o=t[s];++s)i[o]=+i[o]||0;i[2]=(+i[2]||1)-1,i[3]=+i[3]||1,"Z"!==i[8]&&void 0!==i[9]&&(a=60*i[10]+i[11],"+"===i[9]&&(a=0-a)),n=Date.UTC(i[1],i[2],i[3],i[4],i[5]+a,i[6],i[7])}else n=e?e(r):0/0;return n},(Ember.EXTEND_PROTOTYPES===!0||Ember.EXTEND_PROTOTYPES.Date)&&(Date.parse=Ember.Date.parse)}(),function(){{var e=Ember.get;Ember.set}DS.RecordArray=Ember.ArrayProxy.extend(Ember.Evented,{type:null,content:null,isLoaded:!1,isUpdating:!1,store:null,objectAtContent:function(t){var r=e(this,"content");return r.objectAt(t)},update:function(){if(!e(this,"isUpdating")){var t=e(this,"store"),r=e(this,"type");return t.fetchAll(r,this)}},addRecord:function(t){e(this,"content").addObject(t)},removeRecord:function(t){e(this,"content").removeObject(t)},save:function(){var t="DS: RecordArray#save "+e(this,"type"),r=Ember.RSVP.all(this.invoke("save"),t).then(function(e){return Ember.A(e)},null,"DS: RecordArray#save apply Ember.NativeArray");return DS.PromiseArray.create({promise:r})}})}(),function(){var e=Ember.get;DS.FilteredRecordArray=DS.RecordArray.extend({filterFunction:null,isLoaded:!0,replace:function(){var t=e(this,"type").toString();throw new Error("The result of a client-side filter (on "+t+") is immutable.")},updateFilter:Ember.observer(function(){var t=e(this,"manager");t.updateFilter(this,e(this,"type"),e(this,"filterFunction"))},"filterFunction")})}(),function(){{var e=Ember.get;Ember.set}DS.AdapterPopulatedRecordArray=DS.RecordArray.extend({query:null,replace:function(){var t=e(this,"type").toString();throw new Error("The result of a server query (on "+t+") is immutable.")},load:function(t){var r=e(this,"store"),n=e(this,"type"),i=r.pushMany(n,t),a=r.metadataFor(n);this.setProperties({content:Ember.A(i),isLoaded:!0,meta:a}),Ember.run.once(this,"trigger","didLoad")}})}(),function(){var e=Ember.get,t=Ember.set,r=Ember.EnumerableUtils.map;DS.ManyArray=DS.RecordArray.extend({init:function(){this._super.apply(this,arguments),this._changesToSync=Ember.OrderedSet.create()},name:null,owner:null,isPolymorphic:!1,isLoaded:!1,promise:null,loadingRecordsCount:function(e){this.loadingRecordsCount=e},loadedRecord:function(){this.loadingRecordsCount--,0===this.loadingRecordsCount&&(t(this,"isLoaded",!0),this.trigger("didLoad"))},fetch:function(){var t=e(this,"content"),r=e(this,"store"),n=e(this,"owner"),i=Ember.RSVP.defer("DS: ManyArray#fetch "+e(this,"type")),a=t.filterProperty("isEmpty",!0);r.fetchMany(a,n,i)},replaceContent:function(e,t,n){n=r(n,function(e){return Ember.assert("You cannot add '"+e.constructor.typeKey+"' records to this relationship (only '"+this.type.typeKey+"' allowed)",!this.type||e instanceof this.type),e},this),this._super(e,t,n)},arrangedContentDidChange:function(){Ember.run.once(this,"fetch")},arrayContentWillChange:function(t,r){var n=e(this,"owner"),i=e(this,"name");if(!n._suspendedRelationships)for(var a=t;t+r>a;a++){var o=e(this,"content").objectAt(a),s=DS.RelationshipChange.createChange(n,o,e(this,"store"),{parentType:n.constructor,changeType:"remove",kind:"hasMany",key:i});this._changesToSync.add(s)}return this._super.apply(this,arguments)},arrayContentDidChange:function(t,r,n){this._super.apply(this,arguments);var i=e(this,"owner"),a=e(this,"name"),o=e(this,"store");if(!i._suspendedRelationships){for(var s=t;t+n>s;s++){var d=e(this,"content").objectAt(s),u=DS.RelationshipChange.createChange(i,d,o,{parentType:i.constructor,changeType:"add",kind:"hasMany",key:a});u.hasManyName=a,this._changesToSync.add(u)}this._changesToSync.forEach(function(e){e.sync()}),this._changesToSync.clear()}},createRecord:function(t){var r,n=e(this,"owner"),i=e(n,"store"),a=e(this,"type");return Ember.assert("You cannot add '"+a.typeKey+"' records to this polymorphic relationship.",!e(this,"isPolymorphic")),r=i.createRecord.call(i,a,t),this.pushObject(r),r}})}(),function(){function e(e,r,a,o){return r.eachRelationship(function(r,s){if(a.links&&a.links[r])return o&&s.options.async&&(o._relationships[r]=null),void 0;var d=s.kind,u=a[r];null!=u&&("belongsTo"===d?t(e,a,r,s,u):"hasMany"===d&&(n(e,a,r,s,u),i(o,r,u)))}),a}function t(e,t,n,i,a){if(!(R(a)||a instanceof DS.Model)){var o;"number"==typeof a||"string"==typeof a?(o=r(i,n,t),t[n]=e.recordForId(o,a)):"object"==typeof a&&(t[n]=e.recordForId(a.type,a.id))}}function r(e,t,r){return e.options.polymorphic?r[t+"Type"]:e.type}function n(e,r,n,i,a){for(var o=0,s=a.length;s>o;o++)t(e,a,o,i,a[o])}function i(e,t,r){e&&r.pushObjects(e.get(t).filterBy("isNew"))}function a(e){return DS.PromiseObject.create({promise:e})}function o(e){return DS.PromiseArray.create({promise:e})}function s(e){return e&&"function"==typeof e.then}function d(e,t,r){return e.lookup("serializer:"+t)||e.lookup("serializer:application")||e.lookup("serializer:"+r)||e.lookup("serializer:-default")}function u(e){return e.lookup("serializer:application")||e.lookup("serializer:-default")}function c(e,t){var r=e.serializer,n=e.defaultSerializer,i=e.container;return i&&void 0===r&&(r=d(i,t.typeKey,n)),(null===r||void 0===r)&&(r={extract:function(e,t,r){return r}}),r}function l(e,t,r,n){var i=e.find(t,r,n),a=c(e,r);return A(i,"DS: Handle Adapter#find of "+r+" with id: "+n).then(function(e){return Ember.assert("You made a request for a "+r.typeKey+" with id "+n+", but the adapter's response did not have any data",e),e=a.extract(t,r,e,n,"find"),t.push(r,e)},function(e){var i=t.getById(r,n);throw i.notFound(),e},"DS: Extract payload of '"+r+"'")}function h(e,t,r,n,i){var a=e.findMany(t,r,n,i),o=c(e,r);return A(a,"DS: Handle Adapter#findMany of "+r).then(function(e){e=o.extract(t,r,e,null,"findMany"),Ember.assert("The response from a findMany must be an Array, not "+Ember.inspect(e),"array"===Ember.typeOf(e)),t.pushMany(r,e)},null,"DS: Extract payload of "+r)}function p(e,t,r,n,i){var a=e.findHasMany(t,r,n,i),o=c(e,i.type);return A(a,"DS: Handle Adapter#findHasMany of "+r+" : "+i.type).then(function(e){e=o.extract(t,i.type,e,null,"findHasMany"),Ember.assert("The response from a findHasMany must be an Array, not "+Ember.inspect(e),"array"===Ember.typeOf(e));var n=t.pushMany(i.type,e);r.updateHasMany(i.key,n)},null,"DS: Extract payload of "+r+" : hasMany "+i.type)}function f(e,t,r,n,i){var a=e.findBelongsTo(t,r,n,i),o=c(e,i.type);return A(a,"DS: Handle Adapter#findBelongsTo of "+r+" : "+i.type).then(function(e){e=o.extract(t,i.type,e,null,"findBelongsTo");var r=t.push(i.type,e);return r.updateBelongsTo(i.key,r),r},null,"DS: Extract payload of "+r+" : "+i.type)}function m(e,t,r,n){var i=e.findAll(t,r,n),a=c(e,r);return A(i,"DS: Handle Adapter#findAll of "+r).then(function(e){return e=a.extract(t,r,e,null,"findAll"),Ember.assert("The response from a findAll must be an Array, not "+Ember.inspect(e),"array"===Ember.typeOf(e)),t.pushMany(r,e),t.didUpdateAll(r),t.all(r)},null,"DS: Extract payload of findAll "+r)}function y(e,t,r,n,i){var a=e.findQuery(t,r,n,i),o=c(e,r);return A(a,"DS: Handle Adapter#findQuery of "+r).then(function(e){return e=o.extract(t,r,e,null,"findQuery"),Ember.assert("The response from a findQuery must be an Array, not "+Ember.inspect(e),"array"===Ember.typeOf(e)),i.load(e),i},null,"DS: Extract payload of findQuery "+r)}function b(e,t,r,n){var i=n.constructor,a=e[r](t,i,n),o=c(e,i);return Ember.assert("Your adapter's '"+r+"' method must return a promise, but it returned "+a,s(a)),a.then(function(e){return e&&(e=o.extract(t,i,e,g(n,"id"),r)),t.didSaveRecord(n,e),n},function(e){throw e instanceof DS.InvalidError?t.recordWasInvalid(n,e.errors):t.recordWasError(n,e),e},"DS: Extract and notify about "+r+" completion of "+n)}var g=Ember.get,v=Ember.set,E=Ember.run.once,R=Ember.isNone,S=Ember.EnumerableUtils.forEach,D=Ember.EnumerableUtils.indexOf,T=Ember.EnumerableUtils.map,A=Ember.RSVP.resolve,F=Ember.copy,C=function(e){return null==e?null:e+""};DS.Store=Ember.Object.extend({init:function(){this.typeMaps={},this.recordArrayManager=DS.RecordArrayManager.create({store:this}),this._relationshipChanges={},this._pendingSave=[]},adapter:"-rest",serialize:function(e,t){return this.serializerFor(e.constructor.typeKey).serialize(e,t)},defaultAdapter:Ember.computed("adapter",function(){var e=g(this,"adapter");return Ember.assert("You tried to set `adapter` property to an instance of `DS.Adapter`, where it should be a name or a factory",!(e instanceof DS.Adapter)),"string"==typeof e&&(e=this.container.lookup("adapter:"+e)||this.container.lookup("adapter:application")||this.container.lookup("adapter:-rest")),DS.Adapter.detect(e)&&(e=e.create({container:this.container})),e}),createRecord:function(e,t){e=this.modelFor(e),t=F(t)||{},R(t.id)&&(t.id=this._generateId(e)),t.id=C(t.id);var r=this.buildRecord(e,t.id);return r.loadedData(),r.setProperties(t),r},_generateId:function(e){var t=this.adapterFor(e);return t&&t.generateIdForRecord?t.generateIdForRecord(this):null},deleteRecord:function(e){e.deleteRecord()},unloadRecord:function(e){e.unloadRecord()},find:function(e,t){return void 0===t?this.findAll(e):"object"===Ember.typeOf(t)?this.findQuery(e,t):this.findById(e,C(t))},findById:function(e,t){e=this.modelFor(e);var r=this.recordForId(e,t),n=this.fetchRecord(r)||A(r,"DS: Store#findById "+e+" with id: "+t);return a(n)},findByIds:function(e,t){var r=this;return o(Ember.RSVP.all(T(t,function(t){return r.findById(e,t)})).then(Ember.A,null,"DS: Store#findByIds of "+e+" complete"))},fetchRecord:function(e){if(R(e))return null;if(e._loadingPromise)return e._loadingPromise;if(!g(e,"isEmpty"))return null;var t=e.constructor,r=g(e,"id"),n=this.adapterFor(t);Ember.assert("You tried to find a record but you have no adapter (for "+t+")",n),Ember.assert("You tried to find a record but your adapter (for "+t+") does not implement 'find'",n.find);var i=l(n,this,t,r);return e.loadingData(i),i},getById:function(e,t){return this.hasRecordForId(e,t)?this.recordForId(e,t):null},reloadRecord:function(e){var t=e.constructor,r=this.adapterFor(t),n=g(e,"id");return Ember.assert("You cannot reload a record without an ID",n),Ember.assert("You tried to reload a record but you have no adapter (for "+t+")",r),Ember.assert("You tried to reload a record but your adapter does not implement `find`",r.find),l(r,this,t,n)},fetchMany:function(e,t,r){if(e.length){var n=Ember.MapWithDefault.create({defaultValue:function(){return Ember.A()}});S(e,function(e){n.get(e.constructor).push(e)}),S(n,function(e,n){var i=n.mapProperty("id"),a=this.adapterFor(e);Ember.assert("You tried to load many records but you have no adapter (for "+e+")",a),Ember.assert("You tried to load many records but your adapter does not implement `findMany`",a.findMany),r.resolve(h(a,this,e,i,t))},this)}},hasRecordForId:function(e,t){return t=C(t),e=this.modelFor(e),!!this.typeMapFor(e).idToRecord[t]},recordForId:function(e,t){e=this.modelFor(e),t=C(t);var r=this.typeMapFor(e).idToRecord[t];return r||(r=this.buildRecord(e,t)),r},findMany:function(e,t,r,n){r=this.modelFor(r),t=Ember.A(t);var i=t.filterProperty("isEmpty",!0),a=this.recordArrayManager.createManyArray(r,t);return S(i,function(e){e.loadingData()}),a.loadingRecordsCount=i.length,i.length?(S(i,function(e){this.recordArrayManager.registerWaitingRecordArray(e,a)},this),this.fetchMany(i,e,n)):(n&&n.resolve(),a.set("isLoaded",!0),Ember.run.once(a,"trigger","didLoad")),a},findHasMany:function(e,t,r,n){var i=this.adapterFor(e.constructor);Ember.assert("You tried to load a hasMany relationship but you have no adapter (for "+e.constructor+")",i),Ember.assert("You tried to load a hasMany relationship from a specified `link` in the original payload but your adapter does not implement `findHasMany`",i.findHasMany);var a=this.recordArrayManager.createManyArray(r.type,Ember.A([]));return n.resolve(p(i,this,e,t,r)),a},findBelongsTo:function(e,t,r,n){var i=this.adapterFor(e.constructor);Ember.assert("You tried to load a belongsTo relationship but you have no adapter (for "+e.constructor+")",i),Ember.assert("You tried to load a belongsTo relationship from a specified `link` in the original payload but your adapter does not implement `findBelongsTo`",i.findBelongsTo),n.resolve(f(i,this,e,t,r))},findQuery:function(e,t){e=this.modelFor(e);var r=this.recordArrayManager.createAdapterPopulatedRecordArray(e,t),n=this.adapterFor(e),i="DS: Store#findQuery "+e,a=Ember.RSVP.defer(i);return Ember.assert("You tried to load a query but you have no adapter (for "+e+")",n),Ember.assert("You tried to load a query but your adapter does not implement `findQuery`",n.findQuery),a.resolve(y(n,this,e,t,r)),o(a.promise)},findAll:function(e){return e=this.modelFor(e),this.fetchAll(e,this.all(e))},fetchAll:function(e,t){var r=this.adapterFor(e),n=this.typeMapFor(e).metadata.since;return v(t,"isUpdating",!0),Ember.assert("You tried to load all records but you have no adapter (for "+e+")",r),Ember.assert("You tried to load all records but your adapter does not implement `findAll`",r.findAll),o(m(r,this,e,n))},didUpdateAll:function(e){var t=this.typeMapFor(e).findAllCache;v(t,"isUpdating",!1)},all:function(e){e=this.modelFor(e);var t=this.typeMapFor(e),r=t.findAllCache;if(r)return r;var n=this.recordArrayManager.createRecordArray(e);return t.findAllCache=n,n},unloadAll:function(e){e=this.modelFor(e);for(var t,r=this.typeMapFor(e),n=r.records.splice(0);t=n.pop();)t.unloadRecord();r.findAllCache=null},filter:function(e,t,r){var n;3===arguments.length?n=this.findQuery(e,t):2===arguments.length&&(r=t),e=this.modelFor(e);var i=this.recordArrayManager.createFilteredRecordArray(e,r);return n=n||A(i),o(n.then(function(){return i},null,"DS: Store#filter of "+e))},recordIsLoaded:function(e,t){return this.hasRecordForId(e,t)?!g(this.recordForId(e,t),"isEmpty"):!1},metadataFor:function(e){return e=this.modelFor(e),this.typeMapFor(e).metadata},dataWasUpdated:function(e,t){this.recordArrayManager.recordDidChange(t)},scheduleSave:function(e,t){e.adapterWillCommit(),this._pendingSave.push([e,t]),E(this,"flushPendingSave")},flushPendingSave:function(){var e=this._pendingSave.slice();this._pendingSave=[],S(e,function(e){var t,r=e[0],n=e[1],i=this.adapterFor(r.constructor);t=g(r,"isNew")?"createRecord":g(r,"isDeleted")?"deleteRecord":"updateRecord",n.resolve(b(i,this,t,r))},this)},didSaveRecord:function(t,r){r&&(r=e(this,t.constructor,r,t),this.updateId(t,r)),t.adapterDidCommit(r)},recordWasInvalid:function(e,t){e.adapterDidInvalidate(t)},recordWasError:function(e){e.adapterDidError()},updateId:function(e,t){var r=g(e,"id"),n=C(t.id);Ember.assert("An adapter cannot assign a new id to a record that already has an id. "+e+" had id: "+r+" and you tried to update it with "+n+". This likely happened because your server returned data in response to a find or update that had a different id than the one you sent.",null===r||n===r),this.typeMapFor(e.constructor).idToRecord[n]=e,v(e,"id",n)},typeMapFor:function(e){var t,r=g(this,"typeMaps"),n=Ember.guidFor(e);return(t=r[n])?t:(t={idToRecord:{},records:[],metadata:{}},r[n]=t,t)},_load:function(e,t,r){var n=C(t.id),i=this.recordForId(e,n);return i.setupData(t,r),this.recordArrayManager.recordDidChange(i),i},modelFor:function(e){var t;if("string"==typeof e){var r=this.container.normalize("model:"+e);if(t=this.container.lookupFactory(r),!t)throw new Ember.Error("No model was found for '"+e+"'");t.typeKey=r.split(":",2)[1]}else t=e;return t.store=this,t},push:function(t,r,n){return Ember.assert("You must include an `id` in a hash passed to `push`",null!=r.id),t=this.modelFor(t),r=e(this,t,r),this._load(t,r,n),this.recordForId(t,r.id)},pushPayload:function(e,t){var r;t?r=this.serializerFor(e):(t=e,r=u(this.container),Ember.assert("You cannot use `store#pushPayload` without a type unless your default serializer defines `pushPayload`",r.pushPayload)),r.pushPayload(this,t)},update:function(e,t){return Ember.assert("You must include an `id` in a hash passed to `update`",null!=t.id),this.push(e,t,!0)},pushMany:function(e,t){return T(t,function(t){return this.push(e,t)},this)},metaForType:function(e,t){e=this.modelFor(e),Ember.merge(this.typeMapFor(e).metadata,t)},buildRecord:function(e,t,r){var n=this.typeMapFor(e),i=n.idToRecord;Ember.assert("The id "+t+" has already been used with another record of type "+e.toString()+".",!t||!i[t]);var a=e._create({id:t,store:this,container:this.container});return r&&a.setupData(r),t&&(i[t]=a),n.records.push(a),a},dematerializeRecord:function(e){var t=e.constructor,r=this.typeMapFor(t),n=g(e,"id");e.updateRecordArrays(),n&&delete r.idToRecord[n];var i=D(r.records,e);r.records.splice(i,1)},addRelationshipChangeFor:function(e,t,r,n,i){var a=e.clientId,o=r?r:r,s=t+n,d=this._relationshipChanges;a in d||(d[a]={}),o in d[a]||(d[a][o]={}),s in d[a][o]||(d[a][o][s]={}),d[a][o][s][i.changeType]=i},removeRelationshipChangeFor:function(e,t,r,n,i){var a=e.clientId,o=r?r.clientId:r,s=this._relationshipChanges,d=t+n;a in s&&o in s[a]&&d in s[a][o]&&delete s[a][o][d][i]},relationshipChangePairsFor:function(e){var t=[];if(!e)return t;var r=this._relationshipChanges[e.clientId];for(var n in r)if(r.hasOwnProperty(n))for(var i in r[n])r[n].hasOwnProperty(i)&&t.push(r[n][i]);return t},adapterFor:function(e){var t,r=this.container;return r&&(t=r.lookup("adapter:"+e.typeKey)||r.lookup("adapter:application")),t||g(this,"defaultAdapter")},serializerFor:function(e){e=this.modelFor(e);var t=this.adapterFor(e);return d(this.container,e.typeKey,t&&t.defaultSerializer)}}),DS.PromiseArray=Ember.ArrayProxy.extend(Ember.PromiseProxyMixin),DS.PromiseObject=Ember.ObjectProxy.extend(Ember.PromiseProxyMixin)}(),function(){function e(t){var r,n={};for(var i in t)r=t[i],n[i]=r&&"object"==typeof r?e(r):r;return n}function t(e,t){for(var r in t)e[r]=t[r];return e}function r(r){var n=e(s);return t(n,r)}function n(e,r,i){e=t(r?Ember.create(r):{},e),e.parentState=r,e.stateName=i;for(var a in e)e.hasOwnProperty(a)&&"parentState"!==a&&"stateName"!==a&&"object"==typeof e[a]&&(e[a]=n(e[a],e,i+"."+a));return e}var i=Ember.get,a=Ember.set,o=function(e,t){t.value===t.originalValue?(delete e._attributes[t.name],e.send("propertyWasReset",t.name)):t.value!==t.oldValue&&e.send("becomeDirty"),e.updateRecordArraysLater()},s={initialState:"uncommitted",isDirty:!0,uncommitted:{didSetProperty:o,propertyWasReset:function(e){var t=!1;for(var r in e._attributes){t=!0;break}t||e.send("rolledBack")},pushedData:Ember.K,becomeDirty:Ember.K,willCommit:function(e){e.transitionTo("inFlight")},reloadRecord:function(e,t){t(i(e,"store").reloadRecord(e))},rolledBack:function(e){e.transitionTo("loaded.saved")},becameInvalid:function(e){e.transitionTo("invalid")},rollback:function(e){e.rollback()}},inFlight:{isSaving:!0,didSetProperty:o,becomeDirty:Ember.K,pushedData:Ember.K,willCommit:Ember.K,didCommit:function(e){var t=i(this,"dirtyType");e.transitionTo("saved"),e.send("invokeLifecycleCallbacks",t)},becameInvalid:function(e){e.transitionTo("invalid"),e.send("invokeLifecycleCallbacks")},becameError:function(e){e.transitionTo("uncommitted"),e.triggerLater("becameError",e)}},invalid:{isValid:!1,deleteRecord:function(e){e.transitionTo("deleted.uncommitted"),e.clearRelationships()},didSetProperty:function(e,t){i(e,"errors").remove(t.name),o(e,t)},becomeDirty:Ember.K,rolledBack:function(e){i(e,"errors").clear()},becameValid:function(e){e.transitionTo("uncommitted")},invokeLifecycleCallbacks:function(e){e.triggerLater("becameInvalid",e)}}},d=r({dirtyType:"created",isNew:!0});d.uncommitted.rolledBack=function(e){e.transitionTo("deleted.saved")};var u=r({dirtyType:"updated"});d.uncommitted.deleteRecord=function(e){e.clearRelationships(),e.transitionTo("deleted.saved")},d.uncommitted.rollback=function(e){s.uncommitted.rollback.apply(this,arguments),e.transitionTo("deleted.saved")},d.uncommitted.propertyWasReset=Ember.K,u.uncommitted.deleteRecord=function(e){e.transitionTo("deleted.uncommitted"),e.clearRelationships()};var c={isEmpty:!1,isLoading:!1,isLoaded:!1,isDirty:!1,isSaving:!1,isDeleted:!1,isNew:!1,isValid:!0,rolledBack:Ember.K,propertyWasReset:Ember.K,empty:{isEmpty:!0,loadingData:function(e,t){e._loadingPromise=t,e.transitionTo("loading")},loadedData:function(e){e.transitionTo("loaded.created.uncommitted"),e.suspendRelationshipObservers(function(){e.notifyPropertyChange("data")})},pushedData:function(e){e.transitionTo("loaded.saved"),e.triggerLater("didLoad")}},loading:{isLoading:!0,exit:function(e){e._loadingPromise=null},pushedData:function(e){e.transitionTo("loaded.saved"),e.triggerLater("didLoad"),a(e,"isError",!1)},becameError:function(e){e.triggerLater("becameError",e)},notFound:function(e){e.transitionTo("empty")}},loaded:{initialState:"saved",isLoaded:!0,saved:{setup:function(e){var t=e._attributes,r=!1;for(var n in t)if(t.hasOwnProperty(n)){r=!0;break}r&&e.adapterDidDirty()},didSetProperty:o,pushedData:Ember.K,becomeDirty:function(e){e.transitionTo("updated.uncommitted")},willCommit:function(e){e.transitionTo("updated.inFlight")},reloadRecord:function(e,t){t(i(e,"store").reloadRecord(e))},deleteRecord:function(e){e.transitionTo("deleted.uncommitted"),e.clearRelationships()},unloadRecord:function(e){e.clearRelationships(),e.transitionTo("deleted.saved")},didCommit:function(e){e.send("invokeLifecycleCallbacks",i(e,"lastDirtyType"))},notFound:Ember.K},created:d,updated:u},deleted:{initialState:"uncommitted",dirtyType:"deleted",isDeleted:!0,isLoaded:!0,isDirty:!0,setup:function(e){e.updateRecordArrays()},uncommitted:{willCommit:function(e){e.transitionTo("inFlight")},rollback:function(e){e.rollback()},becomeDirty:Ember.K,deleteRecord:Ember.K,rolledBack:function(e){e.transitionTo("loaded.saved")}},inFlight:{isSaving:!0,willCommit:Ember.K,didCommit:function(e){e.transitionTo("saved"),e.send("invokeLifecycleCallbacks")},becameError:function(e){e.transitionTo("uncommitted"),e.triggerLater("becameError",e)}},saved:{isDirty:!1,setup:function(e){var t=i(e,"store");t.dematerializeRecord(e)},invokeLifecycleCallbacks:function(e){e.triggerLater("didDelete",e),e.triggerLater("didCommit",e)}}},invokeLifecycleCallbacks:function(e,t){"created"===t?e.triggerLater("didCreate",e):e.triggerLater("didUpdate",e),e.triggerLater("didCommit",e)}};c=n(c,null,"root"),DS.RootState=c}(),function(){var e=Ember.get,t=Ember.isEmpty;DS.Errors=Ember.Object.extend(Ember.Enumerable,Ember.Evented,{registerHandlers:function(e,t,r){this.on("becameInvalid",e,t),this.on("becameValid",e,r)},errorsByAttributeName:Ember.reduceComputed("content",{initialValue:function(){return Ember.MapWithDefault.create({defaultValue:function(){return Ember.A()}})},addedItem:function(e,t){return e.get(t.attribute).pushObject(t),e},removedItem:function(e,t){return e.get(t.attribute).removeObject(t),e}}),errorsFor:function(t){return e(this,"errorsByAttributeName").get(t)},messages:Ember.computed.mapBy("content","message"),content:Ember.computed(function(){return Ember.A()}),unknownProperty:function(e){var r=this.errorsFor(e);return t(r)?null:r},nextObject:function(t){return e(this,"content").objectAt(t)},length:Ember.computed.oneWay("content.length").readOnly(),isEmpty:Ember.computed.not("length").readOnly(),add:function(t,r){var n=e(this,"isEmpty");r=this._findOrCreateMessages(t,r),e(this,"content").addObjects(r),this.notifyPropertyChange(t),this.enumerableContentDidChange(),n&&!e(this,"isEmpty")&&this.trigger("becameInvalid")},_findOrCreateMessages:function(e,t){var r=this.errorsFor(e);return Ember.makeArray(t).map(function(t){return r.findBy("message",t)||{attribute:e,message:t}})},remove:function(t){if(!e(this,"isEmpty")){var r=e(this,"content").rejectBy("attribute",t);e(this,"content").setObjects(r),this.notifyPropertyChange(t),this.enumerableContentDidChange(),e(this,"isEmpty")&&this.trigger("becameValid")}},clear:function(){e(this,"isEmpty")||(e(this,"content").clear(),this.enumerableContentDidChange(),this.trigger("becameValid"))},has:function(e){return!t(this.errorsFor(e))}})}(),function(){var e=Ember.get,t=Ember.set,r=Ember.merge,n=Ember.computed("currentState",function(t){return e(e(this,"currentState"),t)}).readOnly();DS.Model=Ember.Object.extend(Ember.Evented,{isEmpty:n,isLoading:n,isLoaded:n,isDirty:n,isSaving:n,isDeleted:n,isNew:n,isValid:n,dirtyType:n,isError:!1,isReloading:!1,clientId:null,id:null,transaction:null,currentState:null,errors:null,serialize:function(t){var r=e(this,"store");return r.serialize(this,t)},toJSON:function(e){var t=DS.JSONSerializer.create({container:this.container});return t.serialize(this,e)},didLoad:Ember.K,didUpdate:Ember.K,didCreate:Ember.K,didDelete:Ember.K,becameInvalid:Ember.K,becameError:Ember.K,data:Ember.computed(function(){return this._data=this._data||{},this._data}).property(),_data:null,init:function(){t(this,"currentState",DS.RootState.empty);var e=DS.Errors.create();e.registerHandlers(this,function(){this.send("becameInvalid")},function(){this.send("becameValid")}),t(this,"errors",e),this._super(),this._setup()},_setup:function(){this._changesToSync={},this._deferredTriggers=[],this._data={},this._attributes={},this._inFlightAttributes={},this._relationships={}},send:function(t,r){var n=e(this,"currentState");return n[t]||this._unhandledEvent(n,t,r),n[t](this,r)},transitionTo:function(r){var n=r.split(".",1),i=e(this,"currentState"),a=i;do a.exit&&a.exit(this),a=a.parentState;while(!a.hasOwnProperty(n));var o,s,d=r.split("."),u=[],c=[];for(o=0,s=d.length;s>o;o++)a=a[d[o]],a.enter&&c.push(a),a.setup&&u.push(a);for(o=0,s=c.length;s>o;o++)c[o].enter(this);for(t(this,"currentState",a),o=0,s=u.length;s>o;o++)u[o].setup(this);this.updateRecordArraysLater()},_unhandledEvent:function(e,t,r){var n="Attempted to handle event `"+t+"` ";throw n+="on "+String(this)+" while in state ",n+=e.stateName+". ",void 0!==r&&(n+="Called with "+Ember.inspect(r)+"."),new Ember.Error(n) },withTransaction:function(t){var r=e(this,"transaction");r&&t(r)},loadingData:function(e){this.send("loadingData",e)},loadedData:function(){this.send("loadedData")},notFound:function(){this.send("notFound")},pushedData:function(){this.send("pushedData")},deleteRecord:function(){this.send("deleteRecord")},destroyRecord:function(){return this.deleteRecord(),this.save()},unloadRecord:function(){Ember.assert("You can only unload a loaded, non-dirty record.",!e(this,"isDirty")),this.send("unloadRecord")},clearRelationships:function(){this.eachRelationship(function(e,r){if("belongsTo"===r.kind)t(this,e,null);else if("hasMany"===r.kind){var n=this._relationships[r.name];n&&n.clear()}},this)},updateRecordArrays:function(){this._updatingRecordArraysLater=!1,e(this,"store").dataWasUpdated(this.constructor,this)},changedAttributes:function(){var t,r=e(this,"_data"),n=e(this,"_attributes"),i={};for(t in n)i[t]=[r[t],n[t]];return i},adapterWillCommit:function(){this.send("willCommit")},adapterDidCommit:function(e){t(this,"isError",!1),e?this._data=e:Ember.mixin(this._data,this._inFlightAttributes),this._inFlightAttributes={},this.send("didCommit"),this.updateRecordArraysLater(),e&&this.suspendRelationshipObservers(function(){this.notifyPropertyChange("data")})},adapterDidDirty:function(){this.send("becomeDirty"),this.updateRecordArraysLater()},dataDidChange:Ember.observer(function(){this.reloadHasManys()},"data"),reloadHasManys:function(){var t=e(this.constructor,"relationshipsByName");this.updateRecordArraysLater(),t.forEach(function(e,t){this._data.links&&this._data.links[e]||"hasMany"===t.kind&&this.hasManyDidChange(t.key)},this)},hasManyDidChange:function(e){var r=this._relationships[e];if(r){var n=this._data[e]||[];t(r,"content",Ember.A(n)),t(r,"isLoaded",!0),r.trigger("didLoad")}},updateRecordArraysLater:function(){this._updatingRecordArraysLater||(this._updatingRecordArraysLater=!0,Ember.run.schedule("actions",this,this.updateRecordArrays))},setupData:function(e,t){t?Ember.merge(this._data,e):this._data=e;var r=this._relationships;this.eachRelationship(function(t,n){e.links&&e.links[t]||n.options.async&&(r[t]=null)}),e&&this.pushedData(),this.suspendRelationshipObservers(function(){this.notifyPropertyChange("data")})},materializeId:function(e){t(this,"id",e)},materializeAttributes:function(e){Ember.assert("Must pass a hash of attributes to materializeAttributes",!!e),r(this._data,e)},materializeAttribute:function(e,t){this._data[e]=t},updateHasMany:function(e,t){this._data[e]=t,this.hasManyDidChange(e)},updateBelongsTo:function(e,t){this._data[e]=t},rollback:function(){this._attributes={},e(this,"isError")&&(this._inFlightAttributes={},t(this,"isError",!1)),e(this,"isValid")||(this._inFlightAttributes={}),this.send("rolledBack"),this.suspendRelationshipObservers(function(){this.notifyPropertyChange("data")})},toStringExtension:function(){return e(this,"id")},suspendRelationshipObservers:function(t,r){var n=e(this.constructor,"relationshipNames").belongsTo,i=this;try{this._suspendedRelationships=!0,Ember._suspendObservers(i,n,null,"belongsToDidChange",function(){Ember._suspendBeforeObservers(i,n,null,"belongsToWillChange",function(){t.call(r||i)})})}finally{this._suspendedRelationships=!1}},save:function(){var e="DS: Model#save "+this,t=Ember.RSVP.defer(e);return this.get("store").scheduleSave(this,t),this._inFlightAttributes=this._attributes,this._attributes={},DS.PromiseObject.create({promise:t.promise})},reload:function(){t(this,"isReloading",!0);var e=this,r="DS: Model#reload of "+this,n=new Ember.RSVP.Promise(function(t){e.send("reloadRecord",t)},r).then(function(){return e.set("isReloading",!1),e.set("isError",!1),e},function(t){throw e.set("isError",!0),t},"DS: Model#reload complete, update flags");return DS.PromiseObject.create({promise:n})},adapterDidUpdateAttribute:function(e,t){void 0!==t?(this._data[e]=t,this.notifyPropertyChange(e)):this._data[e]=this._inFlightAttributes[e],this.updateRecordArraysLater()},adapterDidInvalidate:function(t){function r(e){t[e]&&n.add(e,t[e])}var n=e(this,"errors");this.eachAttribute(r),this.eachRelationship(r)},adapterDidError:function(){this.send("becameError"),t(this,"isError",!0)},trigger:function(e){Ember.tryInvoke(this,e,[].slice.call(arguments,1)),this._super.apply(this,arguments)},triggerLater:function(){1===this._deferredTriggers.push(arguments)&&Ember.run.schedule("actions",this,"_triggerDeferredTriggers")},_triggerDeferredTriggers:function(){for(var e=0,t=this._deferredTriggers.length;t>e;e++)this.trigger.apply(this,this._deferredTriggers[e]);this._deferredTriggers.length=0}}),DS.Model.reopenClass({_create:DS.Model.create,create:function(){throw new Ember.Error("You should not call `create` on a model. Instead, call `store.createRecord` with the attributes you would like to set.")}})}(),function(){function e(e,t){return"function"==typeof t.defaultValue?t.defaultValue():t.defaultValue}function t(e,t){return e._attributes.hasOwnProperty(t)||e._inFlightAttributes.hasOwnProperty(t)||e._data.hasOwnProperty(t)}function r(e,t){return e._attributes.hasOwnProperty(t)?e._attributes[t]:e._inFlightAttributes.hasOwnProperty(t)?e._inFlightAttributes[t]:e._data[t]}var n=Ember.get;DS.Model.reopenClass({attributes:Ember.computed(function(){var e=Ember.Map.create();return this.eachComputedProperty(function(t,r){r.isAttribute&&(Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('')` from "+this.toString(),"id"!==t),r.name=t,e.set(t,r))}),e}),transformedAttributes:Ember.computed(function(){var e=Ember.Map.create();return this.eachAttribute(function(t,r){r.type&&e.set(t,r.type)}),e}),eachAttribute:function(e,t){n(this,"attributes").forEach(function(r,n){e.call(t,r,n)},t)},eachTransformedAttribute:function(e,t){n(this,"transformedAttributes").forEach(function(r,n){e.call(t,r,n)})}}),DS.Model.reopen({eachAttribute:function(e,t){this.constructor.eachAttribute(e,t)}}),DS.attr=function(n,i){i=i||{};var a={type:n,isAttribute:!0,options:i};return Ember.computed(function(n,a){if(arguments.length>1){Ember.assert("You may not set `id` as an attribute on your model. Please remove any lines that look like: `id: DS.attr('')` from "+this.constructor.toString(),"id"!==n);var o=this._attributes[n]||this._inFlightAttributes[n]||this._data[n];return this.send("didSetProperty",{name:n,oldValue:o,originalValue:this._data[n],value:a}),this._attributes[n]=a,a}return t(this,n)?r(this,n):e(this,i,n)}).property("data").meta(a)}}(),function(){var e=DS.AttributeChange=function(e){this.record=e.record,this.store=e.store,this.name=e.name,this.value=e.value,this.oldValue=e.oldValue};e.createChange=function(t){return new e(t)},e.prototype={sync:function(){this.value!==this.oldValue&&(this.record.send("becomeDirty"),this.record.updateRecordArraysLater()),this.destroy()},destroy:function(){delete this.record._changesToSync[this.name]}}}(),function(){function e(e){return"object"==typeof e&&(!e.then||"function"!=typeof e.then)}var t=Ember.get,r=Ember.set,n=Ember.EnumerableUtils.forEach;DS.RelationshipChange=function(e){this.parentRecord=e.parentRecord,this.childRecord=e.childRecord,this.firstRecord=e.firstRecord,this.firstRecordKind=e.firstRecordKind,this.firstRecordName=e.firstRecordName,this.secondRecord=e.secondRecord,this.secondRecordKind=e.secondRecordKind,this.secondRecordName=e.secondRecordName,this.changeType=e.changeType,this.store=e.store,this.committed={}},DS.RelationshipChangeAdd=function(e){DS.RelationshipChange.call(this,e)},DS.RelationshipChangeRemove=function(e){DS.RelationshipChange.call(this,e)},DS.RelationshipChange.create=function(e){return new DS.RelationshipChange(e)},DS.RelationshipChangeAdd.create=function(e){return new DS.RelationshipChangeAdd(e)},DS.RelationshipChangeRemove.create=function(e){return new DS.RelationshipChangeRemove(e)},DS.OneToManyChange={},DS.OneToNoneChange={},DS.ManyToNoneChange={},DS.OneToOneChange={},DS.ManyToManyChange={},DS.RelationshipChange._createChange=function(e){return"add"===e.changeType?DS.RelationshipChangeAdd.create(e):"remove"===e.changeType?DS.RelationshipChangeRemove.create(e):void 0},DS.RelationshipChange.determineRelationshipType=function(e,t){var r,n,i=t.key,a=t.kind,o=e.inverseFor(i);return o&&(r=o.name,n=o.kind),o?"belongsTo"===n?"belongsTo"===a?"oneToOne":"manyToOne":"belongsTo"===a?"oneToMany":"manyToMany":"belongsTo"===a?"oneToNone":"manyToNone"},DS.RelationshipChange.createChange=function(e,t,r,n){var i,a=e.constructor;return i=DS.RelationshipChange.determineRelationshipType(a,n),"oneToMany"===i?DS.OneToManyChange.createChange(e,t,r,n):"manyToOne"===i?DS.OneToManyChange.createChange(t,e,r,n):"oneToNone"===i?DS.OneToNoneChange.createChange(e,t,r,n):"manyToNone"===i?DS.ManyToNoneChange.createChange(e,t,r,n):"oneToOne"===i?DS.OneToOneChange.createChange(e,t,r,n):"manyToMany"===i?DS.ManyToManyChange.createChange(e,t,r,n):void 0},DS.OneToNoneChange.createChange=function(e,t,r,n){var i=n.key,a=DS.RelationshipChange._createChange({parentRecord:t,childRecord:e,firstRecord:e,store:r,changeType:n.changeType,firstRecordName:i,firstRecordKind:"belongsTo"});return r.addRelationshipChangeFor(e,i,t,null,a),a},DS.ManyToNoneChange.createChange=function(e,t,r,n){var i=n.key,a=DS.RelationshipChange._createChange({parentRecord:e,childRecord:t,secondRecord:e,store:r,changeType:n.changeType,secondRecordName:n.key,secondRecordKind:"hasMany"});return r.addRelationshipChangeFor(e,i,t,null,a),a},DS.ManyToManyChange.createChange=function(e,t,r,n){var i=n.key,a=DS.RelationshipChange._createChange({parentRecord:t,childRecord:e,firstRecord:e,secondRecord:t,firstRecordKind:"hasMany",secondRecordKind:"hasMany",store:r,changeType:n.changeType,firstRecordName:i});return r.addRelationshipChangeFor(e,i,t,null,a),a},DS.OneToOneChange.createChange=function(e,t,r,n){var i;n.parentType?i=n.parentType.inverseFor(n.key).name:n.key?i=n.key:Ember.assert("You must pass either a parentType or belongsToName option to OneToManyChange.forChildAndParent",!1);var a=DS.RelationshipChange._createChange({parentRecord:t,childRecord:e,firstRecord:e,secondRecord:t,firstRecordKind:"belongsTo",secondRecordKind:"belongsTo",store:r,changeType:n.changeType,firstRecordName:i});return r.addRelationshipChangeFor(e,i,t,null,a),a},DS.OneToOneChange.maintainInvariant=function(e,r,n,i){if("add"===e.changeType&&r.recordIsMaterialized(n)){var a=t(n,i);if(a){var o=DS.OneToOneChange.createChange(n,a,r,{parentType:e.parentType,hasManyName:e.hasManyName,changeType:"remove",key:e.key});r.addRelationshipChangeFor(n,i,e.parentRecord,null,o),o.sync()}}},DS.OneToManyChange.createChange=function(e,t,r,n){var i;n.parentType?(i=n.parentType.inverseFor(n.key).name,DS.OneToManyChange.maintainInvariant(n,r,e,i)):n.key?i=n.key:Ember.assert("You must pass either a parentType or belongsToName option to OneToManyChange.forChildAndParent",!1);var a=DS.RelationshipChange._createChange({parentRecord:t,childRecord:e,firstRecord:e,secondRecord:t,firstRecordKind:"belongsTo",secondRecordKind:"hasMany",store:r,changeType:n.changeType,firstRecordName:i});return r.addRelationshipChangeFor(e,i,t,a.getSecondRecordName(),a),a},DS.OneToManyChange.maintainInvariant=function(e,r,n,i){if("add"===e.changeType&&n){var a=t(n,i);if(a){var o=DS.OneToManyChange.createChange(n,a,r,{parentType:e.parentType,hasManyName:e.hasManyName,changeType:"remove",key:e.key});r.addRelationshipChangeFor(n,i,e.parentRecord,o.getSecondRecordName(),o),o.sync()}}},DS.RelationshipChange.prototype={getSecondRecordName:function(){var e,t=this.secondRecordName;if(!t){if(e=this.secondRecord,!e)return;var r=this.firstRecord.constructor,n=r.inverseFor(this.firstRecordName);this.secondRecordName=n.name}return this.secondRecordName},getFirstRecordName:function(){var e=this.firstRecordName;return e},destroy:function(){var e=this.childRecord,t=this.getFirstRecordName(),r=this.getSecondRecordName(),n=this.store;n.removeRelationshipChangeFor(e,t,this.parentRecord,r,this.changeType)},getSecondRecord:function(){return this.secondRecord},getFirstRecord:function(){return this.firstRecord},coalesce:function(){var e=this.store.relationshipChangePairsFor(this.firstRecord);n(e,function(e){var t=e.add,r=e.remove;t&&r&&(t.destroy(),r.destroy())})}},DS.RelationshipChangeAdd.prototype=Ember.create(DS.RelationshipChange.create({})),DS.RelationshipChangeRemove.prototype=Ember.create(DS.RelationshipChange.create({})),DS.RelationshipChangeAdd.prototype.changeType="add",DS.RelationshipChangeAdd.prototype.sync=function(){var n=this.getSecondRecordName(),i=this.getFirstRecordName(),a=this.getFirstRecord(),o=this.getSecondRecord();o instanceof DS.Model&&a instanceof DS.Model&&("belongsTo"===this.secondRecordKind?o.suspendRelationshipObservers(function(){r(o,n,a)}):"hasMany"===this.secondRecordKind&&o.suspendRelationshipObservers(function(){var r=t(o,n);e(r)&&r.addObject(a)})),a instanceof DS.Model&&o instanceof DS.Model&&t(a,i)!==o&&("belongsTo"===this.firstRecordKind?a.suspendRelationshipObservers(function(){r(a,i,o)}):"hasMany"===this.firstRecordKind&&a.suspendRelationshipObservers(function(){var r=t(a,i);e(r)&&r.addObject(o)})),this.coalesce()},DS.RelationshipChangeRemove.prototype.changeType="remove",DS.RelationshipChangeRemove.prototype.sync=function(){var n=this.getSecondRecordName(),i=this.getFirstRecordName(),a=this.getFirstRecord(),o=this.getSecondRecord();o instanceof DS.Model&&a instanceof DS.Model&&("belongsTo"===this.secondRecordKind?o.suspendRelationshipObservers(function(){r(o,n,null)}):"hasMany"===this.secondRecordKind&&o.suspendRelationshipObservers(function(){var r=t(o,n);e(r)&&r.removeObject(a)})),a instanceof DS.Model&&t(a,i)&&("belongsTo"===this.firstRecordKind?a.suspendRelationshipObservers(function(){r(a,i,null)}):"hasMany"===this.firstRecordKind&&a.suspendRelationshipObservers(function(){var r=t(a,i);e(r)&&r.removeObject(o)})),this.coalesce()}}(),function(){function e(e,n,i){return Ember.computed(function(n,a){var o=t(this,"data"),s=t(this,"store"),d="DS: Async belongsTo "+this+" : "+n;if(2===arguments.length)return Ember.assert("You can only add a '"+e+"' record to this relationship",!a||a instanceof s.modelFor(e)),void 0===a?null:DS.PromiseObject.create({promise:Ember.RSVP.resolve(a,d)});var u=o.links&&o.links[n],c=o[n];if(r(c)){if(u){var l=Ember.RSVP.defer("DS: Async belongsTo (link) "+this+" : "+n);return s.findBelongsTo(this,u,i,l),DS.PromiseObject.create({promise:l.promise})}return null}var h=s.fetchRecord(c)||Ember.RSVP.resolve(c,d);return DS.PromiseObject.create({promise:h})}).property("data").meta(i)}var t=Ember.get,r=(Ember.set,Ember.isNone);DS.belongsTo=function(n,i){"object"==typeof n?(i=n,n=void 0):Ember.assert("The first argument DS.belongsTo must be a model type or string, like DS.belongsTo(App.Person)",!!n&&("string"==typeof n||DS.Model.detect(n))),i=i||{};var a={type:n,isRelationship:!0,options:i,kind:"belongsTo"};return i.async?e(n,i,a):Ember.computed(function(e,i){var a,o,s=t(this,"data"),d=t(this,"store");return o="string"==typeof n?d.modelFor(n):n,2===arguments.length?(Ember.assert("You can only add a '"+n+"' record to this relationship",!i||i instanceof o),void 0===i?null:i):(a=s[e],r(a)?null:(d.fetchRecord(a),a))}).property("data").meta(a)},DS.Model.reopen({belongsToWillChange:Ember.beforeObserver(function(e,r){if(t(e,"isLoaded")){var n=t(e,r);if(n){var i=t(e,"store"),a=DS.RelationshipChange.createChange(e,n,i,{key:r,kind:"belongsTo",changeType:"remove"});a.sync(),this._changesToSync[r]=a}}}),belongsToDidChange:Ember.immediateObserver(function(e,r){if(t(e,"isLoaded")){var n=t(e,r);if(n){var i=t(e,"store"),a=DS.RelationshipChange.createChange(e,n,i,{key:r,kind:"belongsTo",changeType:"add"});a.sync()}}delete this._changesToSync[r]})})}(),function(){function e(e,r,n){return Ember.computed(function(e){var a=this._relationships[e],o="DS: Async hasMany "+this+" : "+e;if(!a){var s=Ember.RSVP.defer(o);a=t(this,e,r,function(t,r){var a,o=r.links&&r.links[e];return a=o?t.findHasMany(this,o,n,s):t.findMany(this,r[e],n.type,s),i(a,"promise",s.promise),a})}var d=a.get("promise").then(function(){return a},null,"DS: Async hasMany records received");return DS.PromiseArray.create({promise:d})}).property("data").meta(n)}function t(e,t,r,i){var o=e._relationships;if(o[t])return o[t];var s=n(e,"data"),d=n(e,"store"),u=o[t]=i.call(e,d,s);return a(u,{owner:e,name:t,isPolymorphic:r.polymorphic})}function r(r,n){n=n||{};var i={type:r,isRelationship:!0,options:n,kind:"hasMany"};return n.async?e(r,n,i):Ember.computed(function(e){return t(this,e,n,function(t,r){var n=r[e];return Ember.assert("You looked up the '"+e+"' relationship on '"+this+"' but some of the associated records were not loaded. Either make sure they are all loaded together with the parent record, or specify that the relationship is async (`DS.hasMany({ async: true })`)",Ember.A(n).everyProperty("isEmpty",!1)),t.findMany(this,r[e],i.type)})}).property("data").meta(i)}var n=Ember.get,i=Ember.set,a=Ember.setProperties;DS.hasMany=function(e,t){return"object"==typeof e&&(t=e,e=void 0),r(e,t)}}(),function(){{var e=Ember.get;Ember.set}DS.Model.reopen({didDefineProperty:function(e,t,r){if(r instanceof Ember.Descriptor){var n=r.meta();n.isRelationship&&"belongsTo"===n.kind&&(Ember.addObserver(e,t,null,"belongsToDidChange"),Ember.addBeforeObserver(e,t,null,"belongsToWillChange")),n.parentType=e.constructor}}}),DS.Model.reopenClass({typeForRelationship:function(t){var r=e(this,"relationshipsByName").get(t);return r&&r.type},inverseFor:function(t){function r(t,n,i){i=i||[];var a=e(n,"relationships");if(a){var o=a.get(t);return o&&i.push.apply(i,a.get(t)),t.superclass&&r(t.superclass,n,i),i}}var n=this.typeForRelationship(t);if(!n)return null;var i=this.metaForProperty(t).options;if(null===i.inverse)return null;var a,o;if(i.inverse)a=i.inverse,o=Ember.get(n,"relationshipsByName").get(a).kind;else{var s=r(this,n);if(0===s.length)return null;Ember.assert("You defined the '"+t+"' relationship on "+this+", but multiple possible inverse relationships of type "+this+" were found on "+n+". Look at http://emberjs.com/guides/models/defining-models/#toc_explicit-inverses for how to explicitly specify inverses",1===s.length),a=s[0].name,o=s[0].kind}return{type:n,name:a,kind:o}},relationships:Ember.computed(function(){var e=new Ember.MapWithDefault({defaultValue:function(){return[]}});return this.eachComputedProperty(function(t,r){if(r.isRelationship){"string"==typeof r.type&&(r.type=this.store.modelFor(r.type));var n=e.get(r.type);n.push({name:t,kind:r.kind})}}),e}),relationshipNames:Ember.computed(function(){var e={hasMany:[],belongsTo:[]};return this.eachComputedProperty(function(t,r){r.isRelationship&&e[r.kind].push(t)}),e}),relatedTypes:Ember.computed(function(){var t,r=Ember.A();return this.eachComputedProperty(function(n,i){i.isRelationship&&(t=i.type,"string"==typeof t&&(t=e(this,t,!1)||this.store.modelFor(t)),Ember.assert("You specified a hasMany ("+i.type+") on "+i.parentType+" but "+i.type+" was not found.",t),r.contains(t)||(Ember.assert("Trying to sideload "+n+" on "+this.toString()+" but the type doesn't exist.",!!t),r.push(t)))}),r}),relationshipsByName:Ember.computed(function(){var e,t=Ember.Map.create();return this.eachComputedProperty(function(r,n){n.isRelationship&&(n.key=r,e=n.type,e||"hasMany"!==n.kind?e||(e=r):e=Ember.String.singularize(r),"string"==typeof e&&(n.type=this.store.modelFor(e)),t.set(r,n))}),t}),fields:Ember.computed(function(){var e=Ember.Map.create();return this.eachComputedProperty(function(t,r){r.isRelationship?e.set(t,r.kind):r.isAttribute&&e.set(t,"attribute")}),e}),eachRelationship:function(t,r){e(this,"relationshipsByName").forEach(function(e,n){t.call(r,e,n)})},eachRelatedType:function(t,r){e(this,"relatedTypes").forEach(function(e){t.call(r,e)})}}),DS.Model.reopen({eachRelationship:function(e,t){this.constructor.eachRelationship(e,t)}})}(),function(){var e=Ember.get,t=(Ember.set,Ember.EnumerableUtils.forEach);DS.RecordArrayManager=Ember.Object.extend({init:function(){this.filteredRecordArrays=Ember.MapWithDefault.create({defaultValue:function(){return[]}}),this.changedRecords=[]},recordDidChange:function(e){1===this.changedRecords.push(e)&&Ember.run.schedule("actions",this,this.updateRecordArrays)},recordArraysForRecord:function(e){return e._recordArrays=e._recordArrays||Ember.OrderedSet.create(),e._recordArrays},updateRecordArrays:function(){t(this.changedRecords,function(t){e(t,"isDeleted")?this._recordWasDeleted(t):this._recordWasChanged(t)},this),this.changedRecords.length=0},_recordWasDeleted:function(e){var r=e._recordArrays;r&&t(r,function(t){t.removeRecord(e)})},_recordWasChanged:function(r){var n,i=r.constructor,a=this.filteredRecordArrays.get(i);t(a,function(t){n=e(t,"filterFunction"),this.updateRecordArray(t,n,i,r)},this);var o=r._loadingRecordArrays;if(o){for(var s=0,d=o.length;d>s;s++)o[s].loadedRecord();r._loadingRecordArrays=[]}},updateRecordArray:function(e,t,r,n){var i;i=t?t(n):!0;var a=this.recordArraysForRecord(n);i?(a.add(e),e.addRecord(n)):i||(a.remove(e),e.removeRecord(n))},updateFilter:function(t,r,n){for(var i,a=this.store.typeMapFor(r),o=a.records,s=0,d=o.length;d>s;s++)i=o[s],e(i,"isDeleted")||e(i,"isEmpty")||this.updateRecordArray(t,n,r,i)},createManyArray:function(e,r){var n=DS.ManyArray.create({type:e,content:r,store:this.store});return t(r,function(e){var t=this.recordArraysForRecord(e);t.add(n)},this),n},createRecordArray:function(e){var t=DS.RecordArray.create({type:e,content:Ember.A(),store:this.store,isLoaded:!0});return this.registerFilteredRecordArray(t,e),t},createFilteredRecordArray:function(e,t){var r=DS.FilteredRecordArray.create({type:e,content:Ember.A(),store:this.store,manager:this,filterFunction:t});return this.registerFilteredRecordArray(r,e,t),r},createAdapterPopulatedRecordArray:function(e,t){return DS.AdapterPopulatedRecordArray.create({type:e,query:t,content:Ember.A(),store:this.store})},registerFilteredRecordArray:function(e,t,r){var n=this.filteredRecordArrays.get(t);n.push(e),this.updateFilter(e,t,r)},registerWaitingRecordArray:function(e,t){var r=e._loadingRecordArrays||[];r.push(t),e._loadingRecordArrays=r}})}(),function(){var e=Ember.get,t=(Ember.set,Ember.ArrayPolyfills.map),r=["description","fileName","lineNumber","message","name","number","stack"];DS.InvalidError=function(e){var t=Error.prototype.constructor.call(this,"The backend rejected the commit because it was invalid: "+Ember.inspect(e));this.errors=e;for(var n=0,i=r.length;i>n;n++)this[r[n]]=t[r[n]]},DS.InvalidError.prototype=Ember.create(Error.prototype),DS.Adapter=Ember.Object.extend({find:Ember.required(Function),findAll:null,findQuery:null,generateIdForRecord:null,serialize:function(t,r){return e(t,"store").serializerFor(t.constructor.typeKey).serialize(t,r)},createRecord:Ember.required(Function),updateRecord:Ember.required(Function),deleteRecord:Ember.required(Function),findMany:function(e,r,n){var i=t.call(n,function(t){return this.find(e,r,t)},this);return Ember.RSVP.all(i)}})}(),function(){var e=Ember.get,t=Ember.String.fmt,r=Ember.EnumerableUtils.indexOf,n=0;DS.FixtureAdapter=DS.Adapter.extend({serializer:null,simulateRemoteResponse:!0,latency:50,fixturesForType:function(e){if(e.FIXTURES){var r=Ember.A(e.FIXTURES);return r.map(function(e){var r=typeof e.id;if("number"!==r&&"string"!==r)throw new Error(t("the id property must be defined as a number or string for fixture %@",[e]));return e.id=e.id+"",e})}return null},queryFixtures:function(){Ember.assert("Not implemented: You must override the DS.FixtureAdapter::queryFixtures method to support querying the fixture store.")},updateFixtures:function(e,t){e.FIXTURES||(e.FIXTURES=[]);var r=e.FIXTURES;this.deleteLoadedFixture(e,t),r.push(t)},mockJSON:function(e,t,r){return e.serializerFor(t).serialize(r,{includeId:!0})},generateIdForRecord:function(){return"fixture-"+n++},find:function(e,t,r){var n,i=this.fixturesForType(t);return Ember.assert("Unable to find fixtures for model type "+t.toString(),i),i&&(n=Ember.A(i).findProperty("id",r)),n?this.simulateRemoteCall(function(){return n},this):void 0},findMany:function(e,t,n){var i=this.fixturesForType(t);return Ember.assert("Unable to find fixtures for model type "+t.toString(),i),i&&(i=i.filter(function(e){return-1!==r(n,e.id)})),i?this.simulateRemoteCall(function(){return i},this):void 0},findAll:function(e,t){var r=this.fixturesForType(t);return Ember.assert("Unable to find fixtures for model type "+t.toString(),r),this.simulateRemoteCall(function(){return r},this)},findQuery:function(e,t,r){var n=this.fixturesForType(t);return Ember.assert("Unable to find fixtures for model type "+t.toString(),n),n=this.queryFixtures(n,r,t),n?this.simulateRemoteCall(function(){return n},this):void 0},createRecord:function(e,t,r){var n=this.mockJSON(e,t,r);return this.updateFixtures(t,n),this.simulateRemoteCall(function(){return n},this)},updateRecord:function(e,t,r){var n=this.mockJSON(e,t,r);return this.updateFixtures(t,n),this.simulateRemoteCall(function(){return n},this)},deleteRecord:function(e,t,r){var n=this.mockJSON(e,t,r);return this.deleteLoadedFixture(t,n),this.simulateRemoteCall(function(){return null})},deleteLoadedFixture:function(e,t){var n=this.findExistingFixture(e,t);if(n){var i=r(e.FIXTURES,n);return e.FIXTURES.splice(i,1),!0}},findExistingFixture:function(t,r){var n=this.fixturesForType(t),i=e(r,"id");return this.findFixtureById(n,i)},findFixtureById:function(t,r){return Ember.A(t).find(function(t){return""+e(t,"id")==""+r?!0:!1})},simulateRemoteCall:function(t,r){var n=this;return new Ember.RSVP.Promise(function(i){e(n,"simulateRemoteResponse")?Ember.run.later(function(){i(t.call(r))},e(n,"latency")):Ember.run.schedule("actions",null,function(){i(t.call(r))})},"DS: FixtureAdapter#simulateRemoteCall")}})}(),function(){function e(e){return null==e?null:e+""}var t=Ember.get,r=(Ember.set,Ember.ArrayPolyfills.forEach),n=Ember.ArrayPolyfills.map;DS.RESTSerializer=DS.JSONSerializer.extend({normalize:function(e,t,r){return this.normalizeId(t),this.normalizeAttributes(e,t),this.normalizeRelationships(e,t),this.normalizeUsingDeclaredMapping(e,t),this.normalizeHash&&this.normalizeHash[r]&&this.normalizeHash[r](t),this._super(e,t,r)},normalizePayload:function(e,t){return t},normalizeId:function(e){var r=t(this,"primaryKey");"id"!==r&&(e.id=e[r],delete e[r])},normalizeUsingDeclaredMapping:function(e,r){var n,i,a=t(this,"attrs");if(a)for(i in a)n=a[i],n&&n.key&&(n=n.key),"string"==typeof n&&(r[i]=r[n],delete r[n])},normalizeAttributes:function(e,t){var r;this.keyForAttribute&&e.eachAttribute(function(e){r=this.keyForAttribute(e),e!==r&&(t[e]=t[r],delete t[r])},this)},normalizeRelationships:function(e,t){var r;this.keyForRelationship&&e.eachRelationship(function(e,n){r=this.keyForRelationship(e,n.kind),e!==r&&(t[e]=t[r],delete t[r])},this)},extractSingle:function(t,n,i,a){i=this.normalizePayload(n,i);var o,s=n.typeKey;for(var d in i){var u=this.typeForRoot(d),c=t.modelFor(u),l=c.typeKey===s;l&&"array"!==Ember.typeOf(i[d])?o=this.normalize(n,i[d],d):r.call(i[d],function(r){var n=this.typeForRoot(d),i=t.modelFor(n),s=t.serializerFor(i);r=s.normalize(i,r,d);var u=l&&!a&&!o,c=l&&e(r.id)===a;u||c?o=r:t.push(n,r)},this)}return o},extractArray:function(e,t,r){r=this.normalizePayload(t,r);var i,a=t.typeKey;for(var o in r){var s=o,d=!1;"_"===o.charAt(0)&&(d=!0,s=o.substr(1));var u=this.typeForRoot(s),c=e.modelFor(u),l=e.serializerFor(c),h=!d&&c.typeKey===a,p=n.call(r[o],function(e){return l.normalize(c,e,o)},this);h?i=p:e.pushMany(u,p)}return i},pushPayload:function(e,t){t=this.normalizePayload(null,t);for(var r in t){var i=this.typeForRoot(r),a=e.modelFor(i),o=n.call(Ember.makeArray(t[r]),function(e){return this.normalize(a,e,r)},this);e.pushMany(i,o)}},typeForRoot:function(e){return Ember.String.singularize(e)},serialize:function(){return this._super.apply(this,arguments)},serializeIntoHash:function(e,t,r,n){var i=Ember.String.camelize(t.typeKey);e[i]=this.serialize(r,n)},serializePolymorphicType:function(e,r,n){var i=n.key,a=t(e,i);i=this.keyForAttribute?this.keyForAttribute(i):i,r[i+"Type"]=Ember.String.camelize(a.constructor.typeKey)}})}(),function(){var e=Ember.get,t=(Ember.set,Ember.ArrayPolyfills.forEach);DS.RESTAdapter=DS.Adapter.extend({defaultSerializer:"-rest",find:function(e,t,r){return this.ajax(this.buildURL(t.typeKey,r),"GET")},findAll:function(e,t,r){var n;return r&&(n={since:r}),this.ajax(this.buildURL(t.typeKey),"GET",{data:n})},findQuery:function(e,t,r){return this.ajax(this.buildURL(t.typeKey),"GET",{data:r})},findMany:function(e,t,r){return this.ajax(this.buildURL(t.typeKey),"GET",{data:{ids:r}})},findHasMany:function(t,r,n){var i=e(this,"host"),a=e(r,"id"),o=r.constructor.typeKey;return i&&"/"===n.charAt(0)&&"/"!==n.charAt(1)&&(n=i+n),this.ajax(this.urlPrefix(n,this.buildURL(o,a)),"GET")},findBelongsTo:function(t,r,n){var i=e(r,"id"),a=r.constructor.typeKey;return this.ajax(this.urlPrefix(n,this.buildURL(a,i)),"GET")},createRecord:function(e,t,r){var n={},i=e.serializerFor(t.typeKey);return i.serializeIntoHash(n,t,r,{includeId:!0}),this.ajax(this.buildURL(t.typeKey),"POST",{data:n})},updateRecord:function(t,r,n){var i={},a=t.serializerFor(r.typeKey);a.serializeIntoHash(i,r,n);var o=e(n,"id");return this.ajax(this.buildURL(r.typeKey,o),"PUT",{data:i})},deleteRecord:function(t,r,n){var i=e(n,"id");return this.ajax(this.buildURL(r.typeKey,i),"DELETE")},buildURL:function(t,r){var n=[],i=e(this,"host"),a=this.urlPrefix();return t&&n.push(this.pathForType(t)),r&&n.push(r),a&&n.unshift(a),n=n.join("/"),!i&&n&&(n="/"+n),n},urlPrefix:function(t,r){var n=e(this,"host"),i=e(this,"namespace"),a=[];return t?"/"===t.charAt(0)?n&&(t=t.slice(1),a.push(n)):/^http(s)?:\/\//.test(t)||a.push(r):(n&&a.push(n),i&&a.push(i)),t&&a.push(t),a.join("/")},pathForType:function(e){var t=Ember.String.camelize(e);return Ember.String.pluralize(t)},ajaxError:function(e){return e&&(e.then=null),e},ajax:function(e,t,r){var n=this;return new Ember.RSVP.Promise(function(i,a){r=n.ajaxOptions(e,t,r),r.success=function(e){Ember.run(null,i,e)},r.error=function(e){Ember.run(null,a,n.ajaxError(e))},Ember.$.ajax(r)},"DS: RestAdapter#ajax "+t+" to "+e)},ajaxOptions:function(e,r,n){if(n=n||{},n.url=e,n.type=r,n.dataType="json",n.context=this,n.data&&"GET"!==r&&(n.contentType="application/json; charset=utf-8",n.data=JSON.stringify(n.data)),void 0!==this.headers){var i=this.headers;n.beforeSend=function(e){t.call(Ember.keys(i),function(t){e.setRequestHeader(t,i[t])})}}return n}})}(),function(){DS.Model.reopen({_debugInfo:function(){var e=["id"],t={belongsTo:[],hasMany:[]},r=[];this.eachAttribute(function(t){e.push(t)},this),this.eachRelationship(function(e,n){t[n.kind].push(e),r.push(e)});var n=[{name:"Attributes",properties:e,expand:!0},{name:"Belongs To",properties:t.belongsTo,expand:!0},{name:"Has Many",properties:t.hasMany,expand:!0},{name:"Flags",properties:["isLoaded","isDirty","isSaving","isDeleted","isError","isNew","isValid"]}];return{propertyInfo:{includeOtherProperties:!0,groups:n,expensiveProperties:r}}}})}(),function(){Ember.String.pluralize=function(e){return Ember.Inflector.inflector.pluralize(e)},Ember.String.singularize=function(e){return Ember.Inflector.inflector.singularize(e)}}(),function(){function e(e,t){for(var r=0,n=t.length;n>r;r++)e.uncountable[t[r].toLowerCase()]=!0}function t(e,t){for(var r,n=0,i=t.length;i>n;n++)r=t[n],e.irregular[r[0].toLowerCase()]=r[1],e.irregularInverse[r[1].toLowerCase()]=r[0]}function r(r){r=r||{},r.uncountable=r.uncountable||{},r.irregularPairs=r.irregularPairs||{};var n=this.rules={plurals:r.plurals||[],singular:r.singular||[],irregular:{},irregularInverse:{},uncountable:{}};e(n,r.uncountable),t(n,r.irregularPairs)}var n=/^\s*$/;r.prototype={plural:function(e,t){this.rules.plurals.push([e,t.toLowerCase()])},singular:function(e,t){this.rules.singular.push([e,t.toLowerCase()])},uncountable:function(t){e(this.rules,[t.toLowerCase()])},irregular:function(e,r){t(this.rules,[[e,r]])},pluralize:function(e){return this.inflect(e,this.rules.plurals,this.rules.irregular)},singularize:function(e){return this.inflect(e,this.rules.singular,this.rules.irregularInverse)},inflect:function(e,t,r){var i,a,o,s,d,u,c,l;if(d=n.test(e))return e;if(s=e.toLowerCase(),u=this.rules.uncountable[s])return e;if(c=r&&r[s])return c;for(var h=t.length,p=0;h>p&&(i=t[h-1],l=i[0],!l.test(e));h--);return i=i||[],l=i[0],a=i[1],o=e.replace(l,a)}},Ember.Inflector=r}(),function(){Ember.Inflector.defaultRules={plurals:[[/$/,"s"],[/s$/i,"s"],[/^(ax|test)is$/i,"$1es"],[/(octop|vir)us$/i,"$1i"],[/(octop|vir)i$/i,"$1i"],[/(alias|status)$/i,"$1es"],[/(bu)s$/i,"$1ses"],[/(buffal|tomat)o$/i,"$1oes"],[/([ti])um$/i,"$1a"],[/([ti])a$/i,"$1a"],[/sis$/i,"ses"],[/(?:([^f])fe|([lr])f)$/i,"$1$2ves"],[/(hive)$/i,"$1s"],[/([^aeiouy]|qu)y$/i,"$1ies"],[/(x|ch|ss|sh)$/i,"$1es"],[/(matr|vert|ind)(?:ix|ex)$/i,"$1ices"],[/^(m|l)ouse$/i,"$1ice"],[/^(m|l)ice$/i,"$1ice"],[/^(ox)$/i,"$1en"],[/^(oxen)$/i,"$1"],[/(quiz)$/i,"$1zes"]],singular:[[/s$/i,""],[/(ss)$/i,"$1"],[/(n)ews$/i,"$1ews"],[/([ti])a$/i,"$1um"],[/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i,"$1sis"],[/(^analy)(sis|ses)$/i,"$1sis"],[/([^f])ves$/i,"$1fe"],[/(hive)s$/i,"$1"],[/(tive)s$/i,"$1"],[/([lr])ves$/i,"$1f"],[/([^aeiouy]|qu)ies$/i,"$1y"],[/(s)eries$/i,"$1eries"],[/(m)ovies$/i,"$1ovie"],[/(x|ch|ss|sh)es$/i,"$1"],[/^(m|l)ice$/i,"$1ouse"],[/(bus)(es)?$/i,"$1"],[/(o)es$/i,"$1"],[/(shoe)s$/i,"$1"],[/(cris|test)(is|es)$/i,"$1is"],[/^(a)x[ie]s$/i,"$1xis"],[/(octop|vir)(us|i)$/i,"$1us"],[/(alias|status)(es)?$/i,"$1"],[/^(ox)en/i,"$1"],[/(vert|ind)ices$/i,"$1ex"],[/(matr)ices$/i,"$1ix"],[/(quiz)zes$/i,"$1"],[/(database)s$/i,"$1"]],irregularPairs:[["person","people"],["man","men"],["child","children"],["sex","sexes"],["move","moves"],["cow","kine"],["zombie","zombies"]],uncountable:["equipment","information","rice","money","species","series","fish","sheep","jeans","police"]} }(),function(){(Ember.EXTEND_PROTOTYPES===!0||Ember.EXTEND_PROTOTYPES.String)&&(String.prototype.pluralize=function(){return Ember.String.pluralize(this)},String.prototype.singularize=function(){return Ember.String.singularize(this)})}(),function(){Ember.Inflector.inflector=new Ember.Inflector(Ember.Inflector.defaultRules)}(),function(){var e=Ember.get,t=Ember.EnumerableUtils.forEach,r=Ember.String.camelize,n=Ember.String.capitalize,i=Ember.String.decamelize,a=Ember.String.singularize,o=Ember.String.underscore;DS.ActiveModelSerializer=DS.RESTSerializer.extend({keyForAttribute:function(e){return i(e)},keyForRelationship:function(e,t){return e=i(e),"belongsTo"===t?e+"_id":"hasMany"===t?a(e)+"_ids":e},serializeHasMany:Ember.K,serializeIntoHash:function(e,t,r,n){var a=o(i(t.typeKey));e[a]=this.serialize(r,n)},serializePolymorphicType:function(t,i,a){var o=a.key,s=e(t,o);o=this.keyForAttribute(o),i[o+"_type"]=n(r(s.constructor.typeKey))},typeForRoot:function(e){var t=r(e);return a(t)},normalize:function(e,t,r){return this.normalizeLinks(t),this._super(e,t,r)},normalizeLinks:function(e){if(e.links){var t=e.links;for(var n in t){var i=r(n);i!==n&&(t[i]=t[n],delete t[n])}}},normalizeRelationships:function(e,r){var n,i;this.keyForRelationship&&e.eachRelationship(function(e,a){if(a.options.polymorphic){if(n=this.keyForAttribute(e),i=r[n],i&&i.type)i.type=this.typeForRoot(i.type);else if(i&&"hasMany"===a.kind){var o=this;t(i,function(e){e.type=o.typeForRoot(e.type)})}}else n=this.keyForRelationship(e,a.kind),i=r[n];r[e]=i,e!==n&&delete r[n]},this)}})}(),function(){function e(n,i,a,o,s){var d=t(i,"attrs");d&&a.eachRelationship(function(i,a){var u,c,l,h,p=d[i],f=n.serializerFor(a.type.typeKey),m=t(f,"primaryKey");if("hasMany"===a.kind&&p&&("always"===p.embedded||"load"===p.embedded)){if(c="_"+Ember.String.pluralize(a.type.typeKey),u=this.keyForRelationship(i,a.kind),l=this.keyForAttribute(i),h=[],!o[l])return;s[c]=s[c]||[],r(o[l],function(t){var r=n.modelFor(a.type.typeKey);e(n,f,r,t,s),h.push(t[m]),s[c].push(t)}),o[u]=h,delete o[l]}},i)}var t=Ember.get,r=Ember.EnumerableUtils.forEach;DS.EmbeddedRecordsMixin=Ember.Mixin.create({serializeHasMany:function(e,r,n){var i=n.key,a=t(this,"attrs"),o=a&&a[i]&&"always"===a[i].embedded;o&&(r[this.keyForAttribute(i)]=t(e,i).map(function(e){var r=e.serialize(),n=t(this,"primaryKey");return r[n]=t(e,n),r},this))},extractSingle:function(t,r,n,i,a){var o=this.keyForAttribute(r.typeKey),s=n[o];return e(t,this,r,s,n),this._super(t,r,n,i,a)},extractArray:function(t,n,i){var a=this.keyForAttribute(n.typeKey),o=i[Ember.String.pluralize(a)];return r(o,function(r){e(t,this,n,r,i)},this),this._super(t,n,i)}})}(),function(){var e=Ember.EnumerableUtils.forEach,t=Ember.String.decamelize,r=Ember.String.underscore,n=Ember.String.pluralize;DS.ActiveModelAdapter=DS.RESTAdapter.extend({defaultSerializer:"-active-model",pathForType:function(e){var i=t(e),a=r(i);return n(a)},ajaxError:function(t){var r=this._super(t);if(t&&422===t.status){var n=Ember.$.parseJSON(t.responseText),i={};if(void 0!==n.errors){var a=n.errors;e(Ember.keys(a),function(e){i[Ember.String.camelize(e)]=a[e]})}return new DS.InvalidError(i)}return r}})}(),function(){Ember.onLoad("Ember.Application",function(e){e.initializer({name:"activeModelAdapter",initialize:function(e,t){var r=new DS.ContainerProxy(e);r.registerDeprecations([{deprecated:"serializer:_ams",valid:"serializer:-active-model"},{deprecated:"adapter:_ams",valid:"adapter:-active-model"}]),t.register("serializer:-active-model",DS.ActiveModelSerializer),t.register("adapter:-active-model",DS.ActiveModelAdapter)}})})}()}(),"undefined"==typeof location||"localhost"!==location.hostname&&"127.0.0.1"!==location.hostname||Ember.Logger.warn("You are running a production build of Ember on localhost and won't receive detailed error messages. If you want full error messages please use the non-minified build provided on the Ember website."); http_version: recorded_at: Mon, 17 Feb 2014 11:45:02 GMT - request: method: get uri: http://builds.emberjs.com/beta/ember.js body: encoding: US-ASCII string: '' headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - '*/*' User-Agent: - Ruby Host: - builds.emberjs.com response: status: code: 200 message: OK headers: X-Amz-Id-2: - GI5brd5E+pjC61gajLS7qRHY+pdFCST9MING9cQrjPcKlPios8GN7I7nkEjs1ua4 X-Amz-Request-Id: - B3F04305615A2622 Date: - Mon, 17 Feb 2014 11:45:25 GMT Last-Modified: - Sun, 16 Feb 2014 02:41:59 GMT Etag: - '"e525bfd359fa6621c1439a9f82320ecb"' Content-Type: - text/javascript Content-Length: - '1220966' Server: - AmazonS3 body: encoding: ASCII-8BIT string: !binary |- LyohCiAqIEBvdmVydmlldyAgRW1iZXIgLSBKYXZhU2NyaXB0IEFwcGxpY2F0 aW9uIEZyYW1ld29yawogKiBAY29weXJpZ2h0IENvcHlyaWdodCAyMDExLTIw MTQgVGlsZGUgSW5jLiBhbmQgY29udHJpYnV0b3JzCiAqICAgICAgICAgICAg UG9ydGlvbnMgQ29weXJpZ2h0IDIwMDYtMjAxMSBTdHJvYmUgSW5jLgogKiAg ICAgICAgICAgIFBvcnRpb25zIENvcHlyaWdodCAyMDA4LTIwMTEgQXBwbGUg SW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLgogKiBAbGljZW5zZSAgIExpY2Vu c2VkIHVuZGVyIE1JVCBsaWNlbnNlCiAqICAgICAgICAgICAgU2VlIGh0dHBz Oi8vcmF3LmdpdGh1Yi5jb20vZW1iZXJqcy9lbWJlci5qcy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bGwpIHJl dHVybiAiKG51bGwpIjsKCiAgdmFyIHJldDsKICB2YXIgdHlwZSA9IHR5cGVv ZiBvYmo7CgogIC8vIERvbid0IGFsbG93IHByb3RvdHlwZSBjaGFuZ2VzIHRv IFN0cmluZyBldGMuIHRvIGNoYW5nZSB0aGUgZ3VpZEZvcgogIHN3aXRjaCh0 eXBlKSB7CiAgICBjYXNlICdudW1iZXInOgogICAgICByZXQgPSBudW1iZXJD YWNoZVtvYmpdOwogICAgICBpZiAoIXJldCkgcmV0ID0gbnVtYmVyQ2FjaGVb b2JqXSA9ICdudScrb2JqOwogICAgICByZXR1cm4gcmV0OwoKICAgIGNhc2Ug J3N0cmluZyc6CiAgICAgIHJldCA9IHN0cmluZ0NhY2hlW29ial07CiAgICAg IGlmICghcmV0KSByZXQgPSBzdHJpbmdDYWNoZVtvYmpdID0gJ3N0JysodXVp ZCsrKTsKICAgICAgcmV0dXJuIHJldDsKCiAgICBjYXNlICdib29sZWFuJzoK ICAgICAgcmV0dXJuIG9iaiA/ICcodHJ1ZSknIDogJyhmYWxzZSknOwoKICAg IGRlZmF1bHQ6CiAgICAgIGlmIChvYmpbR1VJRF9LRVldKSByZXR1cm4gb2Jq W0dVSURfS0VZXTsKICAgICAgaWYgKG9iaiA9PT0gT2JqZWN0KSByZXR1cm4g JyhPYmplY3QpJzsKICAgICAgaWYgKG9iaiA9PT0gQXJyYXkpICByZXR1cm4g JyhBcnJheSknOwogICAgICByZXQgPSAnZW1iZXInICsgKHV1aWQrKyk7Cgog ICAgICBpZiAob2JqW0dVSURfS0VZXSA9PT0gbnVsbCkgewogICAgICAgIG9i altHVUlEX0tFWV0gPSByZXQ7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgR1VJ RF9ERVNDLnZhbHVlID0gcmV0OwogICAgICAgIG9fZGVmaW5lUHJvcGVydHko b2JqLCBHVUlEX0tFWSwgR1VJRF9ERVNDKTsKICAgICAgfQogICAgICByZXR1 cm4gcmV0OwogIH0KfTsKCi8vIC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HJldHVybnMgYW4gZW1wdHkgYXJyYXkuCgogIGBgYGphdmFzY3JpcHQKICBF bWJlci5tYWtlQXJyYXkoKTsgICAgICAgICAgICAgICAgICAgICAgICAgICAv LyBbXQogIEVtYmVyLm1ha2VBcnJheShudWxsKTsgICAgICAgICAgICAgICAg ICAgICAgIC8vIFtdCiAgRW1iZXIubWFrZUFycmF5KHVuZGVmaW5lZCk7ICAg ICAgICAgICAgICAgICAgLy8gW10KICBFbWJlci5tYWtlQXJyYXkoJ2xpbmRz YXknKTsgICAgICAgICAgICAgICAgICAvLyBbJ2xpbmRzYXknXQogIEVtYmVy Lm1ha2VBcnJheShbMSwyLDQyXSk7ICAgICAgICAgICAgICAgICAgIC8vIFsx LDIsNDJdCgogIHZhciBjb250cm9sbGVyID0gRW1iZXIuQXJyYXlQcm94eS5j cmVhdGUoeyBjb250ZW50OiBbXSB9KTsKICBFbWJlci5tYWtlQXJyYXkoY29u dHJvbGxlcikgPT09IGNvbnRyb2xsZXI7ICAvLyB0cnVlCiAgYGBgCgogIEBt ZXRob2QgbWFrZUFycmF5CiAgQGZvciBFbWJlcgogIEBwYXJhbSB7T2JqZWN0 fSBvYmogdGhlIG9iamVjdAogIEByZXR1cm4ge0FycmF5fQoqLwpFbWJlci5t YWtlQXJyYXkgPSBmdW5jdGlvbihvYmopIHsKICBpZiAob2JqID09PSBudWxs IHx8IG9iaiA9PT0gdW5kZWZpbmVkKSB7IHJldHVybiBbXTsgfQogIHJldHVy biBFbWJlci5pc0FycmF5KG9iaikgPyBvYmogOiBbb2JqXTsKfTsKCmZ1bmN0 aW9uIGNhbkludm9rZShvYmosIG1ldGhvZE5hbWUpIHsKICByZXR1cm4gISEo b2JqICYmIHR5cGVvZiBvYmpbbWV0aG9kTmFtZV0gPT09ICdmdW5jdGlvbicp Owp9CgovKioKICBDaGVja3MgdG8gc2VlIGlmIHRoZSBgbWV0aG9kTmFtZWAg ZXhpc3RzIG9uIHRoZSBgb2JqYC4KCiAgYGBgamF2YX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ICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICB8CiAgICAgIHwtLS0tLS0tLS0t LS0tLS18LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tfAogICAgICB8ICdzdHJpbmcnICAgICAgfCBTdHJp bmcgcHJpbWl0aXZlIG9yIFN0cmluZyBvYmplY3QuICAgICAgICAgICAgICAg ICAgIHwKICAgICAgfCAnbnVtYmVyJyAgICAgIHwgTnVtYmVyIHByaW1pdGl2 ZSBvciBOdW1iZXIgb2JqZWN0LiAgICAgICAgICAgICAgICAgICB8CiAgICAg IHwgJ2Jvb2xlYW4nICAgICB8IEJvb2xlYW4gcHJpbWl0aXZlIG9yIEJvb2xl YW4gb2JqZWN0LiAgICAgICAgICAgICAgICAgfAogICAgICB8ICdudWxsJyAg ICAgICAgfCBOdWxsIHZhbHVlICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgIHwKICAgICAgfCAndW5kZWZpbmVkJyAgIHwgVW5k ZWZpbmVkIHZhbHVlICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICB8CiAgICAgIHwgJ2Z1bmN0aW9uJyAgICB8IEEgZnVuY3Rpb24gICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfAogICAg ICB8ICdhcnJheScgICAgICAgfCBBbiBpbnN0YW5jZSBvZiBBcnJheSAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgIHwKICAgICAgfCAncmVnZXhw JyAgICAgIHwgQW4gaW5zdGFuY2Ugb2YgUmVnRXhwICAgICAgICAgICAgICAg ICAgICAgICAgICAgICAgICB8CiAgICAgIHwgJ2RhdGUnICAgICAgICB8IEFu IGluc3RhbmNlIG9mIERhdGUgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgfAogICAgICB8ICdjbGFzcycgICAgICAgfCBBbiBFbWJlciBjbGFz cyAoY3JlYXRlZCB1c2luZyBFbWJlci5PYmplY3QuZXh0ZW5kKCkpIHwKICAg ICAgfCAnaW5zdGFuY2UnICAgIHwgQW4gRW1iZXIgb2JqZWN0IGluc3RhbmNl ICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8CiAgICAgIHwgJ2Vycm9y JyAgICAgICB8IEFuIGluc3RhbmNlIG9mIHRoZSBFcnJvciBvYmplY3QgICAg ICAgICAgICAgICAgICAgICAgfAogICAgICB8ICdvYmplY3QnICAgICAgfCBB IEphdmFTY3JpcHQgb2JqZWN0IG5vdCBpbmhlcml0aW5nIGZyb20gRW1iZXIu T2JqZWN0IHwKCiAgRXhhbXBsZXM6CgogIGBgYGphdmFzY3JpcHQKICBFbWJl ci50eXBlT2YoKTsgICAgICAgICAgICAgICAgICAgICAgIC8vICd1bmRlZmlu ZWQnCiAgRW1iZXIudHlwZU9mKG51bGwpOyAgICAgICAgICAgICAgICAgICAv LyAnbnVsbCcKICBFbWJlci50eXBlT2YodW5kZWZpbmVkKTsgICAgICAgICAg ICAgIC8vICd1bmRlZmluZWQnCiAgRW1iZXIudHlwZU9mKCdtaWNoYWVsJyk7 ICAgICAgICAgICAgICAvLyAnc3RyaW5nJwogIEVtYmVyLnR5cGVPZihuZXcg U3RyaW5nKCdtaWNoYWVsJykpOyAgLy8gJ3N0cmluZycKICBFbWJlci50eXBl T2YoMTAxKTsgICAgICAgICAgICAgICAgICAgIC8vICdudW1iZXInCiAgRW1i ZXIudHlwZU9mKG5ldyBOdW1iZXIoMTAxKSk7ICAgICAgICAvLyAnbnVtYmVy JwogIEVtYmVyLnR5cGVPZih0cnVlKTsgICAgICAgICAgICAgICAgICAgLy8g J2Jvb2xlYW4nCiAgRW1iZXIudHlwZU9mKG5ldyBCb29sZWFuKHRydWUpKTsg ICAgICAvLyAnYm9vbGVhbicKICBFbWJlci50eXBlT2YoRW1iZXIubWFrZUFy cmF5KTsgICAgICAgIC8vICdmdW5jdGlvbicKICBFbWJlci50eXBlT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Y3Nba2V5 TmFtZV0sCiAgICAgIGlzVW5rbm93biwgY3VycmVudFZhbHVlOwogIGlmIChk ZXNjKSB7CiAgICBkZXNjLnNldChvYmosIGtleU5hbWUsIHZhbHVlKTsKICB9 IGVsc2UgewogICAgaXNVbmtub3duID0gJ29iamVjdCcgPT09IHR5cGVvZiBv YmogJiYgIShrZXlOYW1lIGluIG9iaik7CgogICAgLy8gc2V0VW5rbm93blBy b3BlcnR5IGlzIGNhbGxlZCBpZiBgb2JqYCBpcyBhbiBvYmplY3QsCiAgICAv LyB0aGUgcHJvcGVydHkgZG9lcyBub3QgYWxyZWFkeSBleGlzdCwgYW5kIHRo ZQogICAgLy8gYHNldFVua25vd25Qcm9wZXJ0eWAgbWV0aG9kIGV4aXN0cyBv biB0aGUgb2JqZWN0CiAgICBpZiAoaXNVbmtub3duICYmICdmdW5jdGlvbicg PT09IHR5cGVvZiBvYmouc2V0VW5rbm93blByb3BlcnR5KSB7CiAgICAgIG9i ai5zZXRVbmtub3duUHJvcGVydHkoa2V5TmFtZSwgdmFsdWUpOwogICAgfSBl bHNlIGlmIChtZXRhICYmIG1ldGEud2F0Y2hpbmdba2V5TmFtZV0gPiAwKSB7 CiAgICAgIGlmIChNQU5EQVRPUllfU0VUVEVSKSB7CiAgICAgICAgY3VycmVu dFZhbHVlID0gbWV0YS52YWx1ZXNba2V5TmFtZV07CiAgICAgIH0gZWxzZSB7 CiAgICAgICAgY3VycmVudFZhbHVlID0gb2JqW2tleU5hbWVdOwogICAgICB9 CiAgICAgIC8vIG9ubHkgdHJpZ2dlciBhIGNoYW5nZSBpZiB0aGUgdmFsdWUg aGFzIGNoYW5nZWQKICAgICAgaWYgKHZhbHVlICE9PSBjdXJyZW50VmFsdWUp IHsKICAgICAgICBFbWJlci5wcm9wZXJ0eVdpbGxDaGFuZ2Uob2JqLCBrZXlO YW1lKTsKICAgICAgICBpZiAoTUFOREFUT1JZX1NFVFRFUikgewogICAgICAg ICAgaWYgKChjdXJyZW50VmFsd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cyB0aGF0IHdvdWxkIHByZXZlbnQgR0MKICAg IG5vZGUgPSBtZXRhLmNoYWluczsKICAgIGlmIChub2RlKSB7CiAgICAgIE5P REVfU1RBQ0sucHVzaChub2RlKTsKICAgICAgLy8gcHJvY2VzcyB0cmVlCiAg ICAgIHdoaWxlIChOT0RFX1NUQUNLLmxlbmd0aCA+IDApIHsKICAgICAgICBu b2RlID0gTk9ERV9TVEFDSy5wb3AoKTsKICAgICAgICAvLyBwdXNoIGNoaWxk cmVuCiAgICAgICAgbm9kZXMgPSBub2RlLl9jaGFpbnM7CiAgICAgICAgaWYg KG5vZGVzKSB7CiAgICAgICAgICBmb3IgKGtleSBpbiBub2RlcykgewogICAg ICAgICAgICBpZiAobm9kZXMuaGFzT3duUHJvcGVydHkoa2V5KSkgewogICAg ICAgICAgICAgIE5PREVfU1RBQ0sucHVzaChub2Rlc1trZXldKTsKICAgICAg ICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0KICAgICAgICAvLyByZW1v dmUgY2hhaW5XYXRjaGVyIGluIG5vZGUgb2JqZWN0CiAgICAgICAgaWYgKG5v ZGUuX3dhdGNoaW5nKSB7CiAgICAgICAgICBub2RlT2JqZWN0ID0gbm9kZS5f b2JqZWN0OwogICAgICAgICAgaWYgKG5vZGVPYmplY3QpIHsKICAgICAgICAg ICAgcmVtb3ZlQ2hhaW5XYXRjaGVyKG5vZGVPYmplY3QsIG5vZGUuX2tleSwg bm9kZSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9CiAgICB9CiAg fQp9OwoKfSkoKTsKCgoKKGZ1bmN0aW9uKCkgewovKioKQG1vZHVsZSBlbWJl ci1tZXRhbAoqLwoKRW1iZXIud2FybigiVGhlIENQX0RFRkFVTFRfQ0FDSEVB QkxFIGZsYWcgaGFzIGJlZW4gcmVtb3ZlZCBhbmQgY29tcHV0ZWQgcHJvcGVy dGllcyBhcmUgYWx3YXlzIGNhY2hlZCBieSBkZWZhdWx0LiBVc2UgYHZvbGF0 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7CiAgICAgICAgcXVldWUucHVz aCh0YXJnZXQsIG1ldGhvZCwgYXJncywgc3RhY2spOwogICAgICAgIHJldHVy biB7cXVldWU6IHRoaXMsIHRhcmdldDogdGFyZ2V0LCBtZXRob2Q6IG1ldGhv ZH07CiAgICAgIH0sCgogICAgICBwdXNoVW5pcXVlOiBmdW5jdGlvbih0YXJn ZXQsIG1ldGhvZCwgYXJncywgc3RhY2spIHsKICAgICAgICB2YXIgcXVldWUg PSB0aGlzLl9xdWV1ZSwgY3VycmVudFRhcmdldCwgY3VycmVudE1ldGhvZCwg aSwgbDsKCiAgICAgICAgZm9yIChpID0gMCwgbCA9IHF1ZXVlLmxlbmd0aDsg aSA8IGw7IGkgKz0gNCkgewogICAgICAgICAgY3VycmVudFRhcmdldCA9IHF1 ZXVlW2ldOwogICAgICAgICAgY3VycmVudE1ldGhvZCA9IHF1ZXVlW2krMV07 CgogICAgICAgICAgaWYgKGN1cnJlbnRUYXJnZXQgPT09IHRhcmdldCAmJiBj dXJyZW50TWV0aG9kID09PSBtZXRob2QpIHsKICAgICAgICAgICAgcXVldWVb aSsyXSA9IGFyZ3M7IC8vIHJlcGxhY2UgYXJncwogICAgICAgICAgICBxdWV1 ZVtpKzNdID0gc3RhY2s7IC8vIHJlcGxhY2Ugc3RhY2sKICAgICAgICAgICAg cmV0dXJuIHtxdWV1ZTogdGhpcywgdGFyZ2V0OiB0YXJnZXQsIG1ldGhvZDog bWV0aG9kfTsgLy8gVE9ETzogdGVzdCB0aGlzIGNvZGUgcGF0aAogICAgICAg ICAgfQogICAgICAgIH0KCiAgICAgICAgdGhpcy5fcXVldWUucHVzaCh0YXJn ZXQsIG1ldGhvZCwgYXJncywgc3RhY2spOwogICAgICAgIHJldHVybiB7cXVl dWU6IHRoaXMsIHRhcmdldDogdGFyZ2V0LCBtZXRob2Q6IG1ldGhvZH07CiAg ICAgIH0sCgogICAgICAvLyBUT0RPOiByZW1vdmUgbWUsIG9ubHkgYmVpbmcg dXNlZCBmb3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gLy8gRGVidWdnaW5nIGFzc2lz dGFuY2UKCiAgICAgICAgICAgIGlmICh0eXBlb2YgbWV0aG9kID09PSAnc3Ry aW5nJykgeyBtZXRob2QgPSB0YXJnZXRbbWV0aG9kXTsgfQoKICAgICAgICAg ICAgLy8gbWV0aG9kIGNvdWxkIGhhdmUgYmVlbiBudWxsaWZpZWQgLyBjYW5j ZWxlZCBkdXJpbmcgZmx1c2gKICAgICAgICAgICAgaWYgKG1ldGhvZCkgewog ICAgICAgICAgICAgIC8vIFRPRE86IGVycm9yIGhhbmRsaW5nCiAgICAgICAg ICAgICAgaWYgKGFyZ3MgJiYgYXJncy5sZW5ndGggPiAwKSB7CiAgICAgICAg ICAgICAgICBtZXRob2QuYXBwbHkodGFyZ2V0LCBhcmdzKTsKICAgICAgICAg ICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgbWV0aG9kLmNhbGwodGFy Z2V0KTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KCiAgICAgICAg ICAgIHF1ZXVlSW5kZXggKz0gNDsKICAgICAgICAgIH0KICAgICAgICAgIHF1 ZXVlLl9xdWV1ZUJlaW5nRmx1c2hlZCA9IG51bGw7CiAgICAgICAgICBpZiAo bnVtYmVyT2ZRdWV1ZUl0ZW1zICYmIGFmdGVyKSB7IGFmdGVyKCk7IH0KCiAg ICAgICAgICBpZiAoKHByaW9yUXVldWVOYW1lSW5kZXggPSBpbmRleE9mUHJp b3JRdWV1ZVdpdGhBY3Rpb25zKHRoaXMsIHF1ZXVlTmFtZUluZGV4KSkgIT09 IC0xKSB7CiAgICAgICAgICAgIHF1ZXVlTmFtZUluZGV4ID0gcHJpb3JRdWV1 ZU5hbWVJbmRleDsKICAgICAgICAgICAgY29udGludWUgb3V0ZXJsb29wOwog ICAgICAgICAgfQoKICAgICAgICAgIHF1ZXVlTmFtZUluZGV4Kys7CiAgICAg ICAgfQogICAgICB9CiAgICB9OwoKICAgIGZ1bmN0aW9uIGluZGV4T2ZQcmlv clF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4odGhpcy5jdXJyZW50SW5zdGFuY2Us IHByZXZpb3VzSW5zdGFuY2UpOwogICAgICAgIH0KICAgICAgfSwKCiAgICAg IGVuZDogZnVuY3Rpb24oKSB7CiAgICAgICAgdmFyIG9uRW5kID0gdGhpcy5v cHRpb25zICYmIHRoaXMub3B0aW9ucy5vbkVuZCwKICAgICAgICAgICAgY3Vy cmVudEluc3RhbmNlID0gdGhpcy5jdXJyZW50SW5zdGFuY2UsCiAgICAgICAg ICAgIG5leHRJbnN0YW5jZSA9IG51bGw7CgogICAgICAgIHRyeSB7CiAgICAg ICAgICBjdXJyZW50SW5zdGFuY2UuZmx1c2goKTsKICAgICAgICB9IGZpbmFs bHkgewogICAgICAgICAgdGhpcy5jdXJyZW50SW5zdGFuY2UgPSBudWxsOwoK ICAgICAgICAgIGlmICh0aGlzLmluc3RhbmNlU3RhY2subGVuZ3RoKSB7CiAg ICAgICAgICAgIG5leHRJbnN0YW5jZSA9IHRoaXMuaW5zdGFuY2VTdGFjay5w b3AoKTsKICAgICAgICAgICAgdGhpcy5jdXJyZW50SW5zdGFuY2UgPSBuZXh0 SW5zdGFuY2U7CiAgICAgICAgICB9CgogICAgICAgICAgaWYgKG9uRW5kKSB7 CiAgICAgICAgICAgIG9uRW5kKGN1cnJlbnRJbnN0YW5jZSwgbmV4dEluc3Rh bmNlKTsKICAgICAgICAgIH0KICAgICAgICB9CiAgICAgIH0sCgogICAgICBy dW46IGZ1bmN0aW9uKHRhcmdldCwgbWV0aG9kIC8qLCBhcmdzICovKSB7CiAg ICAgICAgdmFyIHJldDsKICAgICAgICB0aGlzLmJlZ2luKCk7CgogICAgICAg IGlmICghbWV0aG9kKSB7CiAgICAgICAgICBtZXRob2QgPSB0YXJnZXQ7CiAg ICAgICAgICB0YXJnZXQgPSBudWxsOwogICAgICAgIH0KCiAgICAgICAgaWYg KHR5cGVvZiBtZXRob2QgPT09ICdzdHJpbmcnKSB7CiAgICAgICAgICBtZXRo b2QgPSB0YXJnZXRbbWV0aG9kXTsKICAgICAgICB9CgogICAgICAgIC8vIFBy ZXZlbnQgU2FmYXJpIGRvdWJsZS1maW5hbGx5LgogICAgICAgIHZhciBmaW5h bGx5QWxyZWFkeUNhbGxlZCA9IGZhbHNlOwogICAgICAgIHRyeSB7CiAgICAg ICAgICBpZiAoYXJndW1lbnRzLmxlbmd0aCA+IDIpIHsKICAgICAgICAgICAg cmV0ID0gbWV0aG9kLmFwcGx5KHRhcmdldCwgc2xpY2UuY2FsbChhcmd1bWVu dHMsIDIpKTsKICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHJldCA9 IG1ldGhvZC5jYWxsKHRhcmdldCk7CiAgICAgICAgICB9CiAgICAgICAgfSBm aW5hbGx5IHsKICAgICAgICAgIGlmICghZmluYWxseUFscmVhZHlDYWxsZWQp IHsKICAgICAgICAgICAgZmluYWxseUFscmVhZHlDYWxsZWQgPSB0cnVlOwog ICAgICAgICAgICB0aGlzLmVuZCgpOwogICAgICAgICAgfQogICAgICAgIH0K ICAgICAgICByZXR1cm4gcmV0OwogICAgICB9LAoKICAgICAgZGVmZXI6IGZ1 bmN0aW9uKHF1ZXVlTmFtZSwgdGFyZ2V0LCBtZXRob2QgLyogLCBhcmdzICov KSB7CiAgICAgICAgaWYgKCFtZXRob2QpIHsKICAgICAgICAgIG1ldGhvZCA9 IHRhcmdldDsKICAgICAgICAgIHRhcmdldCA9IG51bGw7CiAgICAgICAgfQoK ICAgICAgICBpZiAodHlwZW9mIG1ldGhvZCA9PT0gJ3N0cmluZycpIHsKICAg ICAgICAgIG1ldGhvZCA9IHRhcmdldFttZXRob2RdOwogICAgICAgIH0KCiAg ICAgICAgdmFyIHN0YWNrID0gdGhpcy5ERUJVRyA/IG5ldyBFcnJvcigpIDog dW5kZWZpbmVkLAogICAgICAgICAgICBhcmdzID0gYXJndW1lbnRzLmxlbmd0 aCA+IDMgPyBzbGljZS5jYWxsKGFyZ3VtZW50cywgMykgOiB1bmRlZmluZWQ7 CiAgICAgIC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WV0aG9kLCB3YWl0LCB0YXJnZXQ7CiAgICAgICAg dmFyIHNlbGYgPSB0aGlzOwogICAgICAgIHZhciBtZXRob2RPclRhcmdldCwg bWV0aG9kT3JXYWl0LCBtZXRob2RPckFyZ3M7CgogICAgICAgIGlmIChsZW5n dGggPT09IDApIHsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9IGVsc2Ug aWYgKGxlbmd0aCA9PT0gMSkgewogICAgICAgICAgbWV0aG9kID0gYXJncy5z aGlmdCgpOwogICAgICAgICAgd2FpdCA9IDA7CiAgICAgICAgfSBlbHNlIGlm IChsZW5ndGggPT09IDIpIHsKICAgICAgICAgIG1ldGhvZE9yVGFyZ2V0ID0g YXJnc1swXTsKICAgICAgICAgIG1ldGhvZE9yV2FpdCA9IGFyZ3NbMV07Cgog ICAgICAgICAgaWYgKHR5cGVvZiBtZXRob2RPcldhaXQgPT09ICdmdW5jdGlv bicgfHwgdHlwZW9mICBtZXRob2RPclRhcmdldFttZXRob2RPcldhaXRdID09 PSAnZnVuY3Rpb24nKSB7CiAgICAgICAgICAgIHRhcmdldCA9IGFyZ3Muc2hp ZnQoKTsKICAgICAgICAgICAgbWV0aG9kID0gYXJncy5zaGlmdCgpOwogICAg ICAgICAgICB3YWl0ID0gMDsKICAgICAgICAgIH0gZWxzZSBpZiAoaXNDb2Vy Y2FibGVOdW1iZXIobWV0aG9kT3JXYWl0KSkgewogICAgICAgICAgICBtZXRo b2QgPSBhcmdzLnNoaWZ0KCk7CiAgICAgICAgICAgIHdhaXQgPSBhcmdzLnNo aWZ0KCk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICBtZXRob2Qg PSBhcmdzLnNoaWZ0KCk7CiAgICAgICAgICAgIHdhaXQgPSAgMDsKICAgICAg ICAgIH0KICAgICAgICB9IGVsc2UgewogICAgICAgICAgdmFyIGxhc3QgPSBh cmdzW2FyZ3MubGVuZ3RoIC0gMV07CgogICAgICAgICAgaWYgKGlzQ29lcmNh YmxlTnVtYmVyKGxhc3QpKSB7CiAgICAgICAgICAgIHdhaXQgPSBhcmdzLnBv cCgpOwogICAgICAgICAgfQoKICAgICAgICAgIG1ldGhvZE9yVGFyZ2V0ID0g YXJnc1swXTsKICAgICAgICAgIG1ldGhvZE9yQXJncyA9IGFyZ3NbMV07Cgog ICAgICAgICAgaWYgKHR5cGVvZiBtZXRob2RPckFyZ3MgPT09ICdmdW5jdGlv bicgfHwgKHR5cGVvZiBtZXRob2RPckFyZ3MgPT09ICdzdHJpbmcnICYmCiAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgbWV0aG9kT3JUYXJnZXQgIT09IG51bGwgJiYKICAgICAgICAgICAg ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICBtZXRo b2RPckFyZ3MgaW4gbWV0aG9kT3JUYXJnZXQpKSB7CiAgICAgICAgICAgIHRh cmdldCA9IGFyZ3Muc2hpZnQoKTsKICAgICAgICAgICAgbWV0aG9kID0gYXJn cy5zaGlmdCgpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgbWV0 aG9kID0gYXJncy5zaGlmdCgpOwogICAgICAgICAgfQogICAgICAgIH0KCiAg ICAgICAgdmFyIGV4ZWN1dGVBdCA9ICgrbmV3IERhdGUoKSkgKyBwYXJzZUlu dCh3YWl0LCAxMCk7CgogICAgICAgIGlmICh0eXBlb2YgbWV0aG9kID09PSAn c3RyaW5nJykgewogICAgICAgICAgbWV0aG9kID0gdGFyZ2V0W21ldGhvZF07 CiAgICAgICAgfQoKICAgICAgICBmdW5jdGlvbiBmbigpIHsKICAgICAgICAg IG1ldGhvZC5hcHBseSh0YXJnZXQsIGFyZ3MpOwogICAgICAgIH0KCiAgICAg ICAgLy8gZmluZCBwb3NpdGlvbiB0byBpbnNlcnQgLSBUT0RPOiBiaW5hcnkg c2VhcmNoCiAgICAgICAgdmFyIGksIGw7CiAgICAgICAgZm9yIChpID0gMCwg bCA9IHRpbWV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ldFRpbWVvdXQoZnVuY3Rp b24oKSB7CiAgICAgICAgICBpZiAoIWltbWVkaWF0ZSkgewogICAgICAgICAg ICBzZWxmLnJ1bi5hcHBseShzZWxmLCBhcmdzKTsKICAgICAgICAgIH0KICAg ICAgICAgIHZhciBpbmRleCA9IGZpbmRUaHJvdHRsZXIodGFyZ2V0LCBtZXRo b2QpOwogICAgICAgICAgaWYgKGluZGV4ID4gLTEpIHsgdGhyb3R0bGVycy5z cGxpY2UoaW5kZXgsIDEpOyB9CiAgICAgICAgfSwgd2FpdCk7CgogICAgICAg IGlmIChpbW1lZGlhdGUpIHsKICAgICAgICAgIHNlbGYucnVuLmFwcGx5KHNl bGYsIGFyZ3MpOwogICAgICAgIH0KCiAgICAgICAgdGhyb3R0bGVyID0gW3Rh cmdldCwgbWV0aG9kLCB0aW1lcl07CgogICAgICAgIHRocm90dGxlcnMucHVz aCh0aHJvdHRsZXIpOwoKICAgICAgICByZXR1cm4gdGhyb3R0bGVyOwogICAg ICB9LAoKICAgICAgZGVib3VuY2U6IGZ1bmN0aW9uKHRhcmdldCwgbWV0aG9k IC8qICwgYXJncywgd2FpdCwgW2ltbWVkaWF0ZV0gKi8pIHsKICAgICAgICB2 YXIgc2VsZiA9IHRoaXMsCiAgICAgICAgICAgIGFyZ3MgPSBhcmd1bWVudHMs CiAgICAgICAgICAgIGltbWVkaWF0ZSA9IHBvcC5jYWxsKGFyZ3MpLAogICAg ICAgICAgICB3YWl0LAogICAgICAgICAgICBpbmRleCwKICAgICAgICAgICAg ZGVib3VuY2VlLAogICAgICAgICAgICB0aW1lcjsKCiAgICAgICAgaWYgKHR5 cGVvZiBpbW1lZGlhdGUgPT09ICJudW1iZXIiIHx8IHR5cGVvZiBpbW1lZGlh dGUgPT09ICJzdHJpbmciKSB7CiAgICAgICAgICB3YWl0ID0gaW1tZWRpYXRl OwogICAgICAgICAgaW1tZWRpYXRlID0gZmFsc2U7CiAgICAgICAgfSBlbHNl IHsKICAgICAgICAgIHdhaXQgPSBwb3AuY2FsbChhcmdzKTsKICAgICAgICB9 CgogICAgICAgIHdhaXQgPSBwYXJzZUludCh3YWl0LCAxMCk7CiAgICAgICAg Ly8gUmVtb3ZlIGRlYm91bmNlZQogICAgICAgIGluZGV4ID0gZmluZERlYm91 bmNlZSh0YXJnZXQsIG1ldGhvZCk7CgogICAgICAgIGlmIChpbmRleCA+IC0x KSB7CiAgICAgICAgICBkZWJvdW5jZWUgPSBkZWJvdW5jZWVzW2luZGV4XTsK ICAgICAgICAgIGRlYm91bmNlZXMuc3BsaWNlKGluZGV4LCAxKTsKICAgICAg ICAgIGNsZWFyVGltZW91dChkZWJvdW5jZWVbMl0pOwogICAgICAgIH0KCiAg ICAgICAgdGltZXIgPSBnbG9iYWwuc2V0VGltZW91dChmdW5jdGlvbigpIHsK ICAgICAgICAgIGlmICghaW1tZWRpYXRlKSB7CiAgICAgICAgICAgIHNlbGYu cnVuLmFwcGx5KHNlbGYsIGFyZ3MpOwogICAgICAgICAgfQogICAgICAgICAg dmFyIGluZGV4ID0gZmluZERlYm91bmNlZSh0YXJnZXQsIG1ldGhvZCk7CiAg ICAgICAgICBpZiAoaW5kZXggPiAtMSkgewogICAgICAgICAgICBkZWJvdW5j ZWVzLnNwbGljZShpbmRleCwgMSk7CiAgICAgICAgICB9CiAgICAgICAgfSwg d2FpdCk7CgogICAgICAgIGlmIChpbW1lZGlhdGUgJiYgaW5kZXggPT09IC0x KSB7CiAgICAgICAgICBzZWxmLnJ1bi5hcHBseShzZWxmLCBhcmdzKTsKICAg ICAgICB9CgogICAgICAgIGRlYm91bmNlZSA9IFt0YXJnZXQsIG1ldGhvZCwg dGltZXJdOwoKICAgICAgICBkZWJvdW5jZWVzLnB1c2goZGVib3VuY2VlKTsK CiAgICAgICAgcmV0dXJuIGRlYm91bmNlZTsKICAgICAgfSwKCiAgICAgIGNh bmNlbFRpbWVyczogZnVuY3Rpb24oKSB7CiAgICAgICAgdmFyIGksIGxlbjsK CiAgICAgICAgZm9yIChpID0gMCwgbGVuID0gdGhyb3R0bGVycy5sZW5ndGg7 IGkgPCBsZW47IGkrKykgewogICAgICAgICAgY2xlYXJUaW1lb3V0KHRocm90 dGxlcnNbaV1bMl0pOwogICAgICAgIH0KICAgICAgICB0aHJvdHRsZXJzID0g W107CgogICAgICAgIGZvciAoaSA9IDAsIGxlbiA9IGRlYm91bmNlZXMubGVu Z3RoOyBpIDwgbGVuOyBpKyspIHsKICAgICAgICAgIGNsZWFyVGltZW91dChk ZWJvdW5jZWVzW2ldWzJdKTsKICAgICAgICB9CiAgICAgICAgZGVib3VuY2Vl cyA9IFtdOwoKICAgICAgICBpZiAobGF0ZXJUaW1lcikgewogICAgICAgICAg Y2xlYXJUaW1lb3V0KGxhdGVyVGltZXIpOwogICAgICAgICAgbGF0ZXJUaW1l ciA9IG51bGw7CiAgICAgICAgfQogICAgICAgIHRpbWVycyA9IFtdOwoKICAg ICAgICBpZiAoYXV0b3J1bikgewogICAgICAgICAgY2xlYXJUaW1lb3V0KGF1 dG9ydW4pOwogICAgICAgICAgYXV0b3J1biA9IG51bGw7CiAgICAgICAgfQog ICAgICB9LAoKICAgICAgaGFzVGltZXJzOiBmdW5jdGlvbigpIHsKICAgICAg ICByZXR1cm4gISF0aW1lcnMubGVuZ3RoIHx8IGF1dG9ydW47CiAgICAgIH0s CgogICAgICBjYW5jZWw6IGZ1bmN0aW9uKHRpbWVyKSB7CiAgICAgICAgdmFy IHRpbWVyVHlwZSA9IHR5cGVvZiB0aW1lcjsKCiAgICAgICAgaWYgKHRpbWVy ICYmIHRpbWVyVHlwZSA9PT0gJ29iamVjdCcgJiYgdGltZXIucXVldWUgJiYg dGltZXIubWV0aG9kKSB7IC8vIHdlJ3JlIGNhbmNlbGxpbmcgYSBkZWZlck9u Y2UKICAgICAgICAgIHJldHVybiB0aW1lci5xdWV1ZS5jYW5jZWwodGltZXIp OwogICAgICAgIH0gZWxzZSBpZiAodGltZXJUeXBlID09PSAnZnVuY3Rpb24n KSB7IC8vIHdlJ3JlIGNhbmNlbGxpbmcgYSBzZXRUaW1lb3V0CiAgICAgICAg ICBmb3IgKHZhciBpID0gMCwgbCA9IHRpbWVycy5sZW5ndGg7IGkgPCBsOyBp ICs9IDIpIHsKICAgICAgICAgICAgaWYgKHRpbWVyc1tpICsgMV0gPT09IHRp bWVyKSB7CiAgICAgICAgICAgICAgdGltZXJzLnNwbGljZShpLCAyKTsgLy8g cmVtb3ZlIHRoZSB0d28gZWxlbWVudHMKICAgICAgICAgICAgICByZXR1cm4g dHJ1ZTsKICAgICAgICAgICAgfQogICAgICAgICAgfQogICAgICAgIH0gZWxz ZSBpZiAoT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5jYWxsKHRpbWVyKSA9 PT0gIltvYmplY3QgQXJyYXldIil7IC8vIHdlJ3JlIGNhbmNlbGxpbmcgYSB0 aHJvdHRsZSBvciBkZWJvdW5jZQogICAgICAgICAgcmV0dXJuIHRoaXMuX2Nh bmNlbEl0ZW0oZmluZFRocm90dGxlciwgdGhyb3R0bGVycywgdGltZXIpIHx8 CiAgICAgICAgICAgICAgICAgICB0aGlzLl9jYW5jZWxJdGVtKGZpbmREZWJv dW5jZWUsIGRlYm91bmNlZXMsIHRpbWVyKTsKICAgICAgICB9IGVsc2Ugewog ICAgICAgICAgcmV0dXJuOyAvLyB0aW1lciB3YXMgbnVsbCBvciBub3QgYSB0 aW1lcgogICAgICAgIH0KICAgICAgfSwKCiAgICAgIF9jYW5jZWxJdGVtOiBm dW5jdGlvbihmaW5kTWV0aG9kLCBhcnJheSwgdGltZXIpewogICAgICAgIHZh ciBpdGVtLAogICAgICAgICAgICBpbmRleDsKCiAgICAgICAgaWYgKHRpbWVy Lmxlbmd0aCA8IDMpIHsgcmV0dXJuIGZhbHNlOyB9CgogICAgICAgIGluZGV4 ID0gZmluZE1ldGhvZCh0aW1lclswXSwgdGltZXJbMV0pOwoKICAgICAgICBp ZihpbmRleCA+IC0xKSB7CgogICAgICAgICAgaXRlbSA9IGFycmF5W2luZGV4 XTsKCiAgICAgICAgICBpZihpdGVtWzJdID09PSB0aW1lclsyXSl7CiAgICAg ICAgICAgIGFycmF5LnNwbGljZShpbmRleCwgMSk7CiAgICAgICAgICAgIGNs ZWFyVGltZW91dCh0aW1lclsyXSk7CiAgICAgICAgICAgIHJldHVybiB0cnVl OwogICAgICAgICAgfQogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIGZhbHNl OwogICAgICB9CgogICAgfTsKCiAgICBCYWNrYnVybmVyLnByb3RvdHlwZS5z Y2hlZHVsZSA9IEJhY2tidXJuZXIucHJvdG90eXBlLmRlZmVyOwogICAgQmFj a2J1cm5lci5wcm90b3R5cGUuc2NoZWR1bGVPbmNlID0gQmFja2J1cm5lci5w cm90b3R5cGUuZGVmZXJPbmNlOwogICAgQmFja2J1cm5lci5wcm90b3R5cGUu bGF0ZXIgPSBCYWNrYnVybmVyLnByb3RvdHlwZS5zZXRUaW1lb3V0OwoKICAg IGZ1bmN0aW9uIGNyZWF0ZUF1dG9ydW4oYmFja2J1cm5lcikgewogICAgICBi YWNrYnVybmVyLmJlZ2luKCk7CiAgICAgIGF1dG9ydW4gPSBnbG9iYWwuc2V0 VGltZW91dChmdW5jdGlvbigpIHsKICAgICAgICBhdXRvcnVuID0gbnVsbDsK ICAgICAgICBiYWNrYnVybmVyLmVuZCgpOwogICAgICB9KTsKICAgIH0KCiAg ICBmdW5jdGlvbiB1cGRhdGVMYXRlclRpbWVyKHNlbGYsIGV4ZWN1dGVBdCwg d2FpdCkgewogICAgICBpZiAoIWxhdGVyVGltZXIgfHwgZXhlY3V0ZUF0IDwg bGF0ZXJUaW1lckV4cGlyZXNBdCkgewogICAgICAgIGlmIChsYXRlclRpbWVy KSB7CiAgICAgICAgICBjbGVhclRpbWVvdXQobGF0ZXJUaW1lcik7CiAgICAg ICAgfQogICAgICAgIGxhdGVyVGltZXIgPSBnbG9iYWwuc2V0VGltZW91dChm dW5jdGlvbigpIHsKICAgICAgICAgIGxhdGVyVGltZXIgPSBudWxsOwogICAg ICAgICAgbGF0ZXJUaW1lckV4cGlyZXNBdCA9IG51bGw7CiAgICAgICAgICBl eGVjdXRlVGltZXJzKHNlbGYpOwogICAgICAgIH0sIHdhaXQpOwogICAgICAg IGxhdGVyVGltZXJFeHBpcmVzQXQgPSBleGVjdXRlQXQ7CiAgICAgIH0KICAg IH0KCiAgICBmdW5jdGlvbiBleGVjdXRlVGltZXJzKHNlbGYpIHsKICAgICAg dmFyIG5vdyA9ICtuZXcgRGF0ZSgpLAogICAgICAgICAgdGltZSwgZm5zLCBp LCBsOwoKICAgICAgc2VsZi5ydW4oZnVuY3Rpb24oKSB7CiAgICAgICAgLy8g VE9ETzogYmluYXJ5IHNlYXJjaAogICAgICAgIGZvciAoaSA9IDAsIGwgPSB0 aW1lcnMubGVuZ3RoOyBpIDwgbDsgaSArPSAyKSB7CiAgICAgICAgICB0aW1l ID0gdGltZXJzW2ldOwogICAgICAgICAgaWYgKHRpbWUgPiBub3cpIHsgYnJl YWs7IH0KICAgICAgICB9CgogICAgICAgIGZucyA9IHRpbWVycy5zcGxpY2Uo MCwgaSk7CgogICAgICAgIGZvciAoaSA9IDEsIGwgPSBmbnMubGVuZ3RoOyBp IDwgbDsgaSArPSAyKSB7CiAgICAgICAgICBzZWxmLnNjaGVkdWxlKHNlbGYu b3B0aW9ucy5kZWZhdWx0UXVldWUsIG51bGwsIGZuc1tpXSk7CiAgICAgICAg fQogICAgICB9KTsKCiAgICAgIGlmICh0aW1lcnMubGVuZ3RoKSB7CiAgICAg ICAgdXBkYXRlTGF0ZXJUaW1lcihzZWxmLCB0aW1lcnNbMF0sIHRpbWVyc1sw XSAtIG5vdyk7CiAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlvbiBmaW5kRGVi b3VuY2VlKHRhcmdldCwgbWV0aG9kKSB7CiAgICAgIHZhciBkZWJvdW5jZWUs CiAgICAgICAgICBpbmRleCA9IC0xOwoKICAgICAgZm9yICh2YXIgaSA9IDAs IGwgPSBkZWJvdW5jZWVzLmxlbmd0aDsgaSA8IGw7IGkrKykgewogICAgICAg IGRlYm91bmNlZSA9IGRlYm91bmNlZXNbaV07CiAgICAgICAgaWYgKGRlYm91 bmNlZVswXSA9PT0gdGFyZ2V0ICYmIGRlYm91bmNlZVsxXSA9PT0gbWV0aG9k KSB7CiAgICAgICAgICBpbmRleCA9IGk7CiAgICAgICAgICBicmVhazsKICAg ICAgICB9CiAgICAgIH0KCiAgICAgIHJldHVybiBpbmRleDsKICAgIH0KCiAg ICBmdW5jdGlvbiBmaW5kVGhyb3R0bGVyKHRhcmdldCwgbWV0aG9kKSB7CiAg ICAgIHZhciB0aHJvdHRsZXIsCiAgICAgICAgICBpbmRleCA9IC0xOwoKICAg ICAgZm9yICh2YXIgaSA9IDAsIGwgPSB0aHJvdHRsZXJzLmxlbmd0aDsgaSA8 IGw7IGkrKykgewogICAgICAgIHRocm90dGxlciA9IHRocm90dGxlcnNbaV07 CiAgICAgICAgaWYgKHRocm90dGxlclswXSA9PT0gdGFyZ2V0ICYmIHRocm90 dGxlclsxXSA9PT0gbWV0aG9kKSB7CiAgICAgICAgICBpbmRleCA9IGk7CiAg ICAgICAgICBicmVhazsKICAgICAgICB9CiAgICAgIH0KCiAgICAgIHJldHVy biBpbmRleDsKICAgIH0KCiAgICBfX2V4cG9ydHNfXy5CYWNrYnVybmVyID0g QmFja2J1cm5lcjsKICB9KTsKfSkoKTsKCgoKKGZ1bmN0aW9uKCkgewp2YXIg b25CZWdpbiA9IGZ1bmN0aW9uKGN1cnJlbnQpIHsKICBFbWJlci5ydW4uY3Vy cmVudFJ1bkxvb3AgPSBjdXJyZW50Owp9OwoKdmFyIG9uRW5kID0gZnVuY3Rp b24oY3VycmVudCwgbmV4dCkgewogIEVtYmVyLnJ1bi5jdXJyZW50UnVuTG9v cCA9IG5leHQ7Cn07Cgp2YXIgQmFja2J1cm5lciA9IHJlcXVpcmVNb2R1bGUo J2JhY2tidXJuZXInKS5CYWNrYnVybmVyLAog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dOwogICAgZGVsZXRlIHZhbHVlc1tr ZXlOYW1lXTsKICB9CgogIGZvcih2YXIgaT0wLCBsPW1peGlucy5sZW5ndGg7 IGk8bDsgaSsrKSB7CiAgICBtaXhpbiA9IG1peGluc1tpXTsKICAgIEVtYmVy LmFzc2VydCgnRXhwZWN0ZWQgaGFzaCBvciBNaXhpbiBpbnN0YW5jZSwgZ290 ICcgKyBPYmplY3QucHJvdG90eXBlLnRvU3RyaW5nLmNhbGwobWl4aW4pLAog ICAgICAgICAgICAgICAgIHR5cGVvZiBtaXhpbiA9PT0gJ29iamVjdCcgJiYg bWl4aW4gIT09IG51bGwgJiYgT2JqZWN0LnByb3RvdHlwZS50b1N0cmluZy5j YWxsKG1peGluKSAhPT0gJ1tvYmplY3QgQXJyYXldJyk7CgogICAgcHJvcHMg PSBtaXhpblByb3BlcnRpZXMobSwgbWl4aW4pOwogICAgaWYgKHByb3BzID09 PSBDT05USU5VRSkgeyBjb250aW51ZTsgfQoKICAgIGlmIChwcm9wcykgewog ICAgICBtZXRhID0gbWV0YUZvcihiYXNlKTsKICAgICAgaWYgKGJhc2Uud2ls bE1lcmdlTWl4aW4pIHsgYmFzZS53aWxsTWVyZ2VNaXhpbihwcm9wcyk7IH0K ICAgICAgY29uY2F0cyA9IGNvbmNhdGVuYXRlZE1peGluUHJvcGVydGllcygn Y29uY2F0ZW5hdGVkUHJvcGVydGllcycsIHByb3BzLCB2YWx1ZXMsIGJhc2Up OwogICAgICBtZXJnaW5ncyA9IGNvbmNhdGVuYXRlZE1peGluUHJvcGVydGll cygnbWVyZ2VkUHJvcGVydGllcycsIHByb3BzLCB2YWx1ZXMsIGJhc2UpOwoK ICAgICAgZm9yIChrZXkgaW4gcHJvcHMpIHsKICAgICAgICBpZiAoIXByb3Bz Lmhhc093blByb3BlcnR5KGtleSkpIHsgY29udGludWU7IH0KICAgICAgICBr ZXlzLnB1c2goa2V5KTsKICAgICAgICBhZGROb3JtYWxpemVkUHJvcGVydHko YmFzZSwga2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RyaWVzKSkgewogICAg ICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignWW91IG11c3QgcGFzcyBhbiBh cnJheSB0byBhbGxTZXR0bGVkLicpOwogICAgICAgIH0KCiAgICAgICAgdmFy IHJlbWFpbmluZyA9IGVudHJpZXMubGVuZ3RoOwogICAgICAgIHZhciBlbnRy eTsKCiAgICAgICAgaWYgKHJlbWFpbmluZyA9PT0gMCkgewogICAgICAgICAg cmVzb2x2ZShbXSk7CiAgICAgICAgICByZXR1cm47CiAgICAgICAgfQoKICAg ICAgICB2YXIgcmVzdWx0cyA9IG5ldyBBcnJheShyZW1haW5pbmcpOwoKICAg ICAgICBmdW5jdGlvbiBmdWxmaWxsZWRSZXNvbHZlcihpbmRleCkgewogICAg ICAgICAgcmV0dXJuIGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAgICAgICAgIHJl c29sdmVBbGwoaW5kZXgsIGZ1bGZpbGxlZCh2YWx1ZSkpOwogICAgICAgICAg fTsKICAgICAgICB9CgogICAgICAgIGZ1bmN0aW9uIHJlamVjdGVkUmVzb2x2 ZXIoaW5kZXgpIHsKICAgICAgICAgIHJldHVybiBmdW5jdGlvbihyZWFzb24p IHsKICAgICAgICAgICAgcmVzb2x2ZUFsbChpbmRleCwgcmVqZWN0ZWQocmVh c29uKSk7CiAgICAgICAgICB9OwogICAgICAgIH0KCiAgICAgICAgZnVuY3Rp b24gcmVzb2x2ZUFsbChpbmRleCwgdmFsdWUpIHsKICAgICAgICAgIHJlc3Vs dHNbaW5kZXhdID0gdmFsdWU7CiAgICAgICAgICBpZiAoLS1yZW1haW5pbmcg PT09IDApIHsKICAgICAgICAgICAgcmVzb2x2ZShyZXN1bHRzKTsKICAgICAg ICAgIH0KICAgICAgICB9CgogICAgICAgIGZvciAodmFyIGluZGV4ID0gMDsg aW5kZXggPCBlbnRyaWVzLmxlbmd0aDsgaW5kZXgrKykgewogICAgICAgICAg ZW50cnkgPSBlbnRyaWVzW2luZGV4XTsKCiAgICAg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gICAgZGVmZXJyZWQucmVq ZWN0ID0gcmVqZWN0OwogICAgICB9LCBsYWJlbCk7CgogICAgICByZXR1cm4g ZGVmZXJyZWQ7CiAgICB9OwogIH0pOwpkZWZpbmUoInJzdnAvZXZlbnRzIiwg CiAgWyJleHBvcnRzIl0sCiAgZnVuY3Rpb24oX19leHBvcnRzX18pIHsKICAg ICJ1c2Ugc3RyaWN0IjsKICAgIHZhciBpbmRleE9mID0gZnVuY3Rpb24oY2Fs bGJhY2tzLCBjYWxsYmFjaykgewogICAgICBmb3IgKHZhciBpPTAsIGw9Y2Fs bGJhY2tzLmxlbmd0aDsgaTxsOyBpKyspIHsKICAgICAgICBpZiAoY2FsbGJh Y2tzW2ldID09PSBjYWxsYmFjaykgeyByZXR1cm4gaTsgfQogICAgICB9Cgog ICAgICByZXR1cm4gLTE7CiAgICB9OwoKICAgIHZhciBjYWxsYmFja3NGb3Ig PSBmdW5jdGlvbihvYmplY3QpIHsKICAgICAgdmFyIGNhbGxiYWNrcyA9IG9i amVjdC5fcHJvbWlzZUNhbGxiYWNrczsKCiAgICAgIGlmICghY2FsbGJhY2tz KSB7CiAgICAgICAgY2FsbGJhY2tzID0gb2JqZWN0Ll9wcm9taXNlQ2FsbGJh Y2tzID0ge307CiAgICAgIH0KCiAgICAgIHJldHVybiBjYWxsYmFja3M7CiAg ICB9OwoKICAgIC8qKgogICAgICBAY2xhc3MgUlNWUC5FdmVudFRhcmdldAog ICAgKi8KICAgIF9fZXhwb3J0c19fWyJkZWZhdWx0Il0gPSB7CgogICAgICAv KioKICAgICAgICBgUlNWUC5FdmVudFRhcmdldC5taXhpbmAgZXh0ZW5kcyBh biBvYmplY3Qgd2l0aCBFdmVudFRhcmdldCBtZXRob2RzLiBGb3IKICAgICAg ICBFeGFtcGxlOgoKICAgICAgICBgYGBqYXZhc2NyaXB0CiAgICAgICAgdmFy IG9iamVjdCA9IHt9OwoKICAgICAgICBSU1ZQLkV2ZW50VGFyZ2V0Lm1peGlu KG9iamVjdCk7CgogICAgICAgIG9iamVjdC5vbigiZmluaXNoZWQiLCBmdW5j dGlvbihldmVudCkgewogICAgICAgICAgLy8gaGFuZGxlIGV2ZW50CiAgICAg ICAgfSk7CgogICAgICAgIG9iamVjdC50cmlnZ2VyKCJmaW5pc2hlZCIsIHsg ZGV0YWlsOiB2YWx1ZSB9KTsKICAgICAgICBgYGAKCiAgICAgICAgYEV2ZW50 VGFyZ2V0Lm1peGluYCBhbHNvIHdvcmtzIHdpdGggcHJvdG90eXBlczoKCiAg ICAgICAgYGBgamF2YXNjcmlwdAogICAgICAgIHZhciBQZXJzb24gPSBmdW5j dGlvbigpIHt9OwogICAgICAgIFJTVlAuRXZlbnRUYXJnZXQubWl4aW4oUGVy c29uLnByb3RvdHlwZSk7CgogICAgICAgIHZhciB5ZWh1ZGEgPSBuZXcgUGVy c29uKCk7CiAgICAgICAgdmFyIHRvbSA9IG5ldyBQZXJzb24oKTsKCiAgICAg ICAgeWVodWRhLm9uKCJwb2tlIiwgZnVuY3Rpb24oZXZlbnQpIHsKICAgICAg ICAgIGNvbnNvbGUubG9nKCJZZWh1ZGEgc2F5cyBPVyIpOwogICAgICAgIH0p OwoKICAgICAgICB0b20ub24oInBva2UiLCBmdW5jdGlvbihldmVudCkgewog ICAgICAgICAgY29uc29sZS5sb2coIlRvbSBzYXlzIE9XIik7CiAgICAgICAg fSk7CgogICAgICAgIHllaHVkYS50cmlnZ2VyKCJwb2tlIik7CiAgICAgICAg dG9tLnRyaWdnZXIoInBva2UiKTsKICAgICAgICBgYGAKCiAgICAgICAgQG1l dGhvZCBtaXhpbgogICAgICAgIEBwYXJhbSB7T2JqZWN0fSBvYmplY3Qgb2Jq ZWN0IHRvIGV4dGVuZCB3aXRoIEV2ZW50VGFyZ2V0IG1ldGhvZHMKICAgICAg ICBAcHJpdmF0ZQogICAgICAqLwogICAgICBtaXhpbjogZnVuY3Rpb24ob2Jq ZWN0KSB7CiAgICAgICAgb2JqZWN0Lm9uID0gdGhpcy5v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gICAgIGNhbGxiYWNrcyA9IGFsbENhbGxiYWNrc1tl dmVudE5hbWVdOwoKICAgICAgICBpbmRleCA9IGluZGV4T2YoY2FsbGJhY2tz LCBjYWxsYmFjayk7CgogICAgICAgIGlmIChpbmRleCAhPT0gLTEpIHsgY2Fs bGJhY2tzLnNwbGljZShpbmRleCwgMSk7IH0KICAgICAgfSwKCiAgICAgIC8q KgogICAgICAgIFVzZSBgdHJpZ2dlcmAgdG8gZmlyZSBjdXN0b20gZXZlbnRz LiBGb3IgZXhhbXBsZToKCiAgICAgICAgYGBgamF2YXNjcmlwdAogICAgICAg IG9iamVjdC5vbignZm9vJywgZnVuY3Rpb24oKXsKICAgICAgICAgIGNvbnNv bGUubG9nKCdmb28gZXZlbnQgaGFwcGVuZWQhJyk7CiAgICAgICAgfSk7CiAg ICAgICAgb2JqZWN0LnRyaWdnZXIoJ2ZvbycpOwogICAgICAgIC8vICdmb28g ZXZlbnQgaGFwcGVuZWQhJyBsb2dnZWQgdG8gdGhlIGNvbnNvbGUKICAgICAg ICBgYGAKCiAgICAgICAgWW91IGNhbiBhbHNvIHBhc3MgYSB2YWx1ZSBhcyBh IHNlY29uZCBhcmd1bWVudCB0byBgdHJpZ2dlcmAgdGhhdCB3aWxsIGJlCiAg ICAgICAgcGFzc2VkIGFzIGFuIGFyZ3VtZW50IHRvIGFsbCBldmVudCBsaXN0 ZW5lcnMgZm9yIHRoZSBldmVudDoKCiAgICAgICAgYGBgamF2YXNjcmlwdAog ICAgICAgIG9iamVjdC5vbignZm9vJywgZnVuY3Rpb24odmFsdWUpewogICAg ICAgICAgY29uc29sZS5sb2codmFsdWUubmFtZSk7CiAgICAgICAgfSk7Cgog ICAgICAgIG9iamVjdC50cmlnZ2VyKCdmb28nLCB7IG5hbWU6ICdiYXInIH0p OwogICAgICAgIC8vICdiYXInIGxvZ2dlZCB0byB0aGUgY29uc29sZQogICAg ICAgIGBgYAoKICAgICAgICBAbWV0aG9kIHRyaWdnZXIKICAgICAgICBA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aGVtIGJlY29tZSByZWplY3RlZC4KICAgICAgQHN0YXRpYwogICAgKi8KICAg IF9fZXhwb3J0c19fWyJkZWZhdWx0Il0gPSBmdW5jdGlvbiBoYXNoKG9iamVj dCwgbGFiZWwpIHsKICAgICAgcmV0dXJuIG5ldyBQcm9taXNlKGZ1bmN0aW9u KHJlc29sdmUsIHJlamVjdCl7CiAgICAgICAgdmFyIHJlc3VsdHMgPSB7fTsK ICAgICAgICB2YXIga2V5cyA9IGtleXNPZihvYmplY3QpOwogICAgICAgIHZh ciByZW1haW5pbmcgPSBrZXlzLmxlbmd0aDsKICAgICAgICB2YXIgZW50cnks IHByb3BlcnR5OwoKICAgICAgICBpZiAocmVtYWluaW5nID09PSAwKSB7CiAg ICAgICAgICByZXNvbHZlKHJlc3VsdHMpOwogICAgICAgICAgcmV0dXJuOwog ICAgICAgIH0KCiAgICAgICBmdW5jdGlvbiBmdWxmaWxsZWRUbyhwcm9wZXJ0 eSkgewogICAgICAgICAgcmV0dXJuIGZ1bmN0aW9uKHZhbHVlKSB7CiAgICAg ICAgICAgIHJlc3VsdHNbcHJvcGVydHldID0gdmFsdWU7CiAgICAgICAgICAg IGlmICgtLXJlbWFpbmluZyA9PT0gMCkgewogICAgICAgICAgICAgIHJlc29s dmUocmVzdWx0cyk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH07CiAgICAg ICAgfQoKICAgICAgICBmdW5jdGlvbiBvblJlamVjdGlvbihyZWFzb24pIHsK ICAgICAgICAgIHJlbWFpbmluZyA9IDA7CiAgICAgICAgICByZWplY3QocmVh c29uKTsKICAgICAgICB9CgogICAgICAgIGZvciAodmFyIGkgPSAwOyBpIDwg a2V5cy5sZW5ndGg7IGkrKykgewogICAgICAgICAgcHJvcGVydHkgPSBrZXlz W2ldOwogICAgICAgICAgZW50cnkgPSBvYmplY3RbcHJvcGVydHldOwoKICAg ICAgICAgIGlmIChpc05vblRoZW5hYmxlKGVudHJ5KSkgewogICAgICAgICAg ICByZXN1bHRzW3Byb3BlcnR5XSA9IGVudHJ5OwogICAgICAgICAgICBpZiAo LS1yZW1haW5pbmcgPT09IDApIHsKICAgICAgICAgICAgICByZXNvbHZlKHJl c3VsdHMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9IGVsc2UgewogICAg ICAgICAgICBQcm9taXNlLmNhc3QoZW50cnkpLnRoZW4oZnVsZmlsbGVkVG8o cHJvcGVydHkpLCBvblJlamVjdGlvbik7CiAgICAgICAgICB9CiAgICAgICAg fQogICAgICB9KTsKICAgIH07CiAgfSk7CmRlZmluZSgicnN2cC9pbnN0cnVt ZW50IiwgCiAgWyIuL2NvbmZpZyIsIi4vdXRpbHMiLCJleHBvcnRzIl0sCiAg ZnVuY3Rpb24oX19kZXBlbmRlbmN5MV9fLCBfX2RlcGVuZGVuY3kyX18sIF9f ZXhwb3J0c19fKSB7CiAgICAidXNlIHN0cmljdCI7CiAgICB2YXIgY29uZmln ID0gX19kZXBlbmRlbmN5MV9fLmNvbmZpZzsKICAgIHZhciBub3cgPSBfX2Rl cGVuZGVuY3kyX18ubm93OwoKICAgIF9fZXhwb3J0c19fWyJkZWZhdWx0Il0g PSBmdW5jdGlvbiBpbnN0cnVtZW50KGV2ZW50TmFtZSwgcHJvbWlzZSwgY2hp bGQpIHsKICAgICAgLy8gaW5zdHJ1bWVudGF0aW9uIHNob3VsZCBub3QgZGlz cnVwdCBub3JtYWwgdXNhZ2UuCiAgICAgIHRyeSB7CiAgICAgICAgY29uZmln LnRyaWdnZXIoZXZlbnROYW1lLCB7CiAgICAgICAgICBndWlkOiBwcm9taXNl Ll9ndWlkS2V5ICsgcHJvbWlzZS5faWQsCiAgICAgICAgICBldmVudE5hbWU6 IGV2ZW50TmFtZSwKICAgICAgICAgIGRldGFpbDogcHJvbWlzZS5fZGV0YWls LAogICAgICAgICAgY2hpbGRHdWlkOiBjaGlsZCAmJiBwcm9taXNlLl9ndWlk S2V5ICsgY2hpbGQuX2lkLAogICAgICAgICAgbGFiZWw6IHByb21pc2U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N0ZWQuCiAgICAgIEBzdGF0aWMKICAg ICovCiAgICBfX2V4cG9ydHNfX1siZGVmYXVsdCJdID0gZnVuY3Rpb24gbWFw KHByb21pc2VzLCBtYXBGbiwgbGFiZWwpIHsKICAgICAgcmV0dXJuIGFsbChw cm9taXNlcywgbGFiZWwpLnRoZW4oZnVuY3Rpb24ocmVzdWx0cyl7CiAgICAg ICAgaWYgKCFpc0FycmF5KHByb21pc2VzKSkgewogICAgICAgICAgdGhyb3cg bmV3IFR5cGVFcnJvcignWW91IG11c3QgcGFzcyBhbiBhcnJheSB0byBtYXAu Jyk7CiAgICAgICAgfQoKICAgICAgICBpZiAoIWlzRnVuY3Rpb24obWFwRm4p KXsKICAgICAgICAgIHRocm93IG5ldyBUeXBlRXJyb3IoIllvdSBtdXN0IHBh c3MgYSBmdW5jdGlvbiB0byBtYXAncyBzZWNvbmQgYXJndW1lbnQuIik7CiAg ICAgICAgfQoKCiAgICAgICAgdmFyIHJlc3VsdExlbiA9IHJlc3VsdHMubGVu Z3RoLAogICAgICAgICAgICBtYXBwZWRSZXN1bHRzID0gW10sCiAgICAgICAg ICAgIGk7CgogICAgICAgIGZvciAoaSA9IDA7IGkgPCByZXN1bHRMZW47IGkr Kyl7CiAgICAgICAgICBtYXBwZWRSZXN1bHRzLnB1c2gobWFwRm4ocmVzdWx0 c1tpXSkpOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIGFsbChtYXBwZWRS ZXN1bHRzLCBsYWJlbCk7CiAgICAgIH0pOwogICAgfTsKICB9KTsKZGVmaW5l KCJyc3ZwL25vZGUiLCAKICBbIi4vcHJvbWlzZSIsImV4cG9ydHMiXSwKICBm dW5jdGlvbihfX2RlcGVuZGVuY3kxX18sIF9fZXhwb3J0c19fKSB7CiAgICAi dXNlIHN0cmljdCI7CiAgICB2YXIgUHJvbWlzZSA9IF9fZGVwZW5kZW5jeTFf X1siZGVmYXVsdCJdOwoKICAgIHZhciBzbGljZSA9IEFycmF5LnByb3RvdHlw ZS5zbGljZTsKCiAgICBmdW5jdGlvbiBtYWtlTm9kZUNhbGxiYWNrRm9yKHJl c29sdmUsIHJlamVjdCkgewogICAgICByZXR1cm4gZnVuY3Rpb24gKGVycm9y LCB2YWx1ZSkgewogICAgICAgIGlmIChlcnJvcikgewogICAgICAgICAgcmVq ZWN0KGVycm9yKTsKICAgICAgICB9IGVsc2UgaWYgKGFyZ3VtZW50cy5sZW5n dGggPiAyKSB7CiAgICAgICAgICByZXNvbHZlKHNsaWNlLmNhbGwoYXJndW1l bnRzLCAxKSk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHJlc29sdmUo dmFsdWUpOwogICAgICAgIH0KICAgICAgfTsKICAgIH0KCiAgICAvKioKICAg ICAgYFJTVlAuZGVub2RlaWZ5YCB0YWtlcyBhICJub2RlLXN0eWxlIiBmdW5j dGlvbiBhbmQgcmV0dXJucyBhIGZ1bmN0aW9uIHRoYXQKICAgICAgd2lsbCBy ZXR1cm4gYW4gYFJTVlAuUHJvbWlzZWAuIFlvdSBjYW4gdXNlIGBkZW5vZGVp ZnlgIGluIE5vZGUuanMgb3IgdGhlCiAgICAgIGJyb3dzZXIgd2hlbiB5b3Un ZCBwcmVmZXIgdG8gdXNlIHByb21pc2VzIG92ZXIgdXNpbmcgY2FsbGJhY2tz LiBGb3IgZXhhbXBsZSwKICAgICAgYGRlbm9kZWlmeWAgdHJhbnNmb3JtcyB0 aGUgZm9sbG93aW5nOgoKICAgICAgYGBgamF2YXNjcmlwdAogICAgICB2YXIg ZnMgPSByZXF1aXJlKCdmcycpOwoKICAgICAgZnMucmVhZEZpbGUoJ215Zmls ZS50eHQnLCBmdW5jdGlvbihlcnIsIGRhdGEpewogICAgICAgIGlmIChlcnIp IHJldHVybiBoYW5kbGVFcnJvcihlcnIpOwogICAgICAgIGhhbmRsZURhdGEo ZGF0YSk7CiAgICAgIH0pOwogICAgICBgYGAKCiAgICAgIGludG86CgogICAg ICBgYGBqYXZhc2NyaXB0CiAgICAgIH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YXQgKnJlc29sdmVzKiBhIHByb21pc2UgdGhhdCByZWplY3RzIHdp bGwKICAgICAgaXRzZWxmIHJlamVjdCwgYW5kIGEgcHJvbWlzZSB0aGF0ICpy ZXNvbHZlcyogYSBwcm9taXNlIHRoYXQgZnVsZmlsbHMgd2lsbAogICAgICBp dHNlbGYgZnVsZmlsbC4KCgogICAgICBCYXNpYyBVc2FnZToKICAgICAgLS0t LS0tLS0tLS0tCgogICAgICBgYGBqcwogICAgICB2YXIgcHJvbWlzZSA9IG5l dyBQcm9taXNlKGZ1bmN0aW9uKHJlc29sdmUsIHJlamVjdCkgewogICAgICAg IC8vIG9uIHN1Y2Nlc3MKICAgICAgICByZXNvbHZlKHZhbHVlKTsKCiAgICAg ICAgLy8gb24gZmFpbHVyZQogICAgICAgIHJlamVjdChyZWFzb24pOwogICAg ICB9KTsKCiAgICAgIHByb21pc2UudGhlbihmdW5jdGlvbih2YWx1ZSkgewog ICAgICAgIC8vIG9uIGZ1bGZpbGxtZW50CiAgICAgIH0sIGZ1bmN0aW9uKHJl YXNvbikgewogICAgICAgIC8vIG9uIHJlamVjdGlvbgogICAgICB9KTsKICAg ICAgYGBgCgogICAgICBBZHZhbmNlZCBVc2FnZToKICAgICAgLS0tLS0tLS0t LS0tLS0tCgogICAgICBQcm9taXNlcyBzaGluZSB3aGVuIGFic3RyYWN0aW5n IGF3YXkgYXN5bmNocm9ub3VzIGludGVyYWN0aW9ucyBzdWNoIGFzCiAgICAg IGBYTUxIdHRwUmVxdWVzdGBzLgoKICAgICAgYGBganMKICAgICAgZnVuY3Rp b24gZ2V0SlNPTih1cmwpIHsKICAgICAgICByZXR1cm4gbmV3IFByb21pc2Uo ZnVuY3Rpb24ocmVzb2x2ZSwgcmVqZWN0KXsKICAgICAgICAgIHZhciB4aHIg PSBuZXcgWE1MSHR0cFJlcXVlc3QoKTsKCiAgICAgICAgICB4aHIub3Blbign R0VUJywgdXJsKTsKICAgICAgICAgIHhoci5vbnJlYWR5c3RhdGVjaGFuZ2Ug PSBoYW5kbGVyOwogICAgICAgICAgeGhyLnJlc3BvbnNlVHlwZSA9ICdqc29u JzsKICAgICAgICAgIHhoci5zZXRSZXF1ZXN0SGVhZGVyKCdBY2NlcHQnLCAn YXBwbGljYXRpb24vanNvbicpOwogICAgICAgICAgeGhyLnNlbmQoKTsKCiAg ICAgICAgICBmdW5jdGlvbiBoYW5kbGVyKCkgewogICAgICAgICAgICBpZiAo dGhpcy5yZWFkeVN0YXRlID09PSB0aGlzLkRPTkUpIHsKICAgICAgICAgICAg ICBpZiAodGhpcy5zdGF0dXMgPT09IDIwMCkgewogICAgICAgICAgICAgICAg cmVzb2x2ZSh0aGlzLnJlc3BvbnNlKTsKICAgICAgICAgICAgICB9IGVsc2Ug ewogICAgICAgICAgICAgICAgcmVqZWN0KG5ldyBFcnJvcigiZ2V0SlNPTjog YCIgKyB1cmwgKyAiYCBmYWlsZWQgd2l0aCBzdGF0dXM6IFsiICsgdGhpcy5z dGF0dXMgKyAiXSIpOwogICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQog ICAgICAgICAgfTsKICAgICAgICB9KTsKICAgICAgfQoKICAgICAgZ2V0SlNP TignL3Bvc3RzLmpzb24nKS50aGVuKGZ1bmN0aW9uKGpzb24pIHsKICAgICAg ICAvLyBvbiBmdWxmaWxsbWVudAogICAgICB9LCBmdW5jdGlvbihyZWFzb24p IHsKICAgICAgICAvLyBvbiByZWplY3Rpb24KICAgICAgfSk7CiAgICAgIGBg YAoKICAgICAgVW5saWtlIGNhbGxiYWNrcywgcHJvbWlzZXMgYXJlIGdyZWF0 IGNvbXBvc2FibGUgcHJpbWl0aXZlcy4KCiAgICAgIGBgYGpzCiAgICAgIFBy b21pc2UuYWxsKFsKICAgICAgICBnZXRKU09OKCcvcG9zdHMnKSwKICAgICAg ICBnZXRKU09OKCcvY29tbWVudHMnKQogICAgICBdKS50aGVuKGZ1bmN0aW9u KHZhbHVlcyl7CiAgICAgICAgdmFsdWVzWzBdIC8vID0+IHBvc3RzSlNPTgog ICAgICAgIHZhbHVlc1sxXSAvLyA9PiBjb21tZW50c0pTT04KCiAgICAgICAg cmV0dXJuIHZhbHVlczsKICAgICAgfSk7CiAgICAgIGBgYAoKICAgICAgQGNs YXNzIFJTVlAuUHJvbWlzZQogICAgICBAcGFyYW0ge2Z1bmN0aW9ufQogICAg ICBAcGFyYW0ge1N0cmluZ30gbGFiZWwgb3B0aW9uYWwgc3RyaW5nIGZvciBs YWJlbGluZyB0aGUgcHJvbWlzZS4KICAgICAgVXNlZnVsIGZvciB0b29saW5n LgogICAgICBAY29uc3RydWN0b3IKICAgICovCiAgICBmdW5jdGlvbiBQcm9t aXNlKHJlc29sdmVyLCBsYWJlbCkgewogICAgICBpZiAoIWlzRnVuY3Rpb24o cmVzb2x2ZXIpKSB7CiAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJvcignWW91 IG11c3QgcGFzcyBhIHJlc29sdmVyIGZ1bmN0aW9uIGFzIHRoZSBmaXJzdCBh cmd1bWVudCB0byB0aGUgcHJvbWlzZSBjb25zdHJ1Y3RvcicpOwogICAgICB9 CgogICAgICBpZiAoISh0aGlzIGluc3RhbmNlb2YgUHJvbWlzZSkpIHsKICAg ICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCJGYWlsZWQgdG8gY29uc3RydWN0 ICdQcm9taXNlJzogUGxlYXNlIHVzZSB0aGUgJ25ldycgb3BlcmF0b3IsIHRo aXMgb2JqZWN0IGNvbnN0cnVjdG9yIGNhbm5vdCBiZSBjYWxsZWQgYXMgYSBm dW5jdGlvbi4iKTsKICAgICAgfQoKICAgICAgdGhpcy5faWQgPSBjb3VudGVy Kys7CiAgICAgIHRoaXMuX2xhYmVsID0gbGFiZWw7CiAgICAgIHRoaXMuX3N1 YnNjcmliZXJzID0gW107CgogICAgICBpZiAoY29uZmlnLmluc3RydW1lbnQp IHsKICAgICAgICBpbnN0cnVtZW50KCdjcmVhdGVkJywgdGhpcyk7CiAgICAg IH0KCiAgICAgIGlmIChub29wICE9PSByZXNvbHZlcikgewogICAgICAgIGlu dm9rZVJlc29sdmVyKHJlc29sdmVyLCB0aGlzKTsKICAgICAgfQogICAgfQoK ICAgIGZ1bmN0aW9uIGludm9rZVJlc29sdmVyKHJlc29sdmVyLCBwcm9taXNl KSB7CiAgICAgIGZ1bmN0aW9uIHJlc29sdmVQcm9taXNlKHZhbHVlKSB7CiAg ICAgICAgcmVzb2x2ZShwcm9taXNlLCB2YWx1ZSk7CiAgICAgIH0KCiAgICAg IGZ1bmN0aW9uIHJlamVjdFByb21pc2UocmVhc29uKSB7CiAgICAgICAgcmVq ZWN0KHByb21pc2UsIHJlYXNvbik7CiAgICAgIH0KCiAgICAgIHRyeSB7CiAg ICAgICAgcmVzb2x2ZXIocmVzb2x2ZVByb21pc2UsIHJlamVjdFByb21pc2Up OwogICAgICB9IGNhdGNoKGUpIHsKICAgICAgICByZWplY3RQcm9taXNlKGUp OwogICAgICB9CiAgICB9CgogICAgUHJvbWlzZS5jYXN0ID0gY2FzdDsKICAg IFByb21pc2UuYWxsID0gYWxsOwogICAgUHJvbWlzZS5yYWNlID0gcmFjZTsK ICAgIFByb21pc2UucmVzb2x2ZSA9IFJlc29sdmU7CiAgICBQcm9taXNlLnJl amVjdCA9IFJlamVjdDsKCiAgICB2YXIgUEVORElORyAgID0gdm9pZCAwOwog ICAgdmFyIFNFQUxFRCAgICA9IDA7CiAgICB2YXIgRlVMRklMTEVEID0gMTsK ICAgIHZhciBSRUpFQ1RFRCAgPSAyOwoKICAgIGZ1bmN0aW9uIHN1YnNjcmli ZShwYXJlbnQsIGNoaWxkLCBvbkZ1bGZpbGxtZW50LCBvblJlamVjdGlvbikg ewogICAgICB2YXIgc3Vic2NyaWJlcnMgPSBwYXJlbnQuX3N1YnNjcmliZXJz OwogICAgICB2YXIgbGVuZ3RoID0gc3Vic2NyaWJlcnMubGVuZ3RoOwoKICAg ICAgc3Vic2NyaWJlcnNbbGVuZ3RoXSA9IGNoaWxkOwogICA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u ZENvbW1lbnRzQnlBdXRob3IodXNlcik7CiAgICAgIH0pLnRoZW4oZnVuY3Rp b24gKGNvbW1lbnRzKSB7CiAgICAgICAgLy8gVGhlIHVzZXIncyBjb21tZW50 cyBhcmUgbm93IGF2YWlsYWJsZQogICAgICB9KTsKICAgICAgYGBgCgogICAg ICBJZiB0aGUgYXNzaW1saWF0ZWQgcHJvbWlzZSByZWplY3RzLCB0aGVuIHRo ZSBkb3duc3RyZWFtIHByb21pc2Ugd2lsbCBhbHNvIHJlamVjdC4KCiAgICAg IGBgYGpzCiAgICAgIGZpbmRVc2VyKCkudGhlbihmdW5jdGlvbiAodXNlcikg ewogICAgICAgIHJldHVybiBmaW5kQ29tbWVudHNCeUF1dGhvcih1c2VyKTsK ICAgICAgfSkudGhlbihmdW5jdGlvbiAoY29tbWVudHMpIHsKICAgICAgICAv LyBJZiBgZmluZENvbW1lbnRzQnlBdXRob3JgIGZ1bGZpbGxzLCB3ZSdsbCBo YXZlIHRoZSB2YWx1ZSBoZXJlCiAgICAgIH0sIGZ1bmN0aW9uIChyZWFzb24p IHsKICAgICAgICAvLyBJZiBgZmluZENvbW1lbnRzQnlBdXRob3JgIHJlamVj dHMsIHdlJ2xsIGhhdmUgdGhlIHJlYXNvbiBoZXJlCiAgICAgIH0pOwogICAg ICBgYGAKCiAgICAgIFNpbXBsZSBFeGFtcGxlCiAgICAgIC0tLS0tLS0tLS0t LS0tCgogICAgICBTeW5jaHJvbm91cyBFeGFtcGxlCgogICAgICBgYGBqYXZh c2NyaXB0CiAgICAgIHZhciByZXN1bHQ7CgogICAgICB0cnkgewogICAgICAg IHJlc3VsdCA9IGZpbmRSZXN1bHQoKTsKICAgICAgICAvLyBzdWNjZXNzCiAg ICAgIH0gY2F0Y2gocmVhc29uKSB7CiAgICAgICAgLy8gZmFpbHVyZQogICAg ICB9CiAgICAgIGBgYAoKICAgICAgRXJyYmFjayBFeGFtcGxlCgogICAgICBg YGBqcwogICAgICBmaW5kUmVzdWx0KGZ1bmN0aW9uKHJlc3VsdCwgZXJyKXsK ICAgICAgICBpZiAoZXJyKSB7CiAgICAgICAgICAvLyBmYWlsdXJlCiAgICAg ICAgfSBlbHNlIHsKICAgICAgICAgIC8vIHN1Y2Nlc3MKICAgICAgICB9CiAg ICAgIH0pOwogICAgICBgYGAKCiAgICAgIFByb21pc2UgRXhhbXBsZTsKCiAg ICAgIGBgYGphdmFzY3JpcHQKICAgICAgZmluZFJlc3VsdCgpLnRoZW4oZnVu Y3Rpb24ocmVzdWx0KXsKICAgICAgICAvLyBzdWNjZXNzCiAgICAgIH0sIGZ1 bmN0aW9uKHJlYXNvbil7CiAgICAgICAgLy8gZmFpbHVyZQogICAgICB9KTsK ICAgICAgYGBgCgogICAgICBBZHZhbmNlZCBFeGFtcGxlCiAgICAgIC0tLS0t LS0tLS0tLS0tCgogICAgICBTeW5jaHJvbm91cyBFeGFtcGxlCgogICAgICBg YGBqYXZhc2NyaXB0CiAgICAgIHZhciBhdXRob3IsIGJvb2tzOwoKICAgICAg dHJ5IHsKICAgICAgICBhdXRob3IgPSBmaW5kQXV0aG9yKCk7CiAgICAgICAg Ym9va3MgID0gZmluZEJvb2tzQnlBdXRob3IoYXV0aG9yKTsKICAgICAgICAv LyBzdWNjZXNzCiAgICAgIH0gY2F0Y2gocmVhc29uKSB7CiAgICAgICAgLy8g ZmFpbHVyZQogICAgICB9CiAgICAgIGBgYAoKICAgICAgRXJyYmFjayBFeGFt cGxlCgogICAgICBgYGBqcwoKICAgICAgZnVuY3Rpb24gZm91bmRCb29rcyhi b29rcykgewoKICAgICAgfQoKICAgICAgZnVuY3Rpb24gZmFpbHVyZShyZWFz b24pIHsKCiAgICAgIH0KCiAgICAgIGZpbmRBdXRob3IoZnVuY3Rpb24oYXV0 aG9yLCBlcnIpewogICAgICAgIGlmIChlcnIpIHsKICAgICAgICAgIGZhaWx1 cmUoZXJyKTsKICAgICAgICAgIC8vIGZhaWx1cmUKICAgICAgICB9IGVsc2Ug ewogICAgICAgICAgdHJ5IHsKICAgICAgICAgICAgZmluZEJvb29rc0J5QXV0 aG9yKGF1dGhvciwgZnVuY3Rpb24oYm9va3MsIGVycikgewogICAgICAgICAg ICAgIGlmIChlcnIpIHsKICAgICAgICAgICAgICAgIGZhaWx1cmUoZXJyKTsK ICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAgICAgdHJ5IHsK ICAgICAgICAgICAgICAgICAgZm91bmRCb29rcyhib29rcyk7CiAgICAgICAg ICAgICAgICB9IGNhdGNoKHJlYXNvbikgewogICAgICAgICAgICAgICAgICBm YWlsdXJlKHJlYXNvbik7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAg ICAgfQogICAgICAgICAgICB9KTsKICAgICAgICAgIH0gY2F0Y2goZXJyb3Ip IHsKICAgICAgICAgICAgZmFpbHVyZShlcnIpOwogICAgICAgICAgfQogICAg ICAgICAgLy8gc3VjY2VzcwogICAgICAgIH0KICAgICAgfSk7CiAgICAgIGBg YAoKICAgICAgUHJvbWlzZSBFeGFtcGxlOwoKICAgICAgYGBgamF2YXNjcmlw dAogICAgICBmaW5kQXV0aG9yKCkuCiAgICAgICAgdGhlbihmaW5kQm9va3NC eUF1dGhvcikuCiAgICAgICAgdGhlbihmdW5jdGlvbihib29rcyl7CiAgICAg ICAgICAvLyBmb3VuZCBib29rcwogICAgICB9KS5jYXRjaChmdW5jdGlvbihy ZWFzb24pewogICAgICAgIC8vIHNvbWV0aGluZyB3ZW50IHdyb25nCiAgICAg IH0pOwogICAgICBgYGAKCiAgICAgIEBtZXRob2QgdGhlbgogICAgICBAcGFy YW0ge0Z1bmN0aW9ufSBvbkZ1bGZpbGxlZAogICAgICBAcGFyYW0ge0Z1bmN0 aW9ufSBvblJlamVjdGVkCiAgICAgIEBwYXJhbSB7U3RyaW5nfSBsYWJlbCBv cHRpb25hbCBzdHJpbmcgZm9yIGxhYmVsaW5nIHRoZSBwcm9taXNlLgogICAg ICBVc2VmdWwgZm9yIHRvb2xpbmcuCiAgICAgIEByZXR1cm4ge1Byb21pc2V9 CiAgICAqLwogICAgICB0aGVuOiBmdW5jdGlvbihvbkZ1bGZpbGxtZW50LCBv blJlamVjdGlvbiwgbGFiZWwpIHsKICAgICAgICB2YXIgcHJvbWlzZSA9IHRo aXM7CiAgICAgICAgdGhpcy5fb25lcnJvciA9IG51bGw7CgogICAgICAgIHZh ciB0aGVuUHJvbWlzZSA9IG5ldyB0aGlzLmNvbnN0cnVjdG9yKG5vb3AsIGxh YmVsKTsKCiAgICAgICAgaWYgKHRoaXMuX3N0YXRlKSB7CiAgICAgICAgICB2 YXIgY2FsbGJhY2tzID0gYXJndW1lbnRzOwogICAgICAgICAgY29uZmlnLmFz eW5jKGZ1bmN0aW9uIGludm9rZVByb21pc2VDYWxsYmFjaygpIHsKICAgICAg ICAgICAgaW52b2tlQ2FsbGJhY2socHJvbWlzZS5fc3RhdGUsIHRoZW5Qcm9t aXNlLCBjYWxsYmFja3NbcHJvbWlzZS5fc3RhdGUgLSAxXSwgcHJvbWlzZS5f ZGV0YWlsKTsKICAgICAgICAgIH0pOwogICAgICAgIH0gZWxzZSB7CiAgICAg ICAgICBzdWJzY3JpYmUodGhpcywgdGhlblByb21pc2UsIG9uRnVsZmlsbG1l bnQsIG9uUmVqZWN0aW9uKTsKICAgICAgICB9CgogICAgICAgIGlmIChjb25m aWcuaW5zdHJ1bWVudCkgewogICAgICAgICAgaW5zdHJ1bWVudCgnY2hhaW5l ZCcsIHByb21pc2UsIHRoZW5Qcm9taXNlKTsKICAgICAgICB9CgogICAgICAg IHJldHVybiB0aGVuUHJvbWlzZTsKICAgICAgfSwKCiAgICAvKioKICAgICAg YGNhdGNoYCBpcyBzaW1wbHkgc3VnYXIgZm9yIGB0aGVuKHVuZGVmaW5lZCwg b25SZWplY3Rpb24pYCB3aGljaCBtYWtlcyBpdCB0aGUgc2FtZQogICAgICBh cyB0aGUgY2F0Y2ggYmxvY2sgb2YgYSB0cnkvY2F0Y2ggc3RhdGVtZW50LgoK ICAgICAgYGBganMKICAgICAgZnVuY3Rpb24gZmluZEF1dGhvcigpewogICAg ICAgIHRocm93IG5ldyBFcnJvcigiY291bGRuJ3QgZmluZCB0aGF0IGF1dGhv ciIpOwogICAgICB9CgogICAgICAvLyBzeW5jaHJvbm91cwogICAgICB0cnkg ewogICAgICAgIGZpbmRBdXRob3IoKTsKICAgICAgfSBjYXRjaChyZWFzb24p IHsKICAgICAgICAvLyBzb21ldGhpbmcgd2VudCB3cm9uZwogICAgICB9Cgog ICAgICAvLyBhc3luYyB3aXRoIHByb21pc2VzCiAgICAgIGZpbmRBdXRob3Io KS5jYXRjaChmdW5jdGlvbihyZWFzb24pewogICAgICAgIC8vIHNvbWV0aGlu ZyB3ZW50IHdyb25nCiAgICAgIH0pOwogICAgICBgYGAKCiAgICAgIEBtZXRo b2QgY2F0Y2gKICAgICAgQHBhcmFtIHtGdW5jdGlvbn0gb25SZWplY3Rpb24K ICAgICAgQHBhcmFtIHtTdHJpbmd9IGxhYmVsIG9wdGlvbmFsIHN0cmluZyBm b3IgbGFiZWxpbmcgdGhlIHByb21pc2UuCiAgICAgIFVzZWZ1bCBmb3IgdG9v bGluZy4KICAgICAgQHJldHVybiB7UHJvbWlzZX0KICAgICovCiAgICAgICdj YXRjaCc6IGZ1bmN0aW9uKG9uUmVqZWN0aW9uLCBsYWJlbCkgewogICAgICAg IHJldHVybiB0aGlzLnRoZW4obnVsbCwgb25SZWplY3Rpb24sIGxhYmVsKTsK ICAgICAgfSwKCiAgICAvKioKICAgICAgYGZpbmFsbHlgIHdpbGwgYmUgaW52 b2tlZCByZWdhcmRsZXNzIG9mIHRoZSBwcm9taXNlJ3MgZmF0ZSBqdXN0IGFz IG5hdGl2ZQogICAgICB0cnkvY2F0Y2gvZmluYWxseSBiZWhhdmVzCgogICAg ICBTeW5jaHJvbm91cyBleGFtcGxlOgoKICAgICAgYGBganMKICAgICAgZmlu ZEF1dGhvcigpIHsKICAgICAgICBpZiAoTWF0aC5yYW5kb20oKSA+IDAuNSkg ewogICAgICAgICAgdGhyb3cgbmV3IEVycm9yKCk7CiAgICAgICAgfQogICAg ICAgIHJldHVybiBuZXcgQXV0aG9yKCk7CiAgICAgIH0KCiAgICAgIHRyeSB7 CiAgICAgICAgcmV0dXJuIGZpbmRBdXRob3IoKTsgLy8gc3VjY2VlZCBvciBm YWlsCiAgICAgIH0gY2F0Y2goZXJyb3IpIHsKICAgICAgICByZXR1cm4gZmlu ZE90aGVyQXV0aGVyKCk7CiAgICAgIH0gZmluYWxseSB7CiAgICAgICAgLy8g YWx3YXlzIHJ1bnMKICAgICAgICAvLyBkb2Vzbid0IGFmZmVjdCB0aGUgcmV0 dXJuIHZhbHVlCiAgICAgIH0KICAgICAgYGBgCgogICAgICBBc3luY2hyb25v dXMgZXhhbXBsZToKCiAgICAgIGBgYGpzCiAgICAgIGZpbmRBdXRob3IoKS5j YXRjaChmdW5jdGlvbihyZWFzb24pewogICAgICAgIHJldHVybiBmaW5kT3Ro ZXJBdXRoZXIoKTsKICAgICAgfSkuZmluYWxseShmdW5jdGlvbigpewogICAg ICAgIC8vIGF1dGhvciB3YXMgZWl0aGVyIGZvdW5kLCBvciBub3QKICAgICAg fSk7CiAgICAgIGBgYAoKICAgICAgQG1ldGhvZCBmaW5hbGx5CiAgICAgIEBw YXJhbSB7RnVuY3Rpb259IGNhbGxiYWNrCiAgICAgIEBwYXJhbSB7U3RyaW5n fSBsYWJlbCBvcHRpb25hbCBzdHJpbmcgZm9yIGxhYmVsaW5nIHRoZSBwcm9t aXNlLgogICAgICBVc2VmdWwgZm9yIHRvb2xpbmcuCiAgICAgIEByZXR1cm4g e1Byb21pc2V9CiAgICAqLwogICAgICAnZmluYWxseSc6IGZ1bmN0aW9uKGNh bGxiYWNrLCBsYWJlbCkgewogICAgICAgIHZhciBjb25zdHJ1Y3RvciA9IHRo aXMuY29uc3RydWN0b3I7CgogICAgICAgIHJldHVybiB0aGlzLnRoZW4oZnVu Y3Rpb24odmFsdWUpIHsKICAgICAgICAgIHJldHVybiBjb25zdHJ1Y3Rvci5j YXN0KGNhbGxiYWNrKCkpLnRoZW4oZnVuY3Rpb24oKXsKICAgICAgICAgICAg cmV0dXJuIHZhbHVlOwogICAgICAgICAgfSk7CiAgICAgICAgfSwgZnVuY3Rp b24ocmVhc29uKSB7CiAgICAgICAgICByZXR1cm4gY29uc3RydWN0b3IuY2Fz dChjYWxsYmFjaygpKS50aGVuKGZ1bmN0aW9uKCl7CiAgICAgICAgICAgIHRo cm93IHJlYXNvbjsKICAgICAgICAgIH0pOwogICAgICAgIH0sIGxhYmVsKTsK ICAgICAgfQogICAgfTsKCiAgICBmdW5jdGlvbiBpbnZva2VDYWxsYmFjayhz ZXR0bGVkLCBwcm9taXNlLCBjYWxsYmFjaywgZGV0YWlsKSB7CiAgICAgIHZh ciBoYXNDYWxsYmFjayA9IGlzRnVuY3Rpb24oY2FsbGJhY2spLAogICAgICAg ICAgdmFsdWUsIGVycm9yLCBzdWNjZWVkZWQsIGZhaWxlZDsKCiAgICAgIGlm IChoYXNDYWxsYmFjaykgewogICAgICAgIHRyeSB7CiAgICAgICAgICB2YWx1 ZSA9IGNhbGxiYWNrKGRldGFpbCk7CiAgICAgICAgICBzdWNjZWVkZWQgPSB0 cnVlOwogICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAgZmFpbGVkID0g dHJ1ZTsKICAgICAgICAgIGVycm9yID0gZTsKICAgICAgICB9CiAgICAgIH0g ZWxzZSB7CiAgICAgICAgdmFsdWUgPSBkZXRhaWw7CiAgICAgICAgc3VjY2Vl ZGVkID0gdHJ1ZTsKICAgICAgfQoKICAgICAgaWYgKGhhbmRsZVRoZW5hYmxl KHByb21pc2UsIHZhbHVlKSkgewogICAgICAgIHJldHVybjsKICAgICAgfSBl bHNlIGlmIChoYXNDYWxsYmFjayAmJiBzdWNjZWVkZWQpIHsKICAgICAgICBy ZXNvbHZlKHByb21pc2UsIHZhbHVlKTsKICAgICAgfSBlbHNlIGlmIChmYWls ZWQpIHsKICAgICAgICByZWplY3QocHJvbWlzZSwgZXJyb3IpOwogICAgICB9 IGVsc2UgaWYgKHNldHRsZWQgPT09IEZVTEZJTExFRCkgewogICAgICAgIHJl c29sdmUocHJvbWlzZSwgdmFsdWUpOwogICAgICB9IGVsc2UgaWYgKHNldHRs ZWQgPT09IFJFSkVDVEVEKSB7CiAgICAgICAgcmVqZWN0KHByb21pc2UsIHZh bHVlKTsKICAgICAgfQogICAgfQoKICAgIGZ1bmN0aW9uIGhhbmRsZVRoZW5h YmxlKHByb21pc2UsIHZhbHVlKSB7CiAgICAgIHZhciB0aGVuID0gbnVsbCwK ICAgICAgcmVzb2x2ZWQ7CgogICAgICB0cnkgewogICAgICAgIGlmIChwcm9t aXNlID09PSB2YWx1ZSkgewogICAgICAgICAgdGhyb3cgbmV3IFR5cGVFcnJv cigiQSBwcm9taXNlcyBjYWxsYmFjayBjYW5ub3QgcmV0dXJuIHRoYXQgc2Ft ZSBwcm9taXNlLiIpOwogICAgICAgIH0KCiAgICAgICAgaWYgKG9iamVjdE9y RnVuY3Rpb24odmFsdWUpKSB7CiAgICAgICAgICB0aGVuID0gdmFsdWUudGhl bjsKCiAgICAgICAgICBpZiAoaXNGdW5jdGlvbih0aGVuKSkgewogICAgICAg ICAgICB0aGVuLmNhbGwodmFsdWUsIGZ1bmN0aW9uKHZhbCkgewogICAgICAg ICAgICAgIGlmIChyZXNvbHZlZCkgeyByZXR1cm4gdHJ1ZTsgfQogICAgICAg ICAgICAgIHJlc29sdmVkID0gdHJ1ZTsKCiAgICAgICAgICAgICAgaWYgKHZh bHVlICE9PSB2YWwpIHsKICAgICAgICAgICAgICAgIHJlc29sdmUocHJvbWlz ZSwgdmFsKTsKICAgICAgICAgICAgICB9IGVsc2UgewogICAgICAgICAgICAg ICAgZnVsZmlsbChwcm9taXNlLCB2YWwpOwogICAgICAgICAgICAgIH0KICAg ICAgICAgICAgfSwgZnVuY3Rpb24odmFsKSB7CiAgICAgICAgICAgICAgaWYg KHJlc29sdmVkKSB7IHJldHVybiB0cnVlOyB9CiAgICAgICAgICAgICAgcmVz b2x2ZWQgPSB0cnVlOwoKICAgICAgICAgICAgICByZWplY3QocHJvbWlzZSwg dmFsKTsKICAgICAgICAgICAgfSwgJ2Rlcml2ZWQgZnJvbTogJyArIChwcm9t aXNlLl9sYWJlbCB8fCAnIHVua25vd24gcHJvbWlzZScpKTsKCiAgICAgICAg ICAgIHJldHVybiB0cnVlOwogICAgICAgICAgfQogICAgICAgIH0KICAgICAg fSBjYXRjaCAoZXJyb3IpIHsKICAgICAgICBpZiAocmVzb2x2ZWQpIHsgcmV0 dXJuIHRydWU7IH0KICAgICAgICByZWplY3QocHJvbWlzZSwgZXJyb3IpOwog ICAgICAgIHJldHVybiB0cnVlOwogICAgICB9CgogICAgICByZXR1cm4gZmFs c2U7CiAgICB9CgogICAgZnVuY3Rpb24gcmVzb2x2ZShwcm9taXNlLCB2YWx1 ZSkgewogICAgICBpZiAocHJvbWlzZSA9PT0gdmFsdWUpIHsKICAgICAgICBm dWxmaWxsKHByb21pc2UsIHZhbHVlKTsKICAgICAgfSBlbHNlIGlmICghaGFu ZGxlVGhlbmFibGUocHJvbWlzZSwgdmFsdWUpKSB7CiAgICAgICAgZnVsZmls bChwcm9taXNlLCB2YWx1ZSk7CiAgICAgIH0KICAgIH0KCiAgICBmdW5jdGlv biBmdWxmaWxsKHByb21pc2UsIHZhbHVlKSB7CiAgICAgIGlmIChwcm9taXNl Ll9zdGF0ZSAhPT0gUEVORElORykgeyByZXR1cm47IH0KICAgICAgcHJvbWlz ZS5fc3RhdGUgPSBTRUFMRUQ7CiAgICAgIHByb21pc2UuX2RldGFpbCA9IHZh bHVlOwoKICAgICAgY29uZmlnLmFzeW5jKHB1Ymxpc2hGdWxmaWxsbWVudCwg cHJvbWlzZSk7CiAgICB9CgogICAgZnVuY3Rpb24gcmVqZWN0KHByb21pc2Us IHJlYXNvbikgewogICAgICBpZiAocHJvbWlzZS5fc3RhdGUgIT09IFBFT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NvbHZlLCByZWpl Y3QpIHsKICAgICAgICBpZiAoIWlzQXJyYXkoZW50cmllcykpIHsKICAgICAg ICAgIHRocm93IG5ldyBUeXBlRXJyb3IoJ1lvdSBtdXN0IHBhc3MgYW4gYXJy YXkgdG8gYWxsLicpOwogICAgICAgIH0KCiAgICAgICAgdmFyIHJlbWFpbmlu ZyA9IGVudHJpZXMubGVuZ3RoOwogICAgICAgIHZhciByZXN1bHRzID0gbmV3 IEFycmF5KHJlbWFpbmluZyk7CiAgICAgICAgdmFyIGVudHJ5LCBwZW5kaW5n ID0gdHJ1ZTsKCiAgICAgICAgaWYgKHJlbWFpbmluZyA9PT0gMCkgewogICAg ICAgICAgcmVzb2x2ZShyZXN1bHRzKTsKICAgICAgICAgIHJldHVybjsKICAg ICAgICB9CgogICAgICAgIGZ1bmN0aW9uIGZ1bGZpbGxtZW50QXQoaW5kZXgp IHsKICAgICAgICAgIHJldHVybiBmdW5jdGlvbih2YWx1ZSkgewogICAgICAg ICAgICByZXN1bHRzW2luZGV4XSA9IHZhbHVlOwogICAgICAgICAgICBpZiAo LS1yZW1haW5pbmcgPT09IDApIHsKICAgICAgICAgICAgICByZXNvbHZlKHJl c3VsdHMpOwogICAgICAgICAgICB9CiAgICAgICAgICB9OwogICAgICAgIH0K CiAgICAgICAgZnVuY3Rpb24gb25SZWplY3Rpb24ocmVhc29uKSB7CiAgICAg ICAgICByZW1haW5pbmcgPSAwOwogICAgICAgICAgcmVqZWN0KHJlYXNvbik7 CiAgICAgICAgfQoKICAgICAgICBmb3IgKHZhciBpbmRleCA9IDA7IGluZGV4 IDwgZW50cmllcy5sZW5ndGg7IGluZGV4KyspIHsKICAgICAgICAgIGVudHJ5 ID0gZW50cmllc1tpbmRleF07CiAgICAgICAgICBpZiAoaXNOb25UaGVuYWJs ZShlbnRyeSkpIHsKICAgICAgICAgICAgcmVzdWx0c1tpbmRleF0gPSBlbnRy eTsKICAgICAgICAgICAgaWYgKC0tcmVtYWluaW5nID09PSAwKSB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lIHRo ZSBvdGhlciBwcm9taXNlcyBiZWNhbWUgZnVsZmlsbGVkLCB0aGUgcmV0dXJu ZWQKICAgICAgcHJvbWlzZSB3aWxsIGJlY29tZSByZWplY3RlZDoKCiAgICAg IGBgYGphdmFzY3JpcHQKICAgICAgdmFyIHByb21pc2UxID0gbmV3IFJTVlAu UHJvbWlzZShmdW5jdGlvbihyZXNvbHZlLCByZWplY3QpewogICAgICAgIHNl dFRpbWVvdXQoZnVuY3Rpb24oKXsKICAgICAgICAgIHJlc29sdmUoInByb21p c2UgMSIpOwogICAgICAgIH0sIDIwMCk7CiAgICAgIH0pOwoKICAgICAgdmFy IHByb21pc2UyID0gbmV3IFJTVlAuUHJvbWlzZShmdW5jdGlvbihyZXNvbHZl LCByZWplY3QpewogICAgICAgIHNldFRpbWVvdXQoZnVuY3Rpb24oKXsKICAg ICAgICAgIHJlamVjdChuZXcgRXJyb3IoInByb21pc2UgMiIpKTsKICAgICAg ICB9LCAxMDApOwogICAgICB9KTsKCiAgICAgIFJTVlAuUHJvbWlzZS5yYWNl KFtwcm9taXNlMSwgcHJvbWlzZTJdKS50aGVuKGZ1bmN0aW9uKHJlc3VsdCl7 CiAgICAgICAgLy8gQ29kZSBoZXJlIG5ldmVyIHJ1bnMKICAgICAgfSwgZnVu Y3Rpb24ocmVhc29uKXsKICAgICAgICAvLyByZWFzb24ubWVzc2FnZSA9PT0g InByb21pc2UyIiBiZWNhdXNlIHByb21pc2UgMiBiZWNhbWUgcmVqZWN0ZWQg YmVmb3JlCiAgICAgICAgLy8gcHJvbWlzZSAxIGJlY2FtZSBmdWxmaWxsZWQK ICAgICAgfSk7CiAgICAgIGBgYAoKICAgICAgQW4gZXhhbXBsZSByZWFsLXdv cmxkIHVzZSBjYXNlIGlzIGltcGxlbWVudGluZyB0aW1lb3V0czoKCiAgICAg IGBgYGphdmFzY3JpcHQKICAgICAgUlNWUC5Qcm9taXNlLnJhY2UoW2FqYXgo J2Zvby5qc29uJyksIHRpbWVvdXQ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gZmFsc2U7IHJlamVjdChy ZWFzb24pOyB9IH0KCiAgICAgICAgZm9yICh2YXIgaSA9IDA7IGkgPCBlbnRy aWVzLmxlbmd0aDsgaSsrKSB7CiAgICAgICAgICBlbnRyeSA9IGVudHJpZXNb aV07CiAgICAgICAgICBpZiAoaXNOb25UaGVuYWJsZShlbnRyeSkpIHsKICAg ICAgICAgICAgcGVuZGluZyA9IGZhbHNlOwogICAgICAgICAgICByZXNvbHZl KGVudHJ5KTsKICAgICAgICAgICAgcmV0dXJuOwogICAgICAgICAgfSBlbHNl IHsKICAgICAgICAgICAgQ29uc3RydWN0b3IuY2FzdChlbnRyeSkudGhlbihv bkZ1bGZpbGxtZW50LCBvblJlamVjdGlvbik7CiAgICAgICAgICB9CiAgICAg ICAgfQogICAgICB9LCBsYWJlbCk7CiAgICB9OwogIH0pOwpkZWZpbmUoInJz dnAvcHJvbWlzZS9yZWplY3QiLCAKICBbImV4cG9ydHMiXSwKICBmdW5jdGlv bihfX2V4cG9ydHNfXykgewogICAgInVzZSBzdHJpY3QiOwogICAgLyoqCiAg ICAgIGBSU1ZQLlByb21pc2UucmVqZWN0YCByZXR1cm5zIGEgcHJvbWlzZSBy ZWplY3RlZCB3aXRoIHRoZSBwYXNzZWQgYHJlYXNvbmAuCiAgICAgIEl0IGlz IHNob3J0aGFuZCBmb3IgdGhlIGZvbGxvd2luZzoKCiAgICAgIGBgYGphdmFz Y3JpcHQKICAgICAgdmFyIHByb21pc2UgPSBuZXcgUlNWUC5Qcm9taXNlKGZ1 bmN0aW9uKHJlc29sdmUsIHJlamVjdCl7CiAgICAgICAgcmVqZWN0KG5ldyBF cnJvcignV0hPT1BTJykpOwogICAgICB9KTsKCiAgICAgIHByb21pc2UudGhl bihmdW5jdGlvbih2YWx1ZSl7CiAgICAgICAgLy8gQ29kZSBoZXJlIGRvZXNu J3QgcnVuIGJlY2F1c2UgdGhlIHByb21pc2UgaXMgcmVqZWN0ZWQhCiAgICAg IH0sIGZ1bmN0aW9u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FJTVlAuUHJvbWlzZShmdW5jdGlv bihyZXNvbHZlLCByZWplY3QpewogICAgICAgIHRocm93cygpOwogICAgICB9 KTsKCiAgICAgIHByb21pc2UuY2F0Y2goUlNWUC5yZXRocm93KS50aGVuKGZ1 bmN0aW9uKCl7CiAgICAgICAgLy8gQ29kZSBoZXJlIGRvZXNuJ3QgcnVuIGJl Y2F1c2UgdGhlIHByb21pc2UgYmVjYW1lIHJlamVjdGVkIGR1ZSB0byBhbgog ICAgICAgIC8vIGVycm9yIQogICAgICB9LCBmdW5jdGlvbiAoZXJyKXsKICAg ICAgICAvLyBoYW5kbGUgdGhlIGVycm9yIGhlcmUKICAgICAgfSk7CiAgICAg IGBgYAoKICAgICAgVGhlICdXaG9vcHMnIGVycm9yIHdpbGwgYmUgdGhyb3du IG9uIHRoZSBuZXh0IHR1cm4gb2YgdGhlIGV2ZW50IGxvb3AKICAgICAgYW5k IHlvdSBjYW4gd2F0Y2ggZm9yIGl0IGluIHlvdXIgY29uc29sZS4gWW91IGNh biBhbHNvIGhhbmRsZSBpdCB1c2luZyBhCiAgICAgIHJlamVjdGlvbiBoYW5k bGVyIGdpdmVuIHRvIGAudGhlbmAgb3IgYC5jYXRjaGAgb24gdGhlIHJldHVy bmVkIHByb21pc2UuCgogICAgICBAbWV0aG9kIHJldGhyb3cKICAgICAgQGZv ciBSU1ZQCiAgICAgIEBwYXJhbSB7RXJyb3J9IHJlYXNvbiByZWFzb24gdGhl IHByb21pc2UgYmVjYW1lIHJlamVjdGVkLgogICAgICBAdGhyb3dzIEVycm9y CiAgICAgIEBzdGF0aWMKICAgICovCiAgICBfX2V4cG9ydHNfX1siZGVmYXVs dCJdID0gZnVuY3Rpb24gcmV0aHJvdyhyZWFzb24pIHsKICAgICAgc2V0VGlt ZW91dChmdW5jdGlvbigpIHsKICAgICAgICB0aHJvdyByZWFzb247CiAgICAg IH0pOwogICAgICB0aHJvdyByZWFzb247CiAgICB9OwogIH0pOwpkZWZpbmUo InJzdnAvdXR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Wx0IG51bGwKICAgICAgKi8K ICAgICAgcGFyZW50OiBudWxsLAoKICAgICAgLyoqCiAgICAgICAgQHByb3Bl cnR5IGNoaWxkcmVuCiAgICAgICAgQHR5cGUgQXJyYXkKICAgICAgICBAZGVm YXVsdCBbXQogICAgICAqLwogICAgICBjaGlsZHJlbjogbnVsbCwKCiAgICAg IC8qKgogICAgICAgIEBwcm9wZXJ0eSByZXNvbHZlcgogICAgICAgIEB0eXBl IGZ1bmN0aW9uCiAgICAgICovCiAgICAgIHJlc29sdmVyOiBudWxsLAoKICAg ICAgLyoqCiAgICAgICAgQHByb3BlcnR5IHJlZ2lzdHJ5CiAgICAgICAgQHR5 cGUgSW5oZXJpdGluZ0RpY3QKICAgICAgKi8KICAgICAgcmVnaXN0cnk6IG51 bGwsCgogICAgICAvKioKICAgICAgICBAcHJvcGVydHkgY2FjaGUKICAgICAg ICBAdHlwZSBJbmhlcml0aW5nRGljdAogICAgICAqLwogICAgICBjYWNoZTog bnVsbCwKCiAgICAgIC8qKgogICAgICAgIEBwcm9wZXJ0eSB0eXBlSW5qZWN0 aW9ucwogICAgICAgIEB0eXBlIEluaGVyaXRpbmdEaWN0CiAgICAgICovCiAg ICAgIHR5cGVJbmplY3Rpb25zOiBudWxsLAoKICAgICAgLyoqCiAgICAgICAg QHByb3BlcnR5IGluamVjdGlvbnMKICAgICAgICBAdHlwZSBPYmplY3QKICAg ICAgICBAZGVmYXVsdCB7fQogICAgICAqLwogICAgICBpbmplY3Rpb25zOiBu dWxsLAoKICAgICAgLyoqCiAgICAgICAgQHByaXZhdGUKCiAgICAgICAgQHBy b3BlcnR5IF9vcHRpb25zCiAgICAgICAgQHR5cGUgSW5oZXJpdGluZ0RpY3QK ICAgICAgICBAZGVmYXVsdCBudWxsCiAgICAgICovCiAgICAgIF9vcHRpb25z OiBudWxsLAoKICAgICAgLyoqCiAgICAgICAgQHByaXZhdGUKCiAgICAgICAg QHByb3BlcnR5IF90eXBlT3B0aW9ucwogICAgICAgIEB0eXBlIEluaGVyaXRp bmdEaWN0CiAgICAgICovCiAgICAgIF90eXBlT3B0aW9uczogbnVsbCwKCiAg ICAgIC8qKgogICAgICAgIFJldHVybnMgYSBuZXcgY2hpbGQgb2YgdGhlIGN1 cnJlbnQgY29udGFpbmVyLiBUaGVzZSBjaGlsZHJlbiBhcmUgY29uZmlndXJl ZAogICAgICAgIHRvIGNvcnJlY3RseSBpbmhlcml0IGZyb20gdGhlIGN1cnJl bnQgY29udGFpbmVyLgoKICAgICAgICBAbWV0aG9kIGNoaWxkCiAgICAgICAg QHJldHVybiB7Q29udGFpbmVyfQogICAgICAqLwogICAgICBjaGlsZDogZnVu Y3Rpb24oKSB7CiAgICAgICAgdmFyIGNvbnRhaW5lciA9IG5ldyBDb250YWlu ZXIodGhpcyk7CiAgICAgICAgdGhpcy5jaGlsZHJlbi5wdXNoKGNvbnRhaW5l cik7CiAgICAgICAgcmV0dXJuIGNvbnRhaW5lcjsKICAgICAgfSwKCiAgICAg IC8qKgogICAgICAgIFNldHMgYSBrZXktdmFsdWUgcGFpciBvbiB0aGUgY3Vy cmVudCBjb250YWluZXIuIElmIGEgcGFyZW50IGNvbnRhaW5lciwKICAgICAg ICBoYXMgdGhlIHNhbWUga2V5LCBvbmNlIHNldCBvbiBhIGNoaWxkLCB0aGUg cGFyZW50IGFuZCBjaGlsZCB3aWxsIGRpdmVyZ2UKICAgICAgICBhcyBleHBl Y3RlZC4KCiAgICAgICAgQG1ldGhvZCBzZXQKICAgICAgICBAcGFyYW0ge09i amVjdH0gb2JqZWN0CiAgICAgICAgQHBhcmFtIHtTdHJpbmd9IGtleQogICAg ICAgIEBwYXJhbSB7YW55fSB2YWx1ZQogICAgICAqLwogICAgICBzZXQ6IGZ1 bmN0aW9uKG9iamVjdCwga2V5LCB2YWx1ZSkgewogICAgICAgIG9iamVjdFtr ZXldID0gdmFsdWU7CiAgICAgIH0sCgogICAgICAvKioKICAgICAgICBSZWdp c3RlcnMgYSBmYWN0b3J5IGZvciB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GVyQ29ubmVjdGlvbik7 CiAgICAgICAgY29udGFpbmVyLnJlZ2lzdGVyKCdjb25uZWN0aW9uOmZhY2Vi b29rJywgRmFjZWJvb2tDb25uZWN0aW9uKTsKCiAgICAgICAgdmFyIHR3aXR0 ZXIgPSBjb250YWluZXIubG9va3VwKCdjb25uZWN0aW9uOnR3aXR0ZXInKTsK ICAgICAgICB2YXIgdHdpdHRlcjIgPSBjb250YWluZXIubG9va3VwKCdjb25u ZWN0aW9uOnR3aXR0ZXInKTsKCiAgICAgICAgdHdpdHRlciA9PT0gdHdpdHRl cjI7IC8vID0+IGZhbHNlCgogICAgICAgIHZhciBmYWNlYm9vayA9IGNvbnRh aW5lci5sb29rdXAoJ2Nvbm5lY3Rpb246ZmFjZWJvb2snKTsKICAgICAgICB2 YXIgZmFjZWJvb2syID0gY29udGFpbmVyLmxvb2t1cCgnY29ubmVjdGlvbjpm YWNlYm9vaycpOwoKICAgICAgICBmYWNlYm9vayA9PT0gZmFjZWJvb2syOyAv LyA9PiBmYWxzZQogICAgICAgIGBgYAoKICAgICAgICBAbWV0aG9kIG9wdGlv bnNGb3JUeXBlCiAgICAgICAgQHBhcmFtIHtTdHJpbmd9IHR5cGUKICAgICAg ICBAcGFyYW0ge09iamVjdH0gb3B0aW9ucwogICAgICAqLwogICAgICBvcHRp b25zRm9yVHlwZTogZnVuY3Rpb24odHlwZSwgb3B0aW9ucykgewogICAgICAg IGlmICh0aGlzLnBhcmVudCkgeyBpbGxlZ2FsQ2hpbGRPcGVyYXRpb24oJ29w dGlvbnNGb3JUeXBlJyk7IH0KCiAgICAgICAgdGhpcy5fdHlwZU9wdGlvbnMu c2V0KHR5cGUsIG9wdGlvbnMpOwogICAgICB9LAoKICAgICAgLyoqCiAgICAg ICAgQG1ldGhvZCBvcHRpb25zCiAgICAgICAgQHBhcmFtIHtTdHJpbmd9IHR5 cGUKICAgICAgICBAcGFyYW0ge09iamVjdH0gb3B0aW9ucwogICAgICAqLwog ICAgICBvcHRpb25zOiBmdW5jdGlvbih0eXBlLCBvcHRpb25zKSB7CiAgICAg ICAgdGhpcy5vcHRpb25zRm9yVHlwZSh0eXBlLCBvcHRpb25zKTsKICAgICAg fSwKCiAgICAgIC8qKgogICAgICAgIFVzZWQgb25seSB2aWEgYGluamVjdGlv bmAuCgogICAgICAgIFByb3ZpZGVzIGEgc3BlY2lhbGl6ZWQgZm9ybSBvZiBp bmplY3Rpb24sIHNwZWNpZmljYWxseSBlbmFibGluZwogICAgICAgIGFsbCBv YmplY3RzIG9mIG9uZSB0eXBlIHRvIGJlIGluamVjdGVkIHdpdGggYSByZWZl cmVuY2UgdG8gYW5vdGhlcgogICAgICAgIG9iamVjdC4KCiAgICAgICAgRm9y IGV4YW1wbGUsIHByb3ZpZGVkIGVhY2ggb2JqZWN0IG9mIHR5cGUgYGNvbnRy b2xsZXJgIG5lZWRlZCBhIGByb3V0ZXJgLgogICAgICAgIG9uZSB3b3VsZCBk byB0aGUgZm9sbG93aW5nOgoKICAgICAgICBgYGBqYXZhc2NyaXB0CiAgICAg ICAgdmFyIGNvbnRhaW5lciA9IG5ldyBDb250YWluZXIoKTsKCiAgICAgICAg Y29udGFpbmVyLnJlZ2lzdGVyKCdyb3V0ZXI6bWFpbicsIFJvdXRlcik7CiAg ICAgICAgY29udGFpbmVyLnJlZ2lzdGVyKCdjb250cm9sbGVyOnVzZXInLCBV c2VyQ29udHJvbGxlcik7CiAgICAgICAgY29udGFpbmVyLnJlZ2lzdGVyKCdj b250cm9sbGVyOnBvc3QnLCBQb3N0Q29udHJvbGxlcik7CgogICAgICAgIGNv bnRhaW5lci50eXBlSW5qZWN0aW9uKCdjb250cm9sbGVyJywgJ3JvdXRlcics ICdyb3V0ZXI6bWFpbicpOwoKICAgICAgICB2YXIgdXNlciA9IGNvbnRhaW5l ci5sb29rdXAoJ2NvbnRyb2xsZXI6dXNlcicpOwogICAgICAgIHZhciBwb3N0 ID0gY29udGFpbmVyLmxvb2t1cCgnY29udHJvbGxlcjpwb3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vLz0+IHRydWUKCiAgICAgICAgLy8g YW5kIGJvdGggbW9kZWxzIHNoYXJlIHRoZSBzYW1lIHNvdXJjZQogICAgICAg IHVzZXIuc291cmNlID09PSBwb3N0LnNvdXJjZTsgLy89PiB0cnVlCiAgICAg ICAgYGBgCgogICAgICAgIEBtZXRob2QgaW5qZWN0aW9uCiAgICAgICAgQHBh cmFtIHtTdHJpbmd9IGZhY3RvcnlOYW1lCiAgICAgICAgQHBhcmFtIHtTdHJp bmd9IHByb3BlcnR5CiAgICAgICAgQHBhcmFtIHtTdHJpbmd9IGluamVjdGlv bk5hbWUKICAgICAgKi8KICAgICAgaW5qZWN0aW9uOiBmdW5jdGlvbihmdWxs TmFtZSwgcHJvcGVydHksIGluamVjdGlvbk5hbWUpIHsKICAgICAgICBpZiAo dGhpcy5wYXJlbnQpIHsgaWxsZWdhbENoaWxkT3BlcmF0aW9uKCdpbmplY3Rp b24nKTsgfQoKICAgICAgICB2YWxpZGF0ZUZ1bGxOYW1lKGluamVjdGlvbk5h bWUpOwogICAgICAgIHZhciBub3JtYWxpemVkSW5qZWN0aW9uTmFtZSA9IHRo aXMubm9ybWFsaXplKGluamVjdGlvbk5hbWUpOwoKICAgICAgICBpZiAoZnVs bE5hbWUuaW5kZXhPZignOicpID09PSAtMSkgewogICAgICAgICAgcmV0dXJu IHRoaXMudHlwZUluamVjdGlvbihmdWxsTmFtZSwgcHJvcGVydHksIG5vcm1h bGl6ZWRJbmplY3Rpb25OYW1lKTsKICAgICAgICB9CgogICAgICAgIHZhbGlk YXRlRnVsbE5hbWUoZnVsbE5hbWUpOwogICAgICAgIHZhciBub3JtYWxpemVk TmFtZSA9IHRoaXMubm9ybWFsaXplKGZ1bGxOYW1lKTsKCiAgICAgICAgYWRk SW5qZWN0aW9uKHRoaXMuaW5qZWN0aW9ucywgbm9ybWFsaXplZE5hbWUsIHBy b3BlcnR5LCBub3JtYWxpemVkSW5qZWN0aW9uTmFtZSk7CiAgICAgIH0sCgoK ICAgICAg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EBwYXJhbSB7U3RyaW5nfSBmdWxs TmFtZQogICAgICAqLwogICAgICBmYWN0b3J5VHlwZUluamVjdGlvbjogZnVu Y3Rpb24odHlwZSwgcHJvcGVydHksIGZ1bGxOYW1lKSB7CiAgICAgICAgaWYg KHRoaXMucGFyZW50KSB7IGlsbGVnYWxDaGlsZE9wZXJhdGlvbignZmFjdG9y eVR5cGVJbmplY3Rpb24nKTsgfQoKICAgICAgICBhZGRUeXBlSW5qZWN0aW9u KHRoaXMuZmFjdG9yeVR5cGVJbmplY3Rpb25zLCB0eXBlLCBwcm9wZXJ0eSwg dGhpcy5ub3JtYWxpemUoZnVsbE5hbWUpKTsKICAgICAgfSwKCiAgICAgIC8q KgogICAgICAgIERlZmluZXMgZmFjdG9yeSBpbmplY3Rpb24gcnVsZXMuCgog ICAgICAgIFNpbWlsYXIgdG8gcmVndWxhciBpbmplY3Rpb24gcnVsZXMsIGJ1 dCBhcmUgcnVuIGFnYWluc3QgZmFjdG9yaWVzLCB2aWEKICAgICAgICBgQ29u dGFpbmVyI2xvb2t1cEZhY3RvcnlgLgoKICAgICAgICBUaGVzZSBydWxlcyBh cmUgdXNlZCB0byBpbmplY3Qgb2JqZWN0cyBvbnRvIGZhY3RvcmllcyB3aGVu IHRoZXkKICAgICAgICBhcmUgbG9va2VkIHVwLgoKICAgICAgICBUd28gZm9y bXMgb2YgaW5qZWN0aW9ucyBhcmUgcG9zc2libGU6CgogICAgICAqIEluamVj dGluZyBvbmUgZnVsbE5hbWUgb24gYW5vdGhlciBmdWxsTmFtZQogICAgICAq IEluamVjdGluZyBvbmUgZnVsbE5hbWUgb24gYSB0eXBlCgogICAgICAgIEV4 YW1wbGU6CgogICAgICAgIGBgYGphdmFzY3JpcHQKICAgICAgICB2YXIgY29u dGFpbmVyID0gbmV3IENvbnRhaW5lcigpOwoKICAgICAgICBjb250YWluZXIu cmVnaXN0ZXIoJ3N0b3JlOm1haW4nLCBTdG9yZSk7CiAgICAgICAgY29udGFp bmVyLnJ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9ybWFsaXplZE5hbWUsIHBy b3BlcnR5LCBub3JtYWxpemVkSW5qZWN0aW9uTmFtZSk7CiAgICAgIH0sCgog ICAgICAvKioKICAgICAgICBBIGRlcHRoIGZpcnN0IHRyYXZlcnNhbCwgZGVz dHJveWluZyB0aGUgY29udGFpbmVyLCBpdHMgZGVzY2VuZGFudCBjb250YWlu ZXJzIGFuZCBhbGwKICAgICAgICB0aGVpciBtYW5hZ2VkIG9iamVjdHMuCgog ICAgICAgIEBtZXRob2QgZGVzdHJveQogICAgICAqLwogICAgICBkZXN0cm95 OiBmdW5jdGlvbigpIHsKICAgICAgICBmb3IgKHZhciBpPTAsIGw9dGhpcy5j aGlsZHJlbi5sZW5ndGg7IGk8bDsgaSsrKSB7CiAgICAgICAgICB0aGlzLmNo aWxkcmVuW2ldLmRlc3Ryb3koKTsKICAgICAgICB9CgogICAgICAgIHRoaXMu Y2hpbGRyZW4gPSBbXTsKCiAgICAgICAgZWFjaERlc3Ryb3lhYmxlKHRoaXMs IGZ1bmN0aW9uKGl0ZW0pIHsKICAgICAgICAgIGl0ZW0uZGVzdHJveSgpOwog ICAgICAgIH0pOwoKICAgICAgICB0aGlzLnBhcmVudCA9IHVuZGVmaW5lZDsK ICAgICAgICB0aGlzLmlzRGVzdHJveWVkID0gdHJ1ZTsKICAgICAgfSwKCiAg ICAgIC8qKgogICAgICAgIEBtZXRob2QgcmVzZXQKICAgICAgKi8KICAgICAg cmVzZXQ6IGZ1bmN0aW9uKCkgewogICAgICAgIGZvciAodmFyIGk9MCwgbD10 aGlzLmNoaWxkcmVuLmxlbmd0aDsgaTxsOyBpKyspIHsKICAgICAgICAgIHJl c2V0Q2FjaGUodGhpcy5jaGlsZHJlbltpXSk7CiAgICAgICAgfQogICAgICAg IHJlc2V0Q2FjaGUodGhpcyk7CiAgICAgIH0KICAgIH07CgogICAgZnVuY3Rp b24gaGFzKGNvbnRhaW5lciwgZnVsbE5hbWUpewogICAgICBpZiAoY29udGFp bmVyLmNhY2hl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icpOwoKICAgICAgcmV0dXJuIHNpbmdsZXRvbiAh PT0gZmFsc2U7CiAgICB9CgogICAgZnVuY3Rpb24gYnVpbGRJbmplY3Rpb25z KGNvbnRhaW5lciwgaW5qZWN0aW9ucykgewogICAgICB2YXIgaGFzaCA9IHt9 OwoKICAgICAgaWYgKCFpbmplY3Rpb25zKSB7IHJldHVybiBoYXNoOyB9Cgog ICAgICB2YXIgaW5qZWN0aW9uLCBpbmplY3RhYmxlOwoKICAgICAgZm9yICh2 YXIgaT0wLCBsPWluamVjdGlvbnMubGVuZ3RoOyBpPGw7IGkrKykgewogICAg ICAgIGluamVjdGlvbiA9IGluamVjdGlvbnNbaV07CiAgICAgICAgaW5qZWN0 YWJsZSA9IGxvb2t1cChjb250YWluZXIsIGluamVjdGlvbi5mdWxsTmFtZSk7 CgogICAgICAgIGlmIChpbmplY3RhYmxlICE9PSB1bmRlZmluZWQpIHsKICAg ICAgICAgIGhhc2hbaW5qZWN0aW9uLnByb3BlcnR5XSA9IGluamVjdGFibGU7 CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHRocm93IG5ldyBFcnJvcign QXR0ZW1wdGluZyB0byBpbmplY3QgYW4gdW5rbm93biBpbmplY3Rpb246IGAn ICsgaW5qZWN0aW9uLmZ1bGxOYW1lICsgJ2AnKTsKICAgICAgICB9CiAgICAg IH0KCiAgICAgIHJldHVybiBoYXNoOwogICAgfQoKICAgIGZ1bmN0aW9uIG9w dGlvbihjb250YWluZXIsIGZ1bGxOYW1lLCBvcHRpb25OYW1lKSB7CiAgICAg IHZhciBvcHRpb25zID0gY29udGFpbmVyLl9vcHRpb25zLmdldChmdWxsTmFt ZSk7CgogICAgICBpZiAob3B0aW9ucyAmJiBvcHRpb25zW29wdGlvbk5hbWVd ICE9PSB1bmRlZmluZWQpIHsKICAgICAgICByZXR1cm4gb3B0aW9uc1tvcHRp b25OYW1lXTsKICAgICAgfQoKICAgICAgdmFyIHR5cGUgPSBmdWxsTmFtZS5z cGxpdC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iAgICAgIH0pOwogICAgICBjb250YWluZXIuY2FjaGUu ZGljdCA9IHt9OwogICAgfQoKICAgIGZ1bmN0aW9uIGFkZFR5cGVJbmplY3Rp b24ocnVsZXMsIHR5cGUsIHByb3BlcnR5LCBmdWxsTmFtZSkgewogICAgICB2 YXIgaW5qZWN0aW9ucyA9IHJ1bGVzLmdldCh0eXBlKTsKCiAgICAgIGlmICgh aW5qZWN0aW9ucykgewogICAgICAgIGluamVjdGlvbnMgPSBbXTsKICAgICAg ICBydWxlcy5zZXQodHlwZSwgaW5qZWN0aW9ucyk7CiAgICAgIH0KCiAgICAg IGluamVjdGlvbnMucHVzaCh7CiAgICAgICAgcHJvcGVydHk6IHByb3BlcnR5 LAogICAgICAgIGZ1bGxOYW1lOiBmdWxsTmFtZQogICAgICB9KTsKICAgIH0K CiAgICB2YXIgVkFMSURfRlVMTF9OQU1FX1JFR0VYUCA9IC9eW146XSsuKzpb XjpdKyQvOwogICAgZnVuY3Rpb24gdmFsaWRhdGVGdWxsTmFtZShmdWxsTmFt ZSkgewogICAgICBpZiAoIVZBTElEX0ZVTExfTkFNRV9SRUdFWFAudGVzdChm dWxsTmFtZSkpIHsKICAgICAgICB0aHJvdyBuZXcgVHlwZUVycm9yKCdJbnZh bGlkIEZ1bGxuYW1lLCBleHBlY3RlZDogYHR5cGU6bmFtZWAgZ290OiAnICsg ZnVsbE5hbWUpOwogICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gYWRkSW5q ZWN0aW9uKHJ1bGVzLCBmYWN0b3J5TmFtZSwgcHJvcGVydHksIGluamVjdGlv bk5hbWUpIHsKICAgICAgdmFyIGluamVjdGlvbnMgPSBydWxlc1tmYWN0b3J5 TmFtZV0gPSBydWxlc1tmYWN0b3J5TmFtZV0gfHwgW107CiAgICAgIGluamVj dGlvbnMucHVzaCh7IHByb3BlcnR5OiBwcm9wZXJ0eSwgZnVsbE5hbWU6IGlu amVjdGlvbk5hbWUgfSk7CiAgICB9CgogICAgX19leHBvcnRzX19bImRlZmF1 bHQiXSA9IENvbnRhaW5lcjsKICB9KTsKZGVmaW5lKCJjb250YWluZXIvaW5o ZXJpdGluZ19kaWN0IiwgCiAgWyJleHBvcnRzIl0sCiAgZnVuY3Rpb24oX19l eHBvcnRzX18pIHsKICAgICJ1c2Ugc3RyaWN0IjsKICAgIC8vIEEgc2FmZSBh bmQgc2ltcGxlIGluaGVyaXRpbmcgb2JqZWN0LgogICAgZnVuY3Rpb24gSW5o ZXJpdGluZ0RpY3QocGFyZW50KSB7CiAgICAgIHRoaXMucGFyZW50ID0gcGFy ZW50OwogICAgICB0aGlzLmRpY3QgPSB7fTsKICAgIH0KCiAgICBJbmhlcml0 aW5nRGljdC5wcm90b3R5cGUgPSB7CgogICAgICAvKioKICAgICAgICBAcHJv cGVydHkgcGFyZW50CiAgICAgICAgQHR5cGUgSW5oZXJpdGluZ0RpY3QKICAg ICAgICBAZGVmYXVsdCBudWxsCiAgICAgICovCgogICAgICBwYXJlbnQ6IG51 bGwsCgogICAgICAvKioKICAgICAgICBPYmplY3QgdXNlZCB0byBzdG9yZSB0 aGUgY3VycmVudCBub2RlcyBkYXRhLgoKICAgICAgICBAcHJvcGVydHkgZGlj dAogICAgICAgIEB0eXBlIE9iamVjdAogICAgICAgIEBkZWZhdWx0IE9iamVj dAogICAgICAqLwogICAgICBkaWN0OiBudWxsLAoKICAgICAgLyoqCiAgICAg ICAgUmV0cmlldmUgdGhlIHZhbHVlIGdpdmVuIGEga2V5LCBpZiB0aGUgdmFs dWUgaXMgcHJlc2VudCBhdCB0aGUgY3VycmVudAogICAgICAgIGxldmVsIHVz ZSBpdCwgb3RoZXJ3aXNlIHdhbGsgdXAgdGhlIHBhcmVudCBoaWVyYXJjaHkg YW5kIHRyeSBhZ2Fpbi4gSWYKICAgICAgICBubyBtYXRjaGluZyBrZXkgaXMg Zm91bmQsIHJldHVybiB1bmRlZmluZWQuCgogICAgICAgIEBtZXRob2QgZ2V0 CiAgICAgICAgQHBhcmFtIHtTdHJpbmd9IGtleQogICAgICAgIEByZXR1cm4g e2FueX0KICAgICAgKi8KICAgICAgZ2V0OiBmdW5jdGlvbihrZXkpIHsKICAg ICAgICB2YXIgZGljdCA9IHRoaXMuZGljdDsKCiAgICAgICAgaWYgKGRpY3Qu aGFzT3duUHJvcGVydHkoa2V5KSkgewogICAgICAgICAgcmV0dXJuIGRpY3Rb a2V5XTsKICAgICAgICB9CgogICAgICAgIGlmICh0aGlzLnBhcmVudCkgewog ICAgICAgICAgcmV0dXJuIHRoaXMucGFyZW50LmdldChrZXkpOwogICAgICAg IH0KICAgICAgfSwKCiAgICAgIC8qKgogICAgICAgIFNldCB0aGUgZ2l2ZW4g dmFsdWUgZm9yIHRoZSBnaXZlbiBrZXksIGF0IHRoZSBjdXJyZW50IGxldmVs LgoKICAgICAgICBAbWV0aG9kIHNldAogICAgICAgIEBwYXJhbSB7U3RyaW5n fSBrZXkKICAgICAgICBAcGFyYW0ge0FueX0gdmFsdWUKICAgICAgKi8KICAg ICAgc2V0OiBmdW5jdGlvbihrZXksIHZhbHVlKSB7CiAgICAgICAgdGhpcy5k aWN0W2tleV0gPSB2YWx1ZTsKICAgICAgfSwKCiAgICAgIC8qKgogICAgICAg IERlbGV0ZSB0aGUgZ2l2ZW4ga2V5CgogICAgICAgIEBtZXRob2QgcmVtb3Zl CiAgICAgICAgQHBhcmFtIHtTdHJpbmd9IGtleQogICAgICAqLwogICAgICBy ZW1vdmU6IGZ1bmN0aW9uKGtleSkgewogICAgICAgIGRlbGV0ZSB0aGlzLmRp Y3Rba2V5XTsKICAgICAgfSwKCiAgICAgIC8qKgogICAgICAgIENoZWNrIGZv ciB0aGUgZXhpc3RlbmNlIG9mIGdpdmVuIGEga2V5LCBpZiB0aGUga2V5IGlz IHByZXNlbnQgYXQgdGhlIGN1cnJlbnQKICAgICAgICBsZXZlbCByZXR1cm4g dHJ1ZSwgb3RoZXJ3aXNlIHdhbGsgdXAgdGhlIHBhcmVudCBoaWVyYXJjaHkg YW5kIHRyeSBhZ2Fpbi4gSWYKICAgICAgICBubyBtYXRjaGluZyBrZXkgaXMg Zm91bmQsIHJldHVybiBmYWxzZS4KCiAgICAgICAgQG1ldGhvZCBoYXMKICAg ICAgICBAcGFyYW0ge1N0cmluZ30ga2V5CiAgICAgICAgQHJldHVybiB7Qm9v bGVhbn0KICAgICAgKi8KICAgICAgaGFzOiBmdW5jdGlvbihrZXkpIHsKICAg ICAgICB2YXIgZGljdCA9IHRoaXMuZGljdDsKCiAgICAgICAgaWYgKGRpY3Qu aGFzT3duUHJvcGVydHkoa2V5KSkgewogICAgICAgICAgcmV0dXJuIHRydWU7 CiAgICAgICAgfQoKICAgICAgICBpZiAodGhpcy5wYXJlbnQpIHsKICAgICAg ICAgIHJldHVybiB0aGlzLnBhcmVudC5oYXMoa2V5KTsKICAgICAgICB9Cgog ICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgfSwKCiAgICAgIC8qKgogICAg ICAgIEl0ZXJhdGUgYW5kIGludm9rZSBhIGNhbGxiYWNrIGZvciBlYWNoIGxv Y2FsIGtleS12YWx1ZSBwYWlyLgoKICAgICAgICBAbWV0aG9kIGVhY2hMb2Nh bAogICAgICAgIEBwYXJhbSB7RnVuY3Rpb259IGNhbGxiYWNrCiAgICAgICAg QHBhcmFtIHtPYmplY3R9IGJpbmRpbmcKICAgICAgKi8KICAgICAgZWFjaExv Y2FsOiBmdW5jdGlvbihjYWxsYmFjaywgYmluZGluZykgewogICAgICAgIHZh ciBkaWN0ID0gdGhpcy5kaWN0OwoKICAgICAgICBmb3IgKHZhciBwcm9wIGlu IGRpY3QpIHsKICAgICAgICAgIGlmIChkaWN0Lmhhc093blByb3BlcnR5KHBy b3ApKSB7CiAgICAgICAgICAgIGNhbGxiYWNrLmNhbGwoYmluZGluZywgcHJv cCwgZGljdFtwcm9wXSk7CiAgICAgICAgICB9CiAgICAgICAgfQogICAgICB9 CiAgICB9OwoKICAgIF9fZXhwb3J0c19fWyJkZWZhdWx0Il0gPSB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keF1dID0gaWR4 OwogICAgfQoKICAgIC8vIFdlIG5vIGxvbmdlciBuZWVkIEVtYmVyLk9SREVS X0RFRklOSVRJT04uCiAgICBkZWxldGUgRW1iZXIuT1JERVJfREVGSU5JVElP TjsKICB9CgogIHZhciB0eXBlMUluZGV4ID0gbWFwcGluZ1t0eXBlMV07CiAg dmFyIHR5cGUySW5kZXggPSBtYXBwaW5nW3R5cGUyXTsKCiAgaWYgKHR5cGUx SW5kZXggPCB0eXBlMkluZGV4KSB7IHJldHVybiAtMTsgfQogIGlmICh0eXBl MUluZGV4ID4gdHlwZTJJbmRleCkgeyByZXR1cm4gMTsgfQoKICAvLyB0eXBl cyBhcmUgZXF1YWwgLSBzbyB3ZSBoYXZlIHRvIGNoZWNrIHZhbHVlcyBub3cK ICBzd2l0Y2ggKHR5cGUxKSB7CiAgICBjYXNlICdib29sZWFuJzoKICAgIGNh c2UgJ251bWJlcic6CiAgICAgIGlmICh2IDwgdykgeyByZXR1cm4gLTE7IH0K ICAgICAgaWYgKHYgPiB3KSB7IHJldHVybiAxOyB9CiAgICAgIHJldHVybiAw OwoKICAgIGNhc2UgJ3N0cmluZyc6CiAgICAgIHZhciBjb21wID0gdi5sb2Nh bGVDb21wYXJlKHcpOwogICAgICBpZiAoY29tcCA8IDApIHsgcmV0dXJuIC0x OyB9CiAgICAgIGlmIChjb21wID4gMCkgeyByZXR1cm4gMTsgfQogICAgICBy ZXR1cm4gMDsKCiAgICBjYXNlICdhcnJheSc6CiAgICAgIHZhciB2TGVuID0g di5sZW5ndGg7CiAgICAgIHZhciB3TGVuID0gdy5sZW5ndGg7CiAgICAgIHZh ciBsID0gTWF0aC5taW4odkxlbiwgd0xlbik7CiAgICAgIHZhciByID0gMDsK ICAgICAgdmFyIGkgPSAwOwogICAgICB3aGlsZSAociA9PT0gMCAmJiBpIDwg bCkgewogICAgICAgIHIgPSBjb21wYXJlKHZbaV0sd1tpXSk7CiAgICAgICAg aSsrOwogICAgICB9CiAgICAgIGlmIChyICE9PSAwKSB7IHJldHVybiByOyB9 CgogICAgICAvLyBhbGwgZWxlbWVudHMgYXJlIGVxdWFsIG5vdwogICAgICAv LyBzaG9ydGVyIGFycmF5IHNob3VsZCBiZSBvcmRlcmVkIGZpcnN0CiAgICAg IGlmICh2TGVuIDwgd0xlbikgeyByZXR1cm4gLTE7IH0KICAgICAgaWYgKHZM ZW4gPiB3TGVuKSB7IHJldHVybiAxOyB9CiAgICAgIC8vIGFycmF5cyBhcmUg ZXF1YWwgbm93CiAgICAgIHJldHVybiAwOwoKICAgIGNhc2UgJ2luc3RhbmNl JzoKICAgICAgaWYgKEVtYmVyLkNvbXBhcmFibGUgJiYgRW1iZXIuQ29tcGFy YWJsZS5kZXRlY3QodikpIHsKICAgICAgICByZXR1cm4gdi5jb21wYXJlKHYs IHcpOwogICAgICB9CiAgICAgIHJldHVybiAwOwoKICAgIGNhc2UgJ2RhdGUn OgogICAgICB2YXIgdk51bSA9IHYuZ2V0VGltZSgpOwogICAgICB2YXIgd051 bSA9IHcuZ2V0VGltZSgpOwogICAgICBpZiAodk51bSA8IHdOdW0pIHsgcmV0 dXJuIC0xOyB9CiAgICAgIGlmICh2TnVtID4gd051bSkgeyByZXR1cm4gMTsg fQogICAgICByZXR1cm4gMDsKCiAgICBkZWZhdWx0OgogICAgICByZXR1cm4g MDsKICB9Cn07CgpmdW5jdGlvbiBfY29weShvYmosIGRlZXAsIHNlZW4sIGNv cGllcykgewogIHZhciByZXQsIGxvYywga2V5OwoKICAvLyBwcmltaXRpdmUg ZGF0YSB0eXBlcyBhcmUgaW1tdXRhYmxlLCBqdXN0IHJldHVybiB0aGVtLgog IGlmICgnb2JqZWN0JyAhPT0gdHlwZW9mIG9iaiB8fCBvYmo9PT1udWxsKSBy ZXR1cm4gb2JqOwoKICAvLyBhdm9pZCBjeWNsaWNhbCBsb29wcwogIGlmIChk ZWVwICYmIChsb2M9aW5kZXhPZihzZWVuLCBvYmopKT49MCkgcmV0dXJuIGNv cGllc1tsb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GxvbmdlciBzdXBwb3J0cyBtaXhpbmcgaW4gb3RoZXIgZGVmaW5pdGlv bnMsIHVzZSBjcmVhdGVXaXRoTWl4aW5zIGluc3RlYWQuIiwgIShwcm9wZXJ0 aWVzIGluc3RhbmNlb2YgRW1iZXIuTWl4aW4pKTsKCiAgICAgICAgaWYgKHR5 cGVvZiBwcm9wZXJ0aWVzICE9PSAnb2JqZWN0JyAmJiBwcm9wZXJ0aWVzICE9 PSB1bmRlZmluZWQpIHsKICAgICAgICAgIHRocm93IG5ldyBFbWJlci5FcnJv cigiRW1iZXIuT2JqZWN0LmNyZWF0ZSBvbmx5IGFjY2VwdHMgb2JqZWN0cy4i KTsKICAgICAgICB9CgogICAgICAgIGlmICghcHJvcGVydGllcykgeyBjb250 aW51ZTsgfQoKICAgICAgICB2YXIga2V5TmFtZXMgPSBFbWJlci5rZXlzKHBy b3BlcnRpZXMpOwoKICAgICAgICBmb3IgKHZhciBqID0gMCwgbGwgPSBrZXlO YW1lcy5sZW5ndGg7IGogPCBsbDsgaisrKSB7CiAgICAgICAgICB2YXIga2V5 TmFtZSA9IGtleU5hbWVzW2pdOwogICAgICAgICAgaWYgKCFwcm9wZXJ0aWVz Lmhhc093blByb3BlcnR5KGtleU5hbWUpKSB7IGNvbnRpbnVlOyB9CgogICAg ICAgICAgdmFyIHZhbHVlID0gcHJvcGVydGllc1trZXlOYW1lXSwKICAgICAg ICAgICAgICBJU19CSU5ESU5HID0gRW1iZXIuSVNfQklORElORzsKCiAgICAg ICAgICBpZiAoSVNfQklORElORy50ZXN0KGtleU5hbWUpKSB7CiAgICAgICAg ICAgIHZhciBiaW5kaW5ncyA9IG0uYmluZGluZ3M7CiAgICAgICAgICAgIGlm ICghYmluZGluZ3MpIHsKICAgICAgICAgICAgICBiaW5kaW5ncyA9IG0uYmlu ZGluZ3MgPSB7fTsKICAgICAgICAgICAgfSBlbHNlIGlmICghbS5oYXNPd25Q cm9wZXJ0eSgnYmluZGluZ3MnKSkgewogICAgICAg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wZXJ0 aWVzLCBrZXlOYW1lKSA+PSAwKSB7CiAgICAgICAgICAgIHZhciBiYXNlVmFs dWUgPSB0aGlzW2tleU5hbWVdOwoKICAgICAgICAgICAgaWYgKGJhc2VWYWx1 ZSkgewogICAgICAgICAgICAgIGlmICgnZnVuY3Rpb24nID09PSB0eXBlb2Yg YmFzZVZhbHVlLmNvbmNhdCkgewogICAgICAgICAgICAgICAgdmFsdWUgPSBi YXNlVmFsdWUuY29uY2F0KHZhbHVlKTsKICAgICAgICAgICAgICB9IGVsc2Ug ewogICAgICAgICAgICAgICAgdmFsdWUgPSBFbWJlci5tYWtlQXJyYXkoYmFz ZVZhbHVlKS5jb25jYXQodmFsdWUpOwogICAgICAgICAgICAgIH0KICAgICAg ICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgICB2YWx1ZSA9IEVtYmVyLm1h a2VBcnJheSh2YWx1ZSk7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KCiAg ICAgICAgICBpZiAoZGVzYykgewogICAgICAgICAgICBkZXNjLnNldCh0aGlz LCBrZXlOYW1lLCB2YWx1ZSk7CiAgICAgICAgICB9IGVsc2UgewogICAgICAg ICAgICBpZiAodHlwZW9mIHRoaXMuc2V0VW5rbm93blByb3BlcnR5ID09PSAn ZnVuY3Rpb24nICYmICEoa2V5TmFtZSBpbiB0aGlzKSkgewogICAgICAgICAg ICAgIHRoaXMuc2V0VW5rbm93blByb3BlcnR5KGtleU5hbWUsIHZhbHVlKTsK ICAgICAgICAgICAgfSBlbHNlIGlmIChNQU5EQVRPUllfU0VUVEVSKSB7CiAg ICAgICAgICAgICAgRW1iZXIuZGVmaW5lUHJvcGVydHkodGhpcywga2V5TmFt ZSwgbnVsbCwgdmFsdWUpOyAvLyBzZXR1cCBtYW5kYXRvcnkgc2V0dGVyCiAg ICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgICAgdGhpc1trZXlOYW1l XSA9IHZhbHVlOwogICAgICAgICAgICB9CiAgICAgICAgICB9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Db250YWluZXJLZXk6IG51bGwsCgogIHdp bGxXYXRjaFByb3BlcnR5OiBmdW5jdGlvbiAoa2V5KSB7CiAgICB2YXIgY29u dGVudEtleSA9ICdjb250ZW50LicgKyBrZXk7CiAgICBhZGRCZWZvcmVPYnNl cnZlcih0aGlzLCBjb250ZW50S2V5LCBudWxsLCBjb250ZW50UHJvcGVydHlX aWxsQ2hhbmdlKTsKICAgIGFkZE9ic2VydmVyKHRoaXMsIGNvbnRlbnRLZXks IG51bGwsIGNvbnRlbnRQcm9wZXJ0eURpZENoYW5nZSk7CiAgfSwKCiAgZGlk VW53YXRjaFByb3BlcnR5OiBmdW5jdGlvbiAoa2V5KSB7CiAgICB2YXIgY29u dGVudEtleSA9ICdjb250ZW50LicgKyBrZXk7CiAgICByZW1vdmVCZWZvcmVP YnNlcnZlcih0aGlzLCBjb250ZW50S2V5LCBudWxsLCBjb250ZW50UHJvcGVy dHlXaWxsQ2hhbmdlKTsKICAgIHJlbW92ZU9ic2VydmVyKHRoaXMsIGNvbnRl bnRLZXksIG51bGwsIGNvbnRlbnRQcm9wZXJ0eURpZENoYW5nZSk7CiAgfSwK CiAgdW5rbm93blByb3BlcnR5OiBmdW5jdGlvbiAoa2V5KSB7CiAgICB2YXIg Y29udGVudCA9IGdldCh0aGlzLCAnY29udGVudCcpOwogICAgaWYgKGNvbnRl bnQpIHsKICAgICAgcmV0dXJuIGdldChjb250ZW50LCBrZXkpOwogICAgfQog IH0sCgogIHNldFVua25vd25Qcm9wZXJ0eTogZnVuY3Rpb24gKGtleSwgdmFs dWUpIHsKICAgIHZhciBtID0gbWV0YSh0aGlzKTsKICAgIGlmIChtLnByb3Rv ID09PSB0aGlzKSB7CiAgICAgIC8vIGlmIG1hcmtlZCBhcyBwcm90b3R5cGUg dGhlbiBqdXN0IGRlZmluZVByb3BlcnR5CiAgICAgIC8vIHJhdGhlciB0aGFu IGRlbGVnYXRlCiAgICAgIGRlZmluZVByb3BlcnR5KHRoaXMsIGtleSwgbnV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aXMuX29wZXJhdGlvbnNbaW5kZXhd LAogICAgICAgIG90aGVyT3A7CgogICAgaWYgKCFvcCkgewogICAgICAvLyBD b21wb3Npbmcgb3V0IG9mIGJvdW5kcyBpcyBhIG5vLW9wLCBhcyB3aGVuIHJl bW92aW5nIHRoZSBsYXN0IG9wZXJhdGlvbgogICAgICAvLyBpbiB0aGUgbGlz dC4KICAgICAgcmV0dXJuOwogICAgfQoKICAgIGlmIChpbmRleCA+IDApIHsK ICAgICAgb3RoZXJPcCA9IHRoaXMuX29wZXJhdGlvbnNbaW5kZXgtMV07CiAg ICAgIGlmIChvdGhlck9wLnR5cGUgPT09IG9wLnR5cGUpIHsKICAgICAgICBv cC5jb3VudCArPSBvdGhlck9wLmNvdW50OwogICAgICAgIHRoaXMuX29wZXJh dGlvbnMuc3BsaWNlKGluZGV4LTEsIDEpOwogICAgICAgIC0taW5kZXg7CiAg ICAgIH0KICAgIH0KCiAgICBpZiAoaW5kZXggPCB0aGlzLl9vcGVyYXRpb25z Lmxlbmd0aC0xKSB7CiAgICAgIG90aGVyT3AgPSB0aGlzLl9vcGVyYXRpb25z W2luZGV4KzFdOwogICAgICBpZiAob3RoZXJPcC50eXBlID09PSBvcC50eXBl KSB7CiAgICAgICAgb3AuY291bnQgKz0gb3RoZXJPcC5jb3VudDsKICAgICAg ICB0aGlzLl9vcGVyYXRpb25zLnNwbGljZShpbmRleCsxLCAxKTsKICAgICAg fQogICAgfQogIH0sCgogIHRvU3RyaW5nOiBmdW5jdGlvbiAoKSB7CiAgICB2 YXIgc3RyID0gIiI7CiAgICBmb3JFYWNoKHRoaXMuX29wZXJhdGlvbnMsIGZ1 bmN0aW9uIChvcGVyYXRpb24pIHsKICAgICAgc3RyICs9ICIgIiArIG9wZXJh dGlvbi50eXBlICsgIjoiICsgb3BlcmF0aW9uLmNvdW50OwogICAgfSk7CiAg ICByZXR1cm4gc3RyLnN1YnN0cmluZygxKTsKICB9Cn07Cgp9KSgpOwoKCgoo ZnVuY3Rp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ICAgICBzZWxmID0gdGhp czsKCiAgICBpZiAoY29udGVudCAmJiBpc1NvcnRlZCkgewogICAgICBjb250 ZW50ID0gY29udGVudC5zbGljZSgpOwogICAgICBjb250ZW50LnNvcnQoZnVu Y3Rpb24oaXRlbTEsIGl0ZW0yKSB7CiAgICAgICAgcmV0dXJuIHNlbGYub3Jk ZXJCeShpdGVtMSwgaXRlbTIpOwogICAgICB9KTsKICAgICAgZm9yRWFjaChj b250ZW50LCBmdW5jdGlvbihpdGVtKSB7CiAgICAgICAgZm9yRWFjaChzb3J0 UHJvcGVydGllcywgZnVuY3Rpb24oc29ydFByb3BlcnR5KSB7CiAgICAgICAg ICBFbWJlci5hZGRPYnNlcnZlcihpdGVtLCBzb3J0UHJvcGVydHksIHRoaXMs ICdjb250ZW50SXRlbVNvcnRQcm9wZXJ0eURpZENoYW5nZScpOwogICAgICAg IH0sIHRoaXMpOwogICAgICB9LCB0aGlzKTsKICAgICAgcmV0dXJuIEVtYmVy LkEoY29udGVudCk7CiAgICB9CgogICAgcmV0dXJuIGNvbnRlbnQ7CiAgfSks CgogIF9jb250ZW50V2lsbENoYW5nZTogRW1iZXIuYmVmb3JlT2JzZXJ2ZXIo J2NvbnRlbnQnLCBmdW5jdGlvbigpIHsKICAgIHZhciBjb250ZW50ID0gZ2V0 KHRoaXMsICdjb250ZW50JyksCiAgICAgICAgc29ydFByb3BlcnRpZXMgPSBn ZXQodGhpcywgJ3NvcnRQcm9wZXJ0aWVzJyk7CgogICAgaWYgKGNvbnRlbnQg JiYgc29ydFByb3BlcnRpZXMpIHsKICAgICAgZm9yRWFjaChjb250ZW50LCBm dW5jdGlvbihpdGVtKSB7CiAgICAgICAgZm9yRWFjaChzb3J0UHJvcGVydGll cywgZnVuY3Rpb24oc29ydFByb3BlcnR5KSB7CiAgICAgICAgICBFbWJlci5y ZW1vdmVPYnNlcnZlcihpdGVtLCBzb3J0UHJvcGVydHksIHRoaXMsICdjb250 ZW50SXRlbVNvcnRQcm9wZXJ0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zLCBmdW5jdGlvbihpdGVtKSB7CiAg ICAgICAgYXJyYW5nZWRDb250ZW50LnJlbW92ZU9iamVjdChpdGVtKTsKCiAg ICAgICAgZm9yRWFjaChzb3J0UHJvcGVydGllcywgZnVuY3Rpb24oc29ydFBy b3BlcnR5KSB7CiAgICAgICAgICBFbWJlci5yZW1vdmVPYnNlcnZlcihpdGVt LCBzb3J0UHJvcGVydHksIHRoaXMsICdjb250ZW50SXRlbVNvcnRQcm9wZXJ0 eURpZENoYW5nZScpOwogICAgICAgIH0sIHRoaXMpOwogICAgICB9LCB0aGlz KTsKICAgIH0KCiAgICByZXR1cm4gdGhpcy5fc3VwZXIoYXJyYXksIGlkeCwg cmVtb3ZlZENvdW50LCBhZGRlZENvdW50KTsKICB9LAoKICBjb250ZW50QXJy YXlEaWRDaGFuZ2U6IGZ1bmN0aW9uKGFycmF5LCBpZHgsIHJlbW92ZWRDb3Vu dCwgYWRkZWRDb3VudCkgewogICAgdmFyIGlzU29ydGVkID0gZ2V0KHRoaXMs ICdpc1NvcnRlZCcpLAogICAgICAgIHNvcnRQcm9wZXJ0aWVzID0gZ2V0KHRo aXMsICdzb3J0UHJvcGVydGllcycpOwoKICAgIGlmIChpc1NvcnRlZCkgewog ICAgICB2YXIgYWRkZWRPYmplY3RzID0gYXJyYXkuc2xpY2UoaWR4LCBpZHgr YWRkZWRDb3VudCk7CgogICAgICBmb3JFYWNoKGFkZGVkT2JqZWN0cywgZnVu Y3Rpb24oaXRlbSkgewogICAgICAgIHRoaXMuaW5zZXJ0SXRlbVNvcnRlZChp dGVtKTsKCiAgICAgICAgZm9yRWFjaChzb3J0UHJvcGVydGllcywgZnVuY3Rp b24oc29ydFByb3BlcnR5KSB7CiAgICAgICAgICBFbWJlci5hZGRPYnNlcnZl cihpdGVtLCBzb3J0UHJvcGVydHksIHRoaXMsICdjb250ZW50SXRlbVNvcnRQ cm9wZXJ0eURpZENoYW5nZScpOwogICAgICAgIH0sIHRoaXMpOwogICAgICB9 LCB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xlci5leHRlbmQo ewogICAgICBsb29rdXBJdGVtQ29udHJvbGxlcjogZnVuY3Rpb24oIG9iamVj dCApIHsKICAgICAgICBpZiAob2JqZWN0LmdldCgnaXNTcGVjaWFsJykpIHsK ICAgICAgICAgIHJldHVybiAic3BlY2lhbCI7IC8vIHVzZSBBcHAuU3BlY2lh bENvbnRyb2xsZXIKICAgICAgICB9IGVsc2UgewogICAgICAgICAgcmV0dXJu ICJyZWd1bGFyIjsgLy8gdXNlIEFwcC5SZWd1bGFyQ29udHJvbGxlcgogICAg ICAgIH0KICAgICAgfQogICAgfSk7CiAgICBgYGAKCiAgICBAbWV0aG9kIGxv b2t1cEl0ZW1Db250cm9sbGVyCiAgICBAcGFyYW0ge09iamVjdH0gb2JqZWN0 CiAgICBAcmV0dXJuIHtTdHJpbmd9CiAgKi8KICBsb29rdXBJdGVtQ29udHJv bGxlcjogZnVuY3Rpb24ob2JqZWN0KSB7CiAgICByZXR1cm4gZ2V0KHRoaXMs ICdpdGVtQ29udHJvbGxlcicpOwogIH0sCgogIG9iamVjdEF0Q29udGVudDog ZnVuY3Rpb24oaWR4KSB7CiAgICB2YXIgbGVuZ3RoID0gZ2V0KHRoaXMsICds ZW5ndGgnKSwKICAgICAgICBhcnJhbmdlZENvbnRlbnQgPSBnZXQodGhpcywn YXJyYW5nZWRDb250ZW50JyksCiAgICAgICAgb2JqZWN0ID0gYXJyYW5nZWRD b250ZW50ICYmIGFycmFuZ2VkQ29udGVudC5vYmplY3RBdChpZHgpOwoKICAg IGlmIChpZHggPj0gMCAmJiBpZHggPCBsZW5ndGgpIHsKICAgICAgdmFyIGNv bnRyb2xsZXJDbGFzcyA9IHRoaXMubG9va3VwSXRlbUNvbnRyb2xsZXIob2Jq ZWN0KTsKICAgICAgaWYgKGNvbnRyb2xsZXJDbGFzcykgewogICAgICAgIHJl dHVybiB0aGlzLmNvbnRyb2xsZXJBdChpZHgsIG9iamVjdCwgY29udHJvbGxl ckNsYXNzKTsKICAgICAgfQogIC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N1YkNvbnRyb2xsZXJz W2lkeF0sCiAgICAgICAgZnVsbE5hbWU7CgogICAgaWYgKHN1YkNvbnRyb2xs ZXIpIHsgcmV0dXJuIHN1YkNvbnRyb2xsZXI7IH0KCiAgICBmdWxsTmFtZSA9 ICJjb250cm9sbGVyOiIgKyBjb250cm9sbGVyQ2xhc3M7CgogICAgaWYgKCFj b250YWluZXIuaGFzKGZ1bGxOYW1lKSkgewogICAgICB0aHJvdyBuZXcgRW1i ZXIuRXJyb3IoJ0NvdWxkIG5vdCByZXNvbHZlIGl0ZW1Db250cm9sbGVyOiAi JyArIGNvbnRyb2xsZXJDbGFzcyArICciJyk7CiAgICB9CiAgICB2YXIgcGFy ZW50Q29udHJvbGxlcjsKICAgIGlmICh0aGlzLl9pc1ZpcnR1YWwpIHsKICAg ICAgcGFyZW50Q29udHJvbGxlciA9IGdldCh0aGlzLCAncGFyZW50Q29udHJv bGxlcicpOwogICAgfQogICAgcGFyZW50Q29udHJvbGxlciA9IHBhcmVudENv bnRyb2xsZXIgfHwgdGhpczsKICAgIHN1YkNvbnRyb2xsZXIgPSBjb250YWlu ZXIubG9va3VwRmFjdG9yeShmdWxsTmFtZSkuY3JlYXRlKHsKICAgICAgdGFy Z2V0OiB0aGlzLAogICAgICBwYXJlbnRDb250cm9sbGVyOiBwYXJlbnRDb250 cm9sbGVyLAogICAgICBjb250ZW50OiBvYmplY3QKICAgIH0pOwoKICAgIHN1 YkNvbnRyb2xsZXJzW2lkeF0gPSBzdWJDb250cm9sbGVyOwoKICAgIHJldHVy biBzdWJDb250cm9sbGVyOwogIH0sCgogIF9zdWJDb250cm9sbGVyczogbnVs bCwKCiAgX3Jlc2V0U3ViQ29udHJvbGxlcnM6IGZ1bmN0aW9uKCkgewogICAg dmFyIHN1YkNvbnRyb2xsZXJzID0gZ2V0KHRoaXMsICdfc3ViQ29udHJvbGxl cnMnKTsKICAgIGlmIChzdWJDb250cm9sbGVycykgewogICAgICBmb3JFYWNo KHN1YkNvbnRyb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ZSkgewogICAgdGhpcy5lbGVtZW50U3R5bGUgPSAodGhpcy5l bGVtZW50U3R5bGUgfHwge30pOwoKICAgIHRoaXMuZWxlbWVudFN0eWxlW25h bWVdID0gdmFsdWU7CiAgICByZXR1cm4gdGhpczsKICB9LAoKICBiZWdpbjog ZnVuY3Rpb24odGFnTmFtZSkgewogICAgdGhpcy50YWdOYW1lcy5wdXNoKHRh Z05hbWUgfHwgbnVsbCk7CiAgICByZXR1cm4gdGhpczsKICB9LAoKICBwdXNo T3BlbmluZ1RhZzogZnVuY3Rpb24oKSB7CiAgICB2YXIgdGFnTmFtZSA9IHRo aXMuY3VycmVudFRhZ05hbWUoKTsKICAgIGlmICghdGFnTmFtZSkgeyByZXR1 cm47IH0KCiAgICBpZiAodGhpcy5faGFzRWxlbWVudCAmJiAhdGhpcy5fZWxl bWVudCAmJiB0aGlzLmJ1ZmZlci5sZW5ndGggPT09IDApIHsKICAgICAgdGhp cy5fZWxlbWVudCA9IHRoaXMuZ2VuZXJhdGVFbGVtZW50KCk7CiAgICAgIHJl dHVybjsKICAgIH0KCiAgICB2YXIgYnVmZmVyID0gdGhpcy5idWZmZXIsCiAg ICAgICAgaWQgPSB0aGlzLmVsZW1lbnRJZCwKICAgICAgICBjbGFzc2VzID0g dGhpcy5jbGFzc2VzLAogICAgICAgIGF0dHJzID0gdGhpcy5lbGVtZW50QXR0 cmlidXRlcywKICAgICAgICBwcm9wcyA9IHRoaXMuZWxlbWVudFByb3BlcnRp ZXMsCiAgICAgICAgc3R5bGUgPSB0aGlzLmVsZW1lbnRTdHlsZSwKICAgICAg ICBhdHRyLCBwcm9wOwoKICAgIGJ1ZmZlciArPSAnPCcgKyBzdHJpcFRhZ05h bWUodGFnTmFtZSk7CgogICAgaWYgKGlkKSB7CiAgICAgIGJ1ZmZlciArPSAn IGlkPSInICsgZXNjYXBlQXR0cmlidXRlKGlkKSArICciJzsKICAgICAgdGhp cy5lbGVtZW50SWQgPSBudWxsOwogICAgfQogICAgaWYgKGNsYXNzZXMpIHsK ICAgICAgYnVmZmVyICs9ICcgY2xhc3M9IicgKyBlc2NhcGVBdHRyaWJ1dGUo Y2xhc3Nlcy5qb2luKCcgJykpICsgJyInOwogICAgICB0aGlzLmNsYXNzZXMg PSBudWxsOwogICAgICB0aGlzLmVsZW1lbnRDbGFzc2VzID0gbnVsbDsKICAg IH0KCiAgICBpZiAoc3R5bGUpIHsKICAgICAgYnVmZmVyICs9ICcgc3R5bGU9 Iic7CgogICAgICBmb3IgKHByb3AgaW4gc3R5bGUpIHsKICAgICAgICBpZiAo c3R5bGUuaGFzT3duUHJvcGVydHkocHJvcCkpIHsKICAgICAgICAgIGJ1ZmZl ciArPSBwcm9wICsgJzonICsgZXNjYXBlQXR0cmlidXRlKHN0eWxlW3Byb3Bd KSArICc7JzsKICAgICAgICB9CiAgICAgIH0KCiAgICAgIGJ1ZmZlciArPSAn Iic7CgogICAgICB0aGlzLmVsZW1lbnRTdHlsZSA9IG51bGw7CiAgICB9Cgog ICAgaWYgKGF0dHJzKSB7CiAgICAgIGZvciAoYXR0ciBpbiBhdHRycykgewog ICAgICAgIGlmIChhdHRycy5oYXNPd25Qcm9wZXJ0eShhdHRyKSkgewogICAg ICAgICAgYnVmZmVyICs9ICcgJyArIGF0dHIgKyAnPSInICsgZXNjYXBlQXR0 cmlidXRlKGF0dHJzW2F0dHJdKSArICciJzsKICAgICAgICB9CiAgICAgIH0K CiAgICAgIHRoaXMuZWxlbWVudEF0dHJpYnV0ZXMgPSBudWxsOwogICAgfQoK ICAgIGlmIChwcm9wcykgewogICAgICBmb3IgKHByb3AgaW4gcHJvcHMpIHsK ICAgICAgICBpZiAocHJvcHMuaGFzT3duUHJvcGVydHkocHJvcCkpIHsKICAg ICAgICAgIHZhciB2YWx1ZSA9IHByb3BzW3Byb3BdOwogICAgICAgICAgaWYg KHZhbHVlIHx8IHR5cGVvZih2YWx1ZSkgPT09ICdudW1iZXInKSB7CiAgICAg ICAgICAgIGlmICh2YWx1ZSA9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CiAgICAgICAgc3R5 bGVCdWZmZXIgPSAnJywgYXR0ciwgcHJvcCwgdGFnU3RyaW5nOwoKICAgIGlm IChhdHRycyAmJiBhdHRycy5uYW1lICYmICFjYW5TZXROYW1lT25JbnB1dHMp IHsKICAgICAgLy8gSUUgYWxsb3dzIHBhc3NpbmcgYSB0YWcgdG8gY3JlYXRl RWxlbWVudC4gU2VlIG5vdGUgb24gYGNhblNldE5hbWVPbklucHV0c2AgYWJv dmUgYXMgd2VsbC4KICAgICAgdGFnU3RyaW5nID0gJzwnK3N0cmlwVGFnTmFt ZSh0YWdOYW1lKSsnIG5hbWU9IicrZXNjYXBlQXR0cmlidXRlKGF0dHJzLm5h bWUpKyciPic7CiAgICB9IGVsc2UgewogICAgICB0YWdTdHJpbmcgPSB0YWdO YW1lOwogICAgfQoKICAgIHZhciBlbGVtZW50ID0gZG9jdW1lbnQuY3JlYXRl RWxlbWVudCh0YWdTdHJpbmcpLAogICAgICAgICRlbGVtZW50ID0gRW1iZXIu JChlbGVtZW50KTsKCiAgICBpZiAoaWQpIHsKICAgICAgJGVsZW1lbnQuYXR0 cignaWQnLCBpZCk7CiAgICAgIHRoaXMuZWxlbWVudElkID0gbnVsbDsKICAg IH0KICAgIGlmIChjbGFzc2VzKSB7CiAgICAgICRlbGVtZW50LmF0dHIoJ2Ns YXNzJywgY2xhc3Nlcy5qb2luKCcgJykpOwogICAgICB0aGlzLmNsYXNzZXMg PSBudWxsOwogICAgICB0aGlzLmVsZW1lbnRDbGFzc2VzID0gbnVsbDsKICAg IH0KCiAgICBpZiAoc3R5bGUpIHsKICAgICAgZm9yIChwcm9wIGluIHN0eWxl KSB7CiAgICAgICAgaWYgKHN0eWxlLmhhc093blByb3BlcnR5KHByb3ApKSB7 CiAgICAgICAgICBzdHlsZUJ1ZmZlciArPSAocHJvcCArICc6JyArIHN0eWxl W3Byb3BdICsgJzsnKTsKICAgICAgICB9CiAgICAgIH0KCiAgICAgICRlbGVt ZW50LmF0dHIoJ3N0eWxlJywgc3R5bGVCdWZmZXIpOwoKICAgICAgdGhpcy5l bGVtZW50U3R5bGUgPSBudWxsOwogICAgfQoKICAgIGlmIChhdHRycykgewog ICAgICBmb3IgKGF0dHIgaW4gYXR0cnMpIHsKICAgICAgICBpZiAoYXR0cnMu aGFzT3duUHJvcGVydHkoYXR0cikpIHsKICAgICAgICAgICRlbGVtZW50LmF0 dHIoYXR0ciwgYXR0cnNbYXR0cl0pOwogICAgICAgIH0KICAgICAgfQoKICAg ICAgdGhpcy5lbGVtZW50QXR0cmlidXRlcyA9IG51bGw7CiAgICB9CgogICAg aWYgKHByb3BzKSB7CiAgICAgIGZvciAocHJvcCBpbiBwcm9wcykgewogICAg ICAgIGlmIChwcm9wcy5oYXNPd25Qcm9wZXJ0eShwcm9wKSkgewogICAgICAg ICAgJGVsZW1lbnQucHJvcChwcm9wLCBwcm9wc1twcm9wXSk7CiAgICAgICAg fQogICAgICB9CgogICAgICB0aGlzLmVsZW1lbnRQcm9wZXJ0aWVzID0gbnVs bDsKICAgIH0KCiAgICByZXR1cm4gZWxlbWVudDsKICB9LAoKICAvKioKICAg IEBtZXRob2QgZWxlbWVudAogICAgQHJldHVybiB7RE9NRWxlbWVudH0gVGhl IGVsZW1lbnQgY29ycmVzcG9uZGluZyB0byB0aGUgZ2VuZXJhdGVkIEhUTUwK ICAgICAgb2YgdGhpcyBidWZmZXIKICAqLwogIGVsZW1lbnQ6IGZ1bmN0aW9u KCkgewogICAgdmFyIGh0bWwgPSB0aGlzLmlubmVyU3RyaW5nKCk7CgogICAg aWYgKGh0bWwpIHsKICAgICAgdGhpcy5fZWxlbWVudCA9IEVtYmVyLlZpZXdV dGlscy5zZXRJbm5lckhUTUwodGhpcy5fZWxlbWVudCwgaHRtbCk7CiAgICB9 CgogICAgcmV0dXJuIHRoaXMuX2VsZW1lbnQ7CiAgfSwKCiAgLyoqCiAgICBH ZW5lcmF0ZXMgdGhlIEhUTUwgY29udGVudCBmb3IgdGhpcyBidWZmZXIuC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CcsCiAg ICB0b3VjaGNhbmNlbCA6ICd0b3VjaENhbmNlbCcsCiAgICBrZXlkb3duICAg ICA6ICdrZXlEb3duJywKICAgIGtleXVwICAgICAgIDogJ2tleVVwJywKICAg IGtleXByZXNzICAgIDogJ2tleVByZXNzJywKICAgIG1vdXNlZG93biAgIDog J21vdXNlRG93bicsCiAgICBtb3VzZXVwICAgICA6ICdtb3VzZVVwJywKICAg IGNvbnRleHRtZW51IDogJ2NvbnRleHRNZW51JywKICAgIGNsaWNrICAgICAg IDogJ2NsaWNrJywKICAgIGRibGNsaWNrICAgIDogJ2RvdWJsZUNsaWNrJywK ICAgIG1vdXNlbW92ZSAgIDogJ21vdXNlTW92ZScsCiAgICBmb2N1c2luICAg ICA6ICdmb2N1c0luJywKICAgIGZvY3Vzb3V0ICAgIDogJ2ZvY3VzT3V0JywK ICAgIG1vdXNlZW50ZXIgIDogJ21vdXNlRW50ZXInLAogICAgbW91c2VsZWF2 ZSAgOiAnbW91c2VMZWF2ZScsCiAgICBzdWJtaXQgICAgICA6ICdzdWJtaXQn LAogICAgaW5wdXQgICAgICAgOiAnaW5wdXQnLAogICAgY2hhbmdlICAgICAg OiAnY2hhbmdlJywKICAgIGRyYWdzdGFydCAgIDogJ2RyYWdTdGFydCcsCiAg ICBkcmFnICAgICAgICA6ICdkcmFnJywKICAgIGRyYWdlbnRlciAgIDogJ2Ry YWdFbnRlcicsCiAgICBkcmFnbGVhdmUgICA6ICdkcmFnTGVhdmUnLAogICAg ZHJhZ292ZXIgICAgOiAnZHJhZ092ZXInLAogICAgZHJvcCAgICAgICAgOiAn ZHJvcCcsCiAgICBkcmFnZW5kICAgICA6ICdkcmFnRW5kJwogIH0sCgogIC8q KgogICAgVGhlIHJvb3QgRE9NIGVsZW1lbnQgdG8gd2hpY2ggZXZlbnQgbGlz dGVuZXJzIHNob3VsZCBiZSBhdHRhY2hlZC4gRXZlbnQKICAgIGxpc3RlbmVy cyB3aWxsIGJlIGF0dGFjaGVkIHRvIH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250ZW50LCBzdGFy dCwgcmVtb3ZlZCwgYWRkZWQpIHsKICAgIHZhciBhZGRlZFZpZXdzID0gW10s IHZpZXcsIGl0ZW0sIGlkeCwgbGVuLCBpdGVtVmlld0NsYXNzLAogICAgICBl bXB0eVZpZXc7CgogICAgbGVuID0gY29udGVudCA/IGdldChjb250ZW50LCAn bGVuZ3RoJykgOiAwOwoKICAgIGlmIChsZW4pIHsKICAgICAgaXRlbVZpZXdD bGFzcyA9IGdldCh0aGlzLCAnaXRlbVZpZXdDbGFzcycpOwoKICAgICAgaWYg KCdzdHJpbmcnID09PSB0eXBlb2YgaXRlbVZpZXdDbGFzcykgewogICAgICAg IGl0ZW1WaWV3Q2xhc3MgPSBnZXQoaXRlbVZpZXdDbGFzcykgfHwgaXRlbVZp ZXdDbGFzczsKICAgICAgfQoKICAgICAgRW1iZXIuYXNzZXJ0KGZtdCgiaXRl bVZpZXdDbGFzcyBtdXN0IGJlIGEgc3ViY2xhc3Mgb2YgRW1iZXIuVmlldywg bm90ICVAIiwKICAgICAgICAgICAgICAgICAgICAgICBbaXRlbVZpZXdDbGFz c10pLAogICAgICAgICAgICAgICAgICAgICAgICdzdHJpbmcnID09PSB0eXBl b2YgaXRlbVZpZXdDbGFzcyB8fCBFbWJlci5WaWV3LmRldGVjdChpdGVtVmll d0NsYXNzKSk7CgogICAgICBmb3IgKGlkeCA9IHN0YXJ0OyBpZHggPCBzdGFy dCthZGRlZDsgaWR4KyspIHsKICAgICAgICBpdGVtID0gY29udGVudC5vYmpl Y3RBdChpZHgpOwoKICAgICAgICB2aWV3ID0gdGhpcy5jcmVhdGVDaGlsZFZp ZXcoaXRlbVZpZXdDbGFzcywgewogICAgICAgICAgY29udGVudDogaXRlbSwK ICAgICAgICAgIGNvbnRlbnRJbmRleDogaWR4CiAgICAgICAgfSk7CgogICAg ICAgIGFkZGVkVmlld3MucHVzaCh2aWV3KTsKICAgICAgfQogICAgfSBlbHNl IHsKICAgICAgZW1wdHlWaWV3ID0gZ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T09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09 PT09PT09PT09PT09PT09PT09PT09PT09PQoKICAgIHZhciBLID0gZnVuY3Rp b24oKSB7fSwKICAgICAgICBndWlkID0gMCwKICAgICAgICBkaXNhYmxlUmFu Z2UgPSAoZnVuY3Rpb24oKXsKICAgICAgICAgIGlmICgndW5kZWZpbmVkJyAh PT0gdHlwZW9mIE1ldGFtb3JwaEVOVikgewogICAgICAgICAgICByZXR1cm4g TWV0YW1vcnBoRU5WLkRJU0FCTEVfUkFOR0VfQVBJOwogICAgICAgICAgfSBl bHNlIGlmICgndW5kZWZpbmVkJyAhPT0gRU5WKSB7CiAgICAgICAgICAgIHJl dHVybiBFTlYuRElTQUJMRV9SQU5HRV9BUEk7CiAgICAgICAgICB9IGVsc2Ug ewogICAgICAgICAgICByZXR1cm4gZmFsc2U7CiAgICAgICAgICB9CiAgICAg ICAgfSkoKSwKCiAgICAgICAgLy8gRmVhdHVyZS1kZXRlY3QgdGhlIFczQyBy YW5nZSBBUEksIHRoZSBleHRlbmRlZCBjaGVjayBpcyBmb3IgSUU5IHdoaWNo IG9ubHkgcGFydGlhbGx5IHN1cHBvcnRzIHJhbmdlcwogICAgICAgIHN1cHBv cnRzUmFuZ2UgPSAoIWRpc2FibGVSYW5nZSkgJiYgdHlwZW9mIGRvY3VtZW50 ICE9PSAndW5kZWZpbmVkJyAmJiAoJ2NyZWF0ZVJhbmdlJyBpbiBkb2N1bWVu dCkgJiYgKHR5cGVvZiBSYW5nZSAhPT0gJ3VuZGVmaW5lZCcpICYmIFJhbmdl LnByb3RvdHlwZS5jcmVhdGVDb250ZXh0dWFsRnJhZ21lbnQsCgogICAgICAg IC8vIEludGVybmV0IEV4cGxvcmVyIHByaW9yIHRvIDkgZG9lcyBub3QgYWxs b3cgc2V0dGluZyBpbm5lckhUTUwgaWYgdGhlIGZpcnN0IGVsZW1lbnQKICAg ICAgICAvLyBpcyBhICJ6ZXJvLXNjb3BlIiBlbGVtZW50L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ZW50Tm9kZTsKICAgICAgICB9CgogICAgICAgIHJldHVybiBzdGFydDsKICAg ICAgfTsKCiAgICAgIC8qCiAgICAgICAqIFdoZW4gYXV0b21hdGljYWxseSBh ZGRpbmcgYSB0Ym9keSwgSW50ZXJuZXQgRXhwbG9yZXIgaW5zZXJ0cyB0aGUK ICAgICAgICogdGJvZHkgaW1tZWRpYXRlbHkgYmVmb3JlIHRoZSBmaXJzdCA8 dHI+LiBPdGhlciBicm93c2VycyBjcmVhdGUgaXQKICAgICAgICogYmVmb3Jl IHRoZSBmaXJzdCBub2RlLCBubyBtYXR0ZXIgd2hhdC4KICAgICAgICoKICAg ICAgICogVGhpcyBtZWFucyB0aGUgdGhlIGZvbGxvd2luZyBjb2RlOgogICAg ICAgKgogICAgICAgKiAgICAgZGl2ID0gZG9jdW1lbnQuY3JlYXRlRWxlbWVu dCgiZGl2Iik7CiAgICAgICAqICAgICBkaXYuaW5uZXJIVE1MID0gIjx0YWJs ZT48c2NyaXB0IGlkPSdmaXJzdCc+PC9zY3JpcHQ+PHRyPjx0ZD5oaTwvdGQ+ PC90cj48c2NyaXB0IGlkPSdsYXN0Jz48L3NjcmlwdD48L3RhYmxlPgogICAg ICAgKgogICAgICAgKiBHZW5lcmF0ZXMgdGhlIGZvbGxvd2luZyBET00gaW4g SUU6CiAgICAgICAqCiAgICAgICAqICAgICArIGRpdgogICAgICAgKiAgICAg ICArIHRhYmxlCiAgICAgICAqICAgICAgICAgLSBzY3JpcHQgaWQ9J2ZpcnN0 JwogICAgICAgKiAgICAgICAgICsgdGJvZHkKICAgICAgICogICAgICAgICAg ICsgdHIKICAgICAgICogICAgICAgICAgICAgKyB0ZAogICAgICAgKiAgICAg ICAgICAgICAgIC0gImhpIgogICAgICAgKiAgICAgICAgICAgLSBzY3JpcHQg aWQ9J2xhc3QnCiAgICAgICAqCiAgICAgICAqIFdoaWNoIG1lYW5zIHRoYXQg dGhlIHR3byBzY3JpcHQgdGFncywgZXZlbiB0aG91Z2ggdG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VudE5vZGUucmVtb3ZlQ2hpbGQobm9kZSk7CgogICAgICAgICAg Ly8gaWYgdGhpcyBpcyB0aGUgbGFzdCBub2RlIGFuZCB3ZSBkaWRuJ3QgYnJl YWsgYmVmb3JlCiAgICAgICAgICAvLyAoYmVjYXVzZSB3ZSB3YW50ZWQgdG8g cmVtb3ZlIHRoZSBvdXRlciBub2RlcyksIGJyZWFrCiAgICAgICAgICAvLyBu b3cuCiAgICAgICAgICBpZiAobGFzdCkgeyBicmVhazsgfQoKICAgICAgICAg IG5vZGUgPSBuZXh0U2libGluZzsKICAgICAgICB9CgogICAgICAgIC8vIGdl dCB0aGUgZmlyc3Qgbm9kZSBmb3IgdGhlIEhUTUwgc3RyaW5nLCBldmVuIGlu IGNhc2VzIGxpa2UKICAgICAgICAvLyB0YWJsZXMgYW5kIGxpc3RzIHdoZXJl IGEgc2ltcGxlIGlubmVySFRNTCBvbiBhIGRpdiB3b3VsZAogICAgICAgIC8v IHN3YWxsb3cgc29tZSBvZiB0aGUgY29udGVudC4KICAgICAgICBub2RlID0g Zmlyc3ROb2RlRm9yKHN0YXJ0LnBhcmVudE5vZGUsIGh0bWwpOwoKICAgICAg ICBpZiAob3V0ZXJUb28pIHsKICAgICAgICAgIHN0YXJ0LnBhcmVudE5vZGUu cmVtb3ZlQ2hpbGQoc3RhcnQpOwogICAgICAgIH0KCiAgICAgICAgLy8gY29w eSB0aGUgbm9kZXMgZm9yIHRoZSBIVE1MIGJldHdlZW4gdGhlIHN0YXJ0aW5n IGFuZCBlbmRpbmcKICAgICAgICAvLyBwbGFjZWhvbGRlci4KICAgICAgICB3 aGlsZSAobm9kZSkgewogICAgICAgICAgbmV4dFNpYmxpbmcgPSBub2RlLm5l eHRTaWJsaW5nOwogICAgICAgICAgcGFyZW50Tm9kZS5pbnNlcnRCZWZvcmUo bm9kZSwgZW5kKTsKICAgICAgICAgIG5vZGUgPSBuZXh0U2libGluZzsKICAg ICAgICB9CiAgICAgIH07CgogICAgICAvLyByZW1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o dGhpcy5lbmQpOwogICAgICAgIHZhciBpbnNlcnRCZWZvcmUgPSBlbmQubmV4 dFNpYmxpbmc7CiAgICAgICAgdmFyIHBhcmVudE5vZGUgPSBlbmQucGFyZW50 Tm9kZTsKICAgICAgICB2YXIgbmV4dFNpYmxpbmc7CiAgICAgICAgdmFyIG5v ZGU7CgogICAgICAgIC8vIGdldCB0aGUgZmlyc3Qgbm9kZSBmb3IgdGhlIEhU TUwgc3RyaW5nLCBldmVuIGluIGNhc2VzIGxpa2UKICAgICAgICAvLyB0YWJs ZXMgYW5kIGxpc3RzIHdoZXJlIGEgc2ltcGxlIGlubmVySFRNTCBvbiBhIGRp diB3b3VsZAogICAgICAgIC8vIHN3YWxsb3cgc29tZSBvZiB0aGUgY29udGVu dC4KICAgICAgICBub2RlID0gZmlyc3ROb2RlRm9yKHBhcmVudE5vZGUsIGh0 bWwpOwoKICAgICAgICAvLyBjb3B5IHRoZSBub2RlcyBmb3IgdGhlIEhUTUwg YmV0d2VlbiB0aGUgc3RhcnRpbmcgYW5kIGVuZGluZwogICAgICAgIC8vIHBs YWNlaG9sZGVyLgogICAgICAgIHdoaWxlIChub2RlKSB7CiAgICAgICAgICBu ZXh0U2libGluZyA9IG5vZGUubmV4dFNpYmxpbmc7CiAgICAgICAgICBwYXJl bnROb2RlLmluc2VydEJlZm9yZShub2RlLCBpbnNlcnRCZWZvcmUpOwogICAg ICAgICAgbm9kZSA9IG5leHRTaWJsaW5nOwogICAgICAgIH0KICAgICAgfTsK CiAgICAgIHByZXBlbmRGdW5jID0gZnVuY3Rpb24oaHRtbCkgewogICAgICAg IHZhciBzdGFydCA9IGRvY3VtZW50LmdldEVsZW1lbnRCeUlkKHRoaXMuc3Rh cnQpOwogICAgICAgIHZhciBwYXJlbnROb2RlID0gc3RhcnQucGFyZW50Tm9k ZTsKICAgICAgICB2YXIgbmV4dFNpYmxpbmc7CiAgICAgICAgdmFyIG5vZGU7 CgogICAgICAgIG5vZGUgPSBmaXJzdE5vZG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ydGllc1ts b2NdKTsKICAgICAgaWYgKHR5cGVzW2xvY10gPT09ICdJRCcpIHsKICAgICAg ICB2YXIgbm9ybWFsaXplZFByb3AgPSBub3JtYWxpemVQYXRoKGN1cnJlbnRD b250ZXh0LCBwcm9wZXJ0aWVzW2xvY10sIGRhdGEpOwogICAgICAgIG5vcm1h bGl6ZWRQcm9wZXJ0aWVzLnB1c2gobm9ybWFsaXplZFByb3ApOwogICAgICAg IHdhdGNoZWRQcm9wZXJ0aWVzLnB1c2gobm9ybWFsaXplZFByb3ApOwogICAg ICB9IGVsc2UgewogICAgICAgIGlmKGRhdGEuaXNVbmJvdW5kKSB7CiAgICAg ICAgICBub3JtYWxpemVkUHJvcGVydGllcy5wdXNoKHtwYXRoOiBwcm9wZXJ0 aWVzW2xvY119KTsKICAgICAgICB9ZWxzZSB7CiAgICAgICAgICBub3JtYWxp emVkUHJvcGVydGllcy5wdXNoKG51bGwpOwogICAgICAgIH0KICAgICAgfQog ICAgfQoKICAgIC8vIEhhbmRsZSBjYXNlIHdoZW4gaGVscGVyIGludm9jYXRp b24gaXMgcHJlY2VkZWQgYnkgYHVuYm91bmRgLCBlLmcuCiAgICAvLyB7e3Vu Ym91bmQgbXlIZWxwZXIgZm9vfX0KICAgIGlmIChkYXRhLmlzVW5ib3VuZCkg ewogICAgICByZXR1cm4gZXZhbHVhdGVVbmJvdW5kSGVscGVyKHRoaXMsIGZu LCBub3JtYWxpemVkUHJvcGVydGllcywgb3B0aW9ucyk7CiAgICB9CgogICAg dmFyIGJpbmRWaWV3ID0gbmV3IEVtYmVyLl9TaW1wbGVIYW5kbGViYXJzVmll dyhudWxsLCBudWxsLCAhb3B0aW9ucy5oYXNoLnVuZXNjYXBlZCwgb3B0aW9u cy5kYXRhKTsKCiAgICAvLyBPdmVycmlkZSBTaW1wbGVIYW5kbGViYXJzVmll dydzIG1ldGhvZCBmb3IgZ2VuZXJhdGluZyB0aGUgdmlldydzIGNvbnRlbnQu CiAgICBiaW5kVmlldy5ub3JtYWxpemVkVmFsdWUgPSBmdW5jdGlvbigpIHsK ICAgICAgdmFyIGFyZ3MgPSBbXSwgYm91bmRPcHRpb247CgogICAgICAvLyBD b3B5IG92ZXIgYm91bmQgaGFzaCBvcHRpb25zLgogICAgICBmb3IgKGJvdW5k T3B0aW9uIGluIGJvdW5kT3B0aW9ucykgewogICAgICAgIGlmICghYm91bmRP cHRpb25zLmhhc093blByb3BlcnR5KGJvdW5kT3B0aW9uKSkgeyBjb250aW51 ZTsgfQogICAgICAgIHByb3BlcnR5ID0gbm9ybWFsaXplUGF0aChjdXJyZW50 Q29udGV4dCwgYm91bmRPcHRpb25zW2JvdW5kT3B0aW9uXSwgZGF0YSk7CiAg ICAgICAgYmluZFZpZXcucGF0aCA9IHByb3BlcnR5LnBhdGg7CiAgICAgICAg YmluZFZpZXcucGF0aFJvb3QgPSBwcm9wZXJ0eS5yb290OwogICAgICAgIGhh c2hbYm91bmRPcHRpb25dID0gbm9ybWFsaXplZFZhbHVlLmNhbGwoYmluZFZp ZXcpOwogICAgICB9CgogICAgICBmb3IgKGxvYyA9IDA7IGxvYyA8IG51bVBy b3BlcnRpZXM7ICsrbG9jKSB7CiAgICAgICAgcHJvcGVydHkgPSBub3JtYWxp emVkUHJvcGVydGllc1tsb2NdOwogICAgICAgIGlmIChwcm9wZXJ0eSkgewog ICAgICAgICAgYmluZFZpZXcucGF0aCA9IHByb3BlcnR5LnBhdGg7CiAgICAg ICAgICBiaW5kVmlldy5wYXRoUm9vdCA9IHByb3BlcnR5LnJvb3Q7CiAgICAg ICAgICBhcmdzLnB1c2gobm9ybWFsaXplZFZhbHVlLmNhbGwoYmluZFZpZXcp KTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgYXJncy5wdXNoKHByb3Bl cnRpZXNbbG9jXSk7CiAgICAgICAgfQogICAgICB9CiAgICAgIGFyZ3MucHVz aChvcHRpb25zKTsKCiAgICAgIC8vIFJ1biB0aGUgc3VwcGxpZWQgaGVscGVy IGZ1bm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ZXIsICdjb250ZW50JywgcmVz dWx0KTsKICAgICAgICAgICAgcmVzdWx0ID0gX2NvbnRleHRDb250cm9sbGVy OwogICAgICAgICAgfQogICAgICAgICAgc2V0KHRoaXMsICdfY29udGV4dCcs IHJlc3VsdCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAvLyBUaGlzIGlz IG5vdCBhIGJpbmQgYmxvY2ssIGp1c3QgcHVzaCB0aGUgcmVzdWx0IG9mIHRo ZQogICAgICAgIC8vIGV4cHJlc3Npb24gdG8gdGhlIHJlbmRlciBjb250ZXh0 IGFuZCByZXR1cm4uCiAgICAgICAgICBpZiAocmVzdWx0ID09PSBudWxsIHx8 IHJlc3VsdCA9PT0gdW5kZWZpbmVkKSB7CiAgICAgICAgICAgIHJlc3VsdCA9 ICIiOwogICAgICAgICAgfSBlbHNlIGlmICghKHJlc3VsdCBpbnN0YW5jZW9m IEhhbmRsZWJhcnMuU2FmZVN0cmluZykpIHsKICAgICAgICAgICAgcmVzdWx0 ID0gU3RyaW5nKHJlc3VsdCk7CiAgICAgICAgICB9CgogICAgICAgICAgaWYg KGVzY2FwZSkgeyByZXN1bHQgPSBIYW5kbGViYXJzLlV0aWxzLmVzY2FwZUV4 cHJlc3Npb24ocmVzdWx0KTsgfQogICAgICAgICAgYnVmZmVyLnB1c2gocmVz dWx0KTsKICAgICAgICAgIHJldHVybjsKICAgICAgICB9CiAgICAgIH0KICAg IH0gZWxzZSBpZiAoaW52ZXJzZVRlbXBsYXRlKSB7CiAgICAgIHNldCh0aGlz LCAndGVtcGxhdGUnLCBpbnZlcnNlVGVtcGxhdGUpOwoKICAgICAgaWYgKHBy ZXNlcnZlQ29udGV4dCkgewogICAgICAgIHNldCh0aGlzLCAnX2NvbnRleHQn LCBjb250ZXh0KTsKICAgICAgfSBlbHNlIHsKICAgICAgICBzZXQodGhpcywg J19jb250ZXh0JywgcmVzdWx0KTsKICAgICAgfQogICAgfSBlbHNlIHsKICAg ICAgc2V0KHRoaXMsICd0Z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pZmllZCBhbiBpdGVtVmlldywgYnV0 IHRoZSBjdXJyZW50IGNvbnRleHQgaGFzIG5vICcgKwogICAgICAgICAgICAg ICAgICdjb250YWluZXIgdG8gbG9vayB0aGUgaXRlbVZpZXcgdXAgaW4uIFRo aXMgcHJvYmFibHkgbWVhbnMgJyArCiAgICAgICAgICAgICAgICAgJ3RoYXQg eW91IGNyZWF0ZWQgYSB2aWV3IG1hbnVhbGx5LCBpbnN0ZWFkIG9mIHRocm91 Z2ggdGhlICcgKwogICAgICAgICAgICAgICAgICdjb250YWluZXIuIEluc3Rl YWQsIHVzZSBjb250YWluZXIubG9va3VwKCJ2aWV3OnZpZXdOYW1lIiksICcg KwogICAgICAgICAgICAgICAgICd3aGljaCB3aWxsIHByb3Blcmx5IGluc3Rh bnRpYXRlIHlvdXIgdmlldy4nLAogICAgICAgICAgICAgICAgIGNvbnRyb2xs ZXIgJiYgY29udHJvbGxlci5jb250YWluZXIpOwogICAgY29udGFpbmVyID0g Y29udHJvbGxlci5jb250YWluZXI7CiAgICBpdGVtVmlld0NsYXNzID0gY29u dGFpbmVyLmxvb2t1cEZhY3RvcnkoJ3ZpZXc6JyArIGhhc2guaXRlbVZpZXcp OwogICAgRW1iZXIuYXNzZXJ0KCdZb3Ugc3BlY2lmaWVkIHRoZSBpdGVtVmll dyAnICsgaGFzaC5pdGVtVmlldyArICIsIGJ1dCBpdCB3YXMgIiArCiAgICAg ICAgICAgICAgICAgIm5vdCBmb3VuZCBhdCAiICsgY29udGFpbmVyLmRlc2Ny aWJlKCJ2aWV3OiIgKyBoYXNoLml0ZW1WaWV3KSArCiAgICAgICAgICAgICAg ICAgIiAoYW5kIGl0IHdhcyBub3QgcmVnaXN0ZXJlZCBpbiB0aGUgY29udGFp bmVyKSIsICEhaXRlbVZpZXdDbGFzcyk7CiAgfSBlbHNlIGlmIChoYXNoLml0 ZW1WaWV3Q2xhc3MpIHsKICAgIGl0ZW1WaWV3Q2xhc3MgPSBoYW5kbGViYXJz R2V0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N0aW9u KCkgewovKioKQG1vZHVsZSBlbWJlcgpAc3VibW9kdWxlIGVtYmVyLWhhbmRs ZWJhcnMKKi8KCnZhciBnZXQgPSBFbWJlci5nZXQsIHNldCA9IEVtYmVyLnNl dDsKdmFyIGZtdCA9IEVtYmVyLlN0cmluZy5mbXQ7CgpFbWJlci5IYW5kbGVi YXJzLkVhY2hWaWV3ID0gRW1iZXIuQ29sbGVjdGlvblZpZXcuZXh0ZW5kKEVt YmVyLl9NZXRhbW9ycGgsIHsKICBpbml0OiBmdW5jdGlvbigpIHsKICAgIHZh ciBpdGVtQ29udHJvbGxlciA9IGdldCh0aGlzLCAnaXRlbUNvbnRyb2xsZXIn KTsKICAgIHZhciBiaW5kaW5nOwoKICAgIGlmIChpdGVtQ29udHJvbGxlcikg ewogICAgICB2YXIgY29udHJvbGxlciA9IGdldCh0aGlzLCAnY29udHJvbGxl ci5jb250YWluZXInKS5sb29rdXBGYWN0b3J5KCdjb250cm9sbGVyOmFycmF5 JykuY3JlYXRlKHsKICAgICAgICBfaXNWaXJ0dWFsOiB0cnVlLAogICAgICAg IHBhcmVudENvbnRyb2xsZXI6IGdldCh0aGlzLCAnY29udHJvbGxlcicpLAog ICAgICAgIGl0ZW1Db250cm9sbGVyOiBpdGVtQ29udHJvbGxlciwKICAgICAg ICB0YXJnZXQ6IGdldCh0aGlzLCAnY29udHJvbGxlcicpLAogICAgICAgIF9l YWNoVmlldzogdGhpcwogICAgICB9KTsKCiAgICAgIHRoaXMuZGlzYWJsZUNv bnRlbnRPYnNlcnZlcnMoZnVuY3Rpb24oKSB7CiAgICAgICAgc2V0KHRoaXMs ICdjb250ZW50JywgY29udHJvbGxlcik7CiAgICAgICAgYmluZGluZyA9IG5l dyBFbWJlci5CaW5kaW5nKCdjb250ZW50JywgJ19lYWNoVmlldy5kYXRhU291 cmNlJykub25lV2F5KCk7CiAgICAgICAgYmluZGluZy5jb25uZWN0KGNvbnRy b2xsZXIpOwogICAgICB9KTsKCiAgICAgIHNldCh0aGlzLCAnX2FycmF5Q29u dHJvbGxlcicsIGNvbnRyb2xsZXIpOwogICAgfSBlbHNlIHsKICAgICAgdGhp cy5kaXNhYmxlQ29udGVudE9ic2VydmVycyhmdW5jdGlvbigpIHsKICAgICAg ICBiaW5kaW5nID0gbmV3IEVtYmVyLkJpbmRpbmcoJ2NvbnRlbnQnLCAnZGF0 YVNvdXJjZScpLm9uZVdheSgpOwogICAgICAgIGJpbmRpbmcuY29ubmVjdCh0 aGlzKTsKICAgICAgfSk7CiAgICB9CgogICAgcmV0dXJuIHRoaXMuX3N1cGVy KCk7CiAgfSwKCiAgX2Fzc2VydEFycmF5TGlrZTogZnVuY3Rpb24oY29udGVu dCkgewogICAgRW1iZXIuYXNzZXJ0KGZtdCgiVGhlIHZhbHVlIHRoYXQgI2Vh Y2ggbG9vcHMgb3ZlciBtdXN0IGJlIGFuIEFycmF5LiBZb3UgIiArCiAgICAg ICAgICAgICAgICAgICAgICJwYXNzZWQgJUAsIGJ1dCBpdCBzaG91bGQgaGF2 ZSBiZWVuIGFuIEFycmF5Q29udHJvbGxlciIsCiAgICAgICAgICAgICAgICAg ICAgIFtjb250ZW50LmNvbnN0cnVjdG9yXSksCiAgICAgICAgICAgICAgICAg ICAgICFFbWJlci5Db250cm9sbGVyTWl4aW4uZGV0ZWN0KGNvbnRlbnQpIHx8 CiAgICAgICAgICAgICAgICAgICAgICAgKGNvbnRlbnQgJiYgY29udGVudC5p c0dlbmVyYXRlZCkgfHwKICAgICAgICAgICAgICAgICAgICAgICBjb250ZW50 IGluc3RhbmNlb2YgRW1iZXIuQXJyYXlDb250cm9sbGVyKTsKICAgIEVtYmVy LmFzc2VydChmbXQoIlRoZSB2YWx1ZSB0aGF0ICNlYWNoIGxvb3BzIG92ZXIg bXVzdCBiZSBhbiBBcnJheS4gWW91IHBhc3NlZCAlQCIsIFsoRW1iZXIuQ29u dHJvbGxlck1peGluLmRldGVjdChjb250ZW50KSAmJiBjb250ZW50LmdldCgn bW9kZW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CkgewogICAgICAgIHJldHVybiB0aGlzLnN0cmluZy5yZXBsYWNlKGVz Y2FwZVJlZ2V4LCAnXFwkMScpOwogICAgICB9LAoKICAgICAgZ2VuZXJhdGU6 IGZ1bmN0aW9uKCkgewogICAgICAgIHJldHVybiB0aGlzLnN0cmluZzsKICAg ICAgfQogICAgfTsKCiAgICBmdW5jdGlvbiBEeW5hbWljU2VnbWVudChuYW1l KSB7IHRoaXMubmFtZSA9IG5hbWU7IH0KICAgIER5bmFtaWNTZWdtZW50LnBy b3RvdHlwZSA9IHsKICAgICAgZWFjaENoYXI6IGZ1bmN0aW9uKGNhbGxiYWNr KSB7CiAgICAgICAgY2FsbGJhY2soeyBpbnZhbGlkQ2hhcnM6ICIvIiwgcmVw ZWF0OiB0cnVlIH0pOwogICAgICB9LAoKICAgICAgcmVnZXg6IGZ1bmN0aW9u KCkgewogICAgICAgIHJldHVybiAiKFteL10rKSI7CiAgICAgIH0sCgogICAg ICBnZW5lcmF0ZTogZnVuY3Rpb24ocGFyYW1zKSB7CiAgICAgICAgcmV0dXJu IHBhcmFtc1t0aGlzLm5hbWVdOwogICAgICB9CiAgICB9OwoKICAgIGZ1bmN0 aW9uIFN0YXJTZWdtZW50KG5hbWUpIHsgdGhpcy5uYW1lID0gbmFtZTsgfQog ICAgU3RhclNlZ21lbnQucHJvdG90eXBlID0gewogICAgICBlYWNoQ2hhcjog ZnVuY3Rpb24oY2FsbGJhY2spIHsKICAgICAgICBjYWxsYmFjayh7IGludmFs aWRDaGFyczogIiIsIHJlcGVhdDogdHJ1ZSB9KTsKICAgICAgfSwKCiAgICAg IHJlZ2V4OiBmdW5jdGlvbigpIHsKICAgICAgICByZXR1cm4gIiguKykiOwog ICAgICB9LAoKICAgICAgZ2VuZXJhdGU6IGZ1bmN0aW9uKHBhcmFtcykgewog ICAgICAgIHJldHVybiBwYXJhbXNbdGhpcy5uYW1lXTsKICAgICAgfQogICAg fTsKCiAgICBmdW5jdGlvbiBFcHNpbG9uU2VnbWVudCgpIHt9CiAgICBFcHNp bG9uU2VnbWVudC5wcm90b3R5cGUgPSB7CiAgICAgIGVhY2hDaGFyOiBmdW5j dGlvbigpIHt9LAogICAgICByZWdleDogZnVuY3Rpb24oKSB7IHJldHVybiAi IjsgfSwKICAgICAgZ2VuZXJhdGU6IGZ1bmN0aW9uKCkgeyByZXR1cm4gIiI7 IH0KICAgIH07CgogICAgZnVuY3Rpb24gcGFyc2Uocm91dGUsIG5hbWVzLCB0 eXBlcykgewogICAgICAvLyBub3JtYWxpemUgcm91dGUgYXMgbm90IHN0YXJ0 aW5nIHdpdGggYSAiLyIuIFJlY29nbml0aW9uIHdpbGwKICAgICAgLy8gYWxz byBub3JtYWxpemUuCiAgICAgIGlmIChyb3V0ZS5jaGFyQXQoMCkgPT09ICIv IikgeyByb3V0ZSA9IHJvdXRlLnN1YnN0cigxKTsgfQoKICAgICAgdmFyIHNl Z21lbnRzID0gcm91dGUuc3BsaXQoIi8iKSwgcmVzdWx0cyA9IFtdOwoKICAg ICAgZm9yICh2YXIgaT0wLCBsPXNlZ21lbnRzLmxlbmd0aDsgaTxsOyBpKysp IHsKICAgICAgICB2YXIgc2VnbWVudCA9IHNlZ21lbnRzW2ldLCBtYXRjaDsK CiAgICAgICAgaWYgKG1hdGNoID0gc2VnbWVudC5tYXRjaCgvXjooW15cL10r KSQvKSkgewogICAgICAgICAgcmVzdWx0cy5wdXNoKG5ldyBEeW5hbWljU2Vn bWVudChtYXRjaFsxXSkpOwogICAgICAgICAgbmFtZXMucHVzaChtYXRjaFsx XSk7CiAgICAgICAgICB0eXBlcy5keW5hbWljcysrOwogICAgICAgIH0gZWxz ZSBpZiAobWF0Y2ggPSBzZWdtZW50Lm1hdGNoKC9eXCooW15cL10rKSQvKSkg ewogICAgICAgICAgcmVzdWx0cy5wdXNoKG5ldyBTdGFyU2VnbWVudChtYXRj aFsxXSkpOwogICAgICAgICAgbmFtZXMucHVzaChtYXRjaFsxXSk7CiAgICAg ICAgICB0eXBlcy5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dXJuIHRoZSBuZXcgc3RhdGUKICAgICAgICByZXR1cm4gc3Rh dGU7CiAgICAgIH0sCgogICAgICAvLyBGaW5kIGEgbGlzdCBvZiBjaGlsZCBz dGF0ZXMgbWF0Y2hpbmcgdGhlIG5leHQgY2hhcmFjdGVyCiAgICAgIG1hdGNo OiBmdW5jdGlvbihjaCkgewogICAgICAgIC8vIERFQlVHICJQcm9jZXNzaW5n IGAiICsgY2ggKyAiYDoiCiAgICAgICAgdmFyIG5leHRTdGF0ZXMgPSB0aGlz Lm5leHRTdGF0ZXMsCiAgICAgICAgICAgIGNoaWxkLCBjaGFyU3BlYywgY2hh cnM7CgogICAgICAgIC8vIERFQlVHICIgICIgKyBkZWJ1Z1N0YXRlKHRoaXMp CiAgICAgICAgdmFyIHJldHVybmVkID0gW107CgogICAgICAgIGZvciAodmFy IGk9MCwgbD1uZXh0U3RhdGVzLmxlbmd0aDsgaTxsOyBpKyspIHsKICAgICAg ICAgIGNoaWxkID0gbmV4dFN0YXRlc1tpXTsKCiAgICAgICAgICBjaGFyU3Bl YyA9IGNoaWxkLmNoYXJTcGVjOwoKICAgICAgICAgIGlmICh0eXBlb2YgKGNo YXJzID0gY2hhclNwZWMudmFsaWRDaGFycykgIT09ICd1bmRlZmluZWQnKSB7 CiAgICAgICAgICAgIGlmIChjaGFycy5pbmRleE9mKGNoKSAhPT0gLTEpIHsg cmV0dXJuZWQucHVzaChjaGlsZCk7IH0KICAgICAgICAgIH0gZWxzZSBpZiAo dHlwZW9mIChjaGFycyA9IGNoYXJTcGVjLmludmFsaWRDaGFycykgIT09ICd1 bmRlZmluZWQnKSB7CiAgICAgICAgICAgIGlmIChjaGFycy5pbmRleE9mKGNo KSA9PT0gLTEpIHsgcmV0dXJuZWQucHVzaChjaGlsZCk7IH0KICAgICAgICAg IH0KICAgICAgICB9CgogICAgICAgIHJldHVybiByZXR1cm5lZDsKICAgICAg fQoKICAgICAgLyoqIElGIERFQlVHCiAgICAgICwgZGVidWc6IGZ1bm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ICB9KTsKCiAgICAgIHJldHVybiBjdXJyZW50U3RhdGU7 CiAgICB9CgogICAgLy8gVGhlIG1haW4gaW50ZXJmYWNlCgogICAgdmFyIFJv dXRlUmVjb2duaXplciA9IGZ1bmN0aW9uKCkgewogICAgICB0aGlzLnJvb3RT dGF0ZSA9IG5ldyBTdGF0ZSgpOwogICAgICB0aGlzLm5hbWVzID0ge307CiAg ICB9OwoKCiAgICBSb3V0ZVJlY29nbml6ZXIucHJvdG90eXBlID0gewogICAg ICBhZGQ6IGZ1bmN0aW9uKHJvdXRlcywgb3B0aW9ucykgewogICAgICAgIHZh ciBjdXJyZW50U3RhdGUgPSB0aGlzLnJvb3RTdGF0ZSwgcmVnZXggPSAiXiIs CiAgICAgICAgICAgIHR5cGVzID0geyBzdGF0aWNzOiAwLCBkeW5hbWljczog MCwgc3RhcnM6IDAgfSwKICAgICAgICAgICAgaGFuZGxlcnMgPSBbXSwgYWxs U2VnbWVudHMgPSBbXSwgbmFtZTsKCiAgICAgICAgdmFyIGlzRW1wdHkgPSB0 cnVlOwoKICAgICAgICBmb3IgKHZhciBpPTAsIGw9cm91dGVzLmxlbmd0aDsg aTxsOyBpKyspIHsKICAgICAgICAgIHZhciByb3V0ZSA9IHJvdXRlc1tpXSwg bmFtZXMgPSBbXTsKCiAgICAgICAgICB2YXIgc2VnbWVudHMgPSBwYXJzZShy b3V0ZS5wYXRoLCBuYW1lcywgdHlwZXMpOwoKICAgICAgICAgIGFsbFNlZ21l bnRzID0gYWxsU2VnbWVudHMuY29uY2F0KHNlZ21lbnRzKTsKCiAgICAgICAg ICBmb3IgKHZhciBqPTAsIG09c2VnbWVudHMubGVuZ3RoOyBqPG07IGorKykg ewogICAgICAgICAgICB2YXIgc2VnbWVudCA9IHNlZ21lbnRzW2pdOwoKICAg ICAgICAgICAgaWYgKHNlZ21lbnQgaW5zdGFuY2VvZiBFcHNpbG9uU2VnbWVu dCkgeyBjb250aW51ZTsgfQoKICAgICAgICAgICAgaXNFbXB0eSA9IGZhbHNl OwoKICAgICAgICAgICAgLy8gQWRkIGEgIi8iIGZvciB0aGUgbmV3IHNlZ21l bnQKICAgICAgICAgICAgY3VycmVudFN0YXRlID0gY3VycmVudFN0YXRlLnB1 dCh7IHZhbGlkQ2hhcnM6ICIvIiB9KTsKICAgICAgICAgICAgcmVnZXggKz0g Ii8iOwoKICAgICAgICAgICAgLy8gQWRkIGEgcmVwcmVzZW50YXRpb24gb2Yg dGhlIHNlZ21lbnQgdG8gdGhlIE5GQSBhbmQgcmVnZXgKICAgICAgICAgICAg Y3VycmVudFN0YXRlID0gYWRkU2VnbWVudChjdXJyZW50U3RhdGUsIHNlZ21l bnQpOwogICAgICAgICAgICByZWdleCArPSBzZWdtZW50LnJlZ2V4KCk7CiAg ICAgICAgICB9CgogICAgICAgICAgdmFyIGhhbmRsZXIgPSB7IGhhbmRsZXI6 IHJvdXRlLmhhbmRsZXIsIG5hbWVzOiBuYW1lcyB9OwogICAgICAgICAgaGFu ZGxlcnMucHVzaChoYW5kbGVyKTsKICAgICAgICB9CgogICAgICAgIGlmIChp c0VtcHR5KSB7CiAgICAgICAgICBjdXJyZW50U3RhdGUgPSBjdXJyZW50U3Rh dGUucHV0KHsgdmFsaWRDaGFyczogIi8iIH0pOwogICAgICAgICAgcmVnZXgg Kz0gIi8iOwogICAgICAgIH0KCiAgICAgICAgY3VycmVudFN0YXRlLmhhbmRs ZXJzID0gaGFuZGxlcnM7CiAgICAgICAgY3VycmVudFN0YXRlLnJlZ2V4ID0g bmV3IFJlZ0V4cChyZWdleCArICIkIik7CiAgICAgICAgY3VycmVudFN0YXRl LnR5cGVzID0gdHlwZXM7CgogICAgICAgIGlmIChuYW1lID0gb3B0aW9ucyAm JiBvcHRpb25zLmFzKSB7CiAgICAgICAgICB0aGlzLm5hbWVzW25hbWVdID0g ewogICAgICAgICAgICBzZWdtZW50czogYWxsU2VnbWVudHMsCiAgICAgICAg ICAgIGhhbmRsZXJzOiBoYW5kbGVycwogICAgICAgICAgfTsKICAgICAgICB9 CiAgICAgIH0sCgogICAgICBoYW5kbGVyc0ZvcjogZnVuY3Rpb24obmFtZSkg ewogICAgICAgIHZhciByb3V0ZSA9IHRoaXMubmFtZXNbbmFtZV0sIHJlc3Vs dCA9IFtdOwogICAgICAgIGlmICghcm91dGUpIHsgdGhyb3cgbmV3IEVycm9y KCJUaGVyZSBpcyBubyByb3V0ZSBuYW1lZCAiICsgbmFtZSk7IH0KCiAgICAg ICAgZm9yICh2YXIgaT0wLCBsPXJvdXRlLmhhbmRsZXJzLmxlbmd0aDsgaTxs OyBpKyspIHsKICAgICAgICAgIHJlc3VsdC5wdXNoKHJvdXRlLmhhbmRsZXJz W2ldKTsKICAgICAgICB9CgogICAgICAgIHJldHVybiByZXN1bHQ7CiAgICAg IH0sCgogICAgICBoYXNSb3V0ZTogZnVuY3Rpb24obmFtZSkgewogICAgICAg IHJldHVybiAhIXRoaXMubmFtZXNbbmFtZV07CiAgICAgIH0sCgogICAgICBn ZW5lcmF0ZTogZnVuY3Rpb24obmFtZSwgcGFyYW1zKSB7CiAgICAgICAgdmFy IHJvdXRlID0gdGhpcy5uYW1lc1tuYW1lXSwgb3V0cHV0ID0gIiI7CiAgICAg ICAgaWYgKCFyb3V0ZSkgeyB0aHJvdyBuZXcgRXJyb3IoIlRoZXJlIGlzIG5v IHJvdXRlIG5hbWVkICIgKyBuYW1lKTsgfQoKICAgICAgICB2YXIgc2VnbWVu dHMgPSByb3V0ZS5zZWdtZW50czsKCiAgICAgICAgZm9yICh2YXIgaT0wLCBs PXNlZ21lbnRzLmxlbmd0aDsgaTxsOyBpKyspIHsKICAgICAgICAgIHZhciBz ZWdtZW50ID0gc2VnbWVudHNbaV07CgogICAgICAgICAgaWYgKHNlZ21lbnQg aW5zdGFuY2VvZiBFcHNpbG9uU2VnbWVudCkgeyBjb250aW51ZTsgfQoKICAg ICAgICAgIG91dHB1dCArPSAiLyI7CiAgICAgICAgICBvdXRwdXQgKz0gc2Vn bWVudC5nZW5lcmF0ZShwYXJhbXMpOwogICAgICAgIH0KCiAgICAgICAgaWYg KG91dHB1dC5jaGFyQXQoMCkgIT09ICcvJykgeyBvdXRwdXQgPSAnLycgKyBv dXRwdXQ7IH0KCiAgICAgICAgaWYgKHBhcmFtcyAmJiBwYXJhbXMucXVlcnlQ YXJhbXMpIHsKICAgICAgICAgIG91dHB1dCArPSB0aGlzLmdlbmVyYXRlUXVl cnlTdHJpbmcocGFyYW1zLnF1ZXJ5UGFyYW1zLCByb3V0ZS5oYW5kbGVycyk7 CiAgICAgICAgfQoKICAgICAgICByZXR1cm4gb3V0cHV0OwogICAgICB9LAoK ICAgICAgZ2VuZXJhdGVRdWVyeVN0cmluZzogZnVuY3Rpb24ocGFyYW1zLCBo YW5kbGVycykgewogICAgICAgIHZhciBwYWlycyA9IFtdOwogICAgICAgIHZh ciBrZXlzID0gW107CiAgICAgICAgZm9yKHZhciBrZXkgaW4gcGFyYW1zKSB7 CiAgICAgICAgICBpZiAocGFyYW1zLmhhc093blByb3BlcnR5KGtleSkpIHsK ICAgICAgICAgICAga2V5cy5wdXNoKGtleSk7CiAgICAgICAgICB9CiAgICAg ICAgfQogICAgICAgIGtleXMuc29ydCgpOwogICAgICAgIGZvciAodmFyIGkg PSAwLCBsZW4gPSBrZXlzLmxlbmd0aDsgaSA8IGxlbjsgaSsrKSB7CiAgICAg ICAgICBrZXkgPSBrZXlzW2ldOwogICAgICAgICAgdmFyIHZhbHVlID0gcGFy YW1zW2tleV07CiAgICAgICAgICBpZiAodmFsdWUgPT09IGZhbHNlIHx8IHZh bHVlID09IG51bGwpIHsKICAgICAgICAgICAgY29udGludWU7CiAgICAgICAg ICB9CiAgICAgICAgICB2YXIgcGFpciA9IGtleTsKICAgICAgICAgIGlmIChp c0FycmF5KHZhbHVlKSkgewogICAgICAgICAgICBmb3IgKHZhciBqID0gMCwg bCA9IHZhbHVlLmxlbmd0aDsgaiA8IGw7IGorKykgewogICAgICAgICAgICAg IHZhciBhcnJheVBhaXIgPSBrZXkgKyAnW10nICsgJz0nICsgZW5jb2RlVVJJ Q29tcG9uZW50KHZhbHVlW2pdKTsKICAgICAgICAgICAgICBwYWlycy5wdXNo KGFycmF5UGFpcik7CiAgICAgICAgICAgIH0KICAgICAgICAgIH0KICAgICAg ICAgIGVsc2UgaWYgKHZhbHVlICE9PSB0cnVlKSB7CiAgICAgICAgICAgIHBh aXIgKz0gIj0iICsgZW5jb2RlVVJJQ29tcG9uZW50KHZhbHVlKTsKICAgICAg ICAgICAgcGFpcnMucHVzaChwYWlyKTsKICAgICAgICAgIH0gZWxzZSB7CiAg ICAgICAgICAgIHBhaXJzLnB1c2gocGFpcik7CiAgICAgICAgICB9CiAgICAg ICAgfQoKICAgICAgICBpZiAocGFpcnMubGVuZ3RoID09PSAwKSB7IHJldHVy biAnJzsgfQoKICAgICAgICByZXR1cm4gIj8iICsgcGFpcnMuam9pbigiJiIp OwogICAgICB9LAoKICAgICAgcGFyc2VRdWVyeVN0cmluZzogZnVuY3Rpb24o cXVlcnlTdHJpbmcpIHsKICAgICAgICB2YXIgcGFpcnMgPSBxdWVyeVN0cmlu Zy5zcGxpdCgiJiIpLCBxdWVyeVBhcmFtcyA9IHt9OwogICAgICAgIGZvcih2 YXIgaT0wOyBpIDwgcGFpcnMubGVuZ3RoOyBpKyspIHsKICAgICAgICAgIHZh ciBwYWlyICAgICAgPSBwYWlyc1tpXS5zcGxpdCgnPScpLAogICAgICAgICAg ICAgIGtleSAgICAgICA9IGRlY29kZVVSSUNvbXBvbmVudChwYWlyWzBdKSwK ICAgICAgICAgICAgICBrZXlMZW5ndGggPSBrZXkubGVuZ3RoLAogICAgICAg ICAgICAgIGlzQXJyYXkgPSBmYWxzZSwKICAgICAgICAgICAgICB2YWx1ZTsK ICAgICAgICAgIGlmIChwYWlyLmxlbmd0aCA9PT0gMSkgewogICAgICAgICAg ICB2YWx1ZSA9IHRydWU7CiAgICAgICAgICB9IGVsc2UgewogICAgICAgICAg ICAvL0hhbmRsZSBhcnJheXMKICAgICAgICAgICAgaWYgKGtleUxlbmd0aCA+ IDIgJiYga2V5LnNsaWNlKGtleUxlbmd0aCAtMikgPT09ICdbXScpIHsKICAg ICAgICAgICAgICBpc0FycmF5ID0gdHJ1ZTsKICAgICAgICAgICAgICBrZXkg PSBrZXkuc2xpY2UoMCwga2V5TGVuZ3RoIC0gMik7CiAgICAgICAgICAgICAg aWYoIXF1ZXJ5UGFyYW1zW2tleV0pIHsKICAgICAgICAgICAgICAgIHF1ZXJ5 UGFyYW1zW2tleV0gPSBbXTsKICAgICAgICAgICAgICB9CiAgICAgICAgICAg IH0KICAgICAgICAgICAgdmFsdWUgPSBwYWlyWzFdID8gZGVjb2RlVVJJQ29t cG9uZW50KHBhaXJbMV0pIDogJyc7CiAgICAgICAgICB9CiAgICAgICAgICBp ZiAoaXNBcnJheSkgewogICAgICAgICAgICBxdWVyeVBhcmFtc1trZXldLnB1 c2godmFsdWUpOwogICAgICAgICAgfSBlbHNlIHsKICAgICAgICAgICAgcXVl cnlQYXJhbXNba2V5XSA9IHZhbHVlOwogICAgICAgICAgfQoKICAgICAgICB9 CiAgICAgICAgcmV0dXJuIHF1ZXJ5UGFyYW1zOwogICAgICB9LAoKICAgICAg cmVjb2duaXplOiBmdW5jdGlvbihwYXRoKSB7CiAgICAgICAgdmFyIHN0YXRl cyA9IFsgdGhpcy5yb290U3RhdGUgXSwKICAgICAgICAgICAgcGF0aExlbiwg aSwgbCwgcXVlcnlTdGFydCwgcXVlcnlQYXJhbXMgPSB7fSwKICAgICAgICAg ICAgaXNTbGFzaERyb3BwZWQgPSBmYWxzZTsKCiAgICAgICAgcGF0aCA9IGRl Y29kZVVSSShwYXRoKTsKCiAgICAgICAgcXVlcnlTdGFydCA9IHBhdGguaW5k ZXhPZignPycpOwogICAgICAgIGlmIChxdWVyeVN0YXJ0ICE9PSAtMSkgewog ICAgICAgICAgdmFyIHF1ZXJ5U3RyaW5nID0gcGF0aC5zdWJzdHIocXVlcnlT dGFydCArIDEsI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wg cGF5bG9hZCkgewogICAgICAgIHZhciBjaGVja0ZvckFib3J0ICA9IGJpbmQo dGhpcy5jaGVja0ZvckFib3J0LCAgICAgIHRoaXMsIHNob3VsZENvbnRpbnVl KSwKICAgICAgICAgICAgYmVmb3JlTW9kZWwgICAgPSBiaW5kKHRoaXMucnVu QmVmb3JlTW9kZWxIb29rLCB0aGlzLCBhc3luYywgcGF5bG9hZCksCiAgICAg ICAgICAgIG1vZGVsICAgICAgICAgID0gYmluZCh0aGlzLmdldE1vZGVsLCAg ICAgICAgICAgdGhpcywgYXN5bmMsIHBheWxvYWQpLAogICAgICAgICAgICBh ZnRlck1vZGVsICAgICA9IGJpbmQodGhpcy5ydW5BZnRlck1vZGVsSG9vaywg IHRoaXMsIGFzeW5jLCBwYXlsb2FkKSwKICAgICAgICAgICAgYmVjb21lUmVz b2x2ZWQgPSBiaW5kKHRoaXMuYmVjb21lUmVzb2x2ZWQsICAgICB0aGlzLCBw YXlsb2FkKTsKCiAgICAgICAgcmV0dXJuIHJlc29sdmUodW5kZWZpbmVkLCB0 aGlzLnByb21pc2VMYWJlbCgiU3RhcnQgaGFuZGxlciIpKQogICAgICAgICAg ICAgICAudGhlbihjaGVja0ZvckFib3J0LCBudWxsLCB0aGlzLnByb21pc2VM YWJlbCgiQ2hlY2sgZm9yIGFib3J0IikpCiAgICAgICAgICAgICAgIC50aGVu KGJlZm9yZU1vZGVsLCBudWxsLCB0aGlzLnByb21pc2VMYWJlbCgiQmVmb3Jl IG1vZGVsIikpCiAgICAgICAgICAgICAgIC50aGVuKGNoZWNrRm9yQWJvcnQs IG51bGwsIHRoaXMucHJvbWlzZUxhYmVsKCJDaGVjayBpZiBhYm9ydGVkIGR1 cmluZyAnYmVmb3JlTW9kZWwnIGhvb2siKSkKICAgICAgICAgICAgICAgLnRo ZW4obW9kZWwsIG51bGwsIHRoaXMucHJvbWlzZUxhYmVsKCJNb2RlbCIpKQog ICAgICAgICAgICAgICAudGhlbihjaGVja0ZvckFib3J0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WxzID0gcGF5bG9h ZC5yZXNvbHZlZE1vZGVscyB8fCB7fTsKICAgICAgICBwYXlsb2FkLnJlc29s dmVkTW9kZWxzW3RoaXMubmFtZV0gPSByZXNvbHZlZE1vZGVsOwogICAgICB9 LAoKICAgICAgYmVjb21lUmVzb2x2ZWQ6IGZ1bmN0aW9uKHBheWxvYWQsIHJl c29sdmVkQ29udGV4dCkgewogICAgICAgIHZhciBwYXJhbXMgPSB0aGlzLnBh cmFtcyB8fCBzZXJpYWxpemUodGhpcy5oYW5kbGVyLCByZXNvbHZlZENvbnRl eHQsIHRoaXMubmFtZXMpOwoKICAgICAgICBpZiAocGF5bG9hZCkgewogICAg ICAgICAgdGhpcy5zdGFzaFJlc29sdmVkTW9kZWwocGF5bG9hZCwgcmVzb2x2 ZWRDb250ZXh0KTsKICAgICAgICAgIHBheWxvYWQucGFyYW1zID0gcGF5bG9h ZC5wYXJhbXMgfHwge307CiAgICAgICAgICBwYXlsb2FkLnBhcmFtc1t0aGlz Lm5hbWVdID0gcGFyYW1zOwogICAgICAgIH0KCiAgICAgICAgcmV0dXJuIG5l dyBSZXNvbHZlZEhhbmRsZXJJbmZvKHsKICAgICAgICAgIGNvbnRleHQ6IHJl c29sdmVkQ29udGV4dCwKICAgICAgICAgIG5hbWU6IHRoaXMubmFtZSwKICAg ICAgICAgIGhhbmRsZXI6IHRoaXMuaGFuZGxlciwKICAgICAgICAgIHBhcmFt czogcGFyYW1zCiAgICAgICAgfSk7CiAgICAgIH0sCgogICAgICBzaG91bGRT dXBlcmNlZGU6IGZ1bmN0aW9uKG90aGVyKSB7CiAgICAgICAgLy8gUHJlZmVy IHRoaXMgbmV3ZXIgaGFuZGxlckluZm8gb3ZlciBgb3RoZXJgIGlmOgogICAg ICAgIC8vIDEpIFRoZSBvdGhlciBvbmUgZG9lc24ndCBleGlzdAogICAgICAg IC8vIDIpIFRoZSBuYW1lcyBkb24ndCBtYXRjaAogICAgICAgIC8vIDMpIFRo aXMgaGFuZGxlciBo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Ag ICAgIC8vIHRoZSB1c2VyIHRoZSBhYmlsaXR5IHRvIHNldCB0aGUgdXJsIHVw ZGF0ZQogICAgICAgICAgICAgICAgLy8gbWV0aG9kIChkZWZhdWx0IGlzIHJl cGxhY2VTdGF0ZSkuCiAgICAgICAgICAgICAgICBuZXdUcmFuc2l0aW9uID0g bmV3IFRyYW5zaXRpb24odGhpcyk7CiAgICAgICAgICAgICAgICBuZXdUcmFu c2l0aW9uLnVybE1ldGhvZCA9ICdyZXBsYWNlJzsKICAgICAgICAgICAgICAg IG5ld1RyYW5zaXRpb24ucHJvbWlzZSA9IG5ld1RyYW5zaXRpb24ucHJvbWlz ZS50aGVuKGZ1bmN0aW9uKHJlc3VsdCkgewogICAgICAgICAgICAgICAgICB1 cGRhdGVVUkwobmV3VHJhbnNpdGlvbiwgb2xkU3RhdGUsIHRydWUpOwogICAg ICAgICAgICAgICAgICBpZiAocm91dGVyLmRpZFRyYW5zaXRpb24pIHsKICAg ICAgICAgICAgICAgICAgICByb3V0ZXIuZGlkVHJhbnNpdGlvbihyb3V0ZXIu Y3VycmVudEhhbmRsZXJJbmZvcyk7CiAgICAgICAgICAgICAgICAgIH0KICAg ICAgICAgICAgICAgICAgcmV0dXJuIHJlc3VsdDsKICAgICAgICAgICAgICAg IH0sIG51bGwsIHByb21pc2VMYWJlbCgiVHJhbnNpdGlvbiBjb21wbGV0ZSIp KTsKICAgICAgICAgICAgICAgIHJldHVybiBuZXdUcmFuc2l0aW9uOwogICAg ICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICAgICAgLy8gTm8t b3AuIE5vIG5lZWQgdG8gY3JlYXRlIGEgbmV3IHRyYW5zaXRpb24uCiAgICAg ICAgICAgIHJldHVybiBuZXcgVHJhbnNpdGlvbih0aGlzKTsKICAgICAgICAg IH0KCiAgICAgICAgICBpZiAoaXNJbnRlcm1lZGlhdGUpIHsKICAgICAgICAg ICAgc2V0dXBDb250ZXh0cyh0aGlzLCBuZXdTdGF0ZSk7CiAgICAgICAgICAg IHJldHVybjsKICAgICAgICAgIH0KCiAgICAgICAgICAvLyBDcmVhdGUgYSBu ZXcgdHJhbnNpdGlvbiB0byB0aGUgZGVzdGluYXRpb24gcm91dGUuCiAgICAg ICAgICBuZXdUcmFuc2l0aW9uID0gbmV3IFRyYW5zaXRpb24odGhpcywgaW50 ZW50LCBuZXdTdGF0ZSk7CgogICAgICAgICAgLy8gQWJvcnQgYW5kIHVzdXJw IGFueSBwcmV2aW91c2x5IGFjdGl2ZSB0cmFuc2l0aW9uLgogICAgICAgICAg aWYgKHRoaXMuYWN0aXZlVHJhbnNpdGlvbikgewogICAgICAgICAgICB0aGlz LmFjdGl2ZVRyYW5zaXRpb24uYWJvcnQoKTsKICAgICAgICAgIH0KICAgICAg ICAgIHRoaXMuYWN0aXZlVHJhbnNpdGlvbiA9IG5ld1RyYW5zaXRpb247Cgog ICAgICAgICAgLy8gVHJhbnNpdGlvbiBwcm9taXNlcyBieSBkZWZhdWx0IHJl c29sdmUgd2l0aCByZXNvbHZlZCBzdGF0ZS4KICAgICAgICAgIC8vIEZvciBv dXIgcHVycG9zZXMsIHN3YXAgb3V0IHRoZSBwcm9taXNlIHRvIHJlc29sdmUK ICAgICAgICAgIC8vIGFmdGVyIHRoZSB0cmFuc2l0aW9uIGhhcyBiZWVuIGZp bmFsaXplZC4KICAgICAgICAgIG5ld1RyYW5zaXRpb24ucHJvbWlzZSA9IG5l d1RyYW5zaXRpb24ucHJvbWlzZS50aGVuKGZ1bmN0aW9uKHJlc3VsdCkgewog ICAgICAgICAgICByZXR1cm4gcm91dGVyLmFzeW5jKGZ1bmN0aW9uKCkgewog ICAgICAgICAgICAgIHJldHVybiBmaW5hbGl6ZVRyYW5zaXRpb24obmV3VHJh bnNpdGlvbiwgcmVzdWx0LnN0YXRlKTsKICAgICAgICAgICAgfSwgIkZpbmFs aXplIHRyYW5zaXRpb24iKTsKICAgICAgICAgIH0sIG51bGwsIHByb21pc2VM YWJlbCgiU2V0dGxlIHRyYW5zaXRpb24gcHJvbWlzZSB3aGVuIHRyYW5zaXRp b24gaXMgZmluYWxpemVkIikpOwoKICAgICAgICAgIGlmICghd2FzVHJhbnNp dGlvbmluZykgewogICAgICAgICAgICB0cmlnZ2VyKHRoaXMsIHRoaXMuc3Rh dGUuaGFuZGxlckluZm9zLCB0cnVlLCBbJ3dpbGxUcmFuc2l0aW9uJywgbmV3 VHJhbnNpdGlvbl0pOwogICAgICAgICAgfQoKICAgICAgICAgIHJldHVybiBu ZXdUcmFuc2l0aW9uOwogICAgICAgIH0gY2F0Y2goZSkgewogICAgICAgICAg cmV0dXJuIG5ldyBUcmFuc2l0aW9uKHRoaXMsIGludGVudCwgbnVsbCwgZSk7 CiAgICAgICAgfQogICAgICB9LAoKICAgICAgLyoqCiAgICAgICAgQ2xlYXJz IHRoZSBjdXJyZW50IGFuZCB0YXJnZXQgcm91dGUgaGFuZGxlcnMgYW5kIHRy aWdnZXJzIGV4aXQKICAgICAgICBvbiBlYWNoIG9mIHRoZW0gc3RhcnRpbmcg YXQgdGhlIGxlYWYgYW5kIHRyYXZlcnNpbmcgdXAgdGhyb3VnaAogICAgICAg IGl0cyBhbmNlc3RvcnMuCiAgICAgICovCiAgICAgIHJlc2V0OiBmdW5jdGlv bigpIHsKICAgICAgICBpZiAodGhpcy5zdGF0ZSkgewogICAgICAgICAgZm9y RWFjaCh0aGlzLnN0YXRlLmhhbmRsZXJJbmZvcywgZnVuY3Rpb24oaGFuZGxl ckluZm8pIHsKICAgICAgICAgICAgdmFyIGhhbmRsZXIgPSBoYW5kbGVySW5m by5oYW5kbGVyOwogICAgICAgICAgICBpZiAoaGFuZGxlci5leGl0KSB7CiAg ICAgICAgICAgICAgaGFuZGxlci5leGl0KCk7CiAgICAgICAgICAgIH0KICAg ICAgICAgIH0pOwogICAgICAgIH0KCiAgICAgICAgdGhpcy5zdGF0ZSA9IG5l dyBUcmFuc2l0aW9uU3RhdGUoKTsKICAgICAgICB0aGlzLmN1cnJlbnRI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gogICAgICBAcGFyYW0ge1JvdXRl cn0gdHJhbnNpdGlvbgogICAgICBAcGFyYW0ge1RyYW5zaXRpb25TdGF0ZX0g bmV3U3RhdGUKICAgICovCiAgICBmdW5jdGlvbiBzZXR1cENvbnRleHRzKHJv dXRlciwgbmV3U3RhdGUsIHRyYW5zaXRpb24pIHsKICAgICAgdmFyIHBhcnRp dGlvbiA9IHBhcnRpdGlvbkhhbmRsZXJzKHJvdXRlci5zdGF0ZSwgbmV3U3Rh dGUpOwoKICAgICAgZm9yRWFjaChwYXJ0aXRpb24uZXhpdGVkLCBmdW5jdGlv bihoYW5kbGVySW5mbykgewogICAgICAgIHZhciBoYW5kbGVyID0gaGFuZGxl ckluZm8uaGFuZGxlcjsKICAgICAgICBkZWxldGUgaGFuZGxlci5jb250ZXh0 OwogICAgICAgIGlmIChoYW5kbGVyLmV4aXQpIHsgaGFuZGxlci5leGl0KCk7 IH0KICAgICAgfSk7CgogICAgICB2YXIgb2xkU3RhdGUgPSByb3V0ZXIub2xk U3RhdGUgPSByb3V0ZXIuc3RhdGU7CiAgICAgIHJvdXRlci5zdGF0ZSA9IG5l d1N0YXRlOwogICAgICB2YXIgY3VycmVudEhhbmRsZXJJbmZvcyA9IHJvdXRl ci5jdXJyZW50SGFuZGxlckluZm9zID0gcGFydGl0aW9uLnVuY2hhbmdlZC5z bGljZSgpOwoKICAgICAgdHJ5IHsKICAgICAgICBmb3JFYWNoKHBhcnRpdGlv bi51cGRhdGVkQ29udGV4dCwgZnVuY3Rpb24oaGFuZGxlckluZm8pIHsKICAg ICAgICAgIHJldHVybiBoYW5kbGVyRW50ZXJlZE9yVXBkYXRlZChjdXJyZW50 SGFuZGxlckluZm9zLCBoYW5kbGVySW5mbywgZmFsc2UsIHRyYW5zaXRpb24p OwogICAgICAgIH0pOwoKICAgICAgICBmb3JFYWNoKHBhcnRpdGlvbi5lbnRl cmVkLCBmdW5jdGlvbihoYW5kbGVySW5mbykgewogICAgICAgICAgcmV0dXJu IGhhb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XR1cm47CiAgICAgIH0KCiAg ICAgIHZhciByb3V0ZXIgPSB0cmFuc2l0aW9uLnJvdXRlciwKICAgICAgICAg IGhhbmRsZXJJbmZvcyA9IHN0YXRlLmhhbmRsZXJJbmZvcywKICAgICAgICAg IGhhbmRsZXJOYW1lID0gaGFuZGxlckluZm9zW2hhbmRsZXJJbmZvcy5sZW5n dGggLSAxXS5uYW1lLAogICAgICAgICAgcGFyYW1zID0ge307CgogICAgICBm b3IgKHZhciBpID0gaGFuZGxlckluZm9zLmxlbmd0aCAtIDE7IGkgPj0gMDsg LS1pKSB7CiAgICAgICAgdmFyIGhhbmRsZXJJbmZvID0gaGFuZGxlckluZm9z W2ldOwogICAgICAgIG1lcmdlKHBhcmFtcywgaGFuZGxlckluZm8ucGFyYW1z KTsKICAgICAgICBpZiAoaGFuZGxlckluZm8uaGFuZGxlci5pbmFjY2Vzc2li bGVCeVVSTCkgewogICAgICAgICAgdXJsTWV0aG9kID0gbnVsbDsKICAgICAg ICB9CiAgICAgIH0KCiAgICAgIGlmICh1cmxNZXRob2QpIHsKICAgICAgICBw YXJhbXMucXVlcnlQYXJhbXMgPSBzdGF0ZS5xdWVyeVBhcmFtczsKICAgICAg ICB2YXIgdXJsID0gcm91dGVyLnJlY29nbml6ZXIuZ2VuZXJhdGUoaGFuZGxl ck5hbWUsIHBhcmFtcyk7CgogICAgICAgIGlmICh1cmxNZXRob2QgPT09ICdy ZXBsYWNlUXVlcnknKSB7CiAgICAgICAgICBpZiAodXJsICE9PSBpbnB1dFVy bCkgewogICAgICAgICAgICByb3V0ZXIucmVwbGFjZVVSTCh1cmwpOwogICAg ICAgICAgfQogICAgICAgIH0gZWxzZSBpZiAodXJsTWV0aG9kID09PSAncmVw bGFjZScpIHsKICAgICAgICAgIHJvdXRlci5yZXBsYWNlVVJMKHVybCk7CiAg ICAgICAgfSBlbHNlIHsKICAgICAgICAgIHJvdXRlci51cGRhdGVVUkwodXJs KTsKICAgICAgICB9CiAgICAgIH0KICAgI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xlcik7 CiAgICAgICAgICB0cmFuc2l0aW9uLmFib3J0KCk7CiAgICAgICAgfQoKICAg ICAgICB0aHJvdyBlOwogICAgICB9CiAgICB9CgogICAgLyoqCiAgICAgIEBw cml2YXRlCgogICAgICBCZWdpbnMgYW5kIHJldHVybnMgYSBUcmFuc2l0aW9u IGJhc2VkIG9uIHRoZSBwcm92aWRlZAogICAgICBhcmd1bWVudHMuIEFjY2Vw dHMgYXJndW1lbnRzIGluIHRoZSBmb3JtIG9mIGJvdGggVVJMCiAgICAgIHRy YW5zaXRpb25zIGFuZCBuYW1lZCB0cmFuc2l0aW9ucy4KCiAgICAgIEBwYXJh bSB7Um91dGVyfSByb3V0ZXIKICAgICAgQHBhcmFtIHtBcnJheVtPYmplY3Rd fSBhcmdzIGFyZ3VtZW50cyBwYXNzZWQgdG8gdHJhbnNpdGlvblRvLAogICAg ICAgIHJlcGxhY2VXaXRoLCBvciBoYW5kbGVVUkwKICAgICovCiAgICBmdW5j dGlvbiBkb1RyYW5zaXRpb24ocm91dGVyLCBhcmdzLCBpc0ludGVybWVkaWF0 ZSkgewogICAgICAvLyBOb3JtYWxpemUgYmxhbmsgdHJhbnNpdGlvbnMgdG8g cm9vdCBVUkwgdHJhbnNpdGlvbnMuCiAgICAgIHZhciBuYW1lID0gYXJnc1sw XSB8fCAnLyc7CgogICAgICB2YXIgbGFzdEFyZyA9IGFyZ3NbYXJncy5sZW5n dGgtMV07CiAgICAgIHZhciBxdWVyeVBhcmFtcyA9IHt9OwogICAgICBpZiAo bGFzdEFyZyAmJiBsYXN0QXJnLmhhc093blByb3BlcnR5KCdxdWVyeVBhcmFt cycpKSB7CiAgICAgICAgcXVlcnlQYXJhbXMgPSBwb3AuY2FsbChhcmdzKS5x dWVyeVBhcmFtczsKICAgICAgfQoKICAgICAgdmFyIGludGVudDsKICAgICAg aWYgKGFyZ3MubGVuZ3RoID09PSAwKSB7CgogICAgICAgIGxvZyhyb3V0ZXIs ICJVcGRhdGluZyBxdWVyeSBwYXJhbXMiKTsKCiAgICAgICAgLy8gQSBxdWVy eSBwYXJhbSB1cGRhdGUgaXMgcmVhbGx5IGp1c3QgYSB0cmFuc2l0aW9uCiAg ICAgICAgLy8gaW50byB0aGUgcm91dGUgeW91J3JlIGFscmVhZHkgb24uCiAg ICAgICAgdmFyIGhhbmRsZXJJbmZvcyA9IHJvdXRlci5zdGF0ZS5oYW5kbGVy SW5mb3M7CiAgICAgICAgaW50ZW50ID0gbmV3IE5hbWVkVHJhbnNpdGlvbklu dGVudCh7CiAgICAgICAgICBuYW1lOiBoYW5kbGVySW5mb3NbaGFuZGxlcklu Zm9zLmxlbmd0aCAtIDFdLm5hbWUsCiAgICAgICAgICBjb250ZXh0czogW10s CiAgICAgICAgICBxdWVyeVBhcmFtczogcXVlcnlQYXJhbXMKICAgICAgICB9 KTsKCiAgICAgIH0gZWxzZSBpZiAobmFtZS5jaGFyQXQoMCkgPT09ICcvJykg ewoKICAgICAgICBsb2cocm91dGVyLCAiQXR0ZW1wdGluZyBVUkwgdHJhbnNp dGlvbiB0byAiICsgbmFtZSk7CiAgICAgICAgaW50ZW50ID0gbmV3IFVSTFRy YW5zaXRpb25JbnRlbnQoeyB1cmw6IG5hbWUgfSk7CgogICAgICB9IGVsc2Ug ewoKICAgICAgICBsb2cocm91dGVyLCAiQXR0ZW1wdGluZyB0cmFuc2l0aW9u IHRvICIgKyBuYW1lKTsKICAgICAgICBpbnRlbnQgPSBuZXcgTmFtZWRUcmFu c2l0aW9uSW50ZW50KHsKICAgICAgICAgIG5hbWU6IGFyZ3NbMF0sCiAgICAg ICAgICBjb250ZXh0czogc2xpY2UuY2FsbChhcmdzLCAxKSwKICAgICAgICAg IHF1ZXJ5UGFyYW1zOiBxdWVyeVBhcmFtcwogICAgICAgIH0pOwogICAgICB9 CgogICAgICByZXR1cm4gcm91dGVyLnRyYW5zaXRpb25CeUludGVudChpbnRl bnQsIGlzSW50ZXJtZWRpYXRlKTsKICAgIH0KCiAgICBmdW5jdGlv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ZENvbnRleHQ7CiAgICAgICAgfQoKICAg ICAgICB2YXIgaGFuZGxlclRvVXNlID0gb2xkSGFuZGxlckluZm87CiAgICAg ICAgaWYgKGkgPj0gaW52YWxpZGF0ZUluZGV4IHx8IG5ld0hhbmRsZXJJbmZv LnNob3VsZFN1cGVyY2VkZShvbGRIYW5kbGVySW5mbykpIHsKICAgICAgICAg IGludmFsaWRhdGVJbmRleCA9IE1hdGgubWluKGksIGludmFsaWRhdGVJbmRl eCk7CiAgICAgICAgICBoYW5kbGVyVG9Vc2UgPSBuZXdIYW5kbGVySW5mbzsK ICAgICAgICB9CgogICAgICAgIGlmIChpc0ludGVybWVkaWF0ZSAmJiAhY2hl Y2tpbmdJZkFjdGl2ZSkgewogICAgICAgICAgaGFuZGxlclRvVXNlID0gaGFu ZGxlclRvVXNlLmJlY29tZVJlc29sdmVkKG51bGwsIGhhbmRsZXJUb1VzZS5j b250ZXh0KTsKICAgICAgICB9CgogICAgICAgIG5ld1N0YXRlLmhhbmRsZXJJ bmZvcy51bnNoaWZ0KGhhbmRsZXJUb1VzZSk7CiAgICAgIH0KCiAgICAgIGlm IChvYmplY3RzLmxlbmd0aCA+IDApIHsKICAgICAgICB0aHJvdyBuZXcgRXJy b3IoIk1vcmUgY29udGV4dCBvYmplY3RzIHdlcmUgcGFzc2VkIHRoYW4gdGhl cmUgYXJlIGR5bmFtaWMgc2VnbWVudHMgZm9yIHRoZSByb3V0ZTogIiArIHRh cmdldFJvdXRlTmFtZSk7CiAgICAgIH0KCiAgICAgIGlmICghaXNJbnRlcm1l ZGlhdGUpIHsKICAgICAgICB0aGlzLmludmFsaWRhdGVOb25EeW5hbWljSGFu ZGxlcnMobmV3U3RhdGUuaGFuZGxlckluZm9zLCBub25EeW5hbWljSW5kZXhl cywgaW52YWxpZGF0ZUluZGV4KTsKICAgICAgfQoKICAgICAgbWVyZ2UobmV3 U3RhdGUucXVlcnlQYXJhbXMsIG9sZFN0YXRlLnF1ZXJ5UGFyYW1zKTsKICAg ICAgbWVyZ2UobmV3U3RhdGUucXVlcnlQYXJhbXMsIHRoaXMucXVlcnlQYXJh bXMgfHwge30pOwoKICAgICAgcmV0dXJuIG5ld1N0YXRlOwogICAgfTsKCiAg ICBOYW1lZFRyYW5zaXRpb25JbnRlbnQucHJvdG90eXBlLmludmFsaWRhdGVO b25EeW5hbWljSGFuZGxlcnMgPSBmdW5jdGlvbihoYW5kbGVySW5mb3MsIGlu ZGV4ZXMsIGludmFsaWRhdGVJbmRleCkgewogICAgICBmb3JFYWNoKGluZGV4 ZXMsIGZ1bmN0aW9uKGkpIHsKICAgICAgICBpZiAoaSA+PSBpbnZhbGlkYXRl SW5kZXgpIHsKICAgICAgICAgIHZhciBoYW5kbGVySW5mbyA9IGhhbmRsZXJJ bmZvc1tpXTsKICAgICAgICAgIGhhbmRsZXJJbmZvc1tpXSA9IG5ldyBVbnJl c29sdmVkSGFuZGxlckluZm9CeVBhcmFtKHsKICAgICAgICAgICAgbmFtZTog aGFuZGxlckluZm8ubmFtZSwKICAgICAgICAgICAgaGFuZGxlcjogaGFuZGxl ckluZm8uaGFuZGxlciwKICAgICAgICAgICAgcGFyYW1zOiB7fQogICAgICAg ICAgfSk7CiAgICAgICAgfQogICAgICB9KTsKICAgIH07CgogICAgTmFtZWRU cmFuc2l0aW9uSW50ZW50LnByb3RvdHlwZS5nZXRIYW5kbGVySW5mb0ZvckR5 bmFtaWNTZWdtZW50ID0gZnVuY3Rpb24obmFtZSwgaGFuZGxlciwgbmFtZXMs IG9iamVjdHMsIG9sZEhhbmRsZXJJbmZvLCB0YXJnZXRSb3V0ZU5hbWUpIHsK CiAgICAgIHZhciBudW1OYW1lcyA9IG5hbWVzLmxlbmd0aDsKICAgICAgdmFy IG9iamVjdFRvVXNlOwogICAgICBpZiAob2JqZWN0cy5sZW5ndGggPiAwKSB7 CgogICAgICAgIC8vIFVzZSB0aGUgb2JqZWN0cyBwcm92aWRlZCBmb3IgdGhp cyB0cmFuc2l0aW9uLgogICAgICA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N5MV9fLlJlc29sdmVkSGFuZGxlckluZm87CiAgICB2YXIgZm9y RWFjaCA9IF9fZGVwZW5kZW5jeTJfXy5mb3JFYWNoOwogICAgdmFyIHByb21p c2VMYWJlbCA9IF9fZGVwZW5kZW5jeTJfXy5wcm9taXNlTGFiZWw7CiAgICB2 YXIgcmVzb2x2ZSA9IF9fZGVwZW5kZW5jeTNfXy5yZXNvbHZlOwogICAgdmFy IHJlamVjdCA9IF9fZGVwZW5kZW5jeTNfXy5yZWplY3Q7CgogICAgZnVuY3Rp b24gVHJhbnNpdGlvblN0YXRlKG90aGVyKSB7CiAgICAgIHRoaXMuaGFuZGxl ckluZm9zID0gW107CiAgICAgIHRoaXMucXVlcnlQYXJhbXMgPSB7fTsKICAg ICAgdGhpcy5wYXJhbXMgPSB7fTsKICAgIH0KCiAgICBUcmFuc2l0aW9uU3Rh dGUucHJvdG90eXBlID0gewogICAgICBoYW5kbGVySW5mb3M6IG51bGwsCiAg ICAgIHF1ZXJ5UGFyYW1zOiBudWxsLAogICAgICBwYXJhbXM6IG51bGwsCgog ICAgICBwcm9taXNlTGFiZWw6IGZ1bmN0aW9uKGxhYmVsKSB7CiAgICAgICAg dmFyIHRhcmdldE5hbWUgPSAnJzsKICAgICAgICBmb3JFYWNoKHRoaXMuaGFu ZGxlckluZm9zLCBmdW5jdGlvbihoYW5kbGVySW5mbykgewogICAgICAgICAg aWYgKHRhcmdldE5hbWUgIT09ICcnKSB7CiAgICAgICAgICAgIHRhcmdldE5h bWUgKz0gJy4nOwogICAgICAgICAgfQogICAgICAgICAgdGFyZ2V0TmFtZSAr PSBoYW5kbGVySW5mby5uYW1lOwogICAgICAgIH0pOwogICAgICAgIHJldHVy biBwcm9taXNlTGFiZWwoIiciICsgdGFyZ2V0TmFtZSArICInOiAiICsgbGFi ZWwpOwogICAgICB9LAoKICAgICAgcmVzb2x2ZTogZnVuY3Rpb24oYXN5bmMs IHNob3VsZENvbnRpbnVlLCBwYXlsb2FkKSB7CiAgICAg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M YWJlbCgiQ2hlY2sgaWYgc2hvdWxkIGNvbnRpbnVlIikpWydjYXRjaCddKGZ1 bmN0aW9uKHJlYXNvbikgewogICAgICAgICAgICAvLyBXZSBkaXN0aW5ndWlz aCBiZXR3ZWVuIGVycm9ycyB0aGF0IG9jY3VycmVkCiAgICAgICAgICAgIC8v IGR1cmluZyByZXNvbHV0aW9uIChlLmcuIGJlZm9yZU1vZGVsL21vZGVsL2Fm dGVyTW9kZWwpLAogICAgICAgICAgICAvLyBhbmQgYWJvcnRzIGR1ZSB0byBh IHJlamVjdGluZyBwcm9taXNlIGZyb20gc2hvdWxkQ29udGludWUoKS4KICAg ICAgICAgICAgd2FzQWJvcnRlZCA9IHRydWU7CiAgICAgICAgICAgIHJldHVy biByZWplY3QocmVhc29uKTsKICAgICAgICAgIH0sIHByb21pc2VMYWJlbCgi SGFuZGxlIGFib3J0IikpOwogICAgICAgIH0KCiAgICAgICAgZnVuY3Rpb24g aGFuZGxlRXJyb3IoZXJyb3IpIHsKICAgICAgICAgIC8vIFRoaXMgaXMgdGhl IG9ubHkgcG9zc2libGUKICAgICAgICAgIC8vIHJlamVjdCB2YWx1ZSBvZiBU cmFuc2l0aW9uU3RhdGUjcmVzb2x2ZQogICAgICAgICAgdmFyIGhhbmRsZXJJ bmZvcyA9IGN1cnJlbnRTdGF0ZS5oYW5kbGVySW5mb3M7CiAgICAgICAgICB2 YXIgZXJyb3JIYW5kbGVySW5kZXggPSBwYXlsb2FkLnJlc29sdmVJbmRleCA+ PSBoYW5kbGVySW5mb3MubGVuZ3RoID8KICAgICAgICAgICAgICAgICAgICAg ICAgICAgICAgICAgIGhhbmRsZXJJbmZvcy5sZW5ndGggLSAxIDogcGF5bG9h ZC5yZXNvbHZlSW5kZXg7CiAgICAgICAgICByZXR1cm4gcmVqZWN0KHsKICAg ICAgICAgICAgZXJyb3I6IGVycm9yLAogICAgICAgICAgICBoYW5kbGVyV2l0 aEVycm9yOiBjdXJyZW50U3RhdGUuaGFuZGxlckluZm9zW2Vycm9ySGFuZGxl ckluZGV4XS5oYW5kbGVyLAogICAgICAgICAgICB3YXNBYm9ydGVkOiB3YXNB Ym9ydGVkLAogICAgICAgICAgICBzdGF0ZTogY3VycmVudFN0YXRlCiAgICAg ICAgICB9KTsKICAgICAgICB9CgogICAgICAgIGZ1bmN0aW9uIHByb2NlZWQo cmVzb2x2ZWRIYW5kbGVySW5mbykgewogICAgICAgICAgLy8gU3dhcCB0aGUg cHJldmlvdXNseSB1bnJlc29sdmVkIGhhbmRsZXJJbmZvIHdpdGgKICAgICAg ICAgIC8vIHRoZSByZXNvbHZlZCBoYW5kbGVySW5mbwogICAgICAgICAgY3Vy cmVudFN0YXRlLmhhbmRsZXJJbmZvc1twYXlsb2FkLnJlc29sdmVJbmRleCsr XSA9IHJlc29sdmVkSGFuZGxlckluZm87CgogICAgICAgICAgLy8gQ2FsbCB0 aGUgcmVkaXJlY3QgaG9vay4gVGhlIHJlYXNvbiB3ZSBjYWxsIGl0IGhlcmUK ICAgICAgICAgIC8vIHZzLiBhZnRlck1vZGVsIGlzIHNvIHRoYXQgcmVkaXJl Y3RzIGludG8gY2hpbGQKICAgICAgICAgIC8vIHJvdXRlcyBkb24ndCByZS1y dW4gdGhlIG1vZGVsIGhvb2tzIGZvciB0aGlzCiAgICAgICAgICAvLyBhbHJl YWR5LXJlc29sdmVkIHJvdXRlLgogICAgICAgICAgdmFyIGhhbmRsZXIgPSBy ZXNvbHZlZEhhbmRsZXJJbmZvLmhhbmRsZXI7CiAgICAgICAgICBpZiAoaGFu ZGxlciAmJiBoYW5kbGVyLnJlZGlyZWN0KSB7CiAgICAgICAgICAgIGhhbmRs ZXIucmVkaXJlY3QocmVzb2x2ZWRIYW5kbGVySW5mby5jb250ZXh0LCBwYXls b2FkKTsKICAgICAgICAgIH0KCiAgICAgICAgICAvLyBQcm9jZWVkIGFmdGVy IGVuc3VyaW5nIHRoYXQgdGhlIHJlZGlyZWN0IGhvb2sKICAgICAgICAgIC8v IGRpZG4ndCBhYm9ydCB0aGlzIHRyYW5zaXRpb24gYnkgdHJhbnNpdGlvbmlu ZyBlbHNld2hlcmUuCiAgICAgICAgICByZXR1cm4gaW5uZXJTaG91bGRDb250 aW51ZSgpLnRoZW4ocmVzb2x2ZU9uZUhhbmRsZXJJbmZvLCBudWxsLCBwcm9t aXNlTGFiZWwoJ1Jlc29sdmUgaGFuZGxlcicpKTsKICAgICAgICB9CgogICAg ICAgIGZ1bmN0aW9uIHJlc29sdmVPbmVIYW5kbGVySW5mbygpIHsKICAgICAg ICAgIGlmIChwYXlsb2FkLnJlc29sdmVJbmRleCA9PT0gY3VycmVudFN0YXRl LmhhbmRsZXJJbmZvcy5sZW5ndGgpIHsKICAgICAgICAgICAgLy8gVGhpcyBp cyBpcyB0aGUgb25seSBwb3NzaWJsZQogICAgICAgICAgICAvLyBmdWxmaWxs IHZhbHVlIG9mIFRyYW5zaXRpb25TdGF0ZSNyZXNvbHZlCiAgICAgICAgICAg IHJldHVybiB7CiAgICAgICAgICAgICAgZXJyb3I6IG51bGwsCiAgICAgICAg ICAgICAgc3RhdGU6IGN1cnJlbnRTdGF0ZQogICAgICAgICAgICB9OwogICAg ICAgICAgfQoKICAgICAgICAgIHZhciBoYW5kbGVySW5mbyA9IGN1cnJlbnRT dGF0ZS5oYW5kbGVySW5mb3NbcGF5bG9hZC5yZXNvbHZlSW5kZXhdOwoKICAg ICAgICAgIHJldHVybiBoYW5kbGVySW5mby5yZXNvbHZlKGFzeW5jLCBpbm5l clNob3VsZENvbnRpbnVlLCBwYXlsb2FkKQogICAgICAgICAgICAgICAgICAg ICAgICAgICAgLnRoZW4ocHJvY2VlZCwgbnVsbCwgcHJvbWlzZUxhYmVsKCdQ cm9jZWVkJykpOwogICAgICAgIH0KICAgICAgfQogICAgfTsKCiAgICBfX2V4 cG9ydHNfXy5UcmFuc2l0aW9uU3RhdGUgPSBUcmFuc2l0aW9uU3RhdGU7CiAg fSk7CmRlZmluZSgicm91dGVyL3RyYW5za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VhazsK ICAgICAgICAgIH0KICAgICAgICAgIHRoaXMucGl2b3RIYW5kbGVyID0gaGFu ZGxlckluZm8uaGFuZGxlcjsKICAgICAgICB9CgogICAgICAgIHRoaXMuc2Vx dWVuY2UgPSBUcmFuc2l0aW9uLmN1cnJlbnRTZXF1ZW5jZSsrOwogICAgICAg IHRoaXMucHJvbWlzZSA9IHN0YXRlLnJlc29sdmUocm91dGVyLmFzeW5jLCBj aGVja0ZvckFib3J0LCB0aGlzKVsnY2F0Y2gnXShmdW5jdGlvbihyZXN1bHQp IHsKICAgICAgICAgIGlmIChyZXN1bHQud2FzQWJvcnRlZCkgewogICAgICAg ICAgICByZXR1cm4gcmVqZWN0KGxvZ0Fib3J0KHRyYW5zaXRpb24pKTsKICAg ICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAgIHRyYW5zaXRpb24udHJpZ2dl cignZXJyb3InLCByZXN1bHQuZXJyb3IsIHRyYW5zaXRpb24sIHJlc3VsdC5o YW5kbGVyV2l0aEVycm9yKTsKICAgICAgICAgICAgdHJhbnNpdGlvbi5hYm9y dCgpOwogICAgICAgICAgICByZXR1cm4gcmVqZWN0KHJlc3VsdC5lcnJvcik7 CiAgICAgICAgICB9CiAgICAgICAgfSwgcHJvbWlzZUxhYmVsKCdIYW5kbGUg QWJvcnQnKSk7CiAgICAgIH0gZWxzZSB7CiAgICAgICAgdGhpcy5wcm9taXNl ID0gcmVzb2x2ZSh0aGlzLnN0YXRlKTsKICAgICAgICB0aGlzLnBhcmFtcyA9 IHt9OwogICAgICB9CgogICAgICBmdW5jdGlvbiBjaGVja0ZvckFib3J0KCkg ewogICAgICAgIGlmICh0cmFuc2l0aW9uLmlzQWJvcnRlZCkgewogICAgICAg ICAgcmV0dXJuIHJlamVjdCh1bmRlZmluZWQsIHByb21pc2VMYWJlbCgiVHJh bnNpdGlvbiBhYm9ydGVkIC0gcmVqZWN0IikpOwogICAgICAgIH0KICAgICAg fQogICAgfQoKICAgIFRyYW5zaXRpb24uY3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GUgVHJhbnNpdGlvbi4gTm90ZSB5b3UgY2FuIGFsc28gaW1wbGljaXRs eSBhYm9ydCBhIHRyYW5zaXRpb24KICAgICAgICBieSBpbml0aWF0aW5nIGFu b3RoZXIgdHJhbnNpdGlvbiB3aGlsZSBhIHByZXZpb3VzIG9uZSBpcyB1bmRl cndheS4KICAgICAgICovCiAgICAgIGFib3J0OiBmdW5jdGlvbigpIHsKICAg ICAgICBpZiAodGhpcy5pc0Fib3J0ZWQpIHsgcmV0dXJuIHRoaXM7IH0KICAg ICAgICBsb2codGhpcy5yb3V0ZXIsIHRoaXMuc2VxdWVuY2UsIHRoaXMudGFy Z2V0TmFtZSArICI6IHRyYW5zaXRpb24gd2FzIGFib3J0ZWQiKTsKICAgICAg ICB0aGlzLmlzQWJvcnRlZCA9IHRydWU7CiAgICAgICAgdGhpcy5pc0FjdGl2 ZSA9IGZhbHNlOwogICAgICAgIHRoaXMucm91dGVyLmFjdGl2ZVRyYW5zaXRp b24gPSBudWxsOwogICAgICAgIHJldHVybiB0aGlzOwogICAgICB9LAoKICAg ICAgLyoqCiAgICAgICAgQHB1YmxpYwoKICAgICAgICBSZXRyaWVzIGEgcHJl dmlvdXNseS1hYm9ydGVkIHRyYW5zaXRpb24gKG1ha2luZyBzdXJlIHRvIGFi b3J0IHRoZQogICAgICAgIHRyYW5zaXRpb24gaWYgaXQncyBzdGlsbCBhY3Rp dmUpLiBSZXR1cm5zIGEgbmV3IHRyYW5zaXRpb24gdGhhdAogICAgICAgIHJl cHJlc2VudHMgdGhlIG5ldyBhdHRlbXB0IHRvIHRyYW5zaXRpb24uCiAgICAg ICAqLwogICAgICByZXRyeTogZnVuY3Rpb24oKSB7CiAgICAgICAgLy8gVE9E TzogYWRkIHRlc3RzIGZvciBtZXJnZWQgc3RhdGUgcmV0cnkoKXMKICAgICAg ICB0aGlzLmFib3J0KCk7CiAgICAgICAgcmV0dXJuIHRoaXMucm91dGVyLnRy YW5zaXRpb25CeUludGVudCh0aGlzLmludG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KSwgaGVhZCwgcXVlcnlQYXJhbXM7CgogICAgICBp ZihsZW4gJiYgbGVuID4gMCAmJiBhcnJheVtsZW4gLSAxXSAmJiBhcnJheVts ZW4gLSAxXS5oYXNPd25Qcm9wZXJ0eSgncXVlcnlQYXJhbXMnKSkgewogICAg ICAgIHF1ZXJ5UGFyYW1zID0gYXJyYXlbbGVuIC0gMV0ucXVlcnlQYXJhbXM7 CiAgICAgICAgaGVhZCA9IHNsaWNlLmNhbGwoYXJyYXksIDAsIGxlbiAtIDEp OwogICAgICAgIHJldHVybiBbaGVhZCwgcXVlcnlQYXJhbXNdOwogICAgICB9 IGVsc2UgewogICAgICAgIHJldHVybiBbYXJyYXksIG51bGxdOwogICAgICB9 CiAgICB9CgogICAgLyoqCiAgICAgIEBwcml2YXRlCgogICAgICBDb2VyY2Vz IHF1ZXJ5IHBhcmFtIHByb3BlcnRpZXMgYW5kIGFycmF5IGVsZW1lbnRzIGlu dG8gc3RyaW5ncy4KICAgICoqLwogICAgZnVuY3Rpb24gY29lcmNlUXVlcnlQ YXJhbXNUb1N0cmluZyhxdWVyeVBhcmFtcykgewogICAgICBmb3IgKHZhciBr ZXkgaW4gcXVlcnlQYXJhbXMpIHsKICAgICAgICBpZiAodHlwZW9mIHF1ZXJ5 UGFyYW1zW2tleV0gPT09ICdudW1iZXInKSB7CiAgICAgICAgICBxdWVyeVBh cmFtc1trZXldID0gJycgKyBxdWVyeVBhcmFtc1trZXldOwogICAgICAgIH0g ZWxzZSBpZiAoaXNBcnJheShxdWVyeVBhcmFtc1trZXldKSkgewogICAgICAg ICAgZm9yICh2YXIgaSA9IDAsIGwgPSBxdWVyeVBhcmFtc1trZXldLmxlbmd0 aDsgaSA8IGw7IGkrKykgewogICAgICAgICAgICBxdWVyeVBhcmFtc1trZXld W2ldID0gJycgKyBxdWVyeVBhcmFtc1trZXldW2ldOwogICAgICAgICAgfQog ICAgICAgIH0KICAgICAgfQogICAgfQogICAgLyoqCiAgICAgIEBwcml2YXRl C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g IH0gZWxzZSB7CiAgICAgICAgICAgIHJldHVybjsKICAgICAgICAgIH0KICAg ICAgICB9CiAgICAgIH0KCiAgICAgIGlmICghZXZlbnRXYXNIYW5kbGVkICYm ICFpZ25vcmVGYWlsdXJlKSB7CiAgICAgICAgdGhyb3cgbmV3IEVycm9yKCJO b3RoaW5nIGhhbmRsZWQgdGhlIGV2ZW50ICciICsgbmFtZSArICInLiIpOwog ICAgICB9CiAgICB9CgogICAgZnVuY3Rpb24gZ2V0Q2hhbmdlbGlzdChvbGRP YmplY3QsIG5ld09iamVjdCkgewogICAgICB2YXIga2V5OwogICAgICB2YXIg cmVzdWx0cyA9IHsKICAgICAgICBhbGw6IHt9LAogICAgICAgIGNoYW5nZWQ6 IHt9LAogICAgICAgIHJlbW92ZWQ6IHt9CiAgICAgIH07CgogICAgICBtZXJn ZShyZXN1bHRzLmFsbCwgbmV3T2JqZWN0KTsKCiAgICAgIHZhciBkaWRDaGFu Z2UgPSBmYWxzZTsKICAgICAgY29lcmNlUXVlcnlQYXJhbXNUb1N0cmluZyhv bGRPYmplY3QpOwogICAgICBjb2VyY2VRdWVyeVBhcmFtc1RvU3RyaW5nKG5l d09iamVjdCk7CgogICAgICAvLyBDYWxjdWxhdGUgcmVtb3ZhbHMKICAgICAg Zm9yIChrZXkgaW4gb2xkT2JqZWN0KSB7CiAgICAgICAgaWYgKG9sZE9iamVj dC5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7CiAgICAgICAgICBpZiAoIW5ld09i amVjdC5oYXNPd25Qcm9wZXJ0eShrZXkpKSB7CiAgICAgICAgICAgIGRpZENo YW5nZSA9IHRydWU7CiAgICAgICAgICAgIHJlc3VsdHMucmVtb3ZlZFtrZXld ID0gb2xkT2JqZWN0W2tleV07CiAgICAgICAgICB9CiAgICAgICAgfQogICAg ICB9CgogICAgICAvLyBDYWxjdWxhdGUgY2hhbmdlcwogICAgICBmb3IgKGtl eSBpbiBuZXdPYmplY3QpIHsKICAgICAgICBpZiAobmV3T2JqZWN0Lmhhc093 blByb3BlcnR5KGtleSkpIHsKICAgICAgICAgIGlmIChpc0FycmF5KG9sZE9i amVjdFtrZXldKSAmJiBpc0FycmF5KG5ld09iamVjdFtrZXldKSkgewogICAg ICAgICAgICBpZiAob2xkT2JqZWN0W2tleV0ubGVuZ3RoICE9PSBuZXdPYmpl Y3Rba2V5XS5sZW5ndGgpIHsKICAgICAgICAgICAgICByZXN1bHRzLmNoYW5n ZWRba2V5XSA9IG5ld09iamVjdFtrZXldOwogICAgICAgICAgICAgIGRpZENo YW5nZSA9IHRydWU7CiAgICAgICAgICAgIH0gZWxzZSB7CiAgICAgICAgICAg ICAgZm9yICh2YXIgaSA9IDAsIGwgPSBvbGRPYmplY3Rba2V5XS5sZW5ndGg7 IGkgPCBsOyBpKyspIHsKICAgICAgICAgICAgICAgIGlmIChvbGRPYmplY3Rb a2V5XVtpXSAhPT0gbmV3T2JqZWN0W2tleV1baV0pIHsKICAgICAgICAgICAg ICAgICAgcmVzdWx0cy5jaGFuZ2VkW2tleV0gPSBuZXdPYmplY3Rba2V5XTsK ICAgICAgICAgICAgICAgICAgZGlkQ2hhbmdlID0gdHJ1ZTsKICAgICAgICAg ICAgICAgIH0KICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAg ICAgIH0KICAgICAgICAgIGVsc2UgewogICAgICAgICAgICBpZiAob2xkT2Jq ZWN0W2tleV0gIT09IG5ld09iamVjdFtrZXldKSB7CiAgICAgICAgICAgICAg cmVzdWx0cy5jaGFuZ2VkW2tleV0gPSBuZXdPYmplY3Rba2V5XTsKICAgICAg ICAgICAgICBkaWRDaGFuZ2UgPSB0cnVlOwogICAgICAgICAgICB9CiAgICAg ICAgICB9CiAgICAgICAgfQogICAgICB9CgogICAgICByZXR1cm4gZGlkQ2hh bmdlICYmIHJlc3VsdHM7CiAgICB9CgogICAgZnVuY3Rpb24gcHJvbWlzZUxh YmVsKGxhYmVsKSB7CiAgICAgIHJldHVybiAnUm91dGVyOiA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sb2NhdGlvbiBBUEkncwogICAgICAgIHZhciBvcHRpb25zID0ge2ltcGxl bWVudGF0aW9uOiBsb2NhdGlvbn07CgogICAgICAgIGxvY2F0aW9uID0gc2V0 KHRoaXMsICdsb2NhdGlvbicsIEVtYmVyLkxvY2F0aW9uLmNyZWF0ZShvcHRp b25zKSk7CiAgICAgIH0KICAgIH0KCiAgICBpZiAodHlwZW9mIHJvb3RVUkwg PT09ICdzdHJpbmcnKSB7CiAgICAgIGxvY2F0aW9uLnJvb3RVUkwgPSByb290 VVJMOwogICAgfQoKICAgIC8vIGVuc3VyZSB0aGF0IGluaXRTdGF0ZSBpcyBj YWxsZWQgQUZURVIgdGhlIHJvb3RVUkwgaXMgc2V0IG9uCiAgICAvLyB0aGUg bG9jYXRpb24gaW5zdGFuY2UKICAgIGlmICh0eXBlb2YgbG9jYXRpb24uaW5p dFN0YXRlID09PSAnZnVuY3Rpb24nKSB7IGxvY2F0aW9uLmluaXRTdGF0ZSgp OyB9CiAgfSwKCiAgX2dldEhhbmRsZXJGdW5jdGlvbjogZnVuY3Rpb24oKSB7 CiAgICB2YXIgc2VlbiA9IHt9LCBjb250YWluZXIgPSB0aGlzLmNvbnRhaW5l ciwKICAgICAgICBEZWZhdWx0Um91dGUgPSBjb250YWluZXIubG9va3VwRmFj dG9yeSgncm91dGU6YmFzaWMnKSwKICAgICAgICBzZWxmID0gdGhpczsKCiAg ICByZXR1cm4gZnVuY3Rpb24obmFtZSkgewogICAgICB2YXIgcm91dGVOYW1l ID0gJ3JvdXRlOicgKyBuYW1lLAogICAgICAgICAgaGFuZGxlciA9IGNvbnRh aW5lci5sb29rdXAocm91dGVOYW1lKTsKCiAgICAgIGlmIChzZWVuW25hbWVd KSB7IHJldHVybiBoYW5kbGVyOyB9CgogICAgICBzZWVuW25hbWVdID0gdHJ1 ZTsKCiAgICAgIGlmICghaGFuZGxlcikgewogICAgICAgIGNvbnRhaW5lci5y ZWdpc3Rlcihyb3V0ZU5hbWUsIERlZmF1b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0aGlzLnJv dXRlci5hY3RpdmVUcmFuc2l0aW9uLnN0YXRlLmhhbmRsZXJJbmZvcyA6CiAg ICAgICAgICAgICAgICAgICAgICAgICAgIHRoaXMucm91dGVyLnN0YXRlLmhh bmRsZXJJbmZvczsKICAgICAgICBuYW1lID0gaGFuZGxlckluZm9zW2hhbmRs ZXJJbmZvcy5sZW5ndGggLSAxXS5uYW1lOwogICAgICAgIGFyZ3MudW5zaGlm dChuYW1lKTsKICAgICAgfQoKICAgICAgdmFyIHFwTWFwcGluZ3MgPSB0aGlz Ll9xdWVyeVBhcmFtTmFtZXNGb3IobmFtZSk7CgoKICAgICAgRW1iZXIuUm91 dGVyLl90cmFuc2xhdGVRdWVyeVBhcmFtcyhxdWVyeVBhcmFtcywgcXBNYXBw aW5ncy50cmFuc2xhdGlvbnMsIG5hbWUpOwogICAgICB2YXIgdmFsdWU7CiAg ICAgIGZvciAodmFyIGtleSBpbiBxdWVyeVBhcmFtcykgewogICAgICAgIHZh ciBkZXNjb3BlZFBhcmFtID0gRW1iZXIuUm91dGVyLl9kZXNjb3BlUXVlcnlQ YXJhbShrZXkpOwogICAgICAgIGlmIChrZXkgaW4gcXBNYXBwaW5ncy5xdWVy eVBhcmFtcykgewogICAgICAgICAgdmFsdWUgPSBxdWVyeVBhcmFtc1trZXld OwogICAgICAgICAgZGVsZXRlIHF1ZXJ5UGFyYW1zW2tleV07CiAgICAgICAg ICBxdWVyeVBhcmFtc1txcE1hcHBpbmdzLnF1ZXJ5UGFyYW1zW2tleV1dID0g dmFsdWU7CiAgICAgICAgfSBlbHNlIGlmIChkZXNjb3BlZFBhcmFtIGluIHFw TWFwcGluZ3MudmFsaWRRdWVyeVBhcmFtcykgewogICAgICAgICAgdmFsdWUg PSBxdWVyeVBhcmFtc1trZXldOwogICAgICAgICAgZGVsZXRlIHF1ZXJ5UGFy YW1zW2tleV07CiAgICAgICAgICBxdWVyeVBhcmFtc1tkZXNjb3BlZFBhcmFt XSA9IHZhbHVlOwogICA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ic29uZyIpOwogICAgICAgICAgdGhpcy50cmFuc2l0aW9uVG8oIm90aGVy LnJvdXRlIik7CiAgICAgICAgICAuLi4KICAgICAgICB9CiAgICAgIH0KICAg IH0pOwogICAgYGBgCgogICAgSXQgaXMgYWxzbyBwb3NzaWJsZSB0byBjYWxs IGB0aGlzLl9zdXBlcigpYCBmcm9tIHdpdGhpbiBhbgogICAgYWN0aW9uIGhh bmRsZXIgaWYgaXQgb3ZlcnJpZGVzIGEgaGFuZGxlciBkZWZpbmVkIG9uIGEg cGFyZW50CiAgICBjbGFzcyBvciBtaXhpbjoKCiAgICBUYWtlIGZvciBleGFt cGxlIHRoZSBmb2xsb3dpbmcgcm91dGVzOgoKICAgIGBgYGpzCiAgICBBcHAu RGVidWdSb3V0ZSA9IEVtYmVyLk1peGluLmNyZWF0ZSh7CiAgICAgIGFjdGlv bnM6IHsKICAgICAgICBkZWJ1Z1JvdXRlSW5mb3JtYXRpb246IGZ1bmN0aW9u KCkgewogICAgICAgICAgY29uc29sZS5kZWJ1ZygidHJvbG9sbyIpOwogICAg ICAgIH0KICAgICAgfQogICAgfSk7CgogICAgQXBwLkFubm95aW5nRGVidWdS b3V0ZSA9IEVtYmVyLlJvdXRlLmV4dGVuZChBcHAuRGVidWdSb3V0ZSwgewog ICAgICBhY3Rpb25zOiB7CiAgICAgICAgZGVidWdSb3V0ZUluZm9ybWF0aW9u OiBmdW5jdGlvbigpIHsKICAgICAgICAgIC8vIGFsc28gY2FsbCB0aGUgZGVi dWdSb3V0ZUluZm9ybWF0aW9uIG9mIG1peGVkIGluIEFwcC5EZWJ1Z1JvdXRl CiAgICAgICAgICB0aGlzLl9zdXBlcigpOwoKICAgICAgICAgIC8vIHNob3cg YWRkaXRpb25hbCBhbm5veWFuY2UKICAgICAgICAgIHdpbmRvdy5hbGVydCgu Li4pOwogICAgICAgIH0KICAgICAgfQogICAgfSk7CiAgICBgYGAKCiAgICAj IyBCdWJibGluZwoKICAgIEJ5IGRlZmF1bHQsIGF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y cm9ycyBmcm9tIGNoaWxkIHJvdXRlczoKCiAgICBgYGBqcwogICAgQXBwLkFk bWluUm91dGUgPSBFbWJlci5Sb3V0ZS5leHRlbmQoewogICAgICBiZWZvcmVN b2RlbDogZnVuY3Rpb24oKSB7CiAgICAgICAgcmV0dXJuIEVtYmVyLlJTVlAu cmVqZWN0KCJiYWQgdGhpbmdzISIpOwogICAgICB9LAoKICAgICAgYWN0aW9u czogewogICAgICAgIGVycm9yOiBmdW5jdGlvbihlcnJvciwgdHJhbnNpdGlv bikgewogICAgICAgICAgLy8gQXNzdW1pbmcgd2UgZ290IGhlcmUgZHVlIHRv IHRoZSBlcnJvciBpbiBgYmVmb3JlTW9kZWxgLAogICAgICAgICAgLy8gd2Ug Y2FuIGV4cGVjdCB0aGF0IGVycm9yID09PSAiYmFkIHRoaW5ncyEiLAogICAg ICAgICAgLy8gYnV0IGEgcHJvbWlzZSBtb2RlbCByZWplY3Rpbmcgd291bGQg YWxzbwogICAgICAgICAgLy8gY2FsbCB0aGlzIGhvb2ssIGFzIHdvdWxkIGFu eSBlcnJvcnMgZW5jb3VudGVyZWQKICAgICAgICAgIC8vIGluIGBhZnRlck1v ZGVsYC4KCiAgICAgICAgICAvLyBUaGUgYGVycm9yYCBob29rIGlzIGFsc28g cHJvdmlkZWQgdGhlIGZhaWxlZAogICAgICAgICAgLy8gYHRyYW5zaXRpb25g LCB3aGljaCBjYW4gYmUgc3RvcmVkIGFuZCBsYXRlcgogICAgICAgICAgLy8g YC5yZXRyeSgpYGQgaWYgZGVzaXJlZC4KCiAgICAgICAgICB0aGlzLnRyYW5z aXRpb25UbygnbG9naW4nKTsKICAgICAgICB9CiAgICAgIH0KICAgIH0pOwog ICAgYGBgCgogICAgYGVycm9yYCBhY3Rpb25zIHRoYXQgYnViYmxlIHVwIGFs bCB0aGUgd2F5IHRvIGBBcHBsaWNhdGlvblJvdXRlYAogICAgd2lsbCBmaXJl IGEgZGVmYXVsdCBlcnJvciBoYW5kbGVyIHRo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cmUuZmluZChtb2RlbE5hbWUsIGZpbmRBcmd1bWVu dHMpYAoKICAgIEBtZXRob2Qgc3RvcmUKICAgIEBwYXJhbSB7T2JqZWN0fSBz dG9yZQogICovCiAgc3RvcmU6IEVtYmVyLmNvbXB1dGVkKGZ1bmN0aW9uKCl7 CiAgICB2YXIgY29udGFpbmVyID0gdGhpcy5jb250YWluZXI7CiAgICB2YXIg cm91dGVOYW1lID0gdGhpcy5yb3V0ZU5hbWU7CiAgICB2YXIgbmFtZXNwYWNl ID0gZ2V0KHRoaXMsICdyb3V0ZXIubmFtZXNwYWNlJyk7CgogICAgcmV0dXJu IHsKICAgICAgZmluZDogZnVuY3Rpb24obmFtZSwgdmFsdWUpIHsKICAgICAg ICB2YXIgbW9kZWxDbGFzcyA9IGNvbnRhaW5lci5sb29rdXBGYWN0b3J5KCdt b2RlbDonICsgbmFtZSk7CgogICAgICAgIEVtYmVyLmFzc2VydCgiWW91IHVz ZWQgdGhlIGR5bmFtaWMgc2VnbWVudCAiICsgbmFtZSArICJfaWQgaW4geW91 ciByb3V0ZSAiICsKICAgICAgICAgICAgICAgICAgICAgcm91dGVOYW1lICsg IiwgYnV0ICIgKyBuYW1lc3BhY2UgKyAiLiIgKyBjbGFzc2lmeShuYW1lKSAr CiAgICAgICAgICAgICAgICAgICAgICIgZGlkIG5vdCBleGlzdCBhbmQgeW91 IGRpZCBub3Qgb3ZlcnJpZGUgeW91ciByb3V0ZSdzIGBtb2RlbGAgIiArCiAg ICAgICAgICAgICAgICAgICAgICJob29rLiIsIG1vZGVsQ2xhc3MpOwoKICAg ICAgICBpZiAoIW1vZGVsQ2xhc3MpIHsgcmV0dXJuOyB9CgogICAgICAgIHJl dHVybiBtb2RlbENsYXNzLmZpbmQodmFsdWUpOwogICAgICB9CiAgICB9Owog IH0pLAoKICAvKioKICAgIEEgaG9vayB5b3UgY2FuIGltcGxlbWVudCB0byBj b252ZXJ0IHRoZSByb3V0ZSdzIG1vZGVsIGludG8gcGFyYW1ld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CBpbnRvIGFuIG91dGxldC4KCiAgICBZb3UgbWF5IHBhc3MgYW55IG9yIGFs bCBvZiB0aGUgZm9sbG93aW5nIG9wdGlvbnMgdG8gYGRpc2Nvbm5lY3RPdXRs ZXRgOgoKICAgICogYG91dGxldGA6IHRoZSBuYW1lIG9mIHRoZSBvdXRsZXQg dG8gY2xlYXIgKGRlZmF1bHQ6ICdtYWluJykKICAgICogYHBhcmVudFZpZXdg OiB0aGUgbmFtZSBvZiB0aGUgdmlldyBjb250YWluaW5nIHRoZSBvdXRsZXQg dG8gY2xlYXIKICAgICAgIChkZWZhdWx0OiB0aGUgdmlldyByZW5kZXJlZCBi eSB0aGUgcGFyZW50IHJvdXRlKQoKICAgIEV4YW1wbGU6CgogICAgYGBganMK ICAgIEFwcC5BcHBsaWNhdGlvblJvdXRlID0gQXBwLlJvdXRlLmV4dGVuZCh7 CiAgICAgIGFjdGlvbnM6IHsKICAgICAgICBzaG93TW9kYWw6IGZ1bmN0aW9u KGV2dCkgewogICAgICAgICAgdGhpcy5yZW5kZXIoZXZ0Lm1vZGFsTmFtZSwg ewogICAgICAgICAgICBvdXRsZXQ6ICdtb2RhbCcsCiAgICAgICAgICAgIGlu dG86ICdhcHBsaWNhdGlvbicKICAgICAgICAgIH0pOwogICAgICAgIH0sCiAg ICAgICAgaGlkZU1vZGFsOiBmdW5jdGlvbihldnQpIHsKICAgICAgICAgIHRo aXMuZGlzY29ubmVjdE91dGxldCh7CiAgICAgICAgICAgIG91dGxldDogJ21v ZGFsJywKICAgICAgICAgICAgcGFyZW50VmlldzogJ2FwcGxpY2F0aW9uJwog ICAgICAgICAgfSk7CiAgICAgICAgfQogICAgICB9CiAgICB9KTsKICAgIGBg YAoKICAgIEFsdGVybmF0aXZlbHksIHlvdSBjYW4gcGFzcyB0aGUgYG91dGxl dGAgbmFtZSBkaXJlY3RseSBhcyBhIHN0cmluZy4KCiAgICBFeGFtcGxlOgoK ICAgIGBgYGpzCiAgICBoaWRlTW9kYWw6IGZ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Z3RoID0gcGF0aHMubGVuZ3RoLAogICAgICAgICAgcGF0aCwgaSwgbm9y bWFsaXplZFBhdGg7CgogICAgICBpZiAobGlua1RleHRQYXRoKSB7CiAgICAg ICAgbm9ybWFsaXplZFBhdGggPSBFbWJlci5IYW5kbGViYXJzLm5vcm1hbGl6 ZVBhdGgoaGVscGVyUGFyYW1ldGVycy5jb250ZXh0LCBsaW5rVGV4dFBhdGgs IGhlbHBlclBhcmFtZXRlcnMub3B0aW9ucy5kYXRhKTsKICAgICAgICB0aGlz LnJlZ2lzdGVyT2JzZXJ2ZXIobm9ybWFsaXplZFBhdGgucm9vdCwgbm9ybWFs aXplZFBhdGgucGF0aCwgdGhpcywgdGhpcy5yZXJlbmRlcik7CiAgICAgIH0K CiAgICAgIGZvcihpPTA7IGkgPCBsZW5ndGg7IGkrKykgewogICAgICAgIHBh dGggPSBwYXRoc1tpXTsKICAgICAgICBpZiAobnVsbCA9PT0gcGF0aCkgewog ICAgICAgICAgLy8gQSBsaXRlcmFsIHZhbHVlIHdhcyBwcm92aWRlZCwgbm90 IGEgcGF0aCwgc28gbm90aGluZyB0byBvYnNlcnZlLgogICAgICAgICAgY29u dGludWU7CiAgICAgICAgfQoKICAgICAgICBub3JtYWxpemVkUGF0aCA9IEVt YmVyLkhhbmRsZWJhcnMubm9ybWFsaXplUGF0aChoZWxwZXJQYXJhbWV0ZXJz LmNvbnRleHQsIHBhdGgsIGhlbHBlclBhcmFtZXRlcnMub3B0aW9ucy5kYXRh KTsKICAgICAgICB0aGlzLnJlZ2lzdGVyT2JzZXJ2ZXIobm9ybWFsaXplZFBh dGgucm9vdCwgbm9ybWFsaXplZFBhdGgucGF0aCwgdGhpcywgdGhpcy5fcGFy YW1zQ2hhbmdlZCk7CiAgICAgIH0KCiAgICAgIHZhciBxdWVyeVBhcmFtc09i amVjdCA9IHRoaXMucXVlcnlQYXJhbXNPYmplY3Q7CiAgICAgIGlmIChxdWVy eVBhcmFtc09iamVjdCkgewogICAgICAgIH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AgICoqLwogICAgcm91dGVyOiBFbWJlci5jb21wdXRlZChmdW5jdGlvbigp IHsKICAgICAgcmV0dXJuIGdldCh0aGlzLCAnY29udHJvbGxlcicpLmNvbnRh aW5lci5sb29rdXAoJ3JvdXRlcjptYWluJyk7CiAgICB9KSwKCiAgICAvKioK ICAgICAgRXZlbnQgaGFuZGxlciB0aGF0IGludm9rZXMgdGhlIGxpbmssIGFj dGl2YXRpbmcgdGhlIGFzc29jaWF0ZWQgcm91dGUuCgogICAgICBAcHJpdmF0 ZQogICAgICBAbWV0aG9kIF9pbnZva2UKICAgICAgQHBhcmFtIHtFdmVudH0g ZXZlbnQKICAgICovCiAgICBfaW52b2tlOiBmdW5jdGlvbihldmVudCkgewog ICAgICBpZiAoIWlzU2ltcGxlQ2xpY2soZXZlbnQpKSB7IHJldHVybiB0cnVl OyB9CgogICAgICBpZiAodGhpcy5wcmV2ZW50RGVmYXVsdCAhPT0gZmFsc2Up IHsgZXZlbnQucHJldmVudERlZmF1bHQoKTsgfQogICAgICBpZiAodGhpcy5i dWJibGVzID09PSBmYWxzZSkgeyBldmVudC5zdG9wUHJvcGFnYXRpb24oKTsg fQoKICAgICAgaWYgKGdldCh0aGlzLCAnX2lzRGlzYWJsZWQnKSkgeyByZXR1 cm4gZmFsc2U7IH0KCiAgICAgIGlmIChnZXQodGhpcywgJ2xvYWRpbmcnKSkg ewogICAgICAgIEVtYmVyLkxvZ2dlci53YXJuKCJUaGlzIGxpbmstdG8gaXMg aW4gYW4gaW5hY3RpdmUgbG9hZGluZyBzdGF0ZSBiZWNhdXNlIGF0IGxlYXN0 IG9uZSBvZiBpdHMgcGFyYW1ldGVycyBwcmVzZW50bHkgaGFzIGEgbnVsbC91 bmRlZmluZWQgdmFsdWUsIG9yIHRoZSBwcm92aWRlZCByb3V0ZSBuYW1lIGlz IGludmFsaWQuIik7CiAgICAgICAgcmV0dXJuIGZhbHNlOwogICAgICB9Cgog ICAgICB2YXIgcm91dGVyID0gZ2V0KHRoaX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mluZ30gSFRNTCBzdHJpbmcK ICAgIEBzZWUge0VtYmVyLkxpbmtWaWV3fQogICovCiAgRW1iZXIuSGFuZGxl YmFycy5yZWdpc3RlckhlbHBlcignbGluay10bycsIGZ1bmN0aW9uIGxpbmtU b0hlbHBlcihuYW1lKSB7CiAgICB2YXIgb3B0aW9ucyA9IHNsaWNlLmNhbGwo YXJndW1lbnRzLCAtMSlbMF0sCiAgICAgICAgcGFyYW1zID0gc2xpY2UuY2Fs bChhcmd1bWVudHMsIDAsIC0xKSwKICAgICAgICBoYXNoID0gb3B0aW9ucy5o YXNoOwoKICAgIGlmIChwYXJhbXNbcGFyYW1zLmxlbmd0aCAtIDFdIGluc3Rh bmNlb2YgUXVlcnlQYXJhbXMpIHsKICAgICAgaGFzaC5xdWVyeVBhcmFtc09i amVjdCA9IHBhcmFtcy5wb3AoKTsKICAgIH0KCiAgICBoYXNoLmRpc2FibGVk QmluZGluZyA9IGhhc2guZGlzYWJsZWRXaGVuOwoKICAgIGlmICghb3B0aW9u cy5mbikgewogICAgICB2YXIgbGlua1RpdGxlID0gcGFyYW1zLnNoaWZ0KCk7 CiAgICAgIHZhciBsaW5rVHlwZSA9IG9wdGlvbnMudHlwZXMuc2hpZnQoKTsK ICAgICAgdmFyIGNvbnRleHQgPSB0aGlzOwogICAgICBpZiAobGlua1R5cGUg PT09ICdJRCcpIHsKICAgICAgICBvcHRpb25zLmxpbmtUZXh0UGF0aCA9IGxp bmtUaXRsZTsKICAgICAgICBvcHRpb25zLmZuID0gZnVuY3Rpb24oKSB7CiAg ICAgICAgICByZXR1cm4gRW1iZXIuSGFuZGxlYmFycy5nZXRFc2NhcGVkKGNv bnRleHQsIGxpbmtUaXRsZSwgb3B0aW9ucyk7CiAgICAgICAgfTsKICAgICAg fSBlbHNlIHsKICAgICAgICBvcHRpb25zLmZuID0gZnVuY3Rpb24oKSB7CiAg ICAgICAgICByZXR1cm4gbGlua1RpdGxlOwogICAgICAgIH07CiAgICAgIH0K ICAgIH0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z TmFtZXM6IFsnc3BlY2lhbCddCiAgICB9KTsKICAgIGBgYAoKICAgIEBtZXRo b2Qgb3V0bGV0CiAgICBAZm9yIEVtYmVyLkhhbmRsZWJhcnMuaGVscGVycwog ICAgQHBhcmFtIHtTdHJpbmd9IHByb3BlcnR5IHRoZSBwcm9wZXJ0eSBvbiB0 aGUgY29udHJvbGxlcgogICAgICB0aGF0IGhvbGRzIHRoZSB2aWV3IGZvciB0 aGlzIG91dGxldAogICAgQHJldHVybiB7U3RyaW5nfSBIVE1MIHN0cmluZwog ICovCiAgSGFuZGxlYmFycy5yZWdpc3RlckhlbHBlcignb3V0bGV0JywgZnVu Y3Rpb24gb3V0bGV0SGVscGVyKHByb3BlcnR5LCBvcHRpb25zKSB7CiAgIAog ICAgdmFyIG91dGxldFNvdXJjZSwKICAgICAgICBjb250YWluZXIsCiAgICAg ICAgdmlld05hbWUsCiAgICAgICAgdmlld0NsYXNzLAogICAgICAgIHZpZXdG dWxsTmFtZTsKCiAgICBpZiAocHJvcGVydHkgJiYgcHJvcGVydHkuZGF0YSAm JiBwcm9wZXJ0eS5kYXRhLmlzUmVuZGVyRGF0YSkgewogICAgICBvcHRpb25z ID0gcHJvcGVydHk7CiAgICAgIHByb3BlcnR5ID0gJ21haW4nOwogICAgfQoK ICAgIGNvbnRhaW5lciA9IG9wdGlvbnMuZGF0YS52aWV3LmNvbnRhaW5lcjsK CiAgICBvdXRsZXRTb3VyY2UgPSBvcHRpb25zLmRhdGEudmlldzsKICAgIHdo aWxlICghb3V0bGV0U291cmNlLmdldCgndGVtcGxhdGUuaXNUb3AnKSkgewog ICAgICBvdXRsZXRTb3VyY2UgPSBvdXRsZXRTb3VyY2UuZ2V0KCdfcGFyZW50 VmlldycpOwogICAgfQoKICAgIC8vIHByb3ZpZGUgY29udHJvbGxlciBvdmVy cmlkZQogICAgdmlld05hbWUgPSBvcHRpb25zLmhhc2gudmlldzsKCiAgICBp ZiAodmlld05hbWUpIHsKICAgICAgdmlld0Z1b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g Y29udHJvbGxlck5hbWU7CgogICAgaWYgKG9wdGlvbnMuaGFzaC5jb250cm9s bGVyKSB7CiAgICAgIEVtYmVyLmFzc2VydCgiVGhlIGNvbnRyb2xsZXIgbmFt ZSB5b3Ugc3VwcGxpZWQgJyIgKyBjb250cm9sbGVyTmFtZSArICInIGRpZCBu b3QgcmVzb2x2ZSB0byBhIGNvbnRyb2xsZXIuIiwgY29udGFpbmVyLmhhcyhj b250cm9sbGVyRnVsbE5hbWUpKTsKICAgIH0KCiAgICB2YXIgcGFyZW50Q29u dHJvbGxlciA9IG9wdGlvbnMuZGF0YS5rZXl3b3Jkcy5jb250cm9sbGVyOwoK ICAgIC8vIGNob29zZSBuYW1lCiAgICBpZiAobGVuZ3RoID4gMikgewogICAg ICB2YXIgZmFjdG9yeSA9IGNvbnRhaW5lci5sb29rdXBGYWN0b3J5KGNvbnRy b2xsZXJGdWxsTmFtZSkgfHwKICAgICAgICAgICAgICAgICAgICBFbWJlci5n ZW5lcmF0ZUNvbnRyb2xsZXJGYWN0b3J5KGNvbnRhaW5lciwgY29udHJvbGxl ck5hbWUsIGNvbnRleHQpOwoKICAgICAgY29udHJvbGxlciA9IGZhY3Rvcnku Y3JlYXRlKHsKICAgICAgICBtb2RlbDogY29udGV4dCwKICAgICAgICBwYXJl bnRDb250cm9sbGVyOiBwYXJlbnRDb250cm9sbGVyLAogICAgICAgIHRhcmdl dDogcGFyZW50Q29udHJvbGxlcgogICAgICB9KTsKCiAgICB9IGVsc2Ugewog ICAgICBjb250cm9sbGVyID0gY29udGFpbmVyLmxvb2t1cChjb250cm9sbGVy RnVsbE5hbWUpIHx8CiAgICAgICAgICAgICAgICAgICBFbWJlci5nZW5lcmF0 ZUNvbnRyb2xsZXIoY29udGFpbmVyLCBjb250cm9sbGVyTmFtZSk7CgogICAg ICBjb250cm9sbGVyLnNldFByb3BlcnRpZXMoewogICAgICAgIHRhcmdldDog cGFyZW50Q29udHJvbGxlciwKICAgICAgICBwYXJlbnRDb250c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SA9IHsKICAgICAgZXZlbnROYW1lOiBvcHRpb25z LmV2ZW50TmFtZSwKICAgICAgaGFuZGxlcjogZnVuY3Rpb24gaGFuZGxlUmVn aXN0ZXJlZEFjdGlvbihldmVudCkgewogICAgICAgIGlmICghaXNBbGxvd2Vk RXZlbnQoZXZlbnQsIGFsbG93ZWRLZXlzKSkgeyByZXR1cm4gdHJ1ZTsgfQoK ICAgICAgICBpZiAob3B0aW9ucy5wcmV2ZW50RGVmYXVsdCAhPT0gZmFsc2Up IHsKICAgICAgICAgIGV2ZW50LnByZXZlbnREZWZhdWx0KCk7CiAgICAgICAg fQoKICAgICAgICBpZiAob3B0aW9ucy5idWJibGVzID09PSBmYWxzZSkgewog ICAgICAgICAgZXZlbnQuc3RvcFByb3BhZ2F0aW9uKCk7CiAgICAgICAgfQoK ICAgICAgICB2YXIgdGFyZ2V0ID0gb3B0aW9ucy50YXJnZXQsCiAgICAgICAg ICAgIGFjdGlvbk5hbWU7CgogICAgICAgIGlmICh0YXJnZXQudGFyZ2V0KSB7 CiAgICAgICAgICB0YXJnZXQgPSBoYW5kbGViYXJzR2V0KHRhcmdldC5yb290 LCB0YXJnZXQudGFyZ2V0LCB0YXJnZXQub3B0aW9ucyk7CiAgICAgICAgfSBl bHNlIHsKICAgICAgICAgIHRhcmdldCA9IHRhcmdldC5yb290OwogICAgICAg IH0KCiAgICAgICAgCiAgICAgICAgICBpZiAob3B0aW9ucy5ib3VuZFByb3Bl cnR5KSB7CiAgICAgICAgICAgIGFjdGlvbk5hbWUgPSBoYW5kbGViYXJzR2V0 KHRhcmdldCwgYWN0aW9uTmFtZU9yUGF0aCwgb3B0aW9ucy5vcHRpb25zKTsK CiAgICAgICAgICAgIGlmKHR5cGVvZiBhY3Rpb25OYW1lID09PSAndW5kZWZp bmVkJyB8fCB0eXBlb2YgYWN0aW9uTmFtZSA9PT0gJ2Z1bmN0aW9uJykgewog ICAgICAgICAgICAgIEVtYmVyLmFzc2VydCgiWW91IHNwZWNpZmllZCBhIHF1 b3RlbGVzcyBwYXRoIHRvIHRoZSB7e2FjdGlvbn19IGhlbHBlciAnIiArIGFj dGlvbk5hbWVPclBhdGggKyAiJyB3aGljaCBkaWQgbm90IHJlc29sdmUgdG8g YW4gYWN0aW9uTmFtZS4gUGVyaGFwcyB5b3UgbWVhbnQgdG8gdXNlIGEgcXVv dGVkIGFjdGlvbk5hbWU/IChlLmcuIHt7YWN0aW9uICciICsgYWN0aW9uTmFt ZU9yUGF0aCArICInfX0pLiIsIHRydWUpOwogICAgICAgICAgICAgIGFjdGlv bk5hbWUgPSBhY3Rpb25OYW1lT3JQYXRoOwogICAgICAgICAgICB9CiAgICAg ICAgICB9CiAgICAgICAgCiAgICAgICAgaWYgKCFhY3Rpb25OYW1lKSB7CiAg ICAgICAgICBhY3Rpb25OYW1lID0gYWN0aW9uTmFtZU9yUGF0aDsKICAgICAg ICB9CgogICAgICAgIEVtYmVyLnJ1bihmdW5jdGlvbiBydW5SZWdpc3RlcmVk QWN0aW9uKCkgewogICAgICAgICAgaWYgKHRhcmdldC5zZW5kKSB7CiAgICAg ICAgICAgIHRhcmdldC5zZW5kLmFwcGx5KHRhcmdldCwgYXJncyhvcHRpb25z LnBhcmFtZXRlcnMsIGFjdGlvbk5hbWUpKTsKICAgICAgICAgIH0gZWxzZSB7 CiAgICAgICAgICAgIEVtYmVyLmFzc2VydCgiVGhlIGFjdGlvbiAnIiArIGFj dGlvbk5hbWUgKyAiJyBkaWQgbm90IGV4aXN0IG9uICIgKyB0YXJnZXQsIHR5 cGVvZiB0YXJnZXRbYWN0aW9uTmFtZV0gPT09ICdmdW5jdGlvbicpOwogICAg ICAgICAgICB0YXJnZXRbYWN0aW9uTmFtZV0uYXBwbHkodGFyZ2V0LCBhcmdz KG9wdGlvbnMucGFyYW1ldGVycykpOwogICAgICAgICAgfQogICAgICAgIH0p OwogICAgICB9CiAgICB9OwoKICAgIG9wdGlvbnMudmlldy5vbignd2lsbENs ZWFyUmVuZGVyJywgZnVuY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PC9oMT4gJykK ICAgIH0pOwogICAgdmFyIGZvb1ZpZXcgPSBGb29WaWV3LmNyZWF0ZSgpOwog ICAgbXlWaWV3LmNvbm5lY3RPdXRsZXQoJ21haW4nLCBmb29WaWV3KTsKICAg IC8vIFRoZSBodG1sIGZvciBteVZpZXcgbm93IGxvb2tzIGxpa2U6CiAgICAv LyA8ZGl2IGlkPSJlbWJlcjIyOCIgY2xhc3M9ImVtYmVyLXZpZXciPkNoaWxk IHZpZXc6CiAgICAvLyAgIDxkaXYgaWQ9ImVtYmVyMjM0IiBjbGFzcz0iZW1i ZXItdmlldyI+PGgxPkZvbzwvaDE+IDwvZGl2PgogICAgLy8gPC9kaXY+CiAg ICBgYGAKICAgIEBtZXRob2QgY29ubmVjdE91dGxldAogICAgQHBhcmFtICB7 U3RyaW5nfSBvdXRsZXROYW1lIEEgdW5pcXVlIG5hbWUgZm9yIHRoZSBvdXRs ZXQKICAgIEBwYXJhbSAge09iamVjdH0gdmlldyAgICAgICBBbiBFbWJlci5W aWV3CiAgICovCiAgY29ubmVjdE91dGxldDogZnVuY3Rpb24ob3V0bGV0TmFt ZSwgdmlldykgewogICAgaWYgKHRoaXMuX3BlbmRpbmdEaXNjb25uZWN0aW9u cykgewogICAgICBkZWxldGUgdGhpcy5fcGVuZGluZ0Rpc2Nvbm5lY3Rpb25z W291dGxldE5hbWVdOwogICAgfQoKICAgIGlmICh0aGlzLl9oYXNFcXVpdmFs ZW50VmlldyhvdXRsZXROYW1lLCB2aWV3KSkgewogICAgICB2aWV3LmRlc3Ry b3koKTsKICAgICAgcmV0dXJuOwogICAgfQoKICAgIHZhciBvdXRsZXRzID0g Z2V0KHRoaXMsICdfb3V0bGV0cycpLAogICAgICAgIGNvbnRhaW5lciA9IGdl dCh0aGlzLCAnY29udGFpbmVyJyksCiAgICAgICAgcm91dGVyID0gY29udGFp bmVyICYmIGNvbnRhaW5lci5sb29rdXAoJ3JvdXRlcjptYWluJyksCiAgICAg ICAgcmVuZGVyZWROY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vIHdlIHN0YXJ0IG9mZiBjbGVhbiBhbmQgY29uc2lz dGVudC4KICAgICAgICBpZiAoY3VycmVudFBhdGggPT09IGhhc2hQYXRoKSB7 CiAgICAgICAgICBpbXBsZW1lbnRhdGlvbkNsYXNzID0gRW1iZXIuSGFzaExv Y2F0aW9uOwogICAgICAgIH0gZWxzZSB7CiAgICAgICAgICBjYW5jZWxSb3V0 ZXJTZXR1cCA9IHRydWU7CiAgICAgICAgICBsb2NhdGlvbi5yZXBsYWNlKGhh c2hQYXRoKTsKICAgICAgICB9CiAgICAgIH0KCiAgICAgIC8vIElmIG5vbmUg aGFzIGJlZW4gc2V0CiAgICAgIGlmICghaW1wbGVtZW50YXRpb25DbGFzcykg ewogICAgICAgIGltcGxlbWVudGF0aW9uQ2xhc3MgPSBFbWJlci5Ob25lTG9j YXRpb247CiAgICAgIH0KCiAgICAgIHZhciBpbXBsZW1lbnRhdGlvbiA9IGlt cGxlbWVudGF0aW9uQ2xhc3MuY3JlYXRlLmFwcGx5KGltcGxlbWVudGF0aW9u Q2xhc3MsIGFyZ3VtZW50cyk7CgogICAgICBpZiAoY2FuY2VsUm91dGVyU2V0 dXApIHsKICAgICAgICBzZXQoaW1wbGVtZW50YXRpb24sICdjYW5jZWxSb3V0 ZXJTZXR1cCcsIHRydWUpOwogICAgICB9CiAgICAgIAogICAgICByZXR1cm4g aW1wbGVtZW50YXRpb247CiAgICB9LAoKICAgIC8qKgogICAgICBAcHJpdmF0 ZQoKICAgICAgUmV0dXJucyB0aGUgY3VycmVudCBgbG9jYXRpb24ucGF0aG5h bWVgLCBub3JtYWxpemVkIGZvciBJRSBpbmNvbnNpc3RlbmNpZXMuCgogICAg ICBAbWV0aG9kIGdldFBhdGgKICAgICovCiAgICBnZXRQYXRoOiBmdW5jdGlv biAoKSB7CiAgICAgIHZhciBwYXRobmFtZSA9IGxvY2F0aW9uLnBhdGhuYW1l OwogICAgICAvLyBWYXJpb3VzIHZlcnNpb25zIG9mIElFL09wZXJhIG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wZXJ0eSBuYW1lc3BhY2UKICAqLwog IG5hbWVzcGFjZTogbnVsbCwKCiAgbm9ybWFsaXplOiBmdW5jdGlvbihmdWxs TmFtZSkgewogICAgdmFyIHNwbGl0ID0gZnVsbE5hbWUuc3BsaXQoJzonLCAy KSwKICAgICAgICB0eXBlID0gc3BsaXRbMF0sCiAgICAgICAgbmFtZSA9IHNw bGl0WzFdOwoKICAgIEVtYmVyLmFzc2VydCgiVHJpZWQgdG8gbm9ybWFsaXpl IGEgY29udGFpbmVyIG5hbWUgd2l0aG91dCBhIGNvbG9uICg6KSBpbiAiICsK ICAgICAgICAgICAgICAgICAiaXQuIFlvdSBwcm9iYWJseSB0cmllZCB0byBs b29rdXAgYSBuYW1lIHRoYXQgZGlkIG5vdCBjb250YWluICIgKwogICAgICAg ICAgICAgICAgICJhIHR5cGUsIGEgY29sb24sIGFuZCBhIG5hbWUuIEEgcHJv cGVyIGxvb2t1cCBuYW1lIHdvdWxkIGJlICIgKwogICAgICAgICAgICAgICAg ICJgdmlldzpwb3N0YC4iLCBzcGxpdC5sZW5ndGggPT09IDIpOwoKICAgIGlm ICh0eXBlICE9PSAndGVtcGxhdGUnKSB7CiAgICAgIHZhciByZXN1bHQgPSBu YW1lOwoKICAgICAgaWYgKHJlc3VsdC5pbmRleE9mKCcuJykgPiAtMSkgewog ICAgICAgIHJlc3VsdCA9IHJlc3VsdC5yZXBsYWNlKC9cLiguKS9nLCBmdW5j dGlvbihtKSB7IHJldHVybiBtLmNoYXJBdCgxKS50b1VwcGVyQ2FzZSgpOyB9 KTsKICAgICAgfQoKICAgICAgaWYgKG5hbWUuaW5kZXhPZignXycpID4gLTEp IHsKICAgICAgICByZXN1bHQgPSByZXN1bHQucmVwbGFjZSgvXyguKS9nLCBm dW5jdGlvbihtKSB7IHJldHVybiBtLmNoYXJBdCgxKS50b1VwcGVyQ2FzZSgp OyB9KTsKICAgICAgfQoKICAgICAgcmV0dXJuIHR5cGUgKyAnOicgKyByZXN1 bHQ7C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WluZXJfXy5sb29rdXAoJ3JvdXRlcjptYWluJyk7CiAg ICAgIHJvdXRlci5yZXNldCgpOwoKICAgICAgRW1iZXIucnVuKHRoaXMuX19j b250YWluZXJfXywgJ2Rlc3Ryb3knKTsKCiAgICAgIHRoaXMuYnVpbGRDb250 YWluZXIoKTsKCiAgICAgIEVtYmVyLnJ1bi5zY2hlZHVsZSgnYWN0aW9ucycs IHRoaXMsIGZ1bmN0aW9uKCkgewogICAgICAgIHRoaXMuX2luaXRpYWxpemUo KTsKICAgICAgfSk7CiAgICB9CgogICAgRW1iZXIucnVuLmpvaW4odGhpcywg aGFuZGxlUmVzZXQpOwogIH0sCgogIC8qKgogICAgQHByaXZhdGUKICAgIEBt ZXRob2QgcnVuSW5pdGlhbGl6ZXJzCiAgKi8KICBydW5Jbml0aWFsaXplcnM6 IGZ1bmN0aW9uKCkgewogICAgdmFyIGluaXRpYWxpemVycyA9IGdldCh0aGlz LmNvbnN0cnVjdG9yLCAnaW5pdGlhbGl6ZXJzJyksCiAgICAgICAgY29udGFp bmVyID0gdGhpcy5fX2NvbnRhaW5lcl9fLAogICAgICAgIGdyYXBoID0gbmV3 IEVtYmVyLkRBRygpLAogICAgICAgIG5hbWVzcGFjZSA9IHRoaXMsCiAgICAg ICAgbmFtZSwgaW5pdGlhbGl6ZXI7CgogICAgZm9yIChuYW1lIGluIGluaXRp YWxpemVycykgewogICAgICBpbml0aWFsaXplciA9IGluaXRpYWxpemVyc1tu YW1lXTsKICAgICAgZ3JhcGguYWRkRWRnZXMoaW5pdGlhbGl6ZXIubmFtZSwg aW5pdGlhbGl6ZXIuaW5pdGlhbGl6ZSwgaW5pdGlhbGl6ZXIuYmVmb3JlLCBp bml0aWFsaXplci5hZnRlcik7CiAgICB9CgogICAgZ3JhcGgudG9wc29ydChm dW5jdGlvbiAodmVydGV4KSB7CiAgICAgIHZhciBpbml0aWFsaXplciA9IHZl cnRleC52YWx1ZTsKICAgICAgRW1iZXIuYXNzZXJ0KCJObyBhc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gICAgIGBkZWZhdWx0 VGVtcGxhdGVgIHByb3BlcnR5CgogICAgQHByaXZhdGUKICAgIEBtZXRob2Qg YnVpbGRDb250YWluZXIKICAgIEBzdGF0aWMKICAgIEBwYXJhbSB7RW1iZXIu QXBwbGljYXRpb259IG5hbWVzcGFjZSB0aGUgYXBwbGljYXRpb24gdG8gYnVp bGQgdGhlCiAgICAgIGNvbnRhaW5lciBmb3IuCiAgICBAcmV0dXJuIHtFbWJl ci5Db250YWluZXJ9IHRoZSBidWlsdCBjb250YWluZXIKICAqLwogIGJ1aWxk Q29udGFpbmVyOiBmdW5jdGlvbihuYW1lc3BhY2UpIHsKICAgIHZhciBjb250 YWluZXIgPSBuZXcgRW1iZXIuQ29udGFpbmVyKCk7CgogICAgRW1iZXIuQ29u dGFpbmVyLmRlZmF1bHRDb250YWluZXIgPSBuZXcgRGVwcmVjYXRlZENvbnRh aW5lcihjb250YWluZXIpOwoKICAgIGNvbnRhaW5lci5zZXQgPSBFbWJlci5z ZXQ7CiAgICBjb250YWluZXIucmVzb2x2ZXIgID0gcmVzb2x2ZXJGb3IobmFt ZXNwYWNlKTsKICAgIGNvbnRhaW5lci5ub3JtYWxpemUgPSBjb250YWluZXIu cmVzb2x2ZXIubm9ybWFsaXplOwogICAgY29udGFpbmVyLmRlc2NyaWJlICA9 IGNvbnRhaW5lci5yZXNvbHZlci5kZXNjcmliZTsKICAgIGNvbnRhaW5lci5t YWtlVG9TdHJpbmcgPSBjb250YWluZXIucmVzb2x2ZXIubWFrZVRvU3RyaW5n OwoKICAgIGNvbnRhaW5lci5vcHRpb25zRm9yVHlwZSgnY29tcG9uZW50Jywg eyBzaW5nbGV0b246IGZhbHNlIH0pOwogICAgY29udGFpbmVyLm9wdGlvbnNG b3JUeXBlKCd2aWV3JywgeyBzaW5nbGV0b246IGZhbHNlIH0pOwogICAgY29u dGFpbmVyLm9wdGlvbnNGb3JUeXBlKCd0ZW1wbGF0ZScsIHsgaW5zdGFudGlh dGU6IGZhbHN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BuaWNlbHkgd2l0aCBv dGhlciBhc3luY2hyb25vdXMKICAgICBldmVudHMsIHN1Y2ggYXMgYW4gYXBw bGljYXRpb24gdGhhdCBpcyB3YWl0aW5nIGZvciBhIENTUzMKICAgICB0cmFu c2l0aW9uIG9yIGFuIEluZGV4REIgdHJhbnNhY3Rpb24uCgogICAgIEZvciBl eGFtcGxlOgoKICAgICBgYGBqYXZhc2NyaXB0CiAgICAgRW1iZXIuVGVzdC5y ZWdpc3RlcldhaXRlcihmdW5jdGlvbigpIHsKICAgICAgIHJldHVybiBteVBl bmRpbmdUcmFuc2FjdGlvbnMoKSA9PSAwOwogICAgIH0pOwogICAgIGBgYAog ICAgIFRoZSBgY29udGV4dGAgYXJndW1lbnQgYWxsb3dzIHlvdSB0byBvcHRp b25hbGx5IHNwZWNpZnkgdGhlIGB0aGlzYAogICAgIHdpdGggd2hpY2ggeW91 ciBjYWxsYmFjayB3aWxsIGJlIGludm9rZWQuCgogICAgIEZvciBleGFtcGxl OgoKICAgICBgYGBqYXZhc2NyaXB0CiAgICAgRW1iZXIuVGVzdC5yZWdpc3Rl cldhaXRlcihNeURCLCBNeURCLmhhc1BlbmRpbmdUcmFuc2FjdGlvbnMpOwog ICAgIGBgYAoKICAgICBAcHVibGljCiAgICAgQG1ldGhvZCByZWdpc3Rlcldh aXRlcgogICAgIEBwYXJhbSB7T2JqZWN0fSBjb250ZXh0IChvcHRpb25hbCkK ICAgICBAcGFyYW0ge0Z1bmN0aW9ufSBjYWxsYmFjawogICovCiAgcmVnaXN0 ZXJXYWl0ZXI6IGZ1bmN0aW9uKGNvbnRleHQsIGNhbGxiYWNrKSB7CiAgICBp ZiAoYXJndW1lbnRzLmxlbmd0aCA9PT0gMSkgewogICAgICBjYWxsYmFjayA9 IGNvbnRleHQ7CiAgICAgIGNvbnRleHQgPSBudWxsOwogICAgfQogICAgaWYg KCF0aGlzLndhaXRlcnMpIHsKICAgICAgdGhpcy53YWl0ZXJzID0gRW1iZXIu QSgpOwogIC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dXNpbicpIGluc3RlYWQuCiAgICAgICAgaWYgKCFkb2N1bWVudC5oYXNG b2N1cyB8fCBkb2N1bWVudC5oYXNGb2N1cygpKSB7CiAgICAgICAgICB0aGlz LmZvY3VzKCk7CiAgICAgICAgfSBlbHNlIHsKICAgICAgICAgIHRoaXMudHJp Z2dlcignZm9jdXNpbicpOwogICAgICAgIH0KICAgICAgfSk7CiAgICB9CiAg fQoKICBFbWJlci5ydW4oJGVsLCAnbW91c2V1cCcpOwogIEVtYmVyLnJ1bigk ZWwsICdjbGljaycpOwoKICByZXR1cm4gd2FpdChhcHApOwp9CgpmdW5jdGlv biB0cmlnZ2VyRXZlbnQoYXBwLCBzZWxlY3RvciwgY29udGV4dCwgdHlwZSwg b3B0aW9ucyl7CiAgaWYgKGFyZ3VtZW50cy5sZW5ndGggPT09IDMpIHsKICAg IHR5cGUgPSBjb250ZXh0OwogICAgY29udGV4dCA9IG51bGw7CiAgfQoKICBp ZiAodHlwZW9mIG9wdGlvbnMgPT09ICd1bmRlZmluZWQnKSB7CiAgICBvcHRp b25zID0ge307CiAgfQoKICB2YXIgJGVsID0gZmluZFdpdGhBc3NlcnQoYXBw LCBzZWxlY3RvciwgY29udGV4dCk7CgogIHZhciBldmVudCA9IEVtYmVyLiQu RXZlbnQodHlwZSwgb3B0aW9ucyk7CgogIEVtYmVyLnJ1bigkZWwsICd0cmln Z2VyJywgZXZlbnQpOwoKICByZXR1cm4gd2FpdChhcHApOwp9CgpmdW5jdGlv biBrZXlFdmVudChhcHAsIHNlbGVjdG9yLCBjb250ZXh0LCB0eXBlLCBrZXlD b2RlKSB7CiAgaWYgKHR5cGVvZiBrZXlDb2RlID09PSAndW5kZWZpbmVkJykg ewogICAga2V5Q29kZSA9IHR5cGU7CiAgICB0eXBlID0gY29udGV4dDsKICAg IGNvbnRleHQgPSBudWxsOwogIH0KCiAgcmV0dXJuIHRyaWdnZXJFdmVudChh cHAsIHNlbGVjdG9yLCBjb250ZXh0LCB0eXBlLCB7IG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uZXJhdGVSZW1vdmVkQ2xhc3MoY2xh c3NOYW1lKSB7CiAgdmFyIG1zZyA9ICIgaGFzIGJlZW4gbW92ZWQgaW50byBh IHBsdWdpbjogaHR0cHM6Ly9naXRodWIuY29tL2VtYmVyanMvZW1iZXItc3Rh dGVzIjsKCiAgcmV0dXJuIHsKICAgIGV4dGVuZDogdGhyb3dXaXRoTWVzc2Fn ZShjbGFzc05hbWUgKyBtc2cpLAogICAgY3JlYXRlOiB0aHJvd1dpdGhNZXNz YWdlKGNsYXNzTmFtZSArIG1zZykKICB9Owp9CgpFbWJlci5TdGF0ZU1hbmFn ZXIgPSBnZW5lcmF0ZVJlbW92ZWRDbGFzcygiRW1iZXIuU3RhdGVNYW5hZ2Vy Iik7CgovKioKICBUaGlzIHdhcyBleHBvcnRlZCB0byBlbWJlci1zdGF0ZXMg cGx1Z2luIGZvciB2IDEuMC4wIHJlbGVhc2UuIFNlZTogaHR0cHM6Ly9naXRo dWIuY29tL2VtYmVyanMvZW1iZXItc3RhdGVzCiAgCiAgQGNsYXNzIFN0YXRl TWFuYWdlcgogIEBuYW1lc3BhY2UgRW1iZXIKKi8KCkVtYmVyLlN0YXRlID0g Z2VuZXJhdGVSZW1vdmVkQ2xhc3MoIkVtYmVyLlN0YXRlIik7CgovKioKICBU aGlzIHdhcyBleHBvcnRlZCB0byBlbWJlci1zdGF0ZXMgcGx1Z2luIGZvciB2 IDEuMC4wIHJlbGVhc2UuIFNlZTogaHR0cHM6Ly9naXRodWIuY29tL2VtYmVy anMvZW1iZXItc3RhdGVzCiAgCiAgQGNsYXNzIFN0YXRlCiAgQG5hbWVzcGFj ZSBFbWJlcgoqLwoKfSkoKTsKCgp9KSgpOwo= http_version: recorded_at: Mon, 17 Feb 2014 11:45:32 GMT - request: method: get uri: http://builds.emberjs.com/beta/ember.min.js body: encoding: US-ASCII string: '' headers: Accept-Encoding: - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 Accept: - '*/*' User-Agent: - Ruby Host: - builds.emberjs.com response: status: code: 200 message: OK headers: X-Amz-Id-2: - vmFYSDC3xmix7unI9Dn+qykjzRSDkwiAjuKmwrtQa8XLu++WG324EBz3BSzhaXGk X-Amz-Request-Id: - 02C06AB32FD68411 Date: - Mon, 17 Feb 2014 11:45:33 GMT Last-Modified: - Sun, 16 Feb 2014 02:41:59 GMT Etag: - '"f830b8670f3324a8b840bd32b237bbe5"' Content-Type: - text/javascript Content-Length: - '272434' Server: - AmazonS3 body: encoding: ASCII-8BIT string: !binary |- LyohCiAqIEBvdmVydmlldyAgRW1iZXIgLSBKYXZhU2NyaXB0IEFwcGxpY2F0 aW9uIEZyYW1ld29yawogKiBAY29weXJpZ2h0IENvcHlyaWdodCAyMDExLTIw MTQgVGlsZGUgSW5jLiBhbmQgY29udHJpYnV0b3JzCiAqICAgICAgICAgICAg UG9ydGlvbnMgQ29weXJpZ2h0IDIwMDYtMjAxMSBTdHJvYmUgSW5jLgogKiAg ICAgICAgICAgIFBvcnRpb25zIENvcHlyaWdodCAyMDA4LTIwMTEgQXBwbGUg SW5jLiBBbGwgcmlnaHRzIHJlc2VydmVkLgogKiBAbGljZW5zZSAgIExpY2Vu c2VkIHVuZGVyIE1JVCBsaWNlbnNlCiAqICAgICAgICAgICAgU2VlIGh0dHBz Oi8vcmF3LmdpdGh1Yi5jb20vZW1iZXJqcy9lbWJlci5qcy9tYXN0ZXIvTElD RU5TRQogKiBAdmVyc2lvbiAgIDEuNS4wLWJldGEuMitwcmUuM2NlOGY5YWMK ICovCiFmdW5jdGlvbigpe3ZhciBlLHQscixuOyFmdW5jdGlvbigpe3ZhciBp PXt9LG89e307ZT1mdW5jdGlvbihlLHQscil7aVtlXT17ZGVwczp0LGNhbGxi YWNrOnJ9fSxuPXI9dD1mdW5jdGlvbihlKXtmdW5jdGlvbiByKHQpe2lmKCIu IiE9PXQuY2hhckF0KDApKXJldHVybiB0O2Zvcih2YXIgcj10LnNwbGl0KCIv Iiksbj1lLnNwbGl0KCIvIikuc2xpY2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