當前位置: 首頁>>代碼示例>>Python>>正文


Python Policy.network_use方法代碼示例

本文整理匯總了Python中zeroinstall.injector.policy.Policy.network_use方法的典型用法代碼示例。如果您正苦於以下問題:Python Policy.network_use方法的具體用法?Python Policy.network_use怎麽用?Python Policy.network_use使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在zeroinstall.injector.policy.Policy的用法示例。


在下文中一共展示了Policy.network_use方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testFeeds

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
	def testFeeds(self):
		self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="0"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <feed src='http://bar'/>
</interface>""" % foo_iface_uri)
		self.cache_iface('http://bar',
"""<?xml version="1.0" ?>
<interface last-modified="0"
 uri="http://bar"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <feed-for interface='%s'/>
  <name>Bar</name>
  <summary>Bar</summary>
  <description>Bar</description>
  <implementation version='1.0' id='sha1=123' main='dummy'>
    <archive href='foo' size='10'/>
  </implementation>
</interface>""" % foo_iface_uri)
		policy = Policy(foo_iface_uri, config = self.config)
		policy.freshness = 0
		policy.network_use = model.network_full
		recalculate(policy)
		assert policy.ready
		foo_iface = self.config.iface_cache.get_interface(foo_iface_uri)
		self.assertEquals('sha1=123', policy.implementation[foo_iface].id)
開發者ID:gvsurenderreddy,項目名稱:zeroinstall,代碼行數:33,代碼來源:testautopolicy.py

示例2: testConstraints

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
	def testConstraints(self):
		self.cache_iface('http://bar',
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="http://bar"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Bar</name>
  <summary>Bar</summary>
  <description>Bar</description>
  <implementation id='sha1=100' version='1.0'>
    <archive href='foo' size='10'/>
  </implementation>
  <implementation id='sha1=150' stability='developer' version='1.5'>
    <archive href='foo' size='10'/>
  </implementation>
  <implementation id='sha1=200' version='2.0'>
    <archive href='foo' size='10'/>
  </implementation>
</interface>""")
		self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <group main='dummy'>
   <requires interface='http://bar'>
    <version/>
   </requires>
   <implementation id='sha1=123' version='1.0'>
    <archive href='foo' size='10'/>
   </implementation>
  </group>
