@transaction.commit_on_success
    def _import_cif(self, cif):
        """
        Parse a CIF file
        """
        
        # Clear cache once per file - avoid high memory usage
        self._cache = EntityCache()
        
        # Also reset SQL queries log
        reset_queries()
        
        routes = []
        
        this_journey = None
        
        for line in cif:
            
            if line[:2] == 'QS':
                # Journey header
                if this_journey is not None:
                    routes[-1]['journies'].append(this_journey)
                if line[2] == 'D':
                    this_journey = None
                    continue
                this_journey = {
                    'operator-code': line[3:7],
                    'id': line[7:13],
                    'start-date': self._parse_cif_date(line[13:21]),
                    'end-date': self._parse_cif_date(line[21:29]),
                    'days': weekbool(
                        line[29] == '1', # Monday
                        line[30] == '1', # Tuesday
                        line[31] == '1', # Wednesday
                        line[32] == '1', # Thursday
                        line[33] == '1', # Friday
                        line[34] == '1', # Saturday
                        line[35] == '1', # Sunday
                    ),
                    'school-holidays': {
                        'S': 'term-time',
                        'H': 'holidays'
                    }.get(line[36], 'all'),
                    'bank-holidays': {
                        'A': 'additional',
                        'B': 'holidays',
                        'X': 'non-holidays'
                    }.get(line[37], 'all'),
                    'route': line[38:42],
                    'vehicle': line[48:56].strip(),
                    'direction': line[64],
                    'notes': [],
                    'stops': [],
                }
            
            elif line[:2] in ('QN', 'ZN'):
                # Notes
                this_journey['notes'].append(line[7:])
            
            elif line[:2] == 'QO':
                # Journey start
                try:
                    this_journey['stops'].append({
                        'entity': self._cache['atco:%s' % line[2:14].strip()],
                        'sta': None,
                        'std': self._parse_cif_time(line[14:18]),
                        'activity': 'O',
                        'estimated': line[22] == '0',
                        'fare-stage': line[24] == '1'
                    })
                except Http404:
                    pass
            
            elif line[:2] == 'QI':
                # Journey intermediate stop
                try:
                    this_journey['stops'].append({
                        'entity': self._cache[line[2:14].strip() % 'atco:%s'],
                        'sta': self._parse_cif_time(line[14:18]),
                        'std': self._parse_cif_time(line[18:22]),
                        'activity': line[22],
                        'estimated': line[27] == '0',
                        'fare-stage': line[29] == '1'
                    })
                except Http404:
                    pass
            
            elif line[:2] == 'QT':
                # Journey complete
                try:
                    this_journey['stops'].append({
                        'entity': self._cache['atco:%s' % line[2:14].strip()],
                        'sta': self._parse_cif_time(line[14:18]),
                        'std': None,
                        'activity': 'F',
                        'estimated': line[22] == '0',
                        'fare-stage': line[24] == '1'
                    })
                except Http404:
                    pass
            
            elif line[:2] == 'ZL':
                # Route ID
                route_id = line[2:]
            
            elif line[:2] == 'ZD':
                # Days route ID
                route_id += line[18:-1]
            
            elif line[:2] == 'ZS':
                # Route
                
                if this_journey is not None:
                    routes[-1]['journies'].append(this_journey)
                
                routes.append({
                    'id': route_id,
                    'number': line[10:14].strip(),
                    'description': line[14:-1],
                    'stops': [],
                    'journies': []
                })
            
            elif line[:2] == 'ZA':
                
                stop_code = line[3:15].strip()
                
                try:
                    entity = self._cache['atco:%s' % stop_code]
                    if entity.source == self._get_source():
                        # Raise Http404 if this is a bus stop we came up with,
                        # so any name changes, etc, get processed
                        raise Http404()
                except Http404:
                    # Out of zone bus stops with NaPTAN codes
                    try:
                        entity = Entity.objects.get(source=self._get_source(),
                                                    _identifiers__scheme='atco',
                                                    _identifiers__value=stop_code)
                    except Entity.DoesNotExist:
                        entity = Entity(source=self._get_source())
                    identifiers = { 'atco': stop_code }
                    entity_type = self._entity_type
                    entity.primary_type = entity_type
                    entity.save(identifiers=identifiers)
                    set_name_in_language(entity, 'en', title=line[15:63].strip())
                    entity.all_types = (entity_type,)
                    entity.update_all_types_completion()
                    entity.save()
                routes[-1]['stops'].append(entity)
        
        if this_journey is not None:
            routes[-1]['journies'].append(this_journey)
        
        return routes
dataset/ETHPy150Open mollyproject/mollyproject/molly/apps/places/providers/atcocif.py/AtcoCifTimetableProvider._import_cif/swapped operands of `%`