<commit_before># 3rd-party
from lxml.builder import E

# local
from .. import Resource
from ... import JXML
from .base import PhyPortBase

class PhyPortSwitch( PhyPortBase ):

  PORT_SPEED = {
    'auto' : 'auto-negotiation',
    '10m' : 'ethernet-10m',
    '100m' : 'ethernet-100m',
    '1g': 'ethernet-1g'
  }

  ##### -----------------------------------------------------------------------
  ##### XML readers
  ##### -----------------------------------------------------------------------

  def _xml_to_py(self, has_xml, has_py ):
    PhyPortBase._xml_to_py(self, has_xml, has_py )

    # speed, duplex, loopback are all under 'ether-options'
    ethopts = has_xml.find('ether-options')
    if ethopts is None: return

    if ethopts.find('loopback') is not None: has_py['loopback'] = True

    speed = ethopts.find('speed')
    if speed is not None:
      # take the first child element
      has_py['speed'] = speed[0].tag
      PhyPortBase._set_invert(has_py,'speed', self.PORT_SPEED)      

    Resource.copyifexists(ethopts,'link-mode', has_py, 'duplex')
    if 'duplex' in has_py: PhyPortBase._set_invert(has_py, 'duplex', self.PORT_DUPLEX)

  ##### -----------------------------------------------------------------------
  ##### XML writers
  ##### -----------------------------------------------------------------------

  def _xml_hook_build_change_begin(self, xml):
    if any([ this in self.should for this in ['speed','duplex','loopback']]):
      self._ethopts = E('ether-options')
      xml.append(self._ethopts)

  def _xml_change_speed(self, xml):
    speed_tag = self.PORT_SPEED.get(self.speed)
    add_this = E.speed( JXML.DEL ) if speed_tag is None else E.speed(E( speed_tag ))
    self._ethopts.append( add_this )
    return True

  def _xml_change_duplex(self, xml):
    value = self.PORT_DUPLEX.get(self.duplex)
    Resource.xml_set_or_delete(self._ethopts, 'link-mode', value)
    return True

  def _xml_change_loopback(self, xml):
    Resource.xml_set_or_delete(self._ethopts, 'loopback', self.loopback)
    return True<commit_msg>updates<commit_after># 3rd-party
from lxml.builder import E

# local
from .. import Resource
from ... import JXML
from .base import PhyPortBase

class PhyPortSwitch( PhyPortBase ):

  PORT_SPEED = {
    'auto' : 'auto-negotiation',
    '10m' : 'ethernet-10m',
    '100m' : 'ethernet-100m',
    '1g': 'ethernet-1g'
  }

  ##### -----------------------------------------------------------------------
  ##### XML readers
  ##### -----------------------------------------------------------------------

  def _xml_to_py(self, has_xml, has_py ):
    PhyPortBase._xml_to_py(self, has_xml, has_py )

    # speed, duplex, loopback are all under 'ether-options'
    ethopts = has_xml.find('ether-options')
    if ethopts is None: return

    if ethopts.find('loopback') is not None: has_py['loopback'] = True

    speed = ethopts.find('speed')
    if speed is not None:
      # take the first child element
      has_py['speed'] = speed[0].tag
      PhyPortBase._set_invert(has_py,'speed', self.PORT_SPEED)      

    Resource.copyifexists(ethopts,'link-mode', has_py, 'duplex')
    if 'duplex' in has_py: PhyPortBase._set_invert(has_py, 'duplex', self.PORT_DUPLEX)

  ##### -----------------------------------------------------------------------
  ##### XML writers
  ##### -----------------------------------------------------------------------

  def _xml_hook_build_change_begin(self, xml):
    if any([ this in self.should for this in ['speed','duplex','loopback']]):
      self._ethopts = E('ether-options')
      xml.append(self._ethopts)

  def _xml_change_speed(self, xml):
    speed_tag = self.PORT_SPEED.get(self.speed)
    add_this = E.speed( JXML.DEL ) if speed_tag is None else E.speed(E( speed_tag ))
    self._ethopts.append( add_this )
    return True

  def _xml_change_duplex(self, xml):
    value = self.PORT_DUPLEX.get(self.duplex)
    Resource.xml_set_or_delete(self._ethopts, 'link-mode', value)
    return True

  def _xml_change_loopback(self, xml):
    self._ethopts.append(Resource.xmltag_set_or_del('loopback', self.loopback))
    return True
{'fraction_non_alphanumeric': 0.25660926509822946, 'fraction_numerical': 0.006791171477079796, 'mean_word_length': 2.0661710037174723, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 34}, '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': '2254118', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1279, 'n_words': 276}