Guest User

Untitled

a guest
Jan 12th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import json
  2. import os
  3. import sys
  4.  
  5. from selenium import webdriver
  6.  
  7. class FirefoxProfile(webdriver.FirefoxProfile):
  8. """
  9. FirefoxProfileの拡張クラス
  10. """
  11.  
  12. def _addon_details(self, addon_path):
  13. """
  14. install.rdfがない場合、manifest.jsonを探す
  15. """
  16. try:
  17. return super()._addon_details(addon_path)
  18. except webdriver.firefox.firefox_profile.AddonFormatError:
  19. try:
  20. with open(os.path.join(addon_path, 'manifest.json'), 'r', encoding='utf-8_sig') as f:
  21. manifest = json.load(f)
  22. return {
  23. 'id': manifest['applications']['gecko']['id'],
  24. 'version': manifest['version'],
  25. 'name': manifest['name'],
  26. 'unpack': False,
  27. }
  28. except (IOError, KeyError) as e:
  29. raise AddonFormatError(str(e), sys.exc_info()[2])
Add Comment
Please, Sign In to add comment