During the proceedings upon the petition, the petitioner may be represented by counsel of his or her own selection. If the petitioner does not have counsel, he or she shall be represented by the public defender, if there is one in the county, and if there is none, by the adult probation officer of the county, or if in the opinion of the court the petitioner needs counsel, the court shall assign counsel to represent him or her.
Ca. Pen. Code § 4852.08