</interface>""" % foo_iface_uri)
		policy = Policy(foo_iface_uri, config = self.config)
		policy.network_use = model.network_full
		policy.freshness = 0
		#logger.setLevel(logging.DEBUG)
		recalculate(policy)
		#logger.setLevel(logging.WARN)
		foo_iface = self.config.iface_cache.get_interface(foo_iface_uri)
		bar_iface = self.config.iface_cache.get_interface('http://bar')
		assert policy.implementation[bar_iface].id == 'sha1=200'

		dep = policy.implementation[foo_iface].dependencies['http://bar']
		assert len(dep.restrictions) == 1
		restriction = dep.restrictions[0]

		restriction.before = model.parse_version('2.0')
		recalculate(policy)
		assert policy.implementation[bar_iface].id == 'sha1=100'

		restriction.not_before = model.parse_version('1.5')
		recalculate(policy)
		assert policy.implementation[bar_iface].id == 'sha1=150'
開發者ID:gvsurenderreddy,項目名稱:zeroinstall,代碼行數:59,代碼來源:testautopolicy.py

示例3: testBackground

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
    def testBackground(self, verbose=False):
        p = Policy("http://example.com:8000/Hello.xml", config=self.config)
        self.import_feed(p.root, "Hello.xml")
        p.freshness = 0
        p.network_use = model.network_minimal
        p.solver.solve(p.root, arch.get_host_architecture())
        assert p.ready, p.solver.get_failure_reason()

        @tasks.async
        def choose_download(registed_cb, nid, actions):
            try:
                assert actions == ["download", "Download"], actions
                registed_cb(nid, "download")
            except:
                import traceback

                traceback.print_exc()
            yield None

        global ran_gui
        ran_gui = False
        old_out = sys.stdout
        try:
            sys.stdout = StringIO()
            self.child = server.handle_requests("Hello.xml", "6FCF121BE2390E0B.gpg")
            my_dbus.system_services = {
                "org.freedesktop.NetworkManager": {"/org/freedesktop/NetworkManager": NetworkManager()}
            }
            my_dbus.user_callback = choose_download
            pid = os.getpid()
            old_exit = os._exit

            def my_exit(code):
                # The background handler runs in the same process
                # as the tests, so don't let it abort.
                if os.getpid() == pid:
                    raise SystemExit(code)
                    # But, child download processes are OK
                old_exit(code)

            key_info = fetch.DEFAULT_KEY_LOOKUP_SERVER
            fetch.DEFAULT_KEY_LOOKUP_SERVER = None
            try:
                try:
                    os._exit = my_exit
                    background.spawn_background_update(p, verbose)
                    assert False
                except SystemExit, ex:
                    self.assertEquals(1, ex.code)
            finally:
                os._exit = old_exit
                fetch.DEFAULT_KEY_LOOKUP_SERVER = key_info
        finally:
            sys.stdout = old_out
        assert ran_gui
開發者ID:pombredanne,項目名稱:zero-install,代碼行數:57,代碼來源:testdownload.py

示例4: testBestUnusable

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
	def testBestUnusable(self):
		self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <implementation id='sha1=123' version='1.0' arch='odd-weird' main='dummy'/>
</interface>""" % foo_iface_uri)
		policy = Policy(foo_iface_uri, config = self.config)
		policy.network_use = model.network_offline
		recalculate(policy)
		assert not policy.ready, policy.implementation
		try:
			download_and_execute(policy, [])
			assert False
		except model.SafeException as ex:
			assert "has no usable implementations" in str(ex), ex
開發者ID:gvsurenderreddy,項目名稱:zeroinstall,代碼行數:22,代碼來源:testautopolicy.py

示例5: testNeedDL

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
	def testNeedDL(self):
		self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="0"
 uri="%s"
 main='ThisBetterNotExist'
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <implementation version='1.0' id='sha1=123'>
    <archive href='http://foo/foo.tgz' size='100'/>
  </implementation>
</interface>""" % foo_iface_uri)
		policy = Policy(foo_iface_uri, config = self.config)
		policy.freshness = 0
		policy.network_use = model.network_full
		recalculate(policy)
		assert policy.need_download()
		assert policy.ready
開發者ID:gvsurenderreddy,項目名稱:zeroinstall,代碼行數:22,代碼來源:testautopolicy.py

示例6: testDLfeed

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
	def testDLfeed(self):
		self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="1110752708"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <feed src='http://example.com'/>
</interface>""" % foo_iface_uri)
		policy = Policy(foo_iface_uri, config = self.config)
		policy.network_use = model.network_full
		policy.freshness = 0

		assert policy.need_download()

		feed = self.config.iface_cache.get_feed(foo_iface_uri)
		feed.feeds = [model.Feed('/BadFeed', None, False)]

		logger.setLevel(logging.ERROR)
		assert policy.need_download()	# Triggers warning
		logger.setLevel(logging.WARN)
開發者ID:gvsurenderreddy,項目名稱:zeroinstall,代碼行數:25,代碼來源:testautopolicy.py

示例7: testSource

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
    def testSource(self):
        iface_cache = self.config.iface_cache
        warnings.filterwarnings("ignore", category=DeprecationWarning)

        foo = iface_cache.get_interface("http://foo/Binary.xml")
        self.import_feed(foo.uri, "Binary.xml")
        foo_src = iface_cache.get_interface("http://foo/Source.xml")
        self.import_feed(foo_src.uri, "Source.xml")
        compiler = iface_cache.get_interface("http://foo/Compiler.xml")
        self.import_feed(compiler.uri, "Compiler.xml")

        p = Policy("http://foo/Binary.xml", config=self.config)
        p.freshness = 0
        p.network_use = model.network_full
        p.recalculate()  # Deprecated
        assert p.implementation[foo].id == "sha1=123"

        # Now ask for source instead
        p.requirements.source = True
        p.requirements.command = "compile"
        p.recalculate()
        assert p.solver.ready, p.solver.get_failure_reason()
        assert p.implementation[foo].id == "sha1=234"  # The source
        assert p.implementation[compiler].id == "sha1=345"  # A binary needed to compile it
