code
stringlengths
20
13.2k
label
stringlengths
21
6.26k
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from podrum.utlis.Binary import Binary 15 from podrum.utlis.UUID import UUID 16 17 class BinaryStream: 18 buffer = "" 19 offset = None 20 21 def __int__(self, buffer = "", offset = 0): 22 self.buffer = buffer 23 self.offset = offset 24 25 def reset(self): 26 self.buffer = "" 27 self.offset = 0 28 29 def setBuffer(self, buffer = "", offset = 0): 30 self.buffer = buffer 31 self.offset = int(offset) 32 33 def getOffset(self): 34 return self.offset 35 36 def getBuffer(self): 37 return self.buffer 38 39 def get(self, len): 40 if len < 0: 41 self.offset = len(self.buffer) - 1; 42 return "" 43 elif len == True: 44 str = self.buffer[0:self.offset] 45 self.offset = len(self.buffer) 46 return str 47 buffer = self.buffer[self.offset:self.offset+len] 48 self.offset += length 49 return buffer 50 51 def put(self, str): 52 self.buffer += str 53 54 def getBool(self): 55 return self.get(1) != b'\x00' 56 57 def putBool(self, v): 58 self.buffer += (b"\x01" if v else b"\x00") 59 60 def getByte(self): 61 self.offset += 1 62 return ord(self.buffer[self.offset]) 63 64 def putByte(self, v): 65 self.buffer += chr(v) 66 67 def getLong(self): 68 return Binary.readLong(self.get(8)) 69 70 def putLong(self, v): 71 self.buffer += Binary.writeLong(v) 72 73 def getLLong(self): 74 return Binary.readLLong(self.get(8)) 75 76 def putLLong(self, v): 77 self.buffer += Binary.writeLLong(v) 78 79 def getInt(self): 80 return Binary.readInt(self.get(4)) 81 82 def putInt(self, v): 83 self.buffer += Binary.writeInt(v) 84 85 def getLInt(self): 86 return Binary.readLInt(self.get(4)) 87 88 def putLInt(self, v): 89 self.buffer += Binary.writeLInt(v) 90 91 def getShort(self): 92 return Binary.readShort(self.get(2)) 93 94 def putShort(self, v): 95 self.buffer += Binary.writeShort(v) 96 97 def getLShort(self): 98 return Binary.readLShort(self.get(2)) 99 100 def putLShort(self, v): 101 self.buffer += Binary.writeLShort(v) 102 103 def getSignedShort(self): 104 return Binary.readSignedShort(self.get(2)) 105 106 def getSignedLShort(self): 107 return Binary.readSignedLShort(self.get(4)) 108 109 def getFloat(self): 110 return Binary.readFloat(self.get(4)) 111 112 def putFloat(self, v): 113 self.buffer += Binary.writeFloat(v) 114 115 def getLFloat(self): 116 return Binary.readLFloat(self.get(4)) 117 118 def putLFloat(self, v): 119 self.buffer += Binary.writeLFloat(v) 120 121 def getRoundedFloat(self, accuracy): 122 return Binary.readRoundedFloat(self.get(4), accuracy) 123 124 def getRoundedLFloat(self, accuracy): 125 return Binary.readRoundedLFloat(self.get(4), accuracy) 126 127 def getTriad(self): 128 return Binary.readTriad(self.get(3)) 129 130 def putTriad(self, v): 131 self.buffer += Binary.writeTriad(v) 132 133 def getLTriad(self): 134 return Binary.readLTriad(self.get(3)) 135 136 def putLTriad(self, v): 137 self.buffer += Binary.writeLTriad(v) 138 139 def getUnsignedVarInt(self): 140 return Binary.readUnsignedVarInt(self.buffer, self.offset) 141 142 def putUnsignedVarInt(self, v): 143 self.put(Binary.writeUnsignedVarInt(v)) 144 145 def getVarInt(self): 146 return Binary.readVarInt(self.buffer, self.offset) 147 148 def putVarInt(self, v): 149 self.put(Binary.writeVarInt(v)) 150 151 def getUnsignedVarLong(self): 152 return Binary.readUnsignedVarLong(self.buffer, self.offset) 153 154 def putUnsignedVarLong(self, v): 155 self.put(Binary.writeUnsignedVarLong(v)) 156 157 def getVarLong(self): 158 return Binary.readVarLong(self.buffer, self.offset) 159 160 def putVarLong(self, v): 161 self.put(Binary.writeVarLong(v)) 162 163 def getString(self): 164 self.get(self.getUnsignedVarInt()) 165 166 def putString(self, v): 167 self.putUnsignedVarInt(len(v)) 168 self.put(v) 169 170 def getUUID(self): 171 part1 = self.getLInt() 172 part0 = self.getLInt() 173 part3 = self.getLInt() 174 part2 = self.getLInt() 175 return UUID(part0, part1, part2, part3) 176 177 def putUUID(self, uuid: UUID): 178 self.putLInt(uuid.getPart(1)) 179 self.putLInt(uuid.getPart(0)) 180 self.putLInt(uuid.getPart(3)) 181 self.putLInt(uuid.getPart(2)) 182 183 def feof(self): 184 try: 185 self.buffer[self.offset] 186 return True 187 except IndexError: 188 return False
41 - warning: unnecessary-semicolon 3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 39 - warning: redefined-builtin 44 - warning: redefined-builtin 40 - refactor: no-else-return 48 - error: undefined-variable 51 - warning: redefined-builtin 185 - warning: pointless-statement 17 - refactor: too-many-public-methods
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from podrum.network.protocol.DataPacket import DataPacket 15 from podrum.network.protocol.ProtocolInfo import ProtocolInfo 16 17 class ResourcePacksInfoPacket(DataPacket): 18 NID = ProtocolInfo.RESOURCE_PACKS_INFO_PACKET 19 20 mustAccept = False 21 hasScripts = False 22 behaviorPackEntries = [] 23 resourcePackEntries = [] 24 25 def decodePayload(self): 26 self.mustAccept = self.getBool() 27 self.hasScripts = self.getBool() 28 behaviorPackCount = self.getLShort() 29 while behaviorPackCount > 0: 30 self.getString() 31 self.getString() 32 self.getLLong() 33 self.getString() 34 self.getString() 35 self.getString() 36 self.getBool() 37 behaviorPackCount -= 1 38 39 resourcePackCount = self.getLShort() 40 while resourcePackCount > 0: 41 self.getString() 42 self.getString() 43 self.getLLong() 44 self.getString() 45 self.getString() 46 self.getString() 47 self.getBool() 48 resourcePackCount -= 1 49 50 def encodePayload(self): 51 self.putBool(self.mustAccept) 52 self.putBool(self.hasScripts) 53 self.putLShort(len(self.behaviorPackEntries)) 54 for entry in self.behaviorPackEntries: 55 self.putString(entry.getPackId()) 56 self.putString(entry.getPackVersion()) 57 self.putLLong(entry.getPackSize()) 58 self.putString("") # TODO: encryption key 59 self.putString("") # TODO: subpack name 60 self.putString("") # TODO: content identity 61 self.putBool(False) # TODO: has scripts (?) 62 63 self.putLShort(len(self.resourcePackEntries)) 64 for entry in self.resourcePackEntries: 65 self.putString(entry.getPackId()) 66 self.putString(entry.getPackVersion()) 67 self.putLLong(entry.getPackSize()) 68 self.putString("") # TODO: encryption key 69 self.putString("") # TODO: subpack name 70 self.putString("") # TODO: content identity 71 self.putBool(False) # TODO: seems useless for resource packs
58 - warning: fixme 59 - warning: fixme 60 - warning: fixme 61 - warning: fixme 68 - warning: fixme 69 - warning: fixme 70 - warning: fixme 71 - warning: fixme 3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 import re 14 import os 15 import json 16 import yaml 17 import pickle 18 from podrum.utils import Logger 19 20 from podrum.ServerFS.ServerFS import read 21 from podrum.Server import Server 22 23 class Config: 24 DETECT = -1 25 PROPERTIES = 0 26 CNF = PROPERTIES 27 JSON = 1 28 YAML = 2 29 EXPORT = 3 30 SERIALIZED = 4 31 ENUM = 5 32 ENUMERATION = ENUM 33 34 config = [] 35 nestedCache = [] 36 file = '' 37 correct = False 38 type = DETECT 39 is_array = lambda var: isinstance(var, (list, tuple)) 40 41 formats = [{ 42 "properties" : PROPERTIES, 43 "cnf" : CNF, 44 "conf" : CNF, 45 "config" : CNF, 46 "json" : JSON, 47 "js" : JSON, 48 "yml" : YAML, 49 "yaml" : YAML, 50 "export" : EXPORT, 51 "xport" : EXPORT, 52 "sl" : SERIALIZED, 53 "serialize" : SERIALIZED, 54 "txt" : ENUM, 55 "list" : ENUM, 56 "enum" : ENUM, 57 }] 58 59 def __init__(self, file, type = DETECT, default = [], correct=None): 60 self.load(file, type, default) 61 correct = self.correct 62 63 @staticmethod 64 def isset(self, variable): 65 return variable in locals() or variable in globals() 66 67 def reload(self): 68 self.config = [] 69 self.nestedCache = [] 70 self.correct = False 71 self.load(self.file, self.type) 72 73 @staticmethod 74 def fixYAMLIndexes(str): 75 return re.sub(r"#^([ ]*)([a-zA-Z_]{1}[ ]*)\\:$#m", r"$1\"$2\":", str) 76 77 def load(self, file, type=DETECT, default = []): 78 self.correct = True 79 self.type = int(type) 80 self.file = file 81 if not self.is_array(default): 82 default = [] 83 if not os.path.exists(file): 84 self.config = default 85 self.save() 86 else: 87 if self.type == self.DETECT: 88 bname = os.path.basename(self.file) 89 extension = bname.split(".") 90 arrlist = extension.pop() 91 extension = arrlist.strip().lower() 92 if self.isset(self.formats[extension]): 93 self.type = self.formats[extension] 94 else: 95 self.correct = False 96 if self.correct: 97 content = open(self.file).read() 98 if (self.type == self.PROPERTIES) and (self.type == self.CNF): 99 self.parseProperties(content) 100 elif self.type == self.JSON: 101 self.config = json.loads(content) 102 elif self.type == self.YAML: 103 content = self.fixYAMLIndexes(content) 104 self.config = yaml.load(content) 105 elif self.type == self.SERIALIZED: 106 self.config = pickle.loads(content) 107 elif self.type == self.ENUM: 108 self.parseList(content) 109 else: 110 self.correct = False 111 return False 112 if not self.is_array(self.config): # Is array doesn't exist 113 self.config = default 114 if self.fillDefaults(default, self.config) > 0: 115 self.save() 116 else: 117 return False 118 119 return True 120 121 def check(): 122 return correct = True 123 124 def save(): 125 if self.correct == True: 126 try: 127 content = None 128 if (type == PROPERTIES) or (type == CNF): 129 content = writeProperties() 130 elif type == JSON: 131 content = json.dumps(config) 132 elif type == YAML: 133 content = yaml.emit(config) 134 elif type == SERIALIZED: 135 content = pickle.dumps(self.config) 136 elif type == ENUM: 137 "\r\n".join(config.keys()) 138 else: 139 correct = False 140 return False 141 except ValueError: 142 logger.log('error', f'Could not save Config {self.file}') 143 return True 144 else: 145 return false
116 - error: syntax-error
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 class Facing: 15 AXIS_Y = 0 16 AXIS_Z = 1 17 AXIS_X = 2 18 19 FLAG_AXIS_POSITIVE = 1 20 21 DOWN = AXIS_Y << 1 22 UP = (AXIS_Y << 1) | FLAG_AXIS_POSITIVE 23 NORTH = AXIS_Z << 1 24 SOUTH = (AXIS_Z << 1) | FLAG_AXIS_POSITIVE 25 WEST = AXIS_X << 1 26 EAST = (AXIS_X << 1) | FLAG_AXIS_POSITIVE 27 28 ALL = [ 29 DOWN, 30 UP, 31 NORTH, 32 SOUTH, 33 WEST, 34 EAST 35 ] 36 37 HORIZONTAL = [ 38 NORTH, 39 SOUTH, 40 WEST, 41 EAST 42 ] 43 44 CLOCKWISE = { 45 AXIS_Y: { 46 NORTH: EAST, 47 EAST: SOUTH, 48 SOUTH: WEST, 49 WEST: NORTH 50 }, 51 AXIS_Z: { 52 UP: EAST, 53 EAST: DOWN, 54 DOWN: WEST, 55 WEST: UP 56 }, 57 AXIS_X: { 58 UP: NORTH, 59 NORTH: DOWN, 60 DOWN: SOUTH, 61 SOUTH: UP 62 } 63 } 64 65 @staticmethod 66 def axis(direction): 67 return direction >> 1 68 69 @staticmethod 70 def is_positive(direction): 71 return (direction & Facing.FLAG_AXIS_POSITIVE) == Facing.FLAG_AXIS_POSITIVE 72 73 @staticmethod 74 def opposite(direction): 75 return direction ^ Facing.FLAG_AXIS_POSITIVE 76 77 @staticmethod 78 def rotate(direction, axis, clockwise): 79 if not Facing.CLOCKWISE[axis]: 80 raise ValueError("Invalid axis {}".format(axis)) 81 82 if not Facing.CLOCKWISE[axis][direction]: 83 raise ValueError("Cannot rotate direction {} around axis {}".format(direction, axis)) 84 85 rotated = Facing.CLOCKWISE[axis][direction] 86 return rotated if clockwise else Facing.opposite(rotated) 87 88 @staticmethod 89 def validate(facing): 90 if facing in Facing.ALL: 91 raise ValueError("Invalid direction {}".format(facing))
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from podrum.network.protocol.DataPacket import DataPacket 15 from podrum.network.protocol.ProtocolInfo import ProtocolInfo 16 17 class ServerToClientHandshakePacket(DataPacket): 18 NID = ProtocolInfo.SERVER_TO_CLIENT_HANDSHAKE_PACKET 19 20 jwt = None 21 22 def canBeSentBeforeLogin(): 23 return True 24 25 def decodePayload(self): 26 self.jwt = self.getString() 27 28 def encodePayload(self): 29 self.putString(self.jwt)
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 22 - error: no-method-argument
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 #!/usr/bin/env python3 14 15 import sys 16 import inspect 17 from os import getcwd, path 18 from threading import Thread 19 sys.path.insert(0, path.dirname(path.dirname(path.abspath(inspect.getfile(inspect.currentframe()))))) 20 from podrum.Server import Server 21 22 if __name__ == "__main__": 23 if len(sys.argv) >= 3: 24 if sys.argv[1] == "--no_wizard" and sys.argv[2] == "-travis": 25 serverThread = Thread(target=Server, args=(getcwd(), False, True)) 26 else: 27 print("[!] None valid args selected.") 28 serverThread = Thread(target=Server, args=(getcwd(), True)) 29 elif len(sys.argv) == 2: 30 if sys.argv[1] == "--no_wizard": 31 serverThread = Thread(target=Server, args=(getcwd(), False)) 32 else: 33 print("[!] None valid args selected.") 34 serverThread = Thread(target=Server, args=(getcwd(), True)) 35 else: 36 serverThread = Thread(target=Server, args=(getcwd(), True)) 37 38 serverThread.start()
31 - warning: bad-indentation 3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from abc import ABCMeta, abstractmethod 15 16 from podrum.nbt.tag.ByteArrayTag import ByteArrayTag 17 from podrum.nbt.tag.ByteTag import ByteTag 18 from podrum.nbt.tag.CompoundTag import CompoundTag 19 from podrum.nbt.tag.DoubleTag import DoubleTag 20 from podrum.nbt.tag.FloatTag import FloatTag 21 from podrum.nbt.tag.IntArrayTag import IntArrayTag 22 from podrum.nbt.tag.IntTag import IntTag 23 from podrum.nbt.tag.ListTag import ListTag 24 from podrum.nbt.tag.LongArrayTag import LongArrayTag 25 from podrum.nbt.tag.LongTag import LongTag 26 from podrum.nbt.tag.NamedTag import NamedTag 27 from podrum.nbt.tag.ShortTag import ShortTag 28 from podrum.nbt.tag.StringTag import StringTag 29 30 class NBT: 31 __metaclass__ = ABCMeta 32 33 TAG_End = 0 34 TAG_Byte = 1 35 TAG_Short = 2 36 TAG_Int = 3 37 TAG_Long = 4 38 TAG_Float = 5 39 TAG_Double = 6 40 TAG_ByteArray = 7 41 TAG_String = 8 42 TAG_List = 9 43 TAG_COMPOUND = 10 44 TAG_IntArray = 11 45 TAG_LongArray = 12 46 47 @staticmethod 48 def createTag(type: int) -> NamedTag: 49 if type == NBT.TAG_Byte: 50 return ByteTag() 51 elif type == NBT.TAG_Short: 52 return ShortTag() 53 elif type == NBT.TAG_Int: 54 return IntTag() 55 elif type == NBT.TAG_Long: 56 return LongTag() 57 elif type == NBT.TAG_Float: 58 return FloatTag() 59 elif type == NBT.TAG_Double: 60 return DoubleTag() 61 elif type == NBT.TAG_ByteArray: 62 return ByteArrayTag() 63 elif type == NBT.TAG_String: 64 return StringTag() 65 elif type == NBT.TAG_List: 66 return ListTag() 67 elif type == NBT.TAG_Compound: 68 return CompoundTag() 69 elif type == NBT.TAG_IntArray: 70 return IntArrayTag() 71 elif type == NBT.TAG_LongArray: 72 return LongArrayTag() 73 else: 74 raise ValueError("Unknown NBT tag type " + str(type)) 75 76 77
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 48 - warning: redefined-builtin 49 - refactor: no-else-return 67 - error: no-member 48 - refactor: too-many-return-statements 48 - refactor: too-many-branches 30 - refactor: too-few-public-methods 14 - warning: unused-import
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from podrum.network.protocol.DataPacket import DataPacket 15 from podrum.network.protocol.ProtocolInfo import ProtocolInfo 16 17 class DisconnectPacket(DataPacket): 18 NID = ProtocolInfo.DISCONNECT_PACKET 19 20 hideDisconnectionScreen = False 21 message = "" 22 23 def canBeSentBeforeLogin(): 24 return True 25 26 def decodePayload(self): 27 self.hideDisconnectionScreen = self.getBool() 28 if not self.hideDisconnectionScreen: 29 self.message = self.getString() 30 31 def encodePayload(self): 32 self.putBool(self.hideDisconnectionScreen) 33 if not self.hideDisconnectionScreen: 34 self.putString(self.message)
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 23 - error: no-method-argument
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 class Command: 15 16 def onCommand(string, fromConsole): 17 pass
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 16 - error: no-self-argument 14 - refactor: too-few-public-methods
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 import base64 14 import binascii 15 import json 16 import os 17 import signal 18 import sys 19 import socket 20 import time 21 import urllib 22 import hmac 23 import hashlib 24 25 class Utils: 26 27 def getOS(): 28 if sys.platform == 'linux' or sys.platform == 'linux2': 29 return 'linux' 30 elif sys.platform == 'darwin': 31 return 'osx' 32 elif sys.platform == 'win32' or sys.platform == 'win64': 33 return 'windows' 34 35 def killServer(): 36 os.kill(os.getpid(), signal.SIGTERM) 37 38 def getPrivateIpAddress(): 39 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 40 s.connect(("8.8.8.8", 80)) 41 ip = s.getsockname()[0] 42 return ip 43 44 def getPublicIpAddress(): 45 ip = urllib.request.urlopen('https://ident.me').read().decode('utf8') 46 return ip 47 48 def microtime(get_as_float = False) : 49 if get_as_float: 50 return time.time() 51 else: 52 return '%f %d' % math.modf(time.time()) 53 54 def substr(string, start, length = None): 55 if start < 0: 56 start = start + len(string) 57 if not length: 58 return string[start:] 59 elif length > 0: 60 return string[start:start + length] 61 else: 62 return string[start:length] 63 64 def hex2bin(hexdec): 65 if hexdec == 'x': 66 return False 67 if hexdec == '': 68 return False 69 dec = int(hexdec, 16) 70 b = binascii.unhexlify('%x' % dec) 71 return b 72 73 def binToHex(b): 74 return binascii.hexlify(b) 75 76 def HMACSHA256(data, secret): 77 encodedData = data.encode() 78 byteSecret = secret.encode() 79 return hmac.new(byteSecret, encodedData, hashlib.sha256).hexdigest().upper() 80 81 def base64UrlEncode(data): 82 return base64.urlsafe_b64encode(data.encode()).replace(b"=", b"").decode() 83 84 def base64UrlDecode(data): 85 return base64.urlsafe_b64decode(data).decode() 86 87 def encodeJWT(header, payload, secret): 88 body = Utils.base64UrlEncode(json.dumps(header)) + "." + Utils.base64UrlEncode(json.dumps(payload)) 89 secret = Utils.HMACSHA256(body, secret) 90 return body + "." + Utils.base64UrlEncode(secret) 91 92 def decodeJWT(token: str): 93 [headB64, payloadB64, sigB64] = token.split(".") 94 rawPayloadJSON = Utils.base64UrlDecode(payloadB64) 95 if rawPayloadJSON == False: 96 raise Exception("Payload base64 is invalid and cannot be decoded") 97 decodedPayload = json.loads(rawPayloadJSON) 98 if isinstance(decodedPayload, str): 99 decodedPayload = json.loads(decodedPayload) 100 if not isinstance(decodedPayload, dict): 101 raise Exception("Decoded payload should be dict, " + str(type(decodedPayload).__name__) + " received") 102 return decodedPayload
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 27 - error: no-method-argument 28 - refactor: no-else-return 28 - refactor: consider-using-in 32 - refactor: consider-using-in 27 - refactor: inconsistent-return-statements 35 - error: no-method-argument 38 - error: no-method-argument 44 - error: no-method-argument 45 - refactor: consider-using-with 48 - error: no-self-argument 49 - refactor: no-else-return 52 - error: undefined-variable 54 - error: no-self-argument 57 - refactor: no-else-return 58 - error: unsubscriptable-object 60 - error: unsubscriptable-object 62 - error: unsubscriptable-object 64 - error: no-self-argument 73 - error: no-self-argument 76 - error: no-self-argument 77 - error: no-member 81 - error: no-self-argument 82 - error: no-member 84 - error: no-self-argument 87 - error: no-self-argument 92 - error: no-self-argument 93 - error: no-member 96 - warning: broad-exception-raised 101 - warning: broad-exception-raised 93 - warning: unused-variable 93 - warning: unused-variable
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from podrum.network.protocol.DataPacket import DataPacket 15 from podrum.network.protocol.ProtocolInfo import ProtocolInfo 16 17 class ClientToServerHandshakePacket(DataPacket): 18 NID = ProtocolInfo.CLIENT_TO_SERVER_HANDSHAKE_PACKET 19 20 def canBeSentBeforeLogin(): 21 return True 22 23 def encodePayload(): pass 24 25 def decodePayload(): pass
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 20 - error: no-method-argument 23 - error: no-method-argument 25 - error: no-method-argument
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 import hashlib 15 import os 16 import random 17 import time 18 19 from podrum.utils.Binary import Binary 20 from podrum.utils.Utils import Utils 21 22 class UUID: 23 parts = [0, 0, 0, 0] 24 version = None 25 26 def __init__(self, part1 = 0, part2 = 0, part3 = 0, part4 = 0, version = None): 27 self.parts[0] = int(part1) 28 self.parts[1] = int(part2) 29 self.parts[2] = int(part3) 30 self.parts[3] = int(part4) 31 self.version = (self.parts[1] & 0xf000) >> 12 if version == None else int(version) 32 33 def getVersion(self): 34 return self.version 35 36 def equals(self, uuid: UUID): 37 return uuid.parts[0] == self.parts[0] and uuid.parts[1] == self.parts[1] and uuid.parts[2] == self.parts[2] and uuid.parts[3] == self.parts[3] 38 39 def fromBinary(self, uuid, version = None): 40 if len(uuid) != 16: 41 raise Exception("Must have exactly 16 bytes") 42 return UUID(Binary.readInt(Utils.substr(uuid, 0, 4)), Binary.readInt(Utils.substr(uuid, 4, 4)), Binary.readInt(Utils.substr(uuid, 8, 4)), Binary.readInt(Utils.substr(uuid, 12, 4)), version) 43 44 def fromString(self, uuid, version = None): 45 return self.fromBinary(Utils.hex2bin(uuid.strip().replace("-", "")), version) 46 47 def fromData(self, data): 48 hash = hashlib.new("md5").update("".join(data)) 49 return self.fromBinary(hash, 3) 50 51 def fromRandom(self): 52 return self.fromData(Binary.writeInt(int(time.time())), Binary.writeShort(os.getpid()), Binary.writeShort(os.geteuid()), Binary.writeInt(random.randint(-0x7fffffff, 0x7fffffff)), Binary.writeInt(random.randint(-0x7fffffff, 0x7fffffff))) 53 54 def toBinary(self): 55 return Binary.writeInt(self.parts[0]) + Binary.writeInt(self.parts[1]) + Binary.writeInt(self.parts[2]) + Binary.writeInt(self.parts[3]) 56 57 def toString(self): 58 hex = Utils.bin2hex(self.toBinary()) 59 if self.version != None: 60 return Utils.substr(hex, 0, 8) + "-" + Utils.substr(hex, 8, 4) + "-" + int(self.version, 16) + Utils.substr(hex, 13, 3) + "-8" + Utils.substr(hex, 17, 3) + "-" + Utils.substr(hex, 20, 12) 61 return Utils.substr(hex, 0, 8) + "-" + Utils.substr(hex, 8, 4) + "-" + Utils.substr(hex, 12, 4) + "-" + Utils.substr(hex, 16, 4) + "-" + Utils.substr(hex, 20, 12) 62 63 def getPart(self, partNumber: int): 64 if partNumber < 0 or partNumber > 3: 65 raise Exception("Invalid UUID part index" + str(partNumber)) 66 return self.parts[partNumber]
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 26 - refactor: too-many-arguments 26 - refactor: too-many-positional-arguments 36 - error: undefined-variable 41 - warning: broad-exception-raised 48 - warning: redefined-builtin 52 - error: too-many-function-args 58 - warning: redefined-builtin 65 - warning: broad-exception-raised
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from podrum.network.PacketPool import PacketPool 15 16 class Player: 17 connection = None 18 server = None 19 logger = None 20 address = Nome 21 name = None 22 locale = None 23 randomId = None 24 uuid = None 25 xuid = None 26 skin = None 27 viewDistance = None 28 gamemode = 0 29 pitch = 0 30 yaw = 0 31 headYaw = 0 32 onGround = False 33 platformChatId = '' 34 deviceOS = None 35 deviceModel = None 36 deviceId = Nome 37 38 def __init__(self, connection, address, logger, server): 39 self.connection = connection 40 self.address = address 41 self.logger = logger 42 self.server = server
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 20 - error: undefined-variable 36 - error: undefined-variable 16 - refactor: too-few-public-methods 14 - warning: unused-import
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 14 from abc import ABCMeta, abstractmethod 15 16 from podrum.nbt.NBTStream import NBTStream 17 from podrum.nbt.ReaderTracker import ReaderTracker 18 19 class NamedTag: 20 __metaclass__ = ABCMeta 21 22 name = None 23 cloning = False 24 25 def __init__(self, name = ''): 26 if len(name > 32767): 27 raise ValueError("Tag name cannot be more than 32767 bytes, got length " + str(len(name))) 28 self.name = name 29 30 def getName(): 31 return NamedTag.name 32 33 def setName(name): 34 NamedTag.name = name 35 36 def getValue(): pass 37 38 def getType(): pass 39 40 def write(nbt: NBTStream): pass 41 42 def read(nbt: NBTStream, tracker: ReaderTracker): pass 43 44 def toString(indentation = 0): 45 return (" " * indentation) + type(object) + ": " + (("name='NamedTag.name', ") if (NamedTag.name != "") else "") + "value='" + str(NamedTag.getValue()) + "'" 46 47 def safeClone() -> NamedTag: 48 if NamedTag.cloning: 49 raise ValueError("Recursive NBT tag dependency detected") 50 NamedTag.cloning = True 51 retval = NamedTag.copy() 52 NamedTag.cloning = False 53 retval.cloning = False 54 return retval 55 56 def equals(that: NamedTag): 57 return NamedTag.name == that.name and NamedTag.equalsValue(that) 58 59 def equalsValue(that: NamedTag): 60 return isinstance(that, NamedTag()) and NamedTag.getValue() == that.getValue()
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 30 - error: no-method-argument 33 - error: no-self-argument 36 - error: no-method-argument 38 - error: no-method-argument 40 - error: no-self-argument 42 - error: no-self-argument 44 - error: no-self-argument 47 - error: no-method-argument 51 - error: no-member 56 - error: no-self-argument 59 - error: no-self-argument 60 - warning: isinstance-second-argument-not-valid-type 60 - error: too-many-function-args 14 - warning: unused-import
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 import decimal 14 15 class bcmath: 16 @staticmethod 17 def bcmul(num1, num2, scale=None): 18 if scale != None: 19 decimal.getcontext().prec = scale 20 result = decimal.Decimal(num1) * decimal.Decimal(num2) 21 return int(result) 22 23 @staticmethod 24 def bcdiv(num1, num2, scale=None): 25 if scale != None: 26 decimal.getcontext().prec = scale 27 result = decimal.Decimal(num1) / decimal.Decimal(num2) 28 return int(result) 29 30 @staticmethod 31 def bcadd(num1, num2, scale=None): 32 if scale != None: 33 decimal.getcontext().prec = scale 34 result = decimal.Decimal(num1) + decimal.Decimal(num2) 35 return int(result) 36 37 @staticmethod 38 def bcsub(num1, num2, scale=None): 39 if scale != None: 40 decimal.getcontext().prec = scale 41 result = decimal.Decimal(num1) - decimal.Decimal(num2) 42 return int(result) 43 44 @staticmethod 45 def bccomp(num1, num2): 46 result = (int(num1) > int(num2)) - (int(num1) < int(num2)) 47 return int(result) 48 49 @staticmethod 50 def bcmod(num1, num2): 51 result = int(num1) % int(num2) 52 return int(result) 53 54 @staticmethod 55 def bcpow(num1, num2): 56 result = int(num1) ** int(num2) 57 return int(result) 58 59 @staticmethod 60 def bcpowmod(num1, num2, mod): 61 result = pow(num1, num2, mod) 62 return int(result) 63 64 @staticmethod 65 def bcscale(scale): 66 result = decimal.getcontext().prec = scale 67 return int(result) 68 69 @staticmethod 70 def bcsqrt(num): 71 result = math.sqrt(num) 72 return int(result) 73
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 71 - error: undefined-variable
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 import os 14 15 from podrum.lang import Base 16 17 class Parser: 18 19 def checkYesNo(str): 20 str = str.lower() 21 if str == 'y' or str == 'yes': 22 return True 23 elif str == 'n' or str == 'no': 24 return False 25 else: 26 return 27 28 def checkIfLangExists(str): 29 path = os.getcwd() + '/src/podrum/lang/' 30 allLangs = Base.Base.getLangNames(path) 31 if(str in allLangs): 32 return True 33 else: 34 return False
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 19 - error: no-self-argument 19 - warning: redefined-builtin 20 - warning: self-cls-assignment 20 - error: no-member 21 - refactor: no-else-return 21 - refactor: consider-using-in 23 - refactor: consider-using-in 19 - refactor: inconsistent-return-statements 28 - error: no-self-argument 28 - warning: redefined-builtin 31 - refactor: simplifiable-if-statement 31 - refactor: no-else-return
1 """ 2 * ____ _ 3 * | _ \ ___ __| |_ __ _ _ _ __ ___ 4 * | |_) / _ \ / _` | '__| | | | '_ ` _ \ 5 * | __/ (_) | (_| | | | |_| | | | | | | 6 * |_| \___/ \__,_|_| \__,_|_| |_| |_| 7 * 8 * This program is free software: you can redistribute it and/or modify 9 * it under the terms of the GNU Lesser General Public License as published by 10 * the Free Software Foundation, either version 3 of the License, or 11 * (at your option) any later version. 12 """ 13 from datetime import datetime 14 from podrum.utils.TextFormat import TextFormat 15 16 TextFormat = TextFormat() 17 18 class Logger: 19 20 def log(type_, content): 21 time = datetime.now() 22 if type_ == 'info': 23 print(f'{TextFormat.BLUE}[INFO: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 24 elif type_ == 'warn': 25 print(f'{TextFormat.YELLOW}[WARNING: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 26 elif type_ == 'error': 27 print(f'{TextFormat.RED}[ERROR: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 28 elif type_ == 'success': 29 print(f'{TextFormat.GREEN}[SUCCESS: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 30 elif type_ == "emergency": 31 print(f'{TextFormat.GOLD}[EMERGENCY: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 32 elif type_ == "alert": 33 print(f'{TextFormat.PURPLE}[ALERT: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 34 elif type_ == "notice": 35 print(f'{TextFormat.AQUA}[NOTICE: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 36 elif type_ == "critical": 37 print(f'{TextFormat.RED}[CRITICAL: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 38 elif type_ == "debug": 39 print(f'{TTextFormat.GRAY}[DEBUG: {time.strftime("%H:%M")}]{TextFormat.WHITE} {content}') 40 else: 41 print(f'[{type_.upper()}: {time.strftime("%H:%M")}]{content}')
3 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 4 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 6 - warning: anomalous-backslash-in-string 20 - error: no-self-argument 39 - error: undefined-variable 41 - error: no-member 18 - refactor: too-few-public-methods
1 import termcolor2 2 3 x = int(input("Enter First Number: ")) # 20 4 y = int(input("Enter second Number: ")) # 40 5 6 if x > y: 7 print(termcolor2.colored("Error! TryAgain", color="red")) 8 else: 9 for i in range(1,x+1): 10 if x % i == 0 and y % i == 0: 11 bmm = i 12 13 print(f"BMM: {bmm}") 14
13 - error: possibly-used-before-assignment
1 for x in [6, 6, 6, 6]: 2 print x**2 3 for x in [6, 6, 6, 6]: 4 print x**3 5 for x in 'spam': 6 print x*2
2 - error: syntax-error
1 x = 10 2 while x: 3 x=x-1 4 if x % 2 != 0: 5 continue 6 print(x)
3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation
1 class C1: 2 def __init__(self, who): 3 self.who=who 4 #print(C1.who) 5 I1=C1('bob') 6 print(I1.who)
2 - warning: bad-indentation 3 - warning: bad-indentation 1 - refactor: too-few-public-methods
1 L1 = [1,2,3] 2 L2 = [6, 6, 6] 3 print(type(zip(L1, L2))) 4 print(zip(L1, L2)) 5 for (x, y) in zip(L1, L2): 6 print(x, y, '--', x+y)
6 - warning: bad-indentation
1 class test: 2 pass 3 test.name="test" 4 a=test() 5 b=test() 6 a.name="base" 7 print(a.name, b.name)
2 - warning: bad-indentation 1 - refactor: too-few-public-methods
1 def tester(start): 2 def nested(label): 3 print(label, nested.state) 4 nested.state+=1 5 nested.state=start 6 return nested 7 F=tester(0) 8 F('spam') 9 F('ham')
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation
1 D = {'A':6, 'B': 6, 'C': 6} 2 for key in D: 3 print(key+" => %d" % D[key]) 4 import os 5 p = os.popen('pwd') 6 print(p.next()) 7 E = enumerate('spam') 8 I=iter(E) 9 print(next(I)) 10 while True: 11 try: 12 print(next(I)) 13 except StopIteration: 14 break 15
3 - warning: bad-indentation 11 - warning: bad-indentation 12 - warning: bad-indentation 13 - warning: bad-indentation 14 - warning: bad-indentation
1 y=11 2 x=y//2 3 while x>1: 4 if y % x == 0: 5 print(y, 'has factor', x) 6 break 7 x-=1 8 else: 9 print(y, 'is prime')
4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 9 - warning: bad-indentation
1 d={'spam':2, 'ham':1, 'eggs':3}; 2 print(d['spam']); 3 print(d); 4 print(len(d)); 5 print('ham' in d); 6 print(list(d.keys())); 7 print('*****************'); 8 d['ham']=['grill', 'bake', 'fry']; 9 print(d); 10 del d['eggs']; 11 print(d); 12 d['brunch']='Bacon'; 13 print(d); 14 print(d.values()); 15 print(d.keys()); 16 print(d.items()); 17 print(d.get('spam')); 18 print(d.get('toast')); 19 print(d.get('toast', 88)); 20 d1={'toast':6, 'muffin':66}; 21 d.update(d1); 22 print(d); 23 print('*************************'); 24 print(d.pop('muffin')); 25 print(d.pop('toast')); 26 print(d); 27 print('**************************'); 28 table={ 29 'Python': 'Guido van Rossum', 30 'Perl': 'Larry Wail', 31 'Tcl': 'John Ousterhout' 32 }; 33 language = 'Python'; 34 creater = table[language]; 35 print(creater); 36 for lang in table: 37 print(lang, '\t', table[lang]); 38 39 rec={}; 40 rec['name']='mel'; 41 rec['age']=66; 42 rec['job'] = 'trainer/writer'; 43 print(rec); 44 45 46 print('********************'); 47 print(list(zip(['a', 'b', 'c'], [1,2,3]))); 48 d=dict(zip(['a', 'b', 'c'], [1, 2, 4])); 49 print(d); 50 51 d={k:v for (k,v) in zip(['a', 'b', 'c'], [1,2,3])}; 52 print(d); 53 54 55 print('******************'); 56 d={x: x**2 for x in [1,2,3,4]}; 57 print(d); 58 d={c: c*4 for c in 'SPAM'}; 59 print(d); 60 d={c.lower(): c+'!' for c in ['SPAM', 'EGGS', 'HAM']}; 61 print(d); 62 63 d=dict.fromkeys(['a', 'b', 'c'], 0); 64 print(d); 65 66 d={k:0 for k in ['a', 'b', 'c']}; 67 print(d); 68 69 d={k: None for k in 'spam'}; 70 print(d); 71 d=dict(a=1, b=2, c=3); 72 print(d); 73 k=d.keys(); 74 print(k); 75 v=d.values(); 76 print(v); 77 print(list(d.items())); 78 print(k[0]); 79 d={'a':1, 'b':2, 'c':3}; 80 print(d); 81 ks=d.keys(); 82 ks.sort(); 83 for k in ks:print(k, d[k]); 84 sorted(d); 85 print(d); 86
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 25 - warning: unnecessary-semicolon 26 - warning: unnecessary-semicolon 27 - warning: unnecessary-semicolon 32 - warning: unnecessary-semicolon 33 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon 35 - warning: unnecessary-semicolon 37 - warning: bad-indentation 37 - warning: unnecessary-semicolon 39 - warning: unnecessary-semicolon 40 - warning: unnecessary-semicolon 41 - warning: unnecessary-semicolon 42 - warning: unnecessary-semicolon 43 - warning: unnecessary-semicolon 46 - warning: unnecessary-semicolon 47 - warning: unnecessary-semicolon 48 - warning: unnecessary-semicolon 49 - warning: unnecessary-semicolon 51 - warning: unnecessary-semicolon 52 - warning: unnecessary-semicolon 55 - warning: unnecessary-semicolon 56 - warning: unnecessary-semicolon 57 - warning: unnecessary-semicolon 58 - warning: unnecessary-semicolon 59 - warning: unnecessary-semicolon 60 - warning: unnecessary-semicolon 61 - warning: unnecessary-semicolon 63 - warning: unnecessary-semicolon 64 - warning: unnecessary-semicolon 66 - warning: unnecessary-semicolon 67 - warning: unnecessary-semicolon 69 - warning: unnecessary-semicolon 70 - warning: unnecessary-semicolon 71 - warning: unnecessary-semicolon 72 - warning: unnecessary-semicolon 73 - warning: unnecessary-semicolon 74 - warning: unnecessary-semicolon 75 - warning: unnecessary-semicolon 76 - warning: unnecessary-semicolon 77 - warning: unnecessary-semicolon 78 - warning: unnecessary-semicolon 79 - warning: unnecessary-semicolon 80 - warning: unnecessary-semicolon 81 - warning: unnecessary-semicolon 82 - warning: unnecessary-semicolon 83 - warning: unnecessary-semicolon 84 - warning: unnecessary-semicolon 85 - warning: unnecessary-semicolon 51 - refactor: unnecessary-comprehension 71 - refactor: use-dict-literal
1 def func(a, *pargs): 2 print(a, pargs) 3 func(1, 2, 3)
2 - warning: bad-indentation
1 X = 'Spam' 2 def func(): 3 X='Ni!' 4 func() 5 print(X)
3 - warning: bad-indentation 3 - warning: redefined-outer-name 3 - warning: unused-variable
1 def changer(a, b): 2 a = 2 3 b[0] = 'spam' 4 X = 1 5 L = [1, 2] 6 changer(X, L) 7 print(X, L)
2 - warning: bad-indentation 3 - warning: bad-indentation 1 - warning: unused-argument
1 def f(a, b, c): 2 print(a, b, c) 3 f(1, 2, 3) 4 f(c=1, b=2, a=3) 5 def fun1(a, b=2, c=3): 6 print(a, b, c, sep=',') 7 fun1(6) 8 fun1(1) 9 fun1(6, 6, 6) 10 def fun2(*args): 11 print(args) 12 fun2(1) 13 fun2(6, 6) 14 fun2(6, 6, "hello") 15 def fun3(**args): 16 print(args) 17 fun3(a=1, b=2) 18 def fun5(a, *b, **c): 19 print(a, b, c) 20 fun5(1, 2, 3, x=1, y=6) 21 def kwonly(a, *b, c): 22 print(a, b, c) 23 kwonly(1, 2, c=3)
2 - warning: bad-indentation 6 - warning: bad-indentation 11 - warning: bad-indentation 16 - warning: bad-indentation 19 - warning: bad-indentation 22 - warning: bad-indentation
1 def fun(): 2 x=6 3 return (lambda n: x**2) 4 #return action 5 6 x = fun() 7 print(x(2))
2 - warning: bad-indentation 3 - warning: bad-indentation 2 - warning: redefined-outer-name
1 L = [1, 2, 3, 6, 6] 2 print(sum(L)) 3 print('any', any(L)) 4 print('all', all(L)) 5 print('max', max(L)) 6 print('min', min(L)) 7 print('&&'.join([l for l in open('test.py')])) 8 9 print('**********************') 10 Z = zip((1,2,3), (6, 6, 6,)) 11 I=iter(Z) 12 I2=iter(Z) 13 print(I.next()) 14 15 print(I2.next()) 16 print(I.next()) 17 print(I2.next()) 18 print(next(I)) 19 print(next(I2))
7 - refactor: unnecessary-comprehension 7 - refactor: consider-using-with 7 - warning: unspecified-encoding
1 nudge = 1 2 wink = 2 3 nudge, wink = wink, nudge 4 print(nudge, wink) 5 print(type(nudge)) 6 [a, b, c] = (1, 2, 3) 7 print(a, c) 8 (a, b, c) = "ABC" 9 print(a, c) 10 string='SPAM' 11 a, b, c, d=string 12 print(a, d) 13 #a, b, c=string 14 a, b, c = string[0], string[1], string[2:] 15 print(a, b, c) 16 print('****************************') 17 a, b, c=list(string[:2])+[string[2:]] 18 print(a, b, c) 19 print('****************************') 20 ((a, b), c)=('SP', 'AM') 21 print(a, b, c) 22 red, green, blue=range(3) 23 print(red, blue) 24 print('****************************') 25 l = [1, 2, 3, 5, 6] 26 while l: 27 front, l = l[0], l[1:] 28 print(front, l) 29 for (a, b, c) in [(6, 6, 6), (6, 6, 6)]: 30 print(a, b, c) 31 #a, b, c='ab'
27 - warning: bad-indentation 28 - warning: bad-indentation 30 - warning: bad-indentation
1 class Worker: 2 def __init__(self, name, pay): 3 self.name=name; 4 self.pay=pay; 5 def lastName(self): 6 return self.name.split()[-1] 7 def giveRaise(self, percent): 8 self.pay*=(1.0+percent); 9 10 bob=Worker('Bob Smith', 50000); 11 sue=Worker('Sue Jones', 60000); 12 print(bob.lastName()); 13 print(sue.lastName()); 14 sue.giveRaise(.10); 15 print(sue.pay); 16
2 - warning: bad-indentation 3 - warning: bad-indentation 3 - warning: unnecessary-semicolon 4 - warning: bad-indentation 4 - warning: unnecessary-semicolon 5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 8 - warning: bad-indentation 8 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon
1 X = 'Spam' 2 def func(): 3 X='Ni' 4 def nested(): 5 print(X) 6 nested() 7 func() 8 print(X)
3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 3 - warning: redefined-outer-name
1 print(list(filter((lambda x: x>0), range(-5, 5))))ers
1 - error: syntax-error
1 f = open('next.py') 2 print(next(f)) 3 print(f.next()) 4 L = [6, 6, 6] 5 I = iter(L) 6 print(iter(f) is f) 7 while True: 8 print(I.next())
8 - warning: bad-indentation 1 - warning: unspecified-encoding 1 - refactor: consider-using-with
1 x = 1 2 if x: 3 y=2 4 if y: 5 print('block2') 6 print('block1') 7 print('block0') 8 print(type(1<2)) 9 print([] or 3) 10 print(2 or {}) 11 print(type(2 or {}))
3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 8 - refactor: comparison-of-constants
1 summ = 0 2 for x in [1,2 ,3, 5, 6]: 3 summ += x 4 print(summ)
3 - warning: bad-indentation
1 class C1: 2 pass 3 class C2: 4 pass 5 class C3(C1, C2): 6 def setname(self, who): 7 self.name = who 8 I1=C3() 9 I1.setname('bob') 10 print(I1.name)
2 - warning: bad-indentation 4 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 1 - refactor: too-few-public-methods 3 - refactor: too-few-public-methods 7 - warning: attribute-defined-outside-init 5 - refactor: too-few-public-methods
1 title="the meaning";
1 - warning: unnecessary-semicolon
1 L=[123, 'spam', 1.23]; 2 print(L); 3 print(len(L)); 4 print(L[0]); 5 print(L[:-1]); 6 print(L+[4,5,6]); 7 print(L); 8 L=L+[6]; 9 print(L); 10 L.append('NI'); 11 print(L); 12 L.pop(2); 13 print(L); 14 L=['bb', 'aa', 'cc']; 15 L.sort(); 16 print(L); 17 L.reverse(); 18 print(L); 19 M=[[1,2,3],[4,5,6],[7,8,9]]; 20 print(M); 21 print(M[1]); 22 print(M[1][2]); 23 #M[1]=L; 24 print(M); 25 col=[row[1] for row in M]; 26 print(col); 27 col=[row[1]+1 for row in M]; 28 print(col); 29 col=[row[1] for row in M if row[1]%2==0]; 30 print(col); 31 diag=[M[i][i] for i in [0, 1, 2]]; 32 print(diag); 33 doubles=(c*2 for c in 'spam'); 34 print(doubles); 35 G=(sum(row) for row in M); 36 print(next(G)); 37 print(next(G)); 38 print(list(map(sum, M))); 39 print({sum(row) for row in M}); 40 print({i:sum(M[i]) for i in range(3)}); 41 print([ord(x) for x in 'spam']); 42 print({ord(x) for x in 'spam'}); 43 print({x:ord(x) for x in 'spam'})
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 25 - warning: unnecessary-semicolon 26 - warning: unnecessary-semicolon 27 - warning: unnecessary-semicolon 28 - warning: unnecessary-semicolon 29 - warning: unnecessary-semicolon 30 - warning: unnecessary-semicolon 31 - warning: unnecessary-semicolon 32 - warning: unnecessary-semicolon 33 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon 35 - warning: unnecessary-semicolon 36 - warning: unnecessary-semicolon 37 - warning: unnecessary-semicolon 38 - warning: unnecessary-semicolon 39 - warning: unnecessary-semicolon 40 - warning: unnecessary-semicolon 41 - warning: unnecessary-semicolon 42 - warning: unnecessary-semicolon
1 A = 't' if 'spam' else 'f' 2 print(A) 3 A = 't' if '' else 'f' 4 print(A) 5 Z='something' 6 Y='anything' 7 X=True 8 print([Z, Y][X]) 9 print(int(True))
1 - warning: using-constant-test 3 - warning: using-constant-test
1 f=open('data.txt', 'w'); 2 print(f.write('Hello\n')); 3 f.write('World\n'); 4 f.close(); 5 f=open('data.txt'); 6 text=f.read(); 7 print(text); 8 print(text.split()); 9 print(dir(f)); 10 data=open('data.txt', 'rb').read(); 11 print(data); 12 print(data[4:8]);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 1 - warning: unspecified-encoding 1 - refactor: consider-using-with 5 - warning: unspecified-encoding 10 - refactor: consider-using-with 5 - refactor: consider-using-with
1 S='Python'; 2 Y="Python"; 3 print(S[0]); 4 print(Y[1]); 5 print(S[-1]); 6 print(Y[-6]); 7 print(S[1:3]); 8 print(S[:]); 9 print(S[:3]); 10 print(S[1:]); 11 print(S+'xyz'); 12 print(S*8); 13 S='z'+S[1:]; 14 print(S); 15 print(S.find('on')); 16 print(S.replace('on', "XYZ")); 17 print(S); 18 line='aaa, bbb, ccc'; 19 print(line.split(',')); 20 print(S.upper); 21 print(S.isalpha()); 22 line='something\n'; 23 print(line); 24 print(line.rstrip()); 25 print('%s, eggs, and %s'%('spam', "SPAM!")); 26 print('{0}, eggs, and {1}'.format('spam', 'SPAM!')); 27 print(dir(S)); 28 print(len(S)); 29 print(ord('\n')); 30 msg="""aaaaa 31 bbbbb 32 cccc 33 """ 34 print(msg);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 25 - warning: unnecessary-semicolon 26 - warning: unnecessary-semicolon 27 - warning: unnecessary-semicolon 28 - warning: unnecessary-semicolon 29 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon
1 import sys; 2 print('My {1[spam]} runs {0.platform}'.format(sys, {'spam': 'laptop'})); 3 print('My {config[spam]} runs {sys.platform}'.format(sys=sys, config={'spam':'laptop'})); 4 somelist=list('SPAM'); 5 print(somelist); 6 print('first={0[0]}, third={0[2]}'.format(somelist)); 7 print('first={0}, last={1}'.format(somelist[0], somelist[-1])); 8 parts=somelist[0], somelist[-1], somelist[1:3]; 9 print('first={0}, last={1}, middle={2}'.format(*parts));
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon
1 l1=[1,2,3,6]; 2 l2=l1[:]; 3 print(l1, l2); 4 #l1[0]=16; 5 print(l1, l2); 6 print(l1 is l2); 7 print(l1==l2); 8 l2=l1; 9 print(l1 is l2); 10 print(l1==l2);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon
1 D={'food':'spam', 'quantity':4, 'color':'pink'}; 2 print(D['food']); 3 D['quantity']+=1; 4 print(D); 5 Dic={}; 6 Dic['name']='Bob'; 7 Dic['job']='dev'; 8 Dic['age']=40; 9 print(Dic); 10 rec={'name':{'first':'Bob', 'last':'Smith'}, 'job':['dev', 'mgr'], 'age':40.5}; 11 print(rec['name']['last']); 12 print(rec['job']); 13 print(rec['job'][-1]); 14 rec['job'].append('janitor'); 15 print(rec); 16 Ks=list(D.keys()); 17 print(Ks); 18 Ks.sort(); 19 for key in Ks: 20 print(key, '=>', D[key]); 21 for c in 'spam': 22 print(c.upper()); 23 x=4; 24 while x>0: 25 print('spam!'*x); 26 x-=1; 27 for keys in sorted(D): 28 print(keys, '=>', D[keys]); 29 squares=[x**2 for x in[1,2,3,5,6]]; 30 print(squares); 31 squares=[]; 32 for x in [1,2,3,5,6]: 33 squares.append(x**2); 34 print(squares); 35 D['e']=99; 36 print(D); 37 #print(D['f']); 38 if not 'f' in D: 39 print('missing'); 40 if 'f' in D: 41 print("there"); 42 value=D.get('x', 0); 43 print(value); 44 value=D['x'] if 'x' in D else 6; 45 print(value);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 20 - warning: bad-indentation 20 - warning: unnecessary-semicolon 22 - warning: bad-indentation 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 25 - warning: bad-indentation 25 - warning: unnecessary-semicolon 26 - warning: bad-indentation 26 - warning: unnecessary-semicolon 28 - warning: bad-indentation 28 - warning: unnecessary-semicolon 29 - warning: unnecessary-semicolon 30 - warning: unnecessary-semicolon 31 - warning: unnecessary-semicolon 33 - warning: bad-indentation 33 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon 35 - warning: unnecessary-semicolon 36 - warning: unnecessary-semicolon 39 - warning: bad-indentation 39 - warning: unnecessary-semicolon 41 - warning: bad-indentation 41 - warning: unnecessary-semicolon 42 - warning: unnecessary-semicolon 43 - warning: unnecessary-semicolon 44 - warning: unnecessary-semicolon 45 - warning: unnecessary-semicolon
1 def func(a, b, c=5): 2 print(a, b, c) 3 func(1, c=3, b=2)
2 - warning: bad-indentation
1 T=(1,2,3,6); 2 print(len(T)); 3 T+=(5,6); 4 print(T); 5 print(T.index(5)); 6 print(T.count(6)); 7 T1=('spam', 3.0, [11,22,33]); 8 print(T1[1]); 9 print(T1[2][1]); 10 #T1.append(6);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon
1 D = {'A':'a', 'B':'b', 'C':'c'} 2 for key in D: 3 print(key+" => "+D[key])
3 - warning: bad-indentation
1 while True: 2 name = raw_input('Enter name: ') 3 if name == 'stop': 4 break 5 age = raw_input('Enter age: ') 6 if age.isdigit(): 7 print('Hello, '+name+' => ', int(age)**2) 8 else: 9 print('Bad age')
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 8 - warning: bad-indentation 9 - warning: bad-indentation 2 - error: undefined-variable 5 - error: undefined-variable
1 print((1,2)+(3,4)); 2 print((1,2)*4); 3 t=(1,2,3,4); 4 print(t[0], t[1:3]); 5 x=(40); 6 print(x); 7 x=(40,); 8 print(x); 9 print('**********************'); 10 t=(1,2,3,5,6); 11 l=[x+20 for x in t]; 12 print(l);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon
1 def multiple(x, y): 2 x = 2 3 y = [3, 4] 4 return x, y 5 X = 1 6 L = [1, 2] 7 X, L = multiple(X, L) 8 print(X, L)
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation
1 D = {'A': 6, 'B': 6, 'C': 6} 2 print(D) 3 print(sorted(D)) 4 #D = dict(A=1) 5 #print(D) 6 for k in D: 7 print(k) 8
7 - warning: bad-indentation
1 def inc(x): 2 return x + 10 3 counters = [6, 6, 6] 4 print(list(map(inc, counters)))
2 - warning: bad-indentation
1 def gensquares(N): 2 for i in range(N): 3 yield i**2 4 5 for i in gensquares(10): 6 print(i)
2 - warning: bad-indentation 3 - warning: bad-indentation 6 - warning: bad-indentation 2 - warning: redefined-outer-name
1 print(list(map(ord, 'spam')))
Clean Code: No Issues Detected
1 """ 2 Module documentation 3 Words Go Here 4 """ 5 6 spam=40 7 def square(x): 8 """ 9 function documentation 10 can we have your liver then? 11 """ 12 return x**2 13 14 class Employee: 15 "class documentation" 16 pass 17 print(square(6)) 18 print(square.__doc__)
8 - warning: bad-indentation 12 - warning: bad-indentation 15 - warning: bad-indentation 16 - warning: bad-indentation 16 - warning: unnecessary-pass 14 - refactor: too-few-public-methods
1 class FirstClass: 2 def setdata(self, value): 3 self.data=value 4 def display(self): 5 print(self.data) 6 F = FirstClass() 7 F.setdata('some') 8 F.display()
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 3 - warning: attribute-defined-outside-init
1 L = [6, 6, 6] 2 for i in range(len(L)): 3 L[i] += 10 4 print(L) 5 print([x + 10 for x in L])
3 - warning: bad-indentation
1 from functools import reduce 2 print(reduce((lambda x, y: x + y), [1, 2, 3])) 3 print(reduce((lambda x, y: x * y), [1, 2, 3])) 4 reduce((lambda x, y: x*y), [])
Clean Code: No Issues Detected
1 print(len([1,2,3])); 2 print([1,2,3]+[5,6]); 3 print(['Ni!']*4); 4 print(str([1,2])+"36"); 5 print([1,2]+list("36")); 6 print(3 in [1, 2, 3]); 7 for x in [1, 2, 3]: 8 print(x, ' '); 9 10 res=[c*4 for c in 'SPAM']; 11 print(res); 12 res=[]; 13 for c in 'SPAM': 14 res.append(c*4); 15 16 print(res); 17 print(list(map(abs, [-1, -2, 0, 1, 2]))); 18 19 l=['spam', 'Spam', 'SPAM']; 20 l[1]='eggs'; 21 print(l); 22 l[0:2]=['eat', 'more']; 23 print(l); 24 l.append('please'); 25 print(l); 26 l.sort(); 27 print(l); 28 29 30 l=['abc', 'ABD', 'aBe']; 31 print(l.sort()); 32 print(l); 33 print(l.sort(key=str.lower)); 34 print(l); 35 print(l.sort(key=str.lower, reverse=True)); 36 print(l); 37 38 print(sorted(l, key=str.lower, reverse=True)); 39 print(l); 40 print(sorted([x.lower() for x in l], reverse=True)); 41 print(l); 42 43 l=[1,2]; 44 l.extend([3,4,5]); 45 print(l); 46 print(l.pop()); 47 print(l); 48 l.reverse(); 49 print(l); 50 print(list(reversed(l))); 51 52 print('*******************'); 53 l=['spam', 'eggs', 'ham']; 54 print(l.index('eggs')); 55 l.insert(1, 'toast'); 56 print(l); 57 l.remove('eggs'); 58 print(l); 59 l.pop(1); 60 print(l); 61 l=[1,2,3,5,6]; 62 63 64 print('*******************'); 65 print(l); 66 del l[0]; 67 print(l); 68 del l[1:]; 69 print(l);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 8 - warning: bad-indentation 8 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 14 - warning: bad-indentation 14 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 25 - warning: unnecessary-semicolon 26 - warning: unnecessary-semicolon 27 - warning: unnecessary-semicolon 30 - warning: unnecessary-semicolon 31 - warning: unnecessary-semicolon 32 - warning: unnecessary-semicolon 33 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon 35 - warning: unnecessary-semicolon 36 - warning: unnecessary-semicolon 38 - warning: unnecessary-semicolon 39 - warning: unnecessary-semicolon 40 - warning: unnecessary-semicolon 41 - warning: unnecessary-semicolon 43 - warning: unnecessary-semicolon 44 - warning: unnecessary-semicolon 45 - warning: unnecessary-semicolon 46 - warning: unnecessary-semicolon 47 - warning: unnecessary-semicolon 48 - warning: unnecessary-semicolon 49 - warning: unnecessary-semicolon 50 - warning: unnecessary-semicolon 52 - warning: unnecessary-semicolon 53 - warning: unnecessary-semicolon 54 - warning: unnecessary-semicolon 55 - warning: unnecessary-semicolon 56 - warning: unnecessary-semicolon 57 - warning: unnecessary-semicolon 58 - warning: unnecessary-semicolon 59 - warning: unnecessary-semicolon 60 - warning: unnecessary-semicolon 61 - warning: unnecessary-semicolon 64 - warning: unnecessary-semicolon 65 - warning: unnecessary-semicolon 66 - warning: unnecessary-semicolon 67 - warning: unnecessary-semicolon 68 - warning: unnecessary-semicolon 69 - warning: unnecessary-semicolon
1 while True: 2 reply = raw_input('Enter Text:') 3 if reply == 'stop': 4 break 5 print(reply.upper())
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 2 - error: undefined-variable
1 def f1(): 2 X=68 3 def f2(): 4 print(X) 5 return f2 6 a=f1() 7 a()
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation
1 import math; 2 import random; 3 print(len(str(2**1000000))); 4 print(3.1*2); 5 print(math.pi); 6 math.sqrt(85); 7 print(random.random()); 8 print(random.choice([1,2,3,6])); 9 10
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon
1 a = b = c ='spam' 2 print(a, b, c)
Clean Code: No Issues Detected
1 def interssect(seq1, seq2): 2 res = [] 3 for x in seq1: 4 if x in seq2: 5 res.append(x) 6 return res 7 print(interssect('something', ['a', 'b', 'e'])) 8 print(interssect('something', []))
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation
1 f = open('file_parse.py') 2 L = f.readlines() 3 L = [line.rstrip() for line in L] 4 print(L) 5 for line in L: 6 print(line) 7 for line in [l.rstrip() for l in open('file_parse.py')]: 8 print(line) 9 print('************************1*******************') 10 for line in [l.upper() for l in open('file_parse.py')]: 11 print(line) 12 print('************************2*******************') 13 for line in [l.split() for l in open('file_parse.py')]: 14 print(line) 15 print('************************3*******************') 16 for line in [l.replace(' ', '!') for l in open('file_parse.py')]: 17 print(line) 18 print('************************4*******************') 19 for (a, b) in [('sys' in l, l) for l in open('file_parse.py')]: 20 print(a, b) 21 print('***********************5********************') 22 for line in [l for l in open('file_parse.py') if l[0] == 'f']: 23 print(line)
6 - warning: bad-indentation 8 - warning: bad-indentation 11 - warning: bad-indentation 14 - warning: bad-indentation 17 - warning: bad-indentation 20 - warning: bad-indentation 23 - warning: bad-indentation 1 - warning: unspecified-encoding 7 - refactor: consider-using-with 7 - warning: unspecified-encoding 10 - refactor: consider-using-with 10 - warning: unspecified-encoding 13 - refactor: consider-using-with 13 - warning: unspecified-encoding 16 - refactor: consider-using-with 16 - warning: unspecified-encoding 19 - refactor: consider-using-with 19 - warning: unspecified-encoding 22 - refactor: consider-using-with 22 - warning: unspecified-encoding 1 - refactor: consider-using-with
1 while True: 2 reply = raw_input('Enter text: ') 3 if reply == 'stop': 4 break 5 elif not reply.isdigit(): 6 print('Bad!'*8) 7 else: 8 print(int(reply)**2) 9 print('Bye')
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 8 - warning: bad-indentation 2 - error: undefined-variable 3 - refactor: no-else-break
1 s="spam"; 2 print(s.find('a')); 3 l=list(s); 4 s='s,pa,m'; 5 print(s[2:4]); 6 print(s.split(',')[1]);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon
1 a=3; 2 b=4; 3 print(a+1, a-1); 4 print(b*3, b/2); 5 print(a%2, b**2); 6 print(2+4.0, 2.0**b); 7 print(b/2 + a); 8 print(b/(2.0+a)); 9 num=1/3.0; 10 print(num); 11 print('%e' % num); 12 print('%4.2f' % num); 13 print('{0:4.2f}'.format(num)); 14 print(1<2); 15 print(2.0>=1); 16 num=1/3.0; 17 print(str(num)); 18 print(repr(num)); 19 print(2.0==2.0); 20 print(2.0!=2.0); 21 print(2.0==2); 22 x=2; 23 y=4; 24 z=6; 25 print(x<y<z); 26 print(x<y and y<z); 27 print(x<y>z); 28 print(x<y and y>z); 29 print(10/4); 30 print(10//4); 31 print(10/4.0); 32 print(10//4.0); 33 import math; 34 print(math.floor(2.5)); 35 print(math.floor(-2.5)); 36 print(math.trunc(2.5)); 37 print(math.trunc(-2.5)); 38 print('***********'); 39 print(5/2, 5/-2); 40 print(5//2, 5//-2); 41 print(5/2.0, 5/-2.0); 42 print(5//2.0, 5//-2.0); 43 print('***********'); 44 print(0o1, 0o20, 0o377); 45 print(0x01, 0x10, 0xff); 46 print(0b1, 0b10000, 0b11111111); 47 print('**********'); 48 print(oct(255), hex(255), bin(255)); 49 x=0xffffffffffffffffffffffff; 50 print(oct(x)); 51 print(hex(x)); 52 print(bin(x)); 53 x=0b0001; 54 print(x<<2); 55 print(bin(x<<2)); 56 print(bin(x|0b010)); 57 x=0xff; 58 print(bin(x)); 59 print(x^0b10101010); 60 print(bin(x^0b10101010)); 61 print(int('1010101', 2)); 62 print(hex(85)); 63 x=99; 64 print(bin(x), x.bit_length()); 65 print(len(bin(x))); 66 print(math.pi, math.e); 67 print(math.sin(2*math.pi/180)); 68 print(math.sqrt(144), math.sqrt(2)); 69 print(pow(2,4), 2**4); 70 print(abs(-42.0), sum((1,2,3,4))); 71 print(min(3,1,2,4), max(3,1,2,4)); 72 print('********'); 73 print(round(3.1)); 74 print('%.1f' %2.567, '{0:.2f}'.format(2.567)); 75 print('*********'); 76 print(math.sqrt(144), 144**.5, pow(144,.5)); 77 import random; 78 print('********'); 79 print(random.random()); 80 print(random.randint(1,10)); 81 print(random.randint(1,10)); 82 print(random.choice(['Life of Brain', 'Holy Grail', 'Meaning of Life'])); 83 print('********'); 84 import decimal; 85 decimal.getcontext().prec=4; 86 print(decimal.Decimal(1)/decimal.Decimal(8)); 87 print('********'); 88 with decimal.localcontext() as ctx: 89 ctx.prec=2; 90 print(decimal.Decimal('1.00')/decimal.Decimal('3.00')); 91 92 print(decimal.Decimal('1.00')/decimal.Decimal('3.00')); 93 print('********fraction*********'); 94 from fractions import Fraction; 95 x=Fraction(1,3); 96 y=Fraction(4,6); 97 print(x); 98 print(y); 99 print(x+y); 100 print(x-y); 101 print(x*y); 102 print(Fraction('.25')); 103 print(Fraction('1.25')); 104 print((2.5).as_integer_ratio()); 105 f=2.5; 106 z=Fraction(*f.as_integer_ratio()); 107 print(z); 108 print(float(z)); 109 a=Fraction(225, 135); 110 print(a.limit_denominator(10)); 111 print('*********set***********'); 112 x=set('abcde'); 113 y=set('bdxyz'); 114 print(x, y); 115 print(x-y); 116 print(x|y); 117 print(x&y); 118 print(x^y); 119 print(x>y, x<y); 120 z=x.intersection(y); 121 print(z); 122 z.add('SPAM'); 123 print(z); 124 z.update(set(['x', 'Y'])); 125 print(z); 126 z.remove('b'); 127 print(z); 128 for item in set('abc'): 129 print(item*3); 130 131 s={'s', 'p', 'a', 'm'}; 132 s.add('alot'); 133 print(s); 134 print({x**2 for x in [1, 2, 3, 5, 6]}); 135 print({x for x in 'spam'}); 136 print({c*4 for c in 'spam'}); 137 S={c*4 for c in 'spam'}; 138 print(S|{'mmm', 'xxxx'}); 139 print('**************set usage*************'); 140 L=[1,2,3,1,2,3,6]; 141 print('L is', L); 142 print(list(set(L))); 143 engineers={'bob', 'sue', 'ann', 'vic'}; 144 managers={'tom', 'sue'}; 145 print('bob' in engineers); 146 print(engineers & managers); 147 print(engineers | managers); 148 print(engineers-managers); 149 print(managers-engineers); 150 print(engineers>managers); 151 print(engineers^managers); 152 print('****************bool*************'); 153 print(type(True)); 154 print(isinstance(True, int)); 155 print(True ==1); 156 print(True is 1); 157 print(True or False); 158 print(True + 4);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 25 - warning: unnecessary-semicolon 26 - warning: unnecessary-semicolon 27 - warning: unnecessary-semicolon 28 - warning: unnecessary-semicolon 29 - warning: unnecessary-semicolon 30 - warning: unnecessary-semicolon 31 - warning: unnecessary-semicolon 32 - warning: unnecessary-semicolon 33 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon 35 - warning: unnecessary-semicolon 36 - warning: unnecessary-semicolon 37 - warning: unnecessary-semicolon 38 - warning: unnecessary-semicolon 39 - warning: unnecessary-semicolon 40 - warning: unnecessary-semicolon 41 - warning: unnecessary-semicolon 42 - warning: unnecessary-semicolon 43 - warning: unnecessary-semicolon 44 - warning: unnecessary-semicolon 45 - warning: unnecessary-semicolon 46 - warning: unnecessary-semicolon 47 - warning: unnecessary-semicolon 48 - warning: unnecessary-semicolon 49 - warning: unnecessary-semicolon 50 - warning: unnecessary-semicolon 51 - warning: unnecessary-semicolon 52 - warning: unnecessary-semicolon 53 - warning: unnecessary-semicolon 54 - warning: unnecessary-semicolon 55 - warning: unnecessary-semicolon 56 - warning: unnecessary-semicolon 57 - warning: unnecessary-semicolon 58 - warning: unnecessary-semicolon 59 - warning: unnecessary-semicolon 60 - warning: unnecessary-semicolon 61 - warning: unnecessary-semicolon 62 - warning: unnecessary-semicolon 63 - warning: unnecessary-semicolon 64 - warning: unnecessary-semicolon 65 - warning: unnecessary-semicolon 66 - warning: unnecessary-semicolon 67 - warning: unnecessary-semicolon 68 - warning: unnecessary-semicolon 69 - warning: unnecessary-semicolon 70 - warning: unnecessary-semicolon 71 - warning: unnecessary-semicolon 72 - warning: unnecessary-semicolon 73 - warning: unnecessary-semicolon 74 - warning: unnecessary-semicolon 75 - warning: unnecessary-semicolon 76 - warning: unnecessary-semicolon 77 - warning: unnecessary-semicolon 78 - warning: unnecessary-semicolon 79 - warning: unnecessary-semicolon 80 - warning: unnecessary-semicolon 81 - warning: unnecessary-semicolon 82 - warning: unnecessary-semicolon 83 - warning: unnecessary-semicolon 84 - warning: unnecessary-semicolon 85 - warning: unnecessary-semicolon 86 - warning: unnecessary-semicolon 87 - warning: unnecessary-semicolon 89 - warning: bad-indentation 89 - warning: unnecessary-semicolon 90 - warning: bad-indentation 90 - warning: unnecessary-semicolon 92 - warning: unnecessary-semicolon 93 - warning: unnecessary-semicolon 94 - warning: unnecessary-semicolon 95 - warning: unnecessary-semicolon 96 - warning: unnecessary-semicolon 97 - warning: unnecessary-semicolon 98 - warning: unnecessary-semicolon 99 - warning: unnecessary-semicolon 100 - warning: unnecessary-semicolon 101 - warning: unnecessary-semicolon 102 - warning: unnecessary-semicolon 103 - warning: unnecessary-semicolon 104 - warning: unnecessary-semicolon 105 - warning: unnecessary-semicolon 106 - warning: unnecessary-semicolon 107 - warning: unnecessary-semicolon 108 - warning: unnecessary-semicolon 109 - warning: unnecessary-semicolon 110 - warning: unnecessary-semicolon 111 - warning: unnecessary-semicolon 112 - warning: unnecessary-semicolon 113 - warning: unnecessary-semicolon 114 - warning: unnecessary-semicolon 115 - warning: unnecessary-semicolon 116 - warning: unnecessary-semicolon 117 - warning: unnecessary-semicolon 118 - warning: unnecessary-semicolon 119 - warning: unnecessary-semicolon 120 - warning: unnecessary-semicolon 121 - warning: unnecessary-semicolon 122 - warning: unnecessary-semicolon 123 - warning: unnecessary-semicolon 124 - warning: unnecessary-semicolon 125 - warning: unnecessary-semicolon 126 - warning: unnecessary-semicolon 127 - warning: unnecessary-semicolon 129 - warning: bad-indentation 129 - warning: unnecessary-semicolon 131 - warning: unnecessary-semicolon 132 - warning: unnecessary-semicolon 133 - warning: unnecessary-semicolon 134 - warning: unnecessary-semicolon 135 - warning: unnecessary-semicolon 136 - warning: unnecessary-semicolon 137 - warning: unnecessary-semicolon 138 - warning: unnecessary-semicolon 139 - warning: unnecessary-semicolon 140 - warning: unnecessary-semicolon 141 - warning: unnecessary-semicolon 142 - warning: unnecessary-semicolon 143 - warning: unnecessary-semicolon 144 - warning: unnecessary-semicolon 145 - warning: unnecessary-semicolon 146 - warning: unnecessary-semicolon 147 - warning: unnecessary-semicolon 148 - warning: unnecessary-semicolon 149 - warning: unnecessary-semicolon 150 - warning: unnecessary-semicolon 151 - warning: unnecessary-semicolon 152 - warning: unnecessary-semicolon 153 - warning: unnecessary-semicolon 154 - warning: unnecessary-semicolon 155 - warning: unnecessary-semicolon 156 - warning: unnecessary-semicolon 157 - warning: unnecessary-semicolon 158 - warning: unnecessary-semicolon 14 - refactor: comparison-of-constants 15 - refactor: comparison-of-constants 19 - refactor: comparison-with-itself 19 - refactor: comparison-of-constants 20 - refactor: comparison-with-itself 20 - refactor: comparison-of-constants 21 - refactor: comparison-with-itself 21 - refactor: comparison-of-constants 26 - refactor: chained-comparison 135 - refactor: unnecessary-comprehension 155 - refactor: comparison-with-itself 155 - refactor: comparison-of-constants 156 - refactor: comparison-with-itself 156 - refactor: comparison-of-constants 156 - refactor: literal-comparison
1 a=3; 2 print(a); 3 a='abc'; 4 print(a); 5 l=[1,2,3]; 6 l2=l; 7 print(l); 8 print(l2); 9 l.append(6); 10 print(l); 11 print(l2); 12 l1=[]; 13 l1=l2; 14 l2.append(8); 15 print(l1); 16 print(l2);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon
1 print('shrubbery', "shurubbery"); 2 print('knight"s', "knight's"); 3 print("Meaning"'of'"life"); 4 print('a\tb\nc'); 5 print('\a'); 6 print('\0a\0b'); 7 print(len('abc')); 8 print('abc'+'def'); 9 print('Ni!'*4); 10 myjob="hacker"; 11 for c in myjob: print(c, ' ') 12 print('k' in myjob); 13 print(str('spam'), repr('spam')); 14 S='66'; 15 I=1; 16 print(int(S) + I); 17 print(S+str(I)); 18 print(str(3.16), float('1.5')); 19 i='5'; 20 print(chr(ord(i)+1)); 21 print(chr(ord(i)+2)); 22 print('*******************'); 23 b='1101'; 24 i=0; 25 while b!='': 26 i=i*2+(ord(b[0])-ord('0')); 27 b=b[1:]; 28 29 print(bin(i)); 30 print(i); 31 print(b); 32 print(int('1101', 2)); 33 print(bin(13)); 34 print('*****************'); 35 s='splot' 36 s=s.replace('pl', 'pamal'); 37 print(s); 38 print('That is %d %s bird!' %(1, 'lovely')); 39 print('this is {0} {1} bird!'.format(1, 'lovely')); 40 s='spammy'; 41 s=s[:3]+'xx'+s[5:]; 42 print(s); 43 print('***********replace*************'); 44 print(s.replace('xx', 'mm')); 45 print('************************'); 46 s='xxxxxSpamxxxxxxspamxxxxxxx'; 47 where=s.find('Spam'); 48 print(where); 49 s=s[:where]+'EGGS'+s[where+4:]; 50 print(s); 51 print('*********************'); 52 s='spammy'; 53 l=list(s); 54 print(l); 55 l[3]='x'; 56 l[4]='x'; 57 print(l); 58 s=''.join(l); 59 print(s);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 26 - warning: bad-indentation 26 - warning: unnecessary-semicolon 27 - warning: bad-indentation 27 - warning: unnecessary-semicolon 29 - warning: unnecessary-semicolon 30 - warning: unnecessary-semicolon 31 - warning: unnecessary-semicolon 32 - warning: unnecessary-semicolon 33 - warning: unnecessary-semicolon 34 - warning: unnecessary-semicolon 36 - warning: unnecessary-semicolon 37 - warning: unnecessary-semicolon 38 - warning: unnecessary-semicolon 39 - warning: unnecessary-semicolon 40 - warning: unnecessary-semicolon 41 - warning: unnecessary-semicolon 42 - warning: unnecessary-semicolon 43 - warning: unnecessary-semicolon 44 - warning: unnecessary-semicolon 45 - warning: unnecessary-semicolon 46 - warning: unnecessary-semicolon 47 - warning: unnecessary-semicolon 48 - warning: unnecessary-semicolon 49 - warning: unnecessary-semicolon 50 - warning: unnecessary-semicolon 51 - warning: unnecessary-semicolon 52 - warning: unnecessary-semicolon 53 - warning: unnecessary-semicolon 54 - warning: unnecessary-semicolon 55 - warning: unnecessary-semicolon 56 - warning: unnecessary-semicolon 57 - warning: unnecessary-semicolon 58 - warning: unnecessary-semicolon 59 - warning: unnecessary-semicolon 3 - warning: implicit-str-concat
1 S1 = 'abc' 2 S2 = 'xyz123' 3 print(map(None, S1, S2)) 4 print(list(map(ord, 'spam'))) 5 print('**************************') 6 res = [] 7 for c in 'spam': res.append(ord(c)) 8 print(res)
Clean Code: No Issues Detected
1 test=open('test.txt', 'w'); 2 test.write('hello text\n'); 3 print(test.write('goodbye text\n')); 4 test.close(); 5 test=open('test.txt'); 6 print(test.readline()); 7 print(test.readline()); 8 print(test.readline()); 9 test.close(); 10 print(open('test.txt').read()); 11 d={'a':1, 'b':2}; 12 f=open('datafile.pk1', 'wb'); 13 import pickle; 14 pickle.dump(d, f); 15 f.close(); 16 f=open('datafile.pk1', 'rb'); 17 e=pickle.load(f); 18 print(d);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 15 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 1 - warning: unspecified-encoding 1 - refactor: consider-using-with 5 - warning: unspecified-encoding 10 - refactor: consider-using-with 10 - warning: unspecified-encoding 12 - refactor: consider-using-with 5 - refactor: consider-using-with 16 - refactor: consider-using-with
1 action = (lambda x: (lambda y: x + y)) 2 act=action(66) 3 print(act(2))
Clean Code: No Issues Detected
1 print([x + y for x in 'abc' for y in '666'])
Clean Code: No Issues Detected
1 def func(a, **kargs): 2 print(a, kargs) 3 func(a=1, c=3, b=2)
2 - warning: bad-indentation
1 L=[]; 2 print(type(L)); 3 print(type(type(L))); 4 if type(L)==type([]): 5 print('yes'); 6 if type(L)==list: 7 print('yes'); 8 if isinstance(L, list): 9 print('yes'); 10 #if isinstance(list, L): 11 # print('yes');
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 5 - warning: bad-indentation 5 - warning: unnecessary-semicolon 7 - warning: bad-indentation 7 - warning: unnecessary-semicolon 9 - warning: bad-indentation 9 - warning: unnecessary-semicolon
1 X = 'Spam' 2 def func(): 3 print(X) 4 func()
3 - warning: bad-indentation
1 X = 'Spam' 2 def func(): 3 global X 4 X='Ni' 5 func() 6 print(X)
3 - warning: bad-indentation 4 - warning: bad-indentation 3 - warning: global-statement
1 def func(a, b=4, c=5): 2 print(a, b, c) 3 func(1, 2)
2 - warning: bad-indentation
1 import sys 2 from tkinter import Button, mainloop 3 x = Button( 4 text = 'Press me', 5 command=(lambda: sys.stdout.write('Spam\n'))) 6 x.pack()
2 - warning: unused-import
1 def times(x, y): 2 return x * y 3 print(times(3, 2))
2 - warning: bad-indentation
1 f = open('file_iterator.py') 2 print(dir(f)) 3 #f.__next__() 4 while True: 5 s=f.readline() 6 if not s: 7 break 8 print(s) 9 #while True: 10 # print(f.__iter__()) 11 for line in open('file_iterator.py'): 12 print(line.upper())
5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 8 - warning: bad-indentation 12 - warning: bad-indentation 1 - warning: unspecified-encoding 11 - refactor: consider-using-with 11 - warning: unspecified-encoding 1 - refactor: consider-using-with
1 def f(a): 2 a=99 3 b=88 4 f(b) 5 print(b)
2 - warning: bad-indentation 1 - warning: unused-argument
1 branch = {'spam': 1.25, 2 'ham':1.99, 3 'eggs':0.99} 4 print(branch.get('spam', 'Bad choice')) 5 print(branch.get('test', 'Bad choice')) 6 choice = 'bacon' 7 if choice in branch: 8 print(branch[choice]) 9 else: 10 print('Bad choice') 11
8 - warning: bad-indentation 10 - warning: bad-indentation
1 import sys 2 temp=sys.stdout 3 sys.stdout=open('log.txt', 'a') 4 print('spam') 5 print(1, 2, 3) 6 sys.stdout.close() 7 sys.stdout=temp 8 print('back here') 9 print(open('log.txt').read()) 10 sys.stderr.write(('Bad!'*8)+'\n') 11 print >> sys.stderr, 'Bad!'*8
3 - warning: unspecified-encoding 9 - refactor: consider-using-with 9 - warning: unspecified-encoding 11 - warning: pointless-statement 3 - refactor: consider-using-with
1 class Person: 2 def __init__(self, name, job=None, pay=0): 3 self.name = name 4 self.job = job 5 self.pay = pay 6 7 if __name__ == '__main__': 8 bob = Person('Bob') 9 print(bob)
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 8 - warning: bad-indentation 9 - warning: bad-indentation 1 - refactor: too-few-public-methods
1 keys = ['spam', 'eggs', 'toast'] 2 vals = [6, 6, 6] 3 print(list(zip(keys, vals))) 4 D = {} 5 for (k, v) in zip(keys, vals): 6 D[k]=v 7 print(D) 8 print('**********************') 9 D = dict(zip(keys, vals)) 10 print(D)
6 - warning: bad-indentation
1 x = 'spam' 2 while x: 3 print x 4 x = x[1:] 5
3 - error: syntax-error
1 X=set('spam'); 2 Y={'h', 'a', 'm'}; 3 print(X, Y); 4 print(X & Y); 5 print(X | Y); 6 print(X-Y); 7 print({x**2 for x in [1,2,3,6]}); 8 print(1/3); 9 print(2/3+1/2); 10 import decimal; 11 d=decimal.Decimal('3.141'); 12 print(d+1); 13 decimal.getcontext().prec=2; 14 decimal.Decimal('1.00')/decimal.Decimal('3.00'); 15 16 from fractions import Fraction; 17 f=Fraction(2,3); 18 print(f+1); 19 print(f+Fraction(1,2)); 20 print(1>2, 1<2); 21 print(bool('spam')); 22 X=None; 23 print(X); 24 L=[None]*100; 25 print(L);
1 - warning: unnecessary-semicolon 2 - warning: unnecessary-semicolon 3 - warning: unnecessary-semicolon 4 - warning: unnecessary-semicolon 5 - warning: unnecessary-semicolon 6 - warning: unnecessary-semicolon 7 - warning: unnecessary-semicolon 8 - warning: unnecessary-semicolon 9 - warning: unnecessary-semicolon 10 - warning: unnecessary-semicolon 11 - warning: unnecessary-semicolon 12 - warning: unnecessary-semicolon 13 - warning: unnecessary-semicolon 14 - warning: unnecessary-semicolon 16 - warning: unnecessary-semicolon 17 - warning: unnecessary-semicolon 18 - warning: unnecessary-semicolon 19 - warning: unnecessary-semicolon 20 - warning: unnecessary-semicolon 21 - warning: unnecessary-semicolon 22 - warning: unnecessary-semicolon 23 - warning: unnecessary-semicolon 24 - warning: unnecessary-semicolon 25 - warning: unnecessary-semicolon 14 - warning: expression-not-assigned 20 - refactor: comparison-of-constants 20 - refactor: comparison-of-constants
1 class tester: 2 def __init__(self, start): 3 self.state=start 4 5 def __call__(self, label): 6 print(label, self.state) 7 self.state+=1 8 H=tester(99) 9 H('juice')
2 - warning: bad-indentation 3 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 1 - refactor: too-few-public-methods
1 L = [1, 2, 3] 2 for x in L: 3 print(x**2) 4 I = iter(L) 5 while True: 6 try: 7 print(I.next()**2) 8 except StopIteration: 9 break 10
3 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 8 - warning: bad-indentation 9 - warning: bad-indentation
1 X = 'Spam' 2 def func(): 3 X = 'Ni' 4 print(X) 5 func() 6 print(X)
3 - warning: bad-indentation 4 - warning: bad-indentation 3 - warning: redefined-outer-name
1 while True: 2 reply=raw_input('Enter text: ') 3 if reply == 'stop': 4 break 5 try: 6 num=int(reply) 7 except: 8 print('Bad!'*8) 9 else: 10 print(int(reply)**2) 11 print('Bye')
2 - warning: bad-indentation 3 - warning: bad-indentation 4 - warning: bad-indentation 5 - warning: bad-indentation 6 - warning: bad-indentation 7 - warning: bad-indentation 8 - warning: bad-indentation 9 - warning: bad-indentation 10 - warning: bad-indentation 2 - error: undefined-variable 7 - warning: bare-except
1 a=0 2 b=10 3 while a<b: 4 print(a) 5 a+=1 6 while True: 7 pass 8
4 - warning: bad-indentation 5 - warning: bad-indentation 7 - warning: bad-indentation
1 [spam, ham]=['yum', 'YUM'] 2 print(spam) 3 print(ham) 4 a, b, c, d = 'spam' 5 print(a) 6 print(b) 7 #print(*b)
Clean Code: No Issues Detected