Code Duplication    Length = 30-37 lines in 2 locations

il2fb/commons/organization.py 2 locations

@@ 392-428 (lines=37) @@
389
        raise ValueError("Regiment with code name '{0}' is unknown"
390
                         .format(code_name))
391
392
    @classmethod
393
    def filter_by_air_force(cls, air_force):
394
        result = []
395
396
        flight_prefixes = AirForces.get_flight_prefixes()
397
        found = False
398
399
        file_path = _get_data_file_path(cls._file_name)
400
        with open(file_path, mode='r', encoding='cp1251') as f:
401
            for line in f:
402
                line = line.strip()
403
404
                if not line:
405
                    continue
406
407
                if line == air_force.default_flight_prefix:
408
                    # Flag that proper section was found.
409
                    found = True
410
                    continue
411
412
                if found:
413
                    if (
414
                        line in flight_prefixes
415
                        or (line.startswith('[') and line.endswith(']'))
416
                    ):
417
                        # Next section was found. Fullstop.
418
                        break
419
420
                    if line in cls._cache:
421
                        regiment = cls._cache[line]
422
                    else:
423
                        regiment = Regiment(air_force, line)
424
                        cls._cache[line] = regiment
425
426
                    result.append(regiment)
427
428
        return result
429
@@ 361-390 (lines=30) @@
358
    def __new__(cls):
359
        raise TypeError("'{0}' may not be instantiated".format(cls.__name__))
360
361
    @classmethod
362
    def get_by_code_name(cls, code_name):
363
        if code_name in cls._cache:
364
            return cls._cache[code_name]
365
366
        flight_prefixes = AirForces.get_flight_prefixes()
367
        last_flight_prefix = None
368
        found = False
369
370
        file_path = _get_data_file_path(cls._file_name)
371
        with open(file_path, mode='r', encoding='cp1251') as f:
372
            for line in f:
373
                line = line.strip()
374
                if not line:
375
                    continue
376
                if line in flight_prefixes:
377
                    last_flight_prefix = line
378
                    continue
379
                if line == code_name:
380
                    found = True
381
                    break
382
383
        if found and last_flight_prefix:
384
            air_force = AirForces.get_by_flight_prefix(last_flight_prefix)
385
            regiment = Regiment(air_force, code_name)
386
            cls._cache[code_name] = regiment
387
            return regiment
388
389
        raise ValueError("Regiment with code name '{0}' is unknown"
390
                         .format(code_name))
391
392
    @classmethod
393
    def filter_by_air_force(cls, air_force):