開發者ID:pombredanne,項目名稱:zero-install,代碼行數:26,代碼來源:testpolicy.py

示例8: testBinding

# 需要導入模塊: from zeroinstall.injector.policy import Policy [as 別名]
# 或者: from zeroinstall.injector.policy.Policy import network_use [as 別名]
	def testBinding(self):
		local_impl = os.path.dirname(os.path.abspath(__file__))
		tmp = tempfile.NamedTemporaryFile()
		tmp.write(
"""<?xml version="1.0" ?>
<interface
 main='testautopolicy.py'
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Bar</name>
  <summary>Bar</summary>
  <description>Bar</description>
  <group>
    <requires interface='%s'>
      <environment name='FOO_PATH' insert='.'/>
      <environment name='BAR_PATH' insert='.' default='/a:/b'/>
      <environment name='NO_PATH' value='val'/>
      <environment name='XDG_DATA_DIRS' insert='.'/>
    </requires>
    <environment name='SELF_GROUP' insert='group' mode='replace'/>
    <implementation version='1.0' id='%s'>
      <environment name='SELF_IMPL' insert='impl' mode='replace'/>
    </implementation>
  </group>
</interface>""" % (foo_iface_uri, local_impl))
		tmp.flush()
		self.cache_iface(foo_iface_uri,
"""<?xml version="1.0" ?>
<interface last-modified="0"
 uri="%s"
 xmlns="http://zero-install.sourceforge.net/2004/injector/interface">
  <name>Foo</name>
  <summary>Foo</summary>
  <description>Foo</description>
  <implementation version='1.0' id='sha1=123'/>
</interface>""" % foo_iface_uri)
		cached_impl = basedir.save_cache_path('0install.net',
							'implementations',
							'sha1=123')
		policy = Policy(tmp.name, config = self.config)
		policy.network_use = model.network_offline
		os.environ['FOO_PATH'] = "old"
		old, sys.stdout = sys.stdout, StringIO()
		try:
			download_and_execute(policy, ['Hello'])
		finally:
			sys.stdout = old
		self.assertEquals(cached_impl + '/.:old',
				os.environ['FOO_PATH'])
		self.assertEquals(cached_impl + '/.:/a:/b',
				os.environ['BAR_PATH'])
		self.assertEquals('val', os.environ['NO_PATH'])
		
		self.assertEquals(os.path.join(local_impl, 'group'), os.environ['SELF_GROUP'])
		self.assertEquals(os.path.join(local_impl, 'impl'), os.environ['SELF_IMPL'])

		del os.environ['FOO_PATH']
		if 'XDG_DATA_DIRS' in os.environ:
			del os.environ['XDG_DATA_DIRS']
		os.environ['BAR_PATH'] = '/old'
		old, sys.stdout = sys.stdout, StringIO()
		try:
			download_and_execute(policy, ['Hello'])
		finally:
			sys.stdout = old
		self.assertEquals(cached_impl + '/.',
				os.environ['FOO_PATH'])
		self.assertEquals(cached_impl + '/.:/old',
				os.environ['BAR_PATH'])
		self.assertEquals(cached_impl + '/.:/usr/local/share:/usr/share',
				os.environ['XDG_DATA_DIRS'])
開發者ID:gvsurenderreddy,項目名稱:zeroinstall,代碼行數:72,代碼來源:testautopolicy.py


注:本文中的zeroinstall.injector.policy.Policy.network_use方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。