<commit_before>"""
Parses an XML interface into a Python representation.
"""

# Copyright (C) 2006, <NAME>
# See the README file for details, or visit http://0install.net.

import os
import sys
import shutil
import time
from logging import debug, warn, info
from os.path import dirname

from zeroinstall.injector import basedir, qdom
from zeroinstall.injector.namespaces import *
from zeroinstall.injector.model import *
from zeroinstall import version, SafeException

class InvalidInterface(SafeException):
	"""Raised when parsing an invalid interface."""
	def __init__(self, message, ex = None):
		if ex:
			message += "\n\n(exact error: %s)" % ex
		SafeException.__init__(self, message)

def _process_depends(dependency, item):
	# Note: also called from selections
	for e in item.childNodes:
		if e.uri != XMLNS_IFACE: continue
		if e.name == 'environment':
			binding = EnvironmentBinding(e.getAttribute('name'),
						     insert = e.getAttribute('insert'),
						     default = e.getAttribute('default'))
			if not binding.name: raise InvalidInterface("Missing 'name' in binding")
			if not binding.insert: raise InvalidInterface("Missing 'insert' in binding")
			dependency.bindings.append(binding)
		elif e.name == 'version':
			dependency.restrictions.append(
				Restriction(not_before = parse_version(e.getAttribute('not-before')),
					    before = parse_version(e.getAttribute('before'))))

def update_from_cache(interface):
	"""Read a cached interface and any user overrides.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@return: True if cached version and user overrides loaded OK.
	False if upstream not cached. Local interfaces (starting with /) are
	always considered to be cached, although they are not actually stored in the cache.
	@rtype: bool"""
	interface.reset()

	if interface.uri.startswith('/'):
		debug("Loading local interface file '%s'", interface.uri)
		update(interface, interface.uri, local = True)
		interface.last_modified = int(os.stat(interface.uri).st_mtime)
		cached = True
	else:
		cached = basedir.load_first_cache(config_site, 'interfaces', escape(interface.uri))
		if cached:<commit_msg>Fix for previous extra check: it's OK for <environment>'s insert value to be<commit_after>"""
Parses an XML interface into a Python representation.
"""

# Copyright (C) 2006, <NAME>
# See the README file for details, or visit http://0install.net.

import os
import sys
import shutil
import time
from logging import debug, warn, info
from os.path import dirname

from zeroinstall.injector import basedir, qdom
from zeroinstall.injector.namespaces import *
from zeroinstall.injector.model import *
from zeroinstall import version, SafeException

class InvalidInterface(SafeException):
	"""Raised when parsing an invalid interface."""
	def __init__(self, message, ex = None):
		if ex:
			message += "\n\n(exact error: %s)" % ex
		SafeException.__init__(self, message)

def _process_depends(dependency, item):
	# Note: also called from selections
	for e in item.childNodes:
		if e.uri != XMLNS_IFACE: continue
		if e.name == 'environment':
			binding = EnvironmentBinding(e.getAttribute('name'),
						     insert = e.getAttribute('insert'),
						     default = e.getAttribute('default'))
			if not binding.name: raise InvalidInterface("Missing 'name' in binding")
			if binding.insert is None: raise InvalidInterface("Missing 'insert' in binding")
			dependency.bindings.append(binding)
		elif e.name == 'version':
			dependency.restrictions.append(
				Restriction(not_before = parse_version(e.getAttribute('not-before')),
					    before = parse_version(e.getAttribute('before'))))

def update_from_cache(interface):
	"""Read a cached interface and any user overrides.
	@param interface: the interface object to update
	@type interface: L{model.Interface}
	@return: True if cached version and user overrides loaded OK.
	False if upstream not cached. Local interfaces (starting with /) are
	always considered to be cached, although they are not actually stored in the cache.
	@rtype: bool"""
	interface.reset()

	if interface.uri.startswith('/'):
		debug("Loading local interface file '%s'", interface.uri)
		update(interface, interface.uri, local = True)
		interface.last_modified = int(os.stat(interface.uri).st_mtime)
		cached = True
	else:
		cached = basedir.load_first_cache(config_site, 'interfaces', escape(interface.uri))
		if cached:
{'fraction_non_alphanumeric': 0.1071347678369196, 'fraction_numerical': 0.0022650056625141564, 'mean_word_length': 4.7952755905511815, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5371804', 'n_tokens_mistral': 1354, 'n_tokens_neox': 1246, 'n_words': 